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: curl -w with certs prints the whole certificate chain a server sends

Curl
~/tips/tip-curl-write-out-certs

curl -s -o /dev/null -w '%{num_certs}\n%{certs}' https://example.com/ | grep -E '^[0-9]|Subject:|Issuer:|Expire'

See every certificate in the chain, with subject, issuer and dates, from one curl command.

When a site works in one browser and fails in another, the chain is often the reason. curl can print what the server really sends, without a separate OpenSSL command.

Two write-out variables do the work: %{num_certs} counts the certificates and %{certs} prints each of them.

curl -s -o /dev/null -w '%{num_certs}\n%{certs}' https://example.com/ | grep -E '^[0-9]|Subject:|Issuer:|Expire'

For each certificate you get lines like Subject:CN = example.com, the issuer, the serial number, the extensions, Start date and Expire date, followed by the certificate itself in PEM form. The grep keeps it short; drop it to see everything.

The count is the quick check I’d look at first. A public site usually sends two or three: the server certificate plus one or two intermediates. A count of 1 on a site with a public CA usually means the intermediate is missing, which some clients forgive and others do not.

This needs curl 7.88 or newer, and the man page lists only some TLS backends that fill these variables: OpenSSL, GnuTLS, Schannel and Rustls. On another backend you get an empty value instead of an error, so an empty result does not prove there is no chain. Also note it shows what the server sent, not whether curl trusted it. The verification result is in %{ssl_verify_result}, and 0 means OK.

Further reading: curl man page, everything curl: write out

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

More Curl tips curl --trace-ascii – https://example.com/ Retry-After: 120 curl -fsS --fail-early \ url = "https://example.com/data/latest.json" curl -4 -s -o /dev/null -w '%{remote_ip} %{http_code}\n' https://example.com/ All Curl tips (71) All topics

Link