Created
December 17, 2020 09:24
-
-
Save jamesmorrison/0de9c37135e0efe113ea14b2db00be68 to your computer and use it in GitHub Desktop.
Create a self signed TLS certificate for Local Development
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 | |
# Exit on failure | |
set -e | |
# Create the root key | |
openssl genrsa -out ./root.key 2048 | |
# Generate the root certificate | |
openssl req -x509 -new -nodes -key ./root.key -sha256 -days 3650 -out ./root.crt -subj /C=XX/ST=LocalHost/L=LocalHost/O=LocalHost/OU=LocalHost/CN=localhost | |
# Generate the localhost key | |
openssl genrsa -out ./localhost.key 2048 | |
# Create a CSR from the localhost key | |
openssl req -new -key ./localhost.key -out ./localhost.csr -subj /C=XX/ST=LocalHost/L=LocalHost/O=LocalHost/OU=LocalHost/CN=localhost | |
# Create the 'extension' file - this is used to add the additional DNS names (i.e. the wildcards) | |
cat > ./localhost.ext << EOF | |
authorityKeyIdentifier=keyid,issuer | |
basicConstraints=CA:FALSE | |
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment | |
subjectAltName = @alt_names | |
[alt_names] | |
DNS.1 = localhost | |
DNS.2 = *.example | |
DNS.3 = *.invalid | |
DNS.4 = *.localhost | |
DNS.5 = *.test | |
EOF | |
# Generate the localhost certificate, signed by the root certificate, using the extension file | |
openssl x509 -req -in ./localhost.csr -CA ./root.crt -CAkey ./root.key -CAcreateserial -out ./localhost.crt -days 3650. -sha256 -extfile ./localhost.ext |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment