Last active
October 3, 2019 21:41
-
-
Save zentrification/d06d7b88b5bb5375e7ad797d7daf4f07 to your computer and use it in GitHub Desktop.
SSL Rakefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :ssl do | |
desc 'Generate Wildcard CSR' | |
task :csr do | |
domain = ask_with_default('Domain Name', '*.mydomain.com') | |
email = ask_with_default('Email address', 'admin@mydomain.com') | |
subj = "/emailAddress=#{email}/CN=#{domain}/C=US/ST=XXX/L=XXX/O=XXX" | |
# do not want * in directory names | |
dir = domain.sub('*', 'wildcard') | |
key = "#{dir}/#{dir}.key" | |
csr = "#{dir}/#{dir}.csr" | |
# use ruby to do this | |
system("mkdir #{dir}") | |
system("openssl req -new -newkey rsa:2048 -nodes -subj '#{subj}' -keyout #{key} -out #{csr}") | |
system("openssl req -in #{csr} -text -noout") | |
end | |
desc 'Generate PFX' | |
task :pfx do | |
puts "openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt" | |
end | |
end | |
def ask_with_default(question, default) | |
puts "#{question} [#{default}]" | |
input = STDIN.gets.strip | |
input.empty? ? default : input | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment