rsa3072-generate.sh 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/sh
  2. OPENSSL=openssl
  3. echo
  4. echo "---[ DH parameters ]----------------------------------------------------"
  5. echo
  6. if [ -r dh_param_3072.pem ]; then
  7. echo "Use already generated dh_param_3072.pem"
  8. else
  9. openssl dhparam -out dh_param_3072.pem 3072
  10. fi
  11. echo
  12. echo "---[ Root CA ]----------------------------------------------------------"
  13. echo
  14. if [ -r rsa3072-ca.key ]; then
  15. echo "Use already generated Root CA"
  16. else
  17. cat ec-ca-openssl.cnf |
  18. sed "s/#@CN@/commonName_default = Suite B RSA 3k Root CA/" |
  19. sed s%\./ec-ca$%./rsa3072-ca% \
  20. > rsa3072-ca-openssl.cnf.tmp
  21. $OPENSSL req -config rsa3072-ca-openssl.cnf.tmp -batch -x509 -new -newkey rsa:3072 -nodes -keyout rsa3072-ca.key -out rsa3072-ca.pem -outform PEM -days 3650 -sha384
  22. mkdir -p rsa3072-ca/certs rsa3072-ca/crl rsa3072-ca/newcerts rsa3072-ca/private
  23. touch rsa3072-ca/index.txt
  24. rm rsa3072-ca-openssl.cnf.tmp
  25. fi
  26. echo
  27. echo "---[ Server ]-----------------------------------------------------------"
  28. echo
  29. cat ec-ca-openssl.cnf |
  30. sed "s/#@CN@/commonName_default = rsa3072.server.w1.fi/" |
  31. sed "s/#@ALTNAME@/subjectAltName=critical,DNS:rsa3072.server.w1.fi/" |
  32. sed s%\./ec-ca$%./rsa3072-ca% \
  33. > rsa3072-ca-openssl.cnf.tmp
  34. $OPENSSL req -config rsa3072-ca-openssl.cnf.tmp -batch -new -newkey rsa:3072 -nodes -keyout rsa3072-server.key -out rsa3072-server.req -outform PEM -sha384
  35. $OPENSSL ca -config rsa3072-ca-openssl.cnf.tmp -batch -keyfile rsa3072-ca.key -cert rsa3072-ca.pem -create_serial -in rsa3072-server.req -out rsa3072-server.pem -extensions ext_server -days 730 -md sha384
  36. rm rsa3072-ca-openssl.cnf.tmp
  37. echo
  38. echo "---[ User SHA-384 ]-----------------------------------------------------"
  39. echo
  40. cat ec-ca-openssl.cnf |
  41. sed "s/#@CN@/commonName_default = user-rsa3072/" |
  42. sed "s/#@ALTNAME@/subjectAltName=email:user-rsa3072@w1.fi/" |
  43. sed s%\./ec-ca$%./rsa3072-ca% \
  44. > rsa3072-ca-openssl.cnf.tmp
  45. $OPENSSL req -config rsa3072-ca-openssl.cnf.tmp -batch -new -newkey rsa:3072 -nodes -keyout rsa3072-user.key -out rsa3072-user.req -outform PEM -extensions ext_client -sha384
  46. $OPENSSL ca -config rsa3072-ca-openssl.cnf.tmp -batch -keyfile rsa3072-ca.key -cert rsa3072-ca.pem -create_serial -in rsa3072-user.req -out rsa3072-user.pem -extensions ext_client -days 730 -md sha384
  47. rm rsa3072-ca-openssl.cnf.tmp
  48. echo
  49. echo "---[ User RSA2048 ]-----------------------------------------------------"
  50. echo
  51. cat ec-ca-openssl.cnf |
  52. sed "s/#@CN@/commonName_default = user-rsa3072-rsa2048/" |
  53. sed "s/#@ALTNAME@/subjectAltName=email:user-rsa3072-rsa2048@w1.fi/" |
  54. sed s%\./ec-ca$%./rsa3072-ca% \
  55. > rsa3072-ca-openssl.cnf.tmp
  56. $OPENSSL req -config rsa3072-ca-openssl.cnf.tmp -batch -new -newkey rsa:2048 -nodes -keyout rsa3072-user-rsa2048.key -out rsa3072-user-rsa2048.req -outform PEM -extensions ext_client -sha384
  57. $OPENSSL ca -config rsa3072-ca-openssl.cnf.tmp -batch -keyfile rsa3072-ca.key -cert rsa3072-ca.pem -create_serial -in rsa3072-user-rsa2048.req -out rsa3072-user-rsa2048.pem -extensions ext_client -days 730 -md sha384
  58. rm rsa3072-ca-openssl.cnf.tmp
  59. echo
  60. echo "---[ Verify ]-----------------------------------------------------------"
  61. echo
  62. $OPENSSL verify -CAfile rsa3072-ca.pem rsa3072-server.pem
  63. $OPENSSL verify -CAfile rsa3072-ca.pem rsa3072-user.pem
  64. $OPENSSL verify -CAfile rsa3072-ca.pem rsa3072-user-rsa2048.pem