gen_cert.sh 915 B

123456789101112131415161718192021
  1. #! /bin/bash
  2. # TODO: `rustls` (really, `webpki`) doesn't currently use the CN in the subject
  3. # to check if a certificate is valid for a server name sent via SNI. It's not
  4. # clear if this is intended, since certificates _should_ have a `subjectAltName`
  5. # with a DNS name, or if it simply hasn't been implemented yet. See
  6. # https://bugzilla.mozilla.org/show_bug.cgi?id=552346 for a bit more info.
  7. CA_SUBJECT="/C=UK/O=Dim CA/CN=Dim Labs CA"
  8. SUBJECT="/C=UK/O=Dim/CN=localhost"
  9. ALT="DNS:localhost"
  10. openssl genrsa -out ca_key.pem 4096
  11. openssl req -new -x509 -days 3650 -key ca_key.pem -subj "${CA_SUBJECT}" -out ca_cert.pem
  12. openssl req -newkey rsa:4096 -nodes -sha256 -keyout key.pem -subj "${SUBJECT}" -out server.csr
  13. openssl x509 -req -sha256 -extfile <(printf "subjectAltName=${ALT}") -days 3650 \
  14. -CA ca_cert.pem -CAkey ca_key.pem -CAcreateserial \
  15. -in server.csr -out cert.pem
  16. rm ca_cert.srl server.csr