Skip to content

Instantly share code, notes, and snippets.

@Couto
Last active January 2, 2016 02:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Couto/8238753 to your computer and use it in GitHub Desktop.
Save Couto/8238753 to your computer and use it in GitHub Desktop.
Create random SSL certificates for use in development.
# Generate SSL Certificate for dev
export DOMAIN="example.dev"
export PASSPHRASE=$(head -c 500 /dev/urandom | tr -dc a-z0-9A-Z | head -c 128; echo)
export SUBJ="
C=PT
ST=Aveiro
O=Example Organization
localityName=Aveiro
commonName=$DOMAIN
organizationalUnitName=Dev Team
emailAddress=support@$DOMAIN
"
## Create server private key
openssl genrsa -des3 -out $DOMAIN.key -passout env:PASSPHRASE 2048
## Create the Certificate Signing Request
openssl req \
-new \
-batch \
-subj "$(echo -n "$SUBJ" | tr "\n" "/")" \
-key $DOMAIN.key \
-out $DOMAIN.csr \
-passin env:PASSPHRASE
mv $DOMAIN.key $DOMAIN.key.org
## Strip the password so we don't have to type it every time we restart Apache
openssl rsa -in $DOMAIN.key.org -out $DOMAIN.key -passin env:PASSPHRASE
## Config file to allow multiple domains
echo "subjectAltName=DNS:$DOMAIN,DNS:*.$DOMAIN" > multi.config
## Generate the cert (good for 10 years)
openssl x509 -req -days 3650 -in $DOMAIN.csr -signkey $DOMAIN.key -text -extfile multi.config -out $DOMAIN.crt

In any Ubuntu machine, for dev purposes, you can use the already provided certificates

/etc/ssl/certs/ssl-cert-snakeoil.pem
/etc/ssl/private/ssl-cert-snakeoil.key

(if by some reason the certificates are not available, install ssl-cert from apt-get.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment