ec-generate.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/sh
  2. OPENSSL=openssl
  3. CURVE=prime256v1
  4. DIGEST="-sha256"
  5. DIGEST_CA="-md sha256"
  6. echo
  7. echo "---[ Root CA ]----------------------------------------------------------"
  8. echo
  9. cat ec-ca-openssl.cnf |
  10. sed "s/#@CN@/commonName_default = Suite B 128-bit Root CA/" \
  11. > ec-ca-openssl.cnf.tmp
  12. $OPENSSL ecparam -out ec-ca.key -name $CURVE -genkey
  13. $OPENSSL req -config ec-ca-openssl.cnf.tmp -batch -x509 -new -key ec-ca.key -out ec-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 ec-server.key -name $CURVE -genkey
  25. $OPENSSL req -config ec-ca-openssl.cnf.tmp -batch -new -nodes -key ec-server.key -out ec-server.req -outform PEM $DIGEST
  26. $OPENSSL ca -config ec-ca-openssl.cnf.tmp -batch -keyfile ec-ca.key -cert ec-ca.pem -create_serial -in ec-server.req -out ec-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 ec-user.key -name $CURVE -genkey
  36. $OPENSSL req -config ec-ca-openssl.cnf.tmp -batch -new -nodes -key ec-user.key -out ec-user.req -outform PEM -extensions ext_client $DIGEST
  37. $OPENSSL ca -config ec-ca-openssl.cnf.tmp -batch -keyfile ec-ca.key -cert ec-ca.pem -create_serial -in ec-user.req -out ec-user.pem -extensions ext_client $DIGEST_CA
  38. rm ec-ca-openssl.cnf.tmp
  39. echo
  40. echo "---[ Verify ]-----------------------------------------------------------"
  41. echo
  42. $OPENSSL verify -CAfile ec-ca.pem ec-server.pem
  43. $OPENSSL verify -CAfile ec-ca.pem ec-user.pem