Skip to content

Instantly share code, notes, and snippets.

@rynop
Created November 26, 2012 15:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save rynop/4148845 to your computer and use it in GitHub Desktop.
Save rynop/4148845 to your computer and use it in GitHub Desktop.
create client p12 file
#!/bin/bash
function usage () {
echo "$0 [CA section name] [username]"
exit 1
}
if [ $# -ne 2 ]
then
usage
fi
CA_NAME="$1"
USERNAME="$2"
SSL_DIR="/etc/ssl"
SSL_PRIVATE_DIR="$SSL_DIR/${CA_NAME}/private"
SSL_CERTS_DIR="$SSL_DIR/${CA_NAME}/certs"
USERS_DIR="${SSL_CERTS_DIR}/users"
mkdir -p ${USERS_DIR}
# Create the Client Key and CSR
openssl genrsa -des3 -out ${USERS_DIR}/${USERNAME}.key 1024
openssl req -new -key ${USERS_DIR}/${USERNAME}.key -out ${USERS_DIR}/${USERNAME}.csr
# Sign the client certificate with our CA cert. Unlike signing our own server cert, this is what we want to do.
openssl x509 -req -days 1095 -in ${USERS_DIR}/${USERNAME}.csr -CA $SSL_CERTS_DIR/ca.crt -CAkey $SSL_PRIVATE_DIR/ca.key -CAserial $SSL_DIR/${CA_NAME}/serial -CAcreateserial -out ${USERS_DIR}/${USERNAME}.crt
echo "making p12 file"
#browsers need P12s (contain key and cert)
openssl pkcs12 -export -clcerts -in ${USERS_DIR}/${USERNAME}.crt -inkey ${USERS_DIR}/${USERNAME}.key -out ${USERS_DIR}/${USERNAME}.p12
echo "made ${USERS_DIR}/${USERNAME}.p12"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment