Skip to content

Instantly share code, notes, and snippets.

@kwharrigan
Created October 16, 2009 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwharrigan/211849 to your computer and use it in GitHub Desktop.
Save kwharrigan/211849 to your computer and use it in GitHub Desktop.
openssl utility script for adding users
#!/bin/bash
EXPECTED_ARGS=2
if [ $# -ne $EXPECTED_ARGS ]
then
echo $'Usage: \n\tadduser <name> <CA>'
echo $'\tWhere <name>.csr, <name>.pem, and <name>.key exist\n'
exit 0
else
if [ ! -e $1.key ]
then
# Generate private key and csr
echo "Generating private key..."
openssl genrsa -des3 -out $1.key 2048 # 3DES??? Not sure where this came from
else
echo ".key already exists..."
fi
if [ ! -e $1.csr ]
then
# Generate csr
echo "Generating CSR..."
openssl req -new -key $1.key -out $1.csr
else
echo ".csr already exists..."
fi
if [ ! -e $1.crt ]
then
# If crt does not exist, create
echo "Creating $1.crt..."
openssl x509 -req -in $1.csr -out $1.crt -sha1 -CA $2.pem -CAkey $2.key -CAcreateserial -days 365
else
# else, print out msg
echo "$1.crt already exists, creating p12..."
fi
if [ ! -e $1.p12 ]
then
# IF crt does not exist, create
echo "Creating $1.p12"
openssl pkcs12 -export -in $1.crt -inkey $1.key -name "$1 Cert" -out $1.p12
else
echo "$1.p12 already exists, nothing to do..."
fi
# If .p12 does not exist, create
# else, print out message
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment