2
0

mksmime-certs.sh 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/sh
  2. # Utility to recreate S/MIME certificates
  3. OPENSSL=../../apps/openssl
  4. OPENSSL_CONF=./ca.cnf
  5. export OPENSSL_CONF
  6. # Root CA: create certificate directly
  7. CN="Test S/MIME RSA Root" $OPENSSL req -config ca.cnf -x509 -nodes \
  8. -keyout smroot.pem -out smroot.pem -newkey rsa:2048 -days 3650
  9. # EE RSA certificates: create request first
  10. CN="Test S/MIME EE RSA #1" $OPENSSL req -config ca.cnf -nodes \
  11. -keyout smrsa1.pem -out req.pem -newkey rsa:2048
  12. # Sign request: end entity extensions
  13. $OPENSSL x509 -req -in req.pem -CA smroot.pem -days 3600 \
  14. -extfile ca.cnf -extensions usr_cert -CAcreateserial >>smrsa1.pem
  15. CN="Test S/MIME EE RSA #2" $OPENSSL req -config ca.cnf -nodes \
  16. -keyout smrsa2.pem -out req.pem -newkey rsa:2048
  17. $OPENSSL x509 -req -in req.pem -CA smroot.pem -days 3600 \
  18. -extfile ca.cnf -extensions usr_cert -CAcreateserial >>smrsa2.pem
  19. CN="Test S/MIME EE RSA #3" $OPENSSL req -config ca.cnf -nodes \
  20. -keyout smrsa3.pem -out req.pem -newkey rsa:2048
  21. $OPENSSL x509 -req -in req.pem -CA smroot.pem -days 3600 \
  22. -extfile ca.cnf -extensions usr_cert -CAcreateserial >>smrsa3.pem
  23. # Create DSA parameters
  24. $OPENSSL dsaparam -out dsap.pem 2048
  25. CN="Test S/MIME EE DSA #1" $OPENSSL req -config ca.cnf -nodes \
  26. -keyout smdsa1.pem -out req.pem -newkey dsa:dsap.pem
  27. $OPENSSL x509 -req -in req.pem -CA smroot.pem -days 3600 \
  28. -extfile ca.cnf -extensions usr_cert -CAcreateserial >>smdsa1.pem
  29. CN="Test S/MIME EE DSA #2" $OPENSSL req -config ca.cnf -nodes \
  30. -keyout smdsa2.pem -out req.pem -newkey dsa:dsap.pem
  31. $OPENSSL x509 -req -in req.pem -CA smroot.pem -days 3600 \
  32. -extfile ca.cnf -extensions usr_cert -CAcreateserial >>smdsa2.pem
  33. CN="Test S/MIME EE DSA #3" $OPENSSL req -config ca.cnf -nodes \
  34. -keyout smdsa3.pem -out req.pem -newkey dsa:dsap.pem
  35. $OPENSSL x509 -req -in req.pem -CA smroot.pem -days 3600 \
  36. -extfile ca.cnf -extensions usr_cert -CAcreateserial >>smdsa3.pem
  37. # Create EC parameters
  38. $OPENSSL ecparam -out ecp.pem -name P-256
  39. $OPENSSL ecparam -out ecp2.pem -name K-283
  40. CN="Test S/MIME EE EC #1" $OPENSSL req -config ca.cnf -nodes \
  41. -keyout smec1.pem -out req.pem -newkey ec:ecp.pem
  42. $OPENSSL x509 -req -in req.pem -CA smroot.pem -days 3600 \
  43. -extfile ca.cnf -extensions usr_cert -CAcreateserial >>smec1.pem
  44. CN="Test S/MIME EE EC #2" $OPENSSL req -config ca.cnf -nodes \
  45. -keyout smec2.pem -out req.pem -newkey ec:ecp2.pem
  46. $OPENSSL x509 -req -in req.pem -CA smroot.pem -days 3600 \
  47. -extfile ca.cnf -extensions usr_cert -CAcreateserial >>smec2.pem
  48. # Create X9.42 DH parameters.
  49. $OPENSSL genpkey -genparam -algorithm DH -pkeyopt dh_paramgen_type:2 \
  50. -out dhp.pem
  51. # Generate X9.42 DH key.
  52. $OPENSSL genpkey -paramfile dhp.pem -out smdh.pem
  53. $OPENSSL pkey -pubout -in smdh.pem -out dhpub.pem
  54. # Generate dummy request.
  55. CN="Test S/MIME EE DH #1" $OPENSSL req -config ca.cnf -nodes \
  56. -keyout smtmp.pem -out req.pem -newkey rsa:2048
  57. # Sign request but force public key to DH
  58. $OPENSSL x509 -req -in req.pem -CA smroot.pem -days 3600 \
  59. -force_pubkey dhpub.pem \
  60. -extfile ca.cnf -extensions usr_cert -CAcreateserial >>smdh.pem
  61. # Remove temp files.
  62. rm -f req.pem ecp.pem ecp2.pem dsap.pem dhp.pem dhpub.pem smtmp.pem smroot.srl