Skip to content

Instantly share code, notes, and snippets.

@tadman
Created February 10, 2010 19:10
Show Gist options
  • Save tadman/300724 to your computer and use it in GitHub Desktop.
Save tadman/300724 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
PASSPHRASE_CHARS = [ ?0..?9, ?A..?Z, ?a..?z ].collect { |c| c.collect }.flatten.collect { |c| "%c" % c }
cert_name = ARGV[0]
unless (cert_name)
print "Usage: genrsa <certname>"
exit(-1)
end
seed_file = "/tmp/#{$$}.random"
open(seed_file, 'w') do |fh|
2048.times do
fh.putc rand(256)
end
end
passphrase = (1..64).collect { PASSPHRASE_CHARS[rand(PASSPHRASE_CHARS.length)] }.to_s
open("#{cert_name}.pf", 'w') do |fh|
fh.puts passphrase
end
system("openssl genrsa -des3 -rand #{seed_file} -out #{cert_name}.key -passout file:#{cert_name}.pf 2048")
system("openssl rsa -in #{cert_name}.key -out #{cert_name}.pem -passin file:#{cert_name}.pf")
system("openssl req -new -key #{cert_name}.key -out #{cert_name}.csr -passin file:#{cert_name}.pf")
system("openssl x509 -req -days #{365 * 3} -in #{cert_name}.csr -signkey #{cert_name}.key -out #{cert_name}.crt -passin file:#{cert_name}.pf")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment