Do key and certificate belong together?

A certificate contains the public key. Derive it from the private key as well, and both checksums must be identical:

openssl x509 -in cert.pem -noout -pubkey | openssl sha256 openssl pkey -in privkey.pem -pubout | openssl sha256

This comparison works for RSA, EC and Ed25519. The often quoted comparison via -modulus only works for RSA — on an EC certificate it produces an error that is easily misread as “does not match”.

With a mismatched pair Postfix logs private key in … does not match public key in …: disabling TLS support and stops offering TLS — senders then see 454 4.7.0 TLS not available.

Does the CSR belong to the key?

When several keys are lying around and it is unclear which one the request was made with — the same checksum from the CSR:

openssl req -in mail.csr -noout -pubkey | openssl sha256

Is the chain complete?

openssl verify -untrusted chain.pem cert.pem cert.pem: OK

-untrusted passes the intermediates, the root comes from the system store — exactly as for the sender verifying your server. Typical errors:

  • unable to get local issuer certificate — an intermediate is missing or the wrong one.
  • certificate has expired — the certificate or a link in the chain has expired.
  • self-signed certificate — no issuer other than itself.

For a private CA instead of the system roots: openssl verify -CAfile own-ca.pem -untrusted chain.pem cert.pem.

Name, issuer and validity

openssl x509 -in cert.pem -noout -subject -issuer -dates -ext subjectAltName

The MX hostname must appear under Subject Alternative Name — hardly any client still evaluates the CN in the subject. Why it has to be the name from the MX record and not the website's is covered in Set up the MX certificate.

Does it expire within the next 30 days? Exit code 1 means yes — which makes it easy to use in a monitoring script:

openssl x509 -in cert.pem -noout -checkend 2592000

The fingerprint to compare with what the CA shows: openssl x509 -in cert.pem -noout -fingerprint -sha256.

Is the server serving the new certificate?

Forget a reload and the service keeps working with the old one. What senders actually see comes straight from the server:

openssl s_client -starttls smtp -connect mail.yourdomain.com:25 -servername mail.yourdomain.com </dev/null 2>/dev/null | openssl x509 -noout -fingerprint -sha256 -dates

If the fingerprint matches the file's, the switch is complete. The same check with every detail — chain, SAN, key, TLS version — is what the MX check does.

Verify your work

A test mail through your mail server to hello@analyzemy.email shows how it looks from outside: TLS path, SPF, DKIM, DMARC and blacklists in one report.

Analyze your email now

Last updated: · All guides