ica-generate.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/sh
  2. OPENSSL=openssl
  3. echo
  4. echo "---[ Intermediate CA - Server ]-----------------------------------------"
  5. echo
  6. cat ec-ca-openssl.cnf |
  7. sed "s/ec-ca/rootCA/" |
  8. sed "s/#@CN@/commonName_default = Server Intermediate CA/" \
  9. > openssl.cnf.tmp
  10. mkdir -p iCA-server/certs iCA-server/crl iCA-server/newcerts iCA-server/private
  11. touch iCA-server/index.txt
  12. $OPENSSL req -config openssl.cnf.tmp -batch -new -newkey rsa:2048 -nodes -keyout iCA-server/private/cakey.pem -out iCA-server/careq.pem -outform PEM -days 3652 -sha256
  13. $OPENSSL ca -config openssl.cnf.tmp -md sha256 -create_serial -out iCA-server/cacert.pem -days 3652 -batch -keyfile ca-key.pem -cert ca.pem -extensions v3_ca -outdir rootCA/newcerts -infiles iCA-server/careq.pem
  14. cat iCA-server/cacert.pem ca.pem > iCA-server/ca-and-root.pem
  15. rm openssl.cnf.tmp
  16. echo
  17. echo "---[ Intermediate CA - User ]-------------------------------------------"
  18. echo
  19. cat ec-ca-openssl.cnf |
  20. sed "s/ec-ca/rootCA/" |
  21. sed "s/#@CN@/commonName_default = User Intermediate CA/" \
  22. > openssl.cnf.tmp
  23. mkdir -p iCA-user/certs iCA-user/crl iCA-user/newcerts iCA-user/private
  24. touch iCA-user/index.txt
  25. $OPENSSL req -config openssl.cnf.tmp -batch -new -newkey rsa:2048 -nodes -keyout iCA-user/private/cakey.pem -out iCA-user/careq.pem -outform PEM -days 3652 -sha256
  26. $OPENSSL ca -config openssl.cnf.tmp -md sha256 -create_serial -out iCA-user/cacert.pem -days 3652 -batch -keyfile ca-key.pem -cert ca.pem -extensions v3_ca -outdir rootCA/newcerts -infiles iCA-user/careq.pem
  27. cat iCA-user/cacert.pem ca.pem > iCA-user/ca-and-root.pem
  28. rm openssl.cnf.tmp
  29. echo
  30. echo "---[ Server ]-----------------------------------------------------------"
  31. echo
  32. cat ec-ca-openssl.cnf |
  33. sed "s/ec-ca/iCA-server/" |
  34. sed "s/#@CN@/commonName_default = server.w1.fi/" |
  35. sed "s/#@ALTNAME@/subjectAltName=critical,DNS:server.w1.fi/" \
  36. > openssl.cnf.tmp
  37. $OPENSSL req -config openssl.cnf.tmp -batch -new -newkey rsa:2048 -nodes -keyout iCA-server/server.key -out iCA-server/server.req -outform PEM -sha256
  38. $OPENSSL ca -config openssl.cnf.tmp -batch -keyfile iCA-server/private/cakey.pem -cert iCA-server/cacert.pem -create_serial -in iCA-server/server.req -out iCA-server/server.pem -extensions ext_server -md sha256
  39. cat iCA-server/cacert.pem iCA-server/server.pem > iCA-server/server_and_ica.pem
  40. rm openssl.cnf.tmp
  41. echo
  42. echo "---[ Server - revoked ]-------------------------------------------------"
  43. echo
  44. cat ec-ca-openssl.cnf |
  45. sed "s/ec-ca/iCA-server/" |
  46. sed "s/#@CN@/commonName_default = server-revoked.w1.fi/" |
  47. sed "s/#@ALTNAME@/subjectAltName=critical,DNS:server-revoked.w1.fi/" \
  48. > openssl.cnf.tmp
  49. $OPENSSL req -config openssl.cnf.tmp -batch -new -newkey rsa:2048 -nodes -keyout iCA-server/server-revoked.key -out iCA-server/server-revoked.req -outform PEM -sha256
  50. $OPENSSL ca -config openssl.cnf.tmp -batch -keyfile iCA-server/private/cakey.pem -cert iCA-server/cacert.pem -create_serial -in iCA-server/server-revoked.req -out iCA-server/server-revoked.pem -extensions ext_server -md sha256
  51. $OPENSSL ca -config openssl.cnf.tmp -revoke iCA-server/server-revoked.pem -keyfile iCA-server/private/cakey.pem -cert iCA-server/cacert.pem
  52. cat iCA-server/cacert.pem iCA-server/server-revoked.pem > iCA-server/server-revoked_and_ica.pem
  53. rm openssl.cnf.tmp
  54. echo
  55. echo "---[ User ]-----------------------------------------------------------"
  56. echo
  57. cat ec-ca-openssl.cnf |
  58. sed "s/ec-ca/iCA-user/" |
  59. sed "s/#@CN@/commonName_default = user.w1.fi/" |
  60. sed "s/#@ALTNAME@/subjectAltName=critical,DNS:user.w1.fi/" \
  61. > openssl.cnf.tmp
  62. $OPENSSL req -config openssl.cnf.tmp -batch -new -newkey rsa:2048 -nodes -keyout iCA-user/user.key -out iCA-user/user.req -outform PEM -sha256
  63. $OPENSSL ca -config openssl.cnf.tmp -batch -keyfile iCA-user/private/cakey.pem -cert iCA-user/cacert.pem -create_serial -in iCA-user/user.req -out iCA-user/user.pem -extensions ext_client -md sha256
  64. cat iCA-user/user.pem iCA-user/cacert.pem > iCA-user/user_and_ica.pem
  65. rm openssl.cnf.tmp
  66. echo
  67. echo "---[ Verify ]-----------------------------------------------------------"
  68. echo
  69. $OPENSSL verify -CAfile ca.pem iCA-server/cacert.pem
  70. $OPENSSL verify -CAfile ca.pem iCA-user/cacert.pem
  71. $OPENSSL verify -CAfile ca.pem -untrusted iCA-server/cacert.pem iCA-server/server.pem
  72. $OPENSSL verify -CAfile ca.pem -untrusted iCA-server/cacert.pem iCA-server/server-revoked.pem
  73. $OPENSSL verify -CAfile ca.pem iCA-user/cacert.pem
  74. $OPENSSL verify -CAfile ca.pem -untrusted iCA-user/cacert.pem iCA-user/user.pem