Skip to content

Instantly share code, notes, and snippets.

@jqr
Last active April 8, 2018 02:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jqr/b32a0616bb661c197e48 to your computer and use it in GitHub Desktop.
Save jqr/b32a0616bb661c197e48 to your computer and use it in GitHub Desktop.
Easily generate wildcard SSQL certificate requests
#!/usr/bin/env ruby
company_name = "__YOUR_COMPANY_NAME__"
state = "__YOUR_STATE__"
if ARGV.size == 0
puts "Usage: #{$0} <domain>"
puts "Generates a new private key and a certificate signing request."
puts
puts "NOTE: Always produces a wildcard certificate request."
puts
puts "Example:"
puts " #{$0} instrumentalapp.com"
abort
end
domain = ARGV.first
wildcard_domain = "*.#{domain}"
puts "Generating key and request for #{wildcard_domain}"
require "openssl"
our_cert_keypair = OpenSSL::PKey::RSA.new(2048)
private_key_filename = "#{domain}.key"
puts "Writing private key to #{private_key_filename}"
File.open(private_key_filename, "w+") do |f|
f.write our_cert_keypair.to_pem
end
our_cert_req = OpenSSL::X509::Request.new
our_cert_req.subject = OpenSSL::X509::Name.new([
["C", "US"],
["ST", state],
["O", company_name],
["CN", wildcard_domain]
])
our_cert_req.public_key = our_cert_keypair.public_key
our_cert_req.sign our_cert_keypair, OpenSSL::Digest::SHA256.new
request_filename = "#{domain}.csr"
puts "Writing certificate signing request to #{request_filename}"
File.open(request_filename, "w+") do |f|
f.write our_cert_req.to_pem
end
puts
puts our_cert_req.to_pem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment