Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #!/usr/bin/env bash -ex
  2.  
  3. SERVER_CN=localhost
  4. USERNAME=Admin
  5.  
  6. WORKSPACE=/tmp/certs
  7. CA_DIR=${WORKSPACE}/authority
  8. SERVER_DIR=${WORKSPACE}/${SERVER_CN}
  9. USER_DIR=${WORKSPACE}/admin
  10.  
  11. rm -rf ${WORKSPACE}
  12.  
  13. # Cert Authority
  14. mkdir -p ${CA_DIR}
  15. openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout ${CA_DIR}/rootCA.key -out ${CA_DIR}/rootCA.crt -subj "/C=GB/O=Example/OU=Dev/CN=CA" -passin pass:password
  16. keytool -import -keystore ${CA_DIR}/truststore.jks -file ${CA_DIR}/rootCA.crt -alias rootCA -storepass password -noprompt
  17.  
  18. # Server now
  19. mkdir -p ${SERVER_DIR}
  20. openssl req -out ${SERVER_DIR}/${SERVER_CN}.csr -newkey rsa:2048 -nodes -keyout ${SERVER_DIR}/${SERVER_CN}.key -subj "/C=GB/O=Example/OU=Dev/CN=${SERVER_CN}" -passin pass:password
  21. openssl x509 -req -days 360 -in ${SERVER_DIR}/${SERVER_CN}.csr -CA ${CA_DIR}/rootCA.crt -CAkey ${CA_DIR}/rootCA.key -CAcreateserial -out ${SERVER_DIR}/${SERVER_CN}.crt
  22. openssl pkcs12 -export -out ${SERVER_DIR}/${SERVER_CN}.p12 -inkey ${SERVER_DIR}/${SERVER_CN}.key -in ${SERVER_DIR}/${SERVER_CN}.crt -certfile ${CA_DIR}/rootCA.crt -passout pass:password
  23.  
  24. # User
  25. mkdir -p ${USER_DIR}
  26. openssl req -out ${USER_DIR}/${USERNAME}.csr -newkey rsa:2048 -nodes -keyout ${USER_DIR}/${USERNAME}.key -subj "/C=GB/O=Example/OU=Dev/CN=${USERNAME}" -passin pass:password
  27. openssl x509 -req -days 360 -in ${USER_DIR}/${USERNAME}.csr -CA ${CA_DIR}/rootCA.crt -CAkey ${CA_DIR}/rootCA.key -CAcreateserial -out ${USER_DIR}/${USERNAME}.crt
  28. openssl pkcs12 -export -out ${USER_DIR}/${USERNAME}.p12 -inkey ${USER_DIR}/${USERNAME}.key -in ${USER_DIR}/${USERNAME}.crt -certfile ${CA_DIR}/rootCA.crt -passout pass:password
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement