Skip to content

Instantly share code, notes, and snippets.

@ardiesaeidi
Last active December 21, 2018 02:39
Show Gist options
  • Save ardiesaeidi/ca3b37e1fc51b2393587d3264c0c0439 to your computer and use it in GitHub Desktop.
Save ardiesaeidi/ca3b37e1fc51b2393587d3264c0c0439 to your computer and use it in GitHub Desktop.
#!/bin/sh
# certgen <days> <file_name>
if [ "$#" -ne 2 ]; then
echo "certgen <days> <file_name>"
exit 1
fi
read -s -p "password: " password
exp_days=$1
echo "\ncert expires in ${exp_days} days\n"
name=$2
key="${name}.key"
cert="${name}.cer"
pfx="${name}.pfx"
# cert info
C=US
ST=CA
L="Los Angeles"
O="ABC"
OU="."
CN=www.abc.com
[email protected]
# make dir
mkdir $name
# Create the certificate signing request
openssl req -x509 -days $exp_days -nodes -newkey rsa:2048 -keyout "$name/$key" -out "$name/$cert" <<EOF
${C}
${ST}
${L}
${O}
${OU}
${CN}
${EMAIL}
EOF
echo ""
# create pfx
openssl pkcs12 -password pass:$password -export -in "$name/$cert" -inkey "$name/$key" -out "$name/$pfx"
# display cert
echo "\n"
openssl x509 -in "$name/$cert" -text -noout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment