gen-certs.sh 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env bash
  2. openssl genrsa 2048 > key.pem
  3. openssl req -new -batch -config test.conf -key key.pem | openssl x509 -days 3650 -req -signkey key.pem > cert.pem
  4. openssl req -x509 -config test.conf -key key.pem -sha256 -days 3650 -nodes -out cert2.pem -extensions SAN
  5. openssl genrsa 2048 > rootCA.key.pem
  6. openssl req -x509 -new -batch -config test.rootCA.conf -key rootCA.key.pem -days 1024 > rootCA.cert.pem
  7. openssl genrsa 2048 > client.key.pem
  8. 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
  9. openssl genrsa -passout pass:test123! 2048 > key_encrypted.pem
  10. openssl req -new -batch -config test.conf -key key_encrypted.pem | openssl x509 -days 3650 -req -signkey key_encrypted.pem > cert_encrypted.pem
  11. # Encrypted client key: make an unencrypted key + cert first, then wrap the same
  12. # key two ways. Mbed TLS 4.x dropped DES/PBES1, while Ubuntu's Mbed TLS 2.28 has
  13. # no PBES2-AES, so ship both and let test.cc pick by version.
  14. openssl genrsa 2048 > client_encrypted.tmp.key.pem
  15. 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
  16. openssl pkcs8 -topk8 -v2 aes-256-cbc -in client_encrypted.tmp.key.pem -passout pass:test012! -out client_encrypted.key.pem
  17. openssl pkcs8 -topk8 -v1 PBE-SHA1-3DES -in client_encrypted.tmp.key.pem -passout pass:test012! -out client_encrypted_pbes1.key.pem
  18. rm -f client_encrypted.tmp.key.pem
  19. # Certificates for IP-host hostname verification regression tests.
  20. # cert_ip_cn.pem: CN is an IPv4 literal with NO subjectAltName. An IP host must
  21. # NOT be authenticated via the CN, so verifying it against this
  22. # cert must fail.
  23. openssl req -x509 -key key.pem -sha256 -days 3650 -nodes -subj "/CN=127.0.0.1" -out cert_ip_cn.pem
  24. # cert_ipv6.pem: CN is an IPv6 literal plus an IPv6 iPAddress SAN for a
  25. # different address. The SAN address must match; the CN address
  26. # must be ignored.
  27. openssl req -x509 -key key.pem -sha256 -days 3650 -nodes -subj "/CN=::1" -addext "subjectAltName=IP:2001:db8::1" -out cert_ipv6.pem
  28. # cert_san_types.pem: the bytes of each SAN read as the other type:
  29. # DNS:a.zz is 97.46.122.122, IP:42.46.122.122 is "*.zz".
  30. openssl req -x509 -key key.pem -sha256 -days 3650 -nodes -subj "/CN=san-types" -addext "subjectAltName=DNS:a.zz,IP:42.46.122.122" -out cert_san_types.pem
  31. # cert_dns_cn.pem: CN is the DNS name the tests connect to, with NO
  32. # subjectAltName. A host is named by a SAN only (RFC 9525), so
  33. # verifying it against this cert must fail.
  34. openssl req -x509 -key key.pem -sha256 -days 3650 -nodes -subj "/CN=localhost" -out cert_dns_cn.pem
  35. # cert_wildcard_san.pem: a leftmost wildcard next to one that is not leftmost.
  36. # "*.leftmost.example.test" matches a single label; the
  37. # wildcard in "www.*.example.test" must not be honoured.
  38. openssl req -x509 -key key.pem -sha256 -days 3650 -nodes -subj "/CN=wildcard-san" -addext "subjectAltName=DNS:*.leftmost.example.test,DNS:www.*.example.test" -out cert_wildcard_san.pem
  39. # The client certs must chain to a root that openssl accepts as a CA; a root
  40. # without basicConstraints CA:TRUE makes every client-cert test fail.
  41. openssl verify -CAfile rootCA.cert.pem client.cert.pem client_encrypted.cert.pem