How do we remove the incorrect banner about the duplicate question?
This question is not a duplicate of Why does requestjs reject a self-signed SSL certificate that works with Firefox?. While the answer to that question may result in a similar config file, that question was not using DNS:
in the subjectAltName
. This is a key point because all of the examples we can easily find with Google are using DNS:
, which doesn't work for IP addresses.
This question is not a duplicate of Exception on using IP address in certificate name. While the answer to that question may result in a similar config file, that question was missing subjectAltName
altogether.
This question is also not a duplicate of Using ip address for common name in server certificate does not work in Android? for the same reason.
Back to the actual question
I want to write an SSL server that responds to both localhost
and 127.0.0.1
. Various websites say that this can be achieved using subjectAltName
. So I created a server certificate using the following openssl
configuration file:
distinguished_name = dn
x509_extensions = v3_ca
[req]
prompt = no
[dn]
0.CN = localhost
1.CN = 127.0.0.1
[v3_ca]
subjectAltName = DNS:localhost,DNS:127.0.0.1
The subjectAltName
is being sent by the server. For example, as verified by s_client
:
% echo | openssl s_client -showcerts -CAfile keys/cert.pem -connect localhost:8443 | grep -i -A 2 certificate
depth=0 CN = localhost, CN = 127.0.0.1
verify return:1
DONE
Certificate chain
0 s:/CN=localhost/CN=127.0.0.1
i:/CN=localhost/CN=127.0.0.1
-----BEGIN CERTIFICATE-----
MIIC9jCCAd6gAwIBAgIJANlipKdvxVlUMA0GCSqGSIb3DQEBCwUAMCgxEjAQBgNV
BAMMCWxvY2FsaG9zdDESMBAGA1UEAwwJMTI3LjAuMC4xMB4XDTE5MDcyMzAxMjcw
--
-----END CERTIFICATE-----
---
Server certificate
subject=/CN=localhost/CN=127.0.0.1
issuer=/CN=localhost/CN=127.0.0.1
--
No client certificate CA names sent
Peer signing digest: SHA512
Server Temp Key: X25519, 253 bits
We can also verify it with a simple Python client, which reports:
Cipher is ECDHE-RSA-AES256-GCM-SHA384, SSL protocol is TLSv1.2, bits=256
Peer cert is {'subjectAltName': (('DNS', 'localhost'), ('DNS', '127.0.0.1')), 'notBefore': u'Jul 23 01:27:02 2019 GMT', 'serialNumber': u'D962A4A76FC55954', 'notAfter': 'Jul 22 01:27:02 2020 GMT', 'version': 3L, 'subject': ((('commonName', u'localhost'),), (('commonName', u'127.0.0.1'),)), 'issuer': ((('commonName', u'localhost'),), (('commonName', u'127.0.0.1'),))}
Hello from SSL server!
Unfortunately, curl
recognizes only the first name:
% curl --cacert keys/cert.pem https://localhost:8443
Hello from SSL server!
% curl --cacert keys/cert.pem https://127.0.0.1:8443
curl: (51) SSL: no alternative certificate subject name matches target host name '127.0.0.1'
%
How do we get curl
(and other programs) to heed the subjectAltName
, the whole subjectAltName
, and nothing but the subjectAltName
?
Update
Maybe it works with this:
distinguished_name = dn
x509_extensions = v3_ca
[req]
prompt = no
[dn]
CN = IGNORED
[v3_ca]
subjectAltName = DNS:localhost,IP:127.0.0.1
Is this stuff, like, documented anywhere?