mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
d52c3b1e94
ASN.1 type of subject DN elements were wrong. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5581 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
49 lines
983 B
Ruby
49 lines
983 B
Ruby
#!/usr/bin/env ruby
|
|
|
|
require 'getopts'
|
|
require 'openssl'
|
|
|
|
include OpenSSL
|
|
|
|
def usage
|
|
myname = File::basename($0)
|
|
$stderr.puts <<EOS
|
|
Usage: #{myname} name [keypair_file]
|
|
name ... ex. /C=JP/O=RRR/OU=CA/CN=NaHi/emailAddress=nahi@example.org
|
|
EOS
|
|
exit
|
|
end
|
|
|
|
getopts nil, "key:", "csrout:", "keyout:"
|
|
keypair_file = $OPT_key
|
|
csrout = $OPT_csrout || "csr.pem"
|
|
keyout = $OPT_keyout || "keypair.pem"
|
|
|
|
$stdout.sync = true
|
|
name_str = ARGV.shift or usage()
|
|
name = X509::Name.parse(name_str)
|
|
|
|
keypair = nil
|
|
if keypair_file
|
|
keypair = PKey::RSA.new(File.open(keypair_file).read)
|
|
else
|
|
keypair = PKey::RSA.new(1024) { putc "." }
|
|
puts
|
|
puts "Writing #{keyout}..."
|
|
File.open(keyout, "w", 0400) do |f|
|
|
f << keypair.to_pem
|
|
end
|
|
end
|
|
|
|
puts "Generating CSR for #{name_str}"
|
|
|
|
req = X509::Request.new
|
|
req.version = 0
|
|
req.subject = name
|
|
req.public_key = keypair.public_key
|
|
req.sign(keypair, Digest::MD5.new)
|
|
|
|
puts "Writing #{csrout}..."
|
|
File.open(csrout, "w") do |f|
|
|
f << req.to_pem
|
|
end
|