brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: openssl req -addext puts extra host names in a certificate request

Openssl
~/tips/tip-openssl-req-csr-addext

openssl req -new -key site.key \

Make a CSR with several Subject Alternative Names in one line, without a config file.

Requesting a certificate for more than one name used to mean editing an openssl.cnf. Since OpenSSL 1.1.1, -addext does it on the command line.

Make a key and a certificate signing request in two steps:

openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out site.key
openssl req -new -key site.key \
  -subj "/CN=nas.example.com" \
  -addext "subjectAltName=DNS:nas.example.com,DNS:www.example.com,IP:192.0.2.10" \
  -out site.csr

The -subj sets the subject, so OpenSSL does not ask questions, and -addext adds the SAN list. Several names go in one comma separated value, and IP addresses take the IP: prefix.

Check the result before you send it anywhere:

openssl req -in site.csr -noout -text | grep -A1 'Alternative'

I find this handy for a private CA or for a provider that still wants a CSR pasted into a web form. Public CAs validate every name in the list, so only add names you control.

A CA does not have to copy your extensions. Some take only the names you type in their form, and a private CA signing with openssl x509 -req drops them unless told to copy them. So check the issued certificate too, not just the request. Keep site.key private; the CSR is the only file that leaves your machine.

Further reading: OpenSSL: openssl-req

Going deeper: Run degoog on Unraid as your own search page, compared with SearXNG and 4get

More Openssl tips openssl s_client -connect 203.0.113.10:443 -servername example.com </dev/null | openssl x509 -noout -subject openssl x509 -in cert.pem -days 365 -signkey key.pem -out cert-new.pem printf %s hello | openssl dgst -sha256 -hmac secret openssl pkcs12 -legacy -in old.pfx -nokeys echo 'aGVsbG8gd29ybGQ=' | openssl base64 -d All Openssl tips (34) All topics

Link