Generating a self-signed certificate is a common task and the command to generate one with openssl
is well known and well documented. Generating a certificate that includes subjectAltName is not so straght forward however. The following example demonstrates how to generate a SAN certificate without making a permanent change to the openssl configuration.
$ export SAN="DNS:www.domain.localdomain,DNS:domain.localdomain"
NOTE: On OSX [EL Capitan] the openssl configuration file path is: /System/Library/OpenSSL/openssl.cnf
instead of the RHEL/CentOS default of /etc/pki/tls/openssl.cnf
.
$ cat \
/etc/pki/tls/openssl.cnf \
- \
<<-CONFIG > /tmp/www.domain.localdomain.cnf
[ san ]
subjectAltName="${SAN:[email protected]}"
CONFIG
$ openssl req \
-x509 \
-sha256 \
-nodes \
-newkey rsa:2048 \
-days 365 \
-reqexts san \
-extensions san \
-subj "/CN=www.domain.localdomain" \
-config /tmp/www.domain.localdomain.cnf \
-keyout /etc/pki/tls/private/www.domain.localdomain.crt \
-out /etc/pki/tls/certs/www.domain.localdomain.crt
Warning! this takes a while...
$ openssl dhparam \
-out /tmp/dhparams.pem \
2048
Append the DH PARAMS to the certificate.
$ cat /tmp/dhparams.pem \
>> /etc/pki/tls/certs/www.domain.localdomain.crt
Thanks for the gist.
I think there is a typo in the command, you mentioned
while it should be