Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
976
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.64 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function usage () {
  4.  echo "$0 [CA section name] [username] [first name last name] [certificate password] [CA password]"
  5.  echo "example: $0 bncpstest karel.jelinek@unicornsystems.eu \"Karel Jelinek\" password ia81sYLm"
  6.  exit 1
  7. }
  8.  
  9. if [ $# -ne 5 ]
  10. then
  11.         usage
  12. fi
  13.  
  14. CA_NAME="$1"
  15. USERNAME="$2"
  16. NAME="$3"
  17. CERT_PASS="$4"
  18. CA_PASS="$5"
  19.  
  20. SSL_DIR="/etc/ssl"
  21. SSL_PRIVATE_DIR="$SSL_DIR/${CA_NAME}/private"
  22. SSL_CERTS_DIR="$SSL_DIR/${CA_NAME}/certs"
  23. USERS_DIR="${SSL_CERTS_DIR}/users"
  24.  
  25. mkdir -p ${USERS_DIR}
  26.  
  27. # Create the Client Key and CSR
  28. openssl genrsa -des3 -out ${USERS_DIR}/${USERNAME}.key -passout pass:${CERT_PASS} 1024
  29. openssl req \
  30.     -new \
  31.     -key ${USERS_DIR}/${USERNAME}.key\
  32.     -out ${USERS_DIR}/${USERNAME}.csr\
  33.     -subj "/C=EU/ST=Czech Republic/L=Prague/O=Unicorn Systems/CN=${NAME}/emailAddress=${USERNAME}" \
  34.     -passout pass:${CERT_PASS}\
  35.     -passin pass:${CERT_PASS}
  36.  
  37. # Sign the client certificate with our CA cert.  Unlike signing our own server cert, this is what we want to do.
  38. openssl x509 -req -days 1825 -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 -passin pass:${CA_PASS}
  39.  
  40. echo "making p12 file"
  41. #browsers need P12s (contain key and cert)
  42. openssl pkcs12 -export -clcerts -in ${USERS_DIR}/${USERNAME}.crt -inkey ${USERS_DIR}/${USERNAME}.key -out ${USERS_DIR}/${USERNAME}.p12 -passin pass:${CERT_PASS} -passout pass:${CERT_PASS}
  43.  
  44. echo "made ${USERS_DIR}/${USERNAME}.p12"
  45. echo "Certificate serial number:"
  46. openssl x509 -in ${USERS_DIR}/${USERNAME}.crt -serial -noout
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement