You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

84 line
2.0 KiB

  1. #!/bin/sh
  2. # Re-creates certificates for server and client VPN
  3. OPENSSL_BIN=openssl
  4. OPENSSL_REHASH_BIN=c_rehash
  5. TMP_DIR=certs
  6. set -x
  7. create_openvpn_pki()
  8. {
  9. # Create CA key and certificate
  10. ${OPENSSL_BIN} ecparam \
  11. -name secp256r1 \
  12. -genkey \
  13. -out ${TMP_DIR}/ca.key || exit;
  14. ${OPENSSL_BIN} req \
  15. -new \
  16. -config openssl.cnf \
  17. -x509 \
  18. -extensions v3_ca \
  19. -key ${TMP_DIR}/ca.key \
  20. -out ${TMP_DIR}/ca.cert \
  21. -days 9999 \
  22. -subj "/O=Among Bytes, vpn.testlab.com/CN=Root Cert G1" \
  23. -batch || exit;
  24. # Create server certificate
  25. ${OPENSSL_BIN} ecparam \
  26. -name secp256r1 \
  27. -genkey \
  28. -out ${TMP_DIR}/server.key || exit;
  29. ${OPENSSL_BIN} req \
  30. -new \
  31. -config openssl.cnf \
  32. -key ${TMP_DIR}/server.key \
  33. -out ${TMP_DIR}/server.csr \
  34. -subj "/O=Cert Testing ORG/CN=vpn.testlab.com" \
  35. -batch || exit;
  36. ${OPENSSL_BIN} x509 \
  37. -extfile openssl.cnf \
  38. -extensions server_cert \
  39. -req \
  40. -CA ${TMP_DIR}/ca.cert \
  41. -CAkey ${TMP_DIR}/ca.key \
  42. -CAcreateserial \
  43. -in ${TMP_DIR}/server.csr \
  44. -out ${TMP_DIR}/server.cert \
  45. -days 9999 || exit;
  46. OPENSSL=${OPENSSL_BIN} ${OPENSSL_REHASH_BIN} ${TMP_DIR}
  47. ${OPENSSL_BIN} verify \
  48. -CApath ${TMP_DIR} \
  49. ${TMP_DIR}/server.cert || exit;
  50. # Create client certificate
  51. ${OPENSSL_BIN} ecparam \
  52. -name secp256r1 \
  53. -genkey \
  54. -out ${TMP_DIR}/client.key || exit;
  55. ${OPENSSL_BIN} req \
  56. -new \
  57. -config openssl.cnf \
  58. -key ${TMP_DIR}/client.key \
  59. -out ${TMP_DIR}/client.csr \
  60. -subj "/O=Cert Testing ORG/CN=Client Cert" \
  61. -batch || exit;
  62. ${OPENSSL_BIN} x509 \
  63. -extfile openssl.cnf \
  64. -extensions client_cert \
  65. -req \
  66. -CA ${TMP_DIR}/ca.cert \
  67. -CAkey ${TMP_DIR}/ca.key \
  68. -CAcreateserial \
  69. -in ${TMP_DIR}/client.csr \
  70. -out ${TMP_DIR}/client.cert \
  71. -days 9999 || exit;
  72. ${OPENSSL_BIN} verify \
  73. -CApath ${TMP_DIR}/ \
  74. ${TMP_DIR}/client.cert || exit;
  75. }
  76. rm -rf ${TMP_DIR}
  77. mkdir -p ${TMP_DIR}
  78. create_openvpn_pki