Created
April 21, 2022 10:32
-
-
Save uncelvel/a2fbe134d3bdb9668965f11d4a71e167 to your computer and use it in GitHub Desktop.
generate-wildcard-certificate.sh
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
#!/usr/bin/env bash | |
# print usage | |
DOMAIN=$1 | |
if [ -z "$1" ]; then | |
echo "USAGE: $0 ghtk.local" | |
echo "" | |
echo "This will generate a non-secure self-signed wildcard certificate for given domain." | |
echo "This should only be used in a development environment." | |
exit | |
fi | |
# Add wildcard | |
WILDCARD="*.$DOMAIN" | |
# Set our CSR variables | |
SUBJ=" | |
C=VN | |
ST=HN | |
O=GHTK_Local_Development | |
localityName=GHTK_Local_Development | |
commonName=$WILDCARD | |
organizationalUnitName=GHTK_Local_Development | |
[email protected] | |
" | |
# Generate our Private Key, CSR and Certificate | |
openssl genrsa -out "$DOMAIN.key" 2048 | |
openssl req -new -subj "$(echo -n "$SUBJ" | tr "\n" "/")" -key "$DOMAIN.key" -out "$DOMAIN.csr" | |
openssl x509 -req -days 3650 -in "$DOMAIN.csr" -signkey "$DOMAIN.key" -out "$DOMAIN.crt" | |
# Bundle .pem using for bla bla | |
cat $DOMAIN.crt $DOMAIN.key > $DOMAIN.pem | |
# Remove dont need | |
rm "$DOMAIN.csr $DOMAIN.crt $DOMAIN.key"" | |
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'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment