2
0

gen-p521-certs.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/usr/bin/env bash
  2. check_result(){
  3. if [ $1 -ne 0 ]; then
  4. echo "Failed at \"$2\", Abort"
  5. exit 1
  6. else
  7. echo "Step Succeeded!"
  8. fi
  9. }
  10. openssl pkey -in root-p521-priv.pem -noout >/dev/null 2>&1
  11. if [ $? -ne 0 ]; then
  12. echo "OpenSSL does not support P521"
  13. echo "Skipping P521 certificate renewal"
  14. exit 0
  15. fi
  16. ############################################################
  17. ###### update the self-signed root-p521.pem ###############
  18. ############################################################
  19. echo "Updating root-p521.pem"
  20. echo ""
  21. #pipe the following arguments to openssl req...
  22. echo -e "US\\nMontana\\nBozeman\\nwolfSSL_P521\\nRoot-P521\\nwww.wolfssl.com\\ninfo@wolfssl.com\\n.\\n.\\n" | \
  23. openssl req -new -key root-p521-priv.pem -config ../renewcerts/wolfssl.cnf -nodes -out root-p521.csr
  24. check_result $? "Generate request"
  25. openssl x509 -req -in root-p521.csr -days 1000 -extfile ../renewcerts/wolfssl.cnf -extensions ca_ecc_cert -signkey root-p521-priv.pem -out root-p521.pem
  26. check_result $? "Generate certificate"
  27. rm root-p521.csr
  28. openssl x509 -in root-p521.pem -outform DER > root-p521.der
  29. check_result $? "Convert to DER"
  30. openssl x509 -in root-p521.pem -text > tmp.pem
  31. check_result $? "Add text"
  32. mv tmp.pem root-p521.pem
  33. echo "End of section"
  34. echo "---------------------------------------------------------------------"
  35. ############################################################
  36. ###### update ca-p521.pem signed by root ##################
  37. ############################################################
  38. echo "Updating ca-p521.pem"
  39. echo ""
  40. #pipe the following arguments to openssl req...
  41. echo -e "US\\nMontana\\nBozeman\\nwolfSSL_p521\\nCA-p521\\nwww.wolfssl.com\\ninfo@wolfssl.com\\n\\n\\n\\n" | openssl req -new -key ca-p521-priv.pem -config ../renewcerts/wolfssl.cnf -nodes -out ca-p521.csr
  42. check_result $? "Generate request"
  43. openssl x509 -req -in ca-p521.csr -days 1000 -extfile ../renewcerts/wolfssl.cnf -extensions ca_ecc_cert -CA root-p521.pem -CAkey root-p521-priv.pem -set_serial 01 -out ca-p521.pem
  44. check_result $? "Generate certificate"
  45. rm ca-p521.csr
  46. openssl x509 -in ca-p521.pem -outform DER > ca-p521.der
  47. check_result $? "Convert to DER"
  48. openssl x509 -in ca-p521.pem -text > tmp.pem
  49. check_result $? "Add text"
  50. mv tmp.pem ca-p521.pem
  51. echo "End of section"
  52. echo "---------------------------------------------------------------------"
  53. ############################################################
  54. ###### update server-p521.pem signed by ca ################
  55. ############################################################
  56. echo "Updating server-p521.pem"
  57. echo ""
  58. #pipe the following arguments to openssl req...
  59. echo -e "US\\nMontana\\nBozeman\\nwolfSSL_p521\\nServer-p521\\nwww.wolfssl.com\\ninfo@wolfssl.com\\n\\n\\n\\n" | openssl req -new -key server-p521-priv.pem -config ../renewcerts/wolfssl.cnf -nodes -out server-p521.csr
  60. check_result $? "Generate request"
  61. openssl x509 -req -in server-p521.csr -days 1000 -extfile ../renewcerts/wolfssl.cnf -extensions server_ecc -CA ca-p521.pem -CAkey ca-p521-priv.pem -set_serial 01 -out server-p521-cert.pem
  62. check_result $? "Generate certificate"
  63. rm server-p521.csr
  64. openssl x509 -in server-p521-cert.pem -outform DER > server-p521.der
  65. check_result $? "Convert to DER"
  66. openssl x509 -in server-p521-cert.pem -text > tmp.pem
  67. check_result $? "Add text"
  68. mv tmp.pem server-p521-cert.pem
  69. cat server-p521-cert.pem ca-p521.pem > server-p521.pem
  70. check_result $? "Add CA into server cert"
  71. echo "End of section"
  72. echo "---------------------------------------------------------------------"
  73. ############################################################
  74. ###### update the self-signed client-p521.pem #############
  75. ############################################################
  76. echo "Updating client-p521.pem"
  77. echo ""
  78. #pipe the following arguments to openssl req...
  79. echo -e "US\\nMontana\\nBozeman\\nwolfSSL_p521\\nClient-p521\\nwww.wolfssl.com\\ninfo@wolfssl.com\\n\\n\\n\\n" | openssl req -new -key client-p521-priv.pem -config ../renewcerts/wolfssl.cnf -nodes -out client-p521.csr
  80. check_result $? "Generate request"
  81. openssl x509 -req -in client-p521.csr -days 1000 -extfile ../renewcerts/wolfssl.cnf -extensions wolfssl_opts -signkey client-p521-priv.pem -out client-p521.pem
  82. check_result $? "Generate certificate"
  83. rm client-p521.csr
  84. openssl x509 -in client-p521.pem -outform DER > client-p521.der
  85. check_result $? "Convert to DER"
  86. openssl x509 -in client-p521.pem -text > tmp.pem
  87. check_result $? "Add text"
  88. mv tmp.pem client-p521.pem
  89. echo "End of section"
  90. echo "---------------------------------------------------------------------"