Advertisement
Guest User

Untitled

a guest
Nov 10th, 2015
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # @description Converts .pfx/.pcks Certificates to Unix-ready .ca-crt/.crt/.key Plaintext (pem) files
  4. # @arguments Cert Filename
  5.  
  6. # @copyright Copyright (c) 2015 Frederik Winkelsdorf <winkelsdorf@gmail.com>
  7. # @license Released under MIT license
  8.  
  9. inFile=$1
  10. outFile="${inFile%.*}" # = inFile without Extension
  11.  
  12. cat << EOF
  13. PPCCK (PFX/PKCS to CA-CRT/CRT/KEY) Converter Script v1.0
  14. Copyright (c) 2015 Frederik Winkelsdorf <winkelsdorf@gmail.com>
  15. Released under MIT license
  16.  
  17. EOF
  18.  
  19. usage()
  20. {
  21. cat << EOF
  22. This script uses OpenSSL to convert the given pfx/pkcs certficate into a
  23. plaintext (pem format) set of .ca-crt, .crt and .key files. The password
  24. is removed from the exported private key. It MUST be stored and
  25. transferred safely, i.e. not user-accesible!
  26.  
  27. usage: $0 "Filename"
  28.  
  29. EOF
  30. }
  31.  
  32. while getopts “h” option
  33. do
  34. case $option in
  35. h)
  36. usage
  37. exit 1
  38. ;;
  39. ?)
  40. usage
  41. exit
  42. ;;
  43. esac
  44. done
  45.  
  46. if [[ -z $inFile ]]
  47. then
  48. usage
  49. exit 1
  50. fi
  51.  
  52. cat << EOF
  53. Please enter the password for input certificate: $inFile
  54.  
  55. EOF
  56.  
  57. read -s -p "Password: " password
  58. printf "\n\n"
  59.  
  60. printf "OpenSSL Info\n"
  61. echo "------------"
  62. openssl version -a
  63.  
  64. printf "\nBasic Certificate Info\n"
  65. echo "----------------------"
  66.  
  67. openssl pkcs12 -info -nokeys -nocerts -in "$inFile" -passin pass:$password
  68.  
  69. printf "\nExporting\n"
  70. echo "---------"
  71.  
  72. printf "\nExporting: $outFile.ca-crt\n"
  73. openssl pkcs12 -nokeys -cacerts -in "$inFile" -out "$outFile.ca-crt" -password pass:$password
  74.  
  75. printf "\nExporting: $outFile.crt\n"
  76. openssl pkcs12 -nokeys -clcerts -in "$inFile" -out "$outFile.crt" -password pass:$password
  77.  
  78. printf "\nExporting: $outFile.key\n"
  79. openssl pkcs12 -nocerts -in "$inFile" -out "$outFile.pem" -passin pass:$password -passout pass:$password
  80. openssl rsa -in "$outFile.pem" -out "$outFile.key" -passin pass:$password
  81.  
  82. printf "\nRemoving intermediate: $outFile.pem\n"
  83. rm "$outFile.pem"
  84.  
  85. echo "Done."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement