9 myname = File::basename($0)
11 Usage: #{myname} [--key keypair_file] name
12 name ... ex. /C=JP/O=RRR/OU=CA/CN=NaHi/emailAddress=nahi@example.org
17 options = ARGV.getopts(nil, "key:", "csrout:", "keyout:")
18 keypair_file = options["key"]
19 csrout = options["csrout"] || "csr.pem"
20 keyout = options["keyout"] || "keypair.pem"
23 name_str = ARGV.shift or usage()
24 name = X509::Name.parse(name_str)
28 keypair = PKey::RSA.new(File.open(keypair_file).read)
30 keypair = PKey::RSA.new(1024) { putc "." }
32 puts "Writing #{keyout}..."
33 File.open(keyout, "w", 0400) do |f|
38 puts "Generating CSR for #{name_str}"
40 req = X509::Request.new
43 req.public_key = keypair.public_key
44 req.sign(keypair, Digest::MD5.new)
46 puts "Writing #{csrout}..."
47 File.open(csrout, "w") do |f|