Last active
December 19, 2015 14:08
-
-
Save semipermeable/5966809 to your computer and use it in GitHub Desktop.
Utilities to support PostgreSQL client certificate authentication setup example.
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
module CertificateSetup | |
def generate_server_cert(name, cn) | |
system "openssl genrsa -des3 -passout pass:x -out #{name}.pass.key 2048" | |
system "openssl rsa -passin pass:x -in #{name}.pass.key -out #{name}.key" | |
FileUtils.rm "#{name}.pass.key" | |
system "openssl req -new -key #{name}.key -out #{name}.csr -subj '/C=CA/ST=California/L=San Francisco/O=Testing/CN=#{cn}'" | |
system "openssl x509 -req -days 365 -in #{name}.csr -signkey #{name}.key -out #{name}.crt" | |
end | |
def generate_client_cert(name, cn, root) | |
system "openssl genrsa -des3 -passout pass:x -out #{name}.key 1024" | |
system "openssl rsa -passin pass:x -in #{name}.key -out #{name}.key" | |
system "openssl req -new -key #{name}.key -out #{name}.csr -subj '/C=CA/ST=California/L=San Francisco/O=Testing/CN=#{cn}'" | |
system "openssl x509 -req -in #{name}.csr -CA #{root}.crt -CAkey #{root}.key -out #{name}.crt -CAcreateserial" | |
end | |
end | |
# Usage: | |
CertificateSetup.generate_server_cert('postgres', 'server.domain.com') | |
CertificateSetup.generate_client_cert('client-user', 'www-user', 'postgres') | |
CertificateSetup.generate_client_cert('client-repl', 'repl', 'postgres') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment