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 x509 -fingerprint prints a certificate's SHA-256 fingerprint

Openssl
~/tips/tip-security-openssl-x509-fingerprint-sha256

openssl x509 -fingerprint -sha256 -noout -in cert.pem

Prints the SHA-256 fingerprint of a PEM certificate, for comparing with a value you trust.

A fingerprint is a short way to confirm that two people are looking at the same certificate. OpenSSL calculates it in one command.

openssl x509 -fingerprint -sha256 -noout -in cert.pem

The manual explains -fingerprint as printing the digest of the DER-encoded certificate. -noout suppresses the certificate itself so only the requested output appears, and -in names the file. Without -in, the certificate is read from standard input.

Any digest supported by openssl dgst can be selected the same way, which is why -sha256 works.

The caveat is the default. The manual says that when you use -fingerprint without a digest option, SHA1 is used. SHA-1 fingerprints are still printed by many tools, but if you compare against a SHA-256 value, say so explicitly, or the two will never match.

Also be clear about what a match proves. It shows that the certificate in your file is the one that has the fingerprint you compare it to, and that is only worth something when the reference value comes from a trusted second channel, such as the administrator of the server telling you in person. A renewed certificate gets a new fingerprint, so a changed value after a renewal is normal. Compare again with a fresh reference.

Further reading: OpenSSL: openssl-x509

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