paho_gen.sh 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # This file generates the keys and certificates used for testing mosquitto.
  2. # None of the keys are encrypted, so do not just use this script to generate
  3. # files for your own use.
  4. rm -f *.crt *.key *.csr
  5. for a in root signing; do
  6. rm -rf ${a}CA/
  7. mkdir -p ${a}CA/newcerts
  8. touch ${a}CA/index.txt
  9. echo 01 > ${a}CA/serial
  10. echo 01 > ${a}CA/crlnumber
  11. done
  12. rm -rf certs
  13. BASESUBJ="/C=GB/ST=Wiltshire/L=Salisbury/O=Paho Project/OU=Testing"
  14. SBASESUBJ="/C=GB/ST=Wiltshire/L=Salisbury/O=Paho Project/OU=Production"
  15. BBASESUBJ="/C=GB/ST=Wiltshire/L=Salisbury/O=Paho Project/OU=Bridge"
  16. BITS="2048"
  17. # The root CA
  18. openssl genrsa -out test-root-ca.key ${BITS}
  19. openssl req -new -x509 -days 30000 -key test-root-ca.key -out test-root-ca.crt -config openssl.cnf -subj "${BASESUBJ}/CN=Root CA/"
  20. # Another root CA that doesn't sign anything
  21. openssl genrsa -out test-bad-root-ca.key ${BITS}
  22. openssl req -new -x509 -days 30000 -key test-bad-root-ca.key -out test-bad-root-ca.crt -config openssl.cnf -subj "${BASESUBJ}/CN=Bad Root CA/"
  23. # This is a root CA that has the exact same details as the real root CA, but is a different key and certificate. Effectively a "fake" CA.
  24. openssl genrsa -out test-fake-root-ca.key ${BITS}
  25. openssl req -new -x509 -days 30000 -key test-fake-root-ca.key -out test-fake-root-ca.crt -config openssl.cnf -subj "${BASESUBJ}/CN=Root CA/"
  26. # An intermediate CA, signed by the root CA, used to sign server/client csrs.
  27. openssl genrsa -out test-signing-ca.key ${BITS}
  28. openssl req -out test-signing-ca.csr -key test-signing-ca.key -new -config openssl.cnf -subj "${BASESUBJ}/CN=Signing CA/"
  29. openssl ca -config openssl.cnf -name CA_root -extensions v3_ca -out test-signing-ca.crt -infiles test-signing-ca.csr
  30. # An alternative intermediate CA, signed by the root CA, not used to sign anything.
  31. openssl genrsa -out test-alt-ca.key ${BITS}
  32. openssl req -out test-alt-ca.csr -key test-alt-ca.key -new -config openssl.cnf -subj "${BASESUBJ}/CN=Alternative Signing CA/"
  33. openssl ca -config openssl.cnf -name CA_root -extensions v3_ca -out test-alt-ca.crt -infiles test-alt-ca.csr
  34. # Valid server key and certificate.
  35. openssl genrsa -out server.key ${BITS}
  36. openssl req -new -key server.key -out server.csr -config openssl.cnf -subj "${SBASESUBJ}/CN=localhost/"
  37. openssl ca -config openssl.cnf -name CA_signing -out server.crt -infiles server.csr
  38. # Expired server certificate, based on the above server key.
  39. openssl req -new -days 1 -key server.key -out server-expired.csr -config openssl.cnf -subj "${SBASESUBJ}/CN=localhost/"
  40. openssl ca -config openssl.cnf -name CA_signing -days 1 -startdate 120820000000Z -enddate 120821000000Z -out server-expired.crt -infiles server-expired.csr
  41. # Valid client key and certificate.
  42. openssl genrsa -out client.key ${BITS}
  43. openssl req -new -key client.key -out client.csr -config openssl.cnf -subj "${SBASESUBJ}/CN=test client/"
  44. openssl ca -config openssl.cnf -name CA_signing -out client.crt -infiles client.csr
  45. # Expired client certificate, based on the above client key.
  46. openssl req -new -days 1 -key client.key -out client-expired.csr -config openssl.cnf -subj "${SBASESUBJ}/CN=test client expired/"
  47. openssl ca -config openssl.cnf -name CA_signing -days 1 -startdate 120820000000Z -enddate 120821000000Z -out client-expired.crt -infiles client-expired.csr
  48. # Revoked client certificate, based on a new client key.
  49. openssl genrsa -out client-revoked.key ${BITS}
  50. openssl req -new -days 1 -key client-revoked.key -out client-revoked.csr -config openssl.cnf -subj "${SBASESUBJ}/CN=test client revoked/"
  51. openssl ca -config openssl.cnf -name CA_signing -out client-revoked.crt -infiles client-revoked.csr
  52. openssl ca -config openssl.cnf -name CA_signing -revoke client-revoked.crt
  53. openssl ca -config openssl.cnf -name CA_signing -gencrl -out crl.pem
  54. cat test-signing-ca.crt test-root-ca.crt > all-ca.crt
  55. cat client.crt client.key all-ca.crt > client.pem
  56. #mkdir certs
  57. #cp test-signing-ca.crt certs/test-signing-ca.pem
  58. #cp test-root-ca.crt certs/test-root.ca.pem
  59. c_rehash certs