Skip to content

Instantly share code, notes, and snippets.

@kjivan
Last active July 2, 2021 19:49
Show Gist options
  • Save kjivan/0b06fc971264276096d53a52278ebb1b to your computer and use it in GitHub Desktop.
Save kjivan/0b06fc971264276096d53a52278ebb1b to your computer and use it in GitHub Desktop.
Creates Self Signed Cert and PKCS12
#!/usr/bin/env bash
set -euo pipefail
if [ $# -ne 3 ]
then
echo ""${0##*/}" CN OU FILE_NAME"
exit
fi
# Certificate Attributes
# CN: CommonName
# OU: OrganizationalUnit
# O: Organization
# L: Locality
# S: StateOrProvinceName
# C: CountryName
CN=$1
OU=$2
FILE_NAME=$3
# https://stackoverflow.com/a/41366949
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes \
-keyout $FILE_NAME.key -out $FILE_NAME.crt -subj "/CN=$CN/OU=$OU" \
-addext "subjectAltName=DNS:$CN"
# https://stackoverflow.com/a/21144736
openssl pkcs12 -export -out $FILE_NAME.p12 -inkey $FILE_NAME.key -in $FILE_NAME.crt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment