gen-certs.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env bash
  2. if [[ $(openssl version) =~ 3\.[2-9]\.[0-9]+ ]]; then
  3. OPENSSL_X509_FLAG='-x509v1'
  4. else
  5. OPENSSL_X509_FLAG='-x509'
  6. fi
  7. openssl genrsa 2048 > key.pem
  8. openssl req -new -batch -config test.conf -key key.pem | openssl x509 -days 3650 -req -signkey key.pem > cert.pem
  9. openssl req -x509 -config test.conf -key key.pem -sha256 -days 3650 -nodes -out cert2.pem -extensions SAN
  10. openssl genrsa 2048 > rootCA.key.pem
  11. openssl req $OPENSSL_X509_FLAG -new -batch -config test.rootCA.conf -key rootCA.key.pem -days 1024 > rootCA.cert.pem
  12. openssl genrsa 2048 > client.key.pem
  13. openssl req -new -batch -config test.conf -key client.key.pem | openssl x509 -days 370 -req -CA rootCA.cert.pem -CAkey rootCA.key.pem -CAcreateserial > client.cert.pem
  14. openssl genrsa -passout pass:test123! 2048 > key_encrypted.pem
  15. openssl req -new -batch -config test.conf -key key_encrypted.pem | openssl x509 -days 3650 -req -signkey key_encrypted.pem > cert_encrypted.pem
  16. # Encrypted client key: make an unencrypted key + cert first, then wrap the same
  17. # key two ways. Mbed TLS 4.x dropped DES/PBES1, while Ubuntu's Mbed TLS 2.28 has
  18. # no PBES2-AES, so ship both and let test.cc pick by version.
  19. openssl genrsa 2048 > client_encrypted.tmp.key.pem
  20. openssl req -new -batch -config test.conf -key client_encrypted.tmp.key.pem | openssl x509 -days 370 -req -CA rootCA.cert.pem -CAkey rootCA.key.pem -CAcreateserial > client_encrypted.cert.pem
  21. openssl pkcs8 -topk8 -v2 aes-256-cbc -in client_encrypted.tmp.key.pem -passout pass:test012! -out client_encrypted.key.pem
  22. openssl pkcs8 -topk8 -v1 PBE-SHA1-3DES -in client_encrypted.tmp.key.pem -passout pass:test012! -out client_encrypted_pbes1.key.pem
  23. rm -f client_encrypted.tmp.key.pem
  24. # Certificates for IP-host hostname verification regression tests.
  25. # cert_ip_cn.pem: CN is an IPv4 literal with NO subjectAltName. An IP host must
  26. # NOT be authenticated via the CN, so verifying it against this
  27. # cert must fail.
  28. openssl req -x509 -key key.pem -sha256 -days 3650 -nodes -subj "/CN=127.0.0.1" -out cert_ip_cn.pem
  29. # cert_ipv6.pem: CN is an IPv6 literal plus an IPv6 iPAddress SAN for a
  30. # different address. The SAN address must match; the CN address
  31. # must be ignored.
  32. openssl req -x509 -key key.pem -sha256 -days 3650 -nodes -subj "/CN=::1" -addext "subjectAltName=IP:2001:db8::1" -out cert_ipv6.pem