Last active
June 27, 2016 00:10
-
-
Save aculich/9a1675f2344009721d277d6877357473 to your computer and use it in GitHub Desktop.
Generate a self-signed SSL certificate with a key that has a random password
This file contains hidden or 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/sh | |
| HOST=${1:-localhost} | |
| PASSWORD=$(cat /dev/urandom | tr -dc '[:alnum:]' | fold -w 128 | head -n 1) | |
| csr="${HOST}.csr" | |
| key="${HOST}.key" | |
| cert="${HOST}.cert" | |
| C=XX | |
| ST=XX | |
| L=XXXXXXXXX | |
| O=XXXXX | |
| OU=XX | |
| HOST=$HOST | |
| DATE=$(date '+%Y%m%d') | |
| CN=$HOST | |
| # Create the certificate signing request | |
| openssl req -config /etc/ssl/openssl.cnf -new -passin pass:$PASSWORD -passout pass:$PASSWORD -out $csr <<EOF | |
| ${C} | |
| ${ST} | |
| ${L} | |
| ${O} | |
| ${OU} | |
| ${CN} | |
| selfsigned@${CN} | |
| . | |
| . | |
| EOF | |
| [ -f ${csr} ] && openssl req -text -noout -in ${csr} | |
| # Create the Key | |
| openssl rsa -in privkey.pem -passin pass:$PASSWORD -passout pass:$PASSWORD -out ${key} | |
| # Create the Certificate | |
| openssl x509 -in ${csr} -out ${cert} -req -signkey ${key} -days 1000 | |
| chmod 400 $csr $key $cert privkey.pem | |
| # concatenate cert & key together for use with: https://github.com/cesanta/ssl_wrapper | |
| cat localhost.cert localhost.key > server_cert.pem | |
| # git clone https://github.com/cesanta/ssl_wrapper.git | |
| # cd ssl_wrapper | |
| # make | |
| # cd .. | |
| # ./ssl_wrapper/ssl_wrapper ssl://443:server_cert.pem 127.0.0.1:8787 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment