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 -showcerts saves the chain a server sends

Openssl
~/tips/tip-openssl-showcerts-save-chain

echo | openssl s_client -connect example.com:443 -servername example.com -showcerts 2>/dev/null \

Grab every certificate a server presents, so you can inspect or verify the chain offline.

By default s_client prints only the server’s own certificate. With -showcerts you get every certificate the server sends, intermediates included.

Save the whole chain to a file with awk:

echo | openssl s_client -connect example.com:443 -servername example.com -showcerts 2>/dev/null \
  | awk '/BEGIN CERTIFICATE/,/END CERTIFICATE/' > chain.pem
grep -c 'BEGIN CERTIFICATE' chain.pem

The count is the first thing I’d look at. A public site normally sends two or three. One certificate on a site that uses a public CA means the intermediate is missing, which is a common cause of errors on Android and in command line tools while desktop browsers still work.

In the normal output, the Certificate chain section lists each certificate with lines like 0 s:CN=example.com and i: for the issuer, so you can follow the chain without saving anything.

Keep -servername in the command. Without it, a server with several sites may send a default certificate that has nothing to do with the one you wanted. The echo in front closes the connection right after the handshake, otherwise s_client waits for you to type. The root certificate is normally not sent, so your file ends at the last intermediate.

Further reading: OpenSSL: openssl-s_client

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