Last active
May 2, 2017 12:35
-
-
Save wouterds/b9bb126e26dbf3bdba2ee9cec24a1c02 to your computer and use it in GitHub Desktop.
Script to generate self signed certificate working with Chrome 58+
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/bash | |
| if [ ! -d "./ssl" ]; then | |
| mkdir ./ssl | |
| fi | |
| # Hostname | |
| HOSTNAME=$1 | |
| # Fallback to "server" if no hostname provided | |
| if [ -z "$HOSTNAME" ]; then | |
| HOSTNAME=server | |
| fi | |
| # Get valid filename from hostname | |
| FILENAME=${HOSTNAME/\*\./} | |
| # OpenSSL Dir | |
| OPENSSL_DIR=$(openssl version -d) | |
| OPENSSL_DIR=${OPENSSL_DIR/OPENSSLDIR\: /} | |
| OPENSSL_DIR=${OPENSSL_DIR/\"/} | |
| OPENSSL_DIR=${OPENSSL_DIR/\"/} | |
| # Generate key | |
| openssl genrsa -out ./ssl/$FILENAME.key 2048 | |
| # Generate certificate | |
| openssl req \ | |
| -new \ | |
| -x509 \ | |
| -sha256 \ | |
| -days 3650 \ | |
| -key ./ssl/$FILENAME.key \ | |
| -out ./ssl/$FILENAME.crt \ | |
| -subj /CN=$HOSTNAME \ | |
| -reqexts SAN \ | |
| -extensions SAN \ | |
| -config <(cat $OPENSSL_DIR/openssl.cnf <(printf '[SAN]\nsubjectAltName=DNS:'$HOSTNAME)) | |
| # Show info message to user to trust certificate | |
| echo "" | |
| echo "To trust this certificate, run the following: " | |
| echo " sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ./ssl/$FILENAME.crt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment