Created
June 16, 2022 14:08
-
-
Save scolton99/dd2e03b06643c519e4f3ecc834e50a9d to your computer and use it in GitHub Desktop.
Use OpenSSL to generate a self-signed certificate with SANs.
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
if [ -f ".req.conf" ]; then | |
rm .req.conf | |
fi | |
STRBASE="[req]\ndistinguished_name = dn\nx509_extensions = v3_req\nprompt = no\n\n[dn]\nC = US\nST = Illinois\nL = Chicago\nO = Northwestern University\nOU = Information Technology\nCN = $1\n\n[v3_req]\nkeyUsage = keyEncipherment, nonRepudiation, digitalSignature, dataEncipherment, keyAgreement, keyCertSign\nextendedKeyUsage = serverAuth\nbasicConstraints = CA:true\nsubjectKeyIdentifier = hash\nauthorityKeyIdentifier = keyid:always,issuer:always\nsubjectAltName = @alt_names\n\n[alt_names]" | |
C=1 | |
for var in "$@" | |
do | |
STRBASE="${STRBASE}\nDNS.${C} = ${var}" | |
C=$(( $C + 1 )) | |
done | |
echo -e $STRBASE >> .req.conf | |
openssl req -new -x509 -newkey rsa:2048 -sha256 -nodes -keyout $1.key -days 730 -out $1.crt -config .req.conf | |
openssl pkcs12 -export -out $1.pfx -inkey $1.key -in $1.crt | |
rm .req.conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment