sha512-generate.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/sh
  2. OPENSSL=openssl
  3. DIGEST="-sha512"
  4. DIGEST_CA="-md sha512"
  5. echo
  6. echo "---[ Root CA ]----------------------------------------------------------"
  7. echo
  8. cat ec-ca-openssl.cnf |
  9. sed "s/#@CN@/commonName_default = SHA384 and SHA512 Root CA/" \
  10. > ec-ca-openssl.cnf.tmp
  11. $OPENSSL req -config ec-ca-openssl.cnf.tmp -batch -x509 -new -newkey rsa:4096 -nodes -keyout sha512-ca.key -out sha512-ca.pem -outform PEM -days 3650 $DIGEST
  12. mkdir -p ec-ca/certs ec-ca/crl ec-ca/newcerts ec-ca/private
  13. touch ec-ca/index.txt
  14. rm ec-ca-openssl.cnf.tmp
  15. echo
  16. echo "---[ Server SHA-512 ]---------------------------------------------------"
  17. echo
  18. cat ec-ca-openssl.cnf |
  19. sed "s/#@CN@/commonName_default = sha512.server.w1.fi/" |
  20. sed "s/#@ALTNAME@/subjectAltName=critical,DNS:sha512.server.w1.fi/" \
  21. > ec-ca-openssl.cnf.tmp
  22. $OPENSSL req -config ec-ca-openssl.cnf.tmp -batch -new -newkey rsa:3500 -nodes -keyout sha512-server.key -out sha512-server.req -outform PEM $DIGEST
  23. $OPENSSL ca -config ec-ca-openssl.cnf.tmp -batch -keyfile sha512-ca.key -cert sha512-ca.pem -create_serial -in sha512-server.req -out sha512-server.pem -extensions ext_server $DIGEST_CA
  24. rm ec-ca-openssl.cnf.tmp
  25. echo
  26. echo "---[ Server SHA-384 ]---------------------------------------------------"
  27. echo
  28. cat ec-ca-openssl.cnf |
  29. sed "s/#@CN@/commonName_default = sha384.server.w1.fi/" |
  30. sed "s/#@ALTNAME@/subjectAltName=critical,DNS:sha384.server.w1.fi/" \
  31. > ec-ca-openssl.cnf.tmp
  32. $OPENSSL req -config ec-ca-openssl.cnf.tmp -batch -new -newkey rsa:3072 -nodes -keyout sha384-server.key -out sha384-server.req -outform PEM $DIGEST
  33. $OPENSSL ca -config ec-ca-openssl.cnf.tmp -batch -keyfile sha512-ca.key -cert sha512-ca.pem -create_serial -in sha384-server.req -out sha384-server.pem -extensions ext_server -md sha384
  34. rm ec-ca-openssl.cnf.tmp
  35. echo
  36. echo "---[ User SHA-512 ]-----------------------------------------------------"
  37. echo
  38. cat ec-ca-openssl.cnf |
  39. sed "s/#@CN@/commonName_default = user-sha512/" |
  40. sed "s/#@ALTNAME@/subjectAltName=email:user-sha512@w1.fi/" \
  41. > ec-ca-openssl.cnf.tmp
  42. $OPENSSL req -config ec-ca-openssl.cnf.tmp -batch -new -newkey rsa:3400 -nodes -keyout sha512-user.key -out sha512-user.req -outform PEM -extensions ext_client $DIGEST
  43. $OPENSSL ca -config ec-ca-openssl.cnf.tmp -batch -keyfile sha512-ca.key -cert sha512-ca.pem -create_serial -in sha512-user.req -out sha512-user.pem -extensions ext_client $DIGEST_CA
  44. rm ec-ca-openssl.cnf.tmp
  45. echo
  46. echo "---[ User SHA-384 ]-----------------------------------------------------"
  47. echo
  48. cat ec-ca-openssl.cnf |
  49. sed "s/#@CN@/commonName_default = user-sha384/" |
  50. sed "s/#@ALTNAME@/subjectAltName=email:user-sha384@w1.fi/" \
  51. > ec-ca-openssl.cnf.tmp
  52. $OPENSSL req -config ec-ca-openssl.cnf.tmp -batch -new -newkey rsa:2900 -nodes -keyout sha384-user.key -out sha384-user.req -outform PEM -extensions ext_client $DIGEST
  53. $OPENSSL ca -config ec-ca-openssl.cnf.tmp -batch -keyfile sha512-ca.key -cert sha512-ca.pem -create_serial -in sha384-user.req -out sha384-user.pem -extensions ext_client -md sha384
  54. rm ec-ca-openssl.cnf.tmp
  55. echo
  56. echo "---[ Verify ]-----------------------------------------------------------"
  57. echo
  58. $OPENSSL verify -CAfile sha512-ca.pem sha512-server.pem
  59. $OPENSSL verify -CAfile sha512-ca.pem sha384-server.pem
  60. $OPENSSL verify -CAfile sha512-ca.pem sha512-user.pem
  61. $OPENSSL verify -CAfile sha512-ca.pem sha384-user.pem