Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save dmadisetti/16006751fd6e1526fa9c2f2e1660e8e3 to your computer and use it in GitHub Desktop.
Save dmadisetti/16006751fd6e1526fa9c2f2e1660e8e3 to your computer and use it in GitHub Desktop.
Generate self-signed wildcard SSL certificate for development environment
#!/usr/bin/env bash
# print usage
DOMAIN=$1
if [ -z "$1" ]; then
echo "USAGE: $0 tld"
echo ""
echo "This will generate a non-secure self-signed wildcard certificate for "
echo "a given development tld."
echo "This should only be used in a development environment."
exit
fi
# Add wildcard
WILDCARD="*.$DOMAIN"
# Set our variables
cat <<EOF > req.cnf
[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
C = US
ST = MD
O = home
localityName = home
commonName = $WILDCARD
organizationalUnitName = home
emailAddress = $(git config user.email)
[v3_req]
keyUsage = keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1 = https.$DOMAIN
DNS.2 = *.https.$DOMAIN
IP = 10.0.0.1
EOF
# Generate our Private Key, and Certificate directly
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 \
-keyout "$DOMAIN.key" -config req.cnf \
-out "$DOMAIN.crt" -sha256
rm req.cnf
echo ""
echo "Next manual steps:"
echo "- Use $DOMAIN.crt and $DOMAIN.key to configure Apache/nginx"
echo "- Import $DOMAIN.crt into Chrome settings: chrome://settings/certificates > tab 'Authorities'"
@dmadisetti
Copy link
Author

SAN required to serve https.

Note IP hardcoded on 38.

In conjunction with nginx rule that forwards xxx.https.tld -> xxx.tld and port.https.tld -> ip:port

@CaptainCannabis
Copy link

CaptainCannabis commented Jan 30, 2022

problems making Certificate Request ... error:0D07A098:asn1 encoding routines:ASN1_mbstring_ncopy:string too short:

if $(git config user.email is empty/not set. Just put something in there

@divyekapoor
Copy link

https://superuser.com/questions/1451895/err-ssl-key-usage-incompatible-solution

Replace line 32 (keyUsage) with:

keyUsage = nonRepudiation, digitalSignature, keyEncipherment

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