Certificate Chains: Why a Valid SSL Cert Still Fails
A certificate can be unexpired, issued to the correct hostname, and still produce NET::ERR_CERT_AUTHORITY_INVALID in Chrome and curl: (60) SSL certificate problem: unable to verify the first certificate from a server. The certificate is usually fine. What surrounds it is not.
Three checks, three different failure messages
When a TLS client validates your site it performs three independent checks. Knowing which one failed saves an hour of guessing:
- Trust — the chain leads to a root certificate in the client's trust store. Failure:
ERR_CERT_AUTHORITY_INVALID,unable to get local issuer certificate. - Identity — the Subject Alternative Name contains the hostname you requested. Failure:
ERR_CERT_COMMON_NAME_INVALID. - Validity — every certificate in the chain is inside its own date window. Failure:
ERR_CERT_DATE_INVALID,certificate has expired.
Most production incidents that get labelled "expired certificate" are actually the first one.
What the chain actually looks like
A chain is three layers: a root certificate (self-signed, shipped inside operating systems and browsers), one or more intermediates (signed by the root), and your leaf certificate (signed by an intermediate). Your server must send the leaf plus every intermediate above it. It must not send the root: the client already has it, and sending it wastes roughly 1.5 KB on every handshake.
Forgetting the intermediate is the single most common misconfiguration. The leaf looks perfect in openssl x509 -text, the dates are fine, the SAN matches, and yet half your users get a browser warning.
Why it works on your laptop and fails on a phone
Browsers cache intermediates they have seen from other sites signed by the same CA, and several platforms fall back to the AIA URL embedded in your leaf to download the missing issuer. A dev machine that browses a lot of HTTPS has those intermediates in cache. A freshly imaged Android device, a Java client with a pinned trust store, a Go binary or a strict CI check does not — and those are the clients that page you at 2 a.m.
So never test the chain from the machine that built it. Test from outside:
openssl s_client -connect example.com:443 -servername example.com -showcerts < /dev/null
Count the -----BEGIN CERTIFICATE----- blocks in the output. One block means you are only sending the leaf and every strict client will reject you. Two or three is normal.
Decoding the verify errors
20 unable to get local issuer certificate— the intermediate is missing or you attached the wrong one for this leaf.21 unable to verify the first certificate— the same root cause, reported by OpenSSL when no CA bundle is supplied. This is the message curl and most language runtimes print.10 certificate has expired— something in the chain is out of date. Check every certificate, not just the first one; an intermediate expiring takes the site down exactly like a leaf does.2 unable to get issuer certificate— usually a chain written in the wrong order, so the verifier cannot follow issuer links.
Order matters more than people expect
A PEM bundle must be ordered leaf first, then each issuer. Nginx reads ssl_certificate fullchain.pem as one ordered file. Apache wants the leaf in SSLCertificateFile and the intermediates either appended to it or in SSLCertificateChainFile. Reverse the order and some clients break while Chrome quietly repairs the chain, which is exactly why the bug survives review.
SNI: testing the wrong virtual host
On a server with several vhosts, a connection without SNI gets the default vhost's certificate. If you run openssl s_client -connect 203.0.113.10:443 and see the wrong name, you have learned nothing about your site. Always pass -servername with the exact hostname you are debugging, and test www and the apex separately — they are often served by different vhosts with different certificates.
Expiry is a chain-wide property
In September 2021 the DST Root CA X3 cross-sign expired and Let's Encrypt sites stopped loading on Android 7.1.1 and older, while desktop browsers kept working because they trusted the newer ISRG Root X1. Nothing on the leaf had changed. Monitoring that only reads the leaf's notAfter misses this entire class of outage, so collect dates for every certificate the server presents and alert on the earliest one.
A five-minute checklist
- Fetch the chain from outside the network with
-showcerts; confirm leaf plus at least one intermediate. - Verify against a clean bundle:
openssl verify -CAfile /etc/ssl/certs/ca-certificates.crt -untrusted chain.pem leaf.pemshould printleaf.pem: OK. - Print dates for each certificate in the file, not only the first.
- Confirm the served certificate matches the hostname — with SNI, for apex and www.
- Reproduce from a container or a device with an untouched trust store before declaring the fix done.
If step 2 fails while step 1 shows two certificates, you are almost certainly sending the wrong intermediate. Download the full chain from your CA's repository rather than assembling it by hand; CAs rotate intermediates, and the copy in a 2021 blog post is not the one that signs your current leaf.
Where the hosted tools fit
The SSL certificate checker fetches the chain the way a strict client does and reports the issuer, SANs and validity window per certificate, which is faster than reading raw OpenSSL output on a phone. When the certificate is fine but the site still behaves oddly, HTTP headers inspector shows whether HSTS and the redirect to HTTPS are actually in place, and DNS lookup tells you whether a proxy or CDN terminates TLS in front of your origin — the certificate you fixed on the server may not be the one visitors see. Finally, HTTP availability checker confirms that plain HTTP still redirects correctly after the TLS change, because a broken redirect chain turns one outage into two.