mkacerts.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/sh
  2. # Recreate the demo certificates in the apps directory.
  3. opensslcmd() {
  4. LD_LIBRARY_PATH=../../.. ../../../apps/openssl $@
  5. }
  6. opensslcmd version
  7. # Root CA: create certificate directly
  8. CN="OpenSSL Test Root CA" opensslcmd req -config apps.cnf -x509 -nodes \
  9. -keyout root.pem -out root.pem -key rootkey.pem -new -days 3650
  10. # Intermediate CA: request first
  11. CN="OpenSSL Test Intermediate CA" opensslcmd req -config apps.cnf -nodes \
  12. -key intkey.pem -out intreq.pem -new
  13. # Sign request: CA extensions
  14. opensslcmd x509 -req -in intreq.pem -CA root.pem -CAkey rootkey.pem -days 3630 \
  15. -extfile apps.cnf -extensions v3_ca -CAcreateserial -out intca.pem
  16. # Client certificate: request first
  17. CN="Test Client Cert" opensslcmd req -config apps.cnf -nodes \
  18. -key ckey.pem -out creq.pem -new
  19. # Sign using intermediate CA
  20. opensslcmd x509 -req -in creq.pem -CA intca.pem -CAkey intkey.pem -days 3600 \
  21. -extfile apps.cnf -extensions usr_cert -CAcreateserial | \
  22. opensslcmd x509 -nameopt oneline -subject -issuer >client.pem
  23. # Server certificate: request first
  24. CN="Test Server Cert" opensslcmd req -config apps.cnf -nodes \
  25. -key skey.pem -out sreq.pem -new
  26. # Sign using intermediate CA
  27. opensslcmd x509 -req -in sreq.pem -CA intca.pem -CAkey intkey.pem -days 3600 \
  28. -extfile apps.cnf -extensions usr_cert -CAcreateserial | \
  29. opensslcmd x509 -nameopt oneline -subject -issuer >server.pem
  30. # Server certificate #2: request first
  31. CN="Test Server Cert #2" opensslcmd req -config apps.cnf -nodes \
  32. -key skey2.pem -out sreq2.pem -new
  33. # Sign using intermediate CA
  34. opensslcmd x509 -req -in sreq2.pem -CA intca.pem -CAkey intkey.pem -days 3600 \
  35. -extfile apps.cnf -extensions usr_cert -CAcreateserial | \
  36. opensslcmd x509 -nameopt oneline -subject -issuer >server2.pem
  37. # Append keys to file.
  38. cat skey.pem >>server.pem
  39. cat skey2.pem >>server2.pem
  40. cat ckey.pem >>client.pem
  41. opensslcmd verify -CAfile root.pem -untrusted intca.pem \
  42. server2.pem server.pem client.pem