Last active
March 21, 2017 18:10
-
-
Save ansemjo/d176ae50a67d8ee781d99c3caf2cf88e to your computer and use it in GitHub Desktop.
extracts pem certificate and key with $hostname nick from certutil database
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
#!/bin/bash | |
db=./ssl | |
nick=$(hostname -f) | |
rand=$(< /dev/urandom tr -dc "A-Za-z0-9" | head -c32;echo;) | |
# remove any previous | |
rm server.{p12,key,crt} 2>/dev/null | |
# extract server | |
certutil -d "$db" -L -a -n "$nick" > server.crt | |
pk12util -d "$db" -o server.p12 -n "$nick" -W "$rand" | |
openssl pkcs12 -in server.p12 -out server.key -nodes -passin "pass:$rand" | |
rm server.p12 | |
# extract ca | |
certutil -d "$db" -L -a -n 'Certificate Authority' > ca.crt | |
# permissions | |
chown postgres:postgres server.{crt,key} ca.crt | |
chmod 0400 server.{key,crt} ca.crt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment