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 s_client -servername shows which certificate a shared IP serves

Openssl
~/tips/tip-openssl-s-client-servername-sni

openssl s_client -connect 203.0.113.10:443 -servername example.com </dev/null | openssl x509 -noout -subject

Sends a chosen host name in the TLS handshake so you see that site's certificate.

One IP address can serve many HTTPS sites. The server decides which certificate to send from a name the client puts in the handshake. When a site shows the wrong certificate, I want to control that name myself.

openssl s_client -connect 203.0.113.10:443 -servername example.com </dev/null | openssl x509 -noout -subject

-servername sets the TLS SNI extension (Server Name Indication) in the ClientHello. If you leave it out, the docs say SNI is filled with the name you gave to -connect, as long as that looks like a DNS name. If -connect is missing too, it is set to localhost. That is why connecting to a bare IP address sends no useful name, and a server with several sites on it may answer with a default certificate.

I did run a local test with openssl s_server holding two certificates. Without -servername I got the default one. With -servername other.test I got the other one. Same IP, same port, different subject.

Two details. The name is sent whether or not it is a DNS name, even an IP address. And -noservername does the opposite and leaves the extension out, which is a quick way to see what a server does for clients that send no name. You can’t combine the two options.

This also helps when you test a new server before DNS points to it. Connect to the new IP and pass the real name with -servername.

Further reading: openssl-s_client documentation

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

More Openssl tips 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 | openssl s_client -connect example.com:443 -servername example.com -quiet -keylogfile keys.log All Openssl tips (34) All topics

Link