ec2-generate.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/sh
  2. OPENSSL=openssl
  3. CURVE=secp384r1
  4. DIGEST="-sha384"
  5. DIGEST_CA="-md sha384"
  6. echo
  7. echo "---[ Root CA ]----------------------------------------------------------"
  8. echo
  9. cat ec-ca-openssl.cnf |
  10. sed "s/#@CN@/commonName_default = Suite B 192-bit Root CA/" \
  11. > ec-ca-openssl.cnf.tmp
  12. $OPENSSL ecparam -out ec2-ca.key -name $CURVE -genkey
  13. $OPENSSL req -config ec-ca-openssl.cnf.tmp -batch -x509 -new -key ec2-ca.key -out ec2-ca.pem -outform PEM -days 3650 $DIGEST
  14. mkdir -p ec-ca/certs ec-ca/crl ec-ca/newcerts ec-ca/private
  15. touch ec-ca/index.txt
  16. rm ec-ca-openssl.cnf.tmp
  17. echo
  18. echo "---[ Server ]-----------------------------------------------------------"
  19. echo
  20. cat ec-ca-openssl.cnf |
  21. sed "s/#@CN@/commonName_default = server.w1.fi/" |
  22. sed "s/#@ALTNAME@/subjectAltName=critical,DNS:server.w1.fi/" \
  23. > ec-ca-openssl.cnf.tmp
  24. $OPENSSL ecparam -out ec2-server.key -name $CURVE -genkey
  25. $OPENSSL req -config ec-ca-openssl.cnf.tmp -batch -new -nodes -key ec2-server.key -out ec2-server.req -outform PEM $DIGEST
  26. $OPENSSL ca -config ec-ca-openssl.cnf.tmp -batch -keyfile ec2-ca.key -cert ec2-ca.pem -create_serial -in ec2-server.req -out ec2-server.pem -extensions ext_server $DIGEST_CA
  27. rm ec-ca-openssl.cnf.tmp
  28. echo
  29. echo "---[ User ]-------------------------------------------------------------"
  30. echo
  31. cat ec-ca-openssl.cnf |
  32. sed "s/#@CN@/commonName_default = user/" |
  33. sed "s/#@ALTNAME@/subjectAltName=email:user@w1.fi/" \
  34. > ec-ca-openssl.cnf.tmp
  35. $OPENSSL ecparam -out ec2-user.key -name $CURVE -genkey
  36. $OPENSSL req -config ec-ca-openssl.cnf.tmp -batch -new -nodes -key ec2-user.key -out ec2-user.req -outform PEM -extensions ext_client $DIGEST
  37. $OPENSSL ca -config ec-ca-openssl.cnf.tmp -batch -keyfile ec2-ca.key -cert ec2-ca.pem -create_serial -in ec2-user.req -out ec2-user.pem -extensions ext_client $DIGEST_CA
  38. rm ec-ca-openssl.cnf.tmp
  39. echo
  40. echo "---[ User p256 ]--------------------------------------------------------"
  41. echo
  42. cat ec-ca-openssl.cnf |
  43. sed "s/#@CN@/commonName_default = user-p256/" |
  44. sed "s/#@ALTNAME@/subjectAltName=email:user-p256@w1.fi/" \
  45. > ec-ca-openssl.cnf.tmp
  46. $OPENSSL ecparam -out ec2-user-p256.key -name prime256v1 -genkey
  47. $OPENSSL req -config ec-ca-openssl.cnf.tmp -batch -new -nodes -key ec2-user-p256.key -out ec2-user-p256.req -outform PEM -extensions ext_client -sha256
  48. $OPENSSL ca -config ec-ca-openssl.cnf.tmp -batch -keyfile ec2-ca.key -cert ec2-ca.pem -create_serial -in ec2-user-p256.req -out ec2-user-p256.pem -extensions ext_client -md sha256
  49. rm ec-ca-openssl.cnf.tmp
  50. echo
  51. echo "---[ Verify ]-----------------------------------------------------------"
  52. echo
  53. $OPENSSL verify -CAfile ec2-ca.pem ec2-server.pem
  54. $OPENSSL verify -CAfile ec2-ca.pem ec2-user.pem
  55. $OPENSSL verify -CAfile ec2-ca.pem ec2-user-p256.pem