TLSx509certificatecachainintermediate

Certificates and the Chain of Trust

A certificate binds a hostname to a public key with a signature from an issuer the client already trusts; the client walks leaf → intermediate → root, checks names, dates and signatures, and every classic TLS outage is one of those checks failing.

Conceptual
▶ InteractiveInterview question
Progress

Builds on TCP and DNS in the Networking roadmap.

The problem

Key agreement gives two parties a shared secret, but not knowledge of who the other party is. The browser has never seen api.example.com’s public key before. How can it decide, offline and in microseconds, that a key presented by a stranger really belongs to that name — and how does that decision get revoked when the key is stolen?

What a certificate says

An X.509 certificate is a signed statement: "issuer *I* asserts that public key *K* belongs to subject *S*, valid from *t₁* to *t₂*". The parts that matter for TLS are the Subject Alternative Name extension listing the DNS names (and IPs) the certificate is valid for, the public key, the validity period, the issuer name, key usage flags, and the issuer’s signature over all of it. The Common Name field in the subject is historical; browsers have ignored it for hostname matching since around 2017 and only SANs count.

The signature is what makes the statement checkable: anyone with the issuer’s public key can verify it, and nobody without the issuer’s private key can forge it. So the question "is this key really api.example.com’s?" becomes "do I trust the issuer, and did the issuer really sign this?" — which is the same question one level up.

The fields that matter, from `openssl x509 -in leaf.pem -noout -text` (trimmed)
Certificate:
    Data:
        Serial Number: 04:a1:...:9c
        Signature Algorithm: ecdsa-with-SHA384
        Issuer: C = US, O = Let's Encrypt, CN = E6
        Validity
            Not Before: Jun 12 09:14:33 2026 GMT
            Not After : Sep 10 09:14:32 2026 GMT
        Subject: CN = api.example.com
        Subject Public Key Info:
            Public Key Algorithm: id-ecPublicKey  (P-256)
        X509v3 extensions:
            X509v3 Subject Alternative Name:
                DNS:api.example.com, DNS:www.example.com
            X509v3 Key Usage: critical  Digital Signature
            X509v3 Extended Key Usage:  TLS Web Server Authentication
            Authority Information Access:
                OCSP - URI:http://e6.o.lencr.org
                CA Issuers - URI:http://e6.i.lencr.org/
            CT Precertificate SCTs: ...

The chain: leaf → intermediate → root

Conceptual

The recursion terminates at a root certificate that is self-signed and trusted not because of any signature but because it ships in the client’s trust store — the OS store (Windows, macOS, Android), Mozilla’s NSS bundle (Firefox, and the source of ca-certificates on most Linux distributions), or a language-runtime bundle (Java’s cacerts, Python’s certifi, Node’s compiled-in Mozilla list). Roots are kept offline and precious; they sign a handful of intermediate CAs, and intermediates sign the millions of leaf certificates servers present.

During the The TLS Handshake the server sends the leaf and the intermediates — not the root, which the client must already have. The client builds a path: leaf’s issuer must be the intermediate’s subject, the intermediate’s signature over the leaf must verify, the intermediate’s issuer must be a root in the store, and so on. Each certificate’s validity window, key usage and name constraints are checked along the way. A missing intermediate is the single most common chain misconfiguration, and it fails inconsistently: browsers often fetch the missing certificate via the AIA URL or have it cached, while curl, Java and mobile apps do not.

Hostname validation is the last step: the name the client connected to must match a SAN entry. A wildcard *.example.com matches exactly one label — api.example.com but not example.com and not a.b.example.com. IP addresses must appear as IP: SANs; connecting to a server by IP with a DNS-only certificate fails even when everything else is fine.

Verification walks upward until it hits something already trusted
  1. Leaf: CN=api.example.com, SAN: api.example.comSent by the server; signed by the intermediate; must match the hostname and be within validity
    ↓
  2. Intermediate: Let’s Encrypt E6Sent by the server; signed by the root; missing it is the classic "works in Chrome, fails in curl"
    ↓
  3. Root: ISRG Root X1Not sent; must already be in the client trust store; self-signed
    ↓
  4. Trust storeOS, Mozilla/NSS, Java cacerts, certifi — different clients consult different stores

Revocation, and why it is weak

A certificate is valid until Not After regardless of what happens to the key. If the private key leaks, the issuer needs a way to say "no longer trust this one". Two mechanisms exist. A CRL is a signed list of revoked serial numbers published by the CA — simple, but large and slow to propagate, and a client must download it. OCSP lets the client ask the CA about one serial in real time, which leaks browsing history to the CA and adds a network round trip to every handshake.

Both mechanisms fail open in practice. If the OCSP responder is unreachable, browsers soft-fail and proceed, because a hard failure would let anyone who can block one URL take down every site using that CA. An attacker with a stolen key and on-path position can block the OCSP check, which is exactly the situation revocation was meant to cover. OCSP stapling helps: the server fetches a signed OCSP response periodically and sends it in the handshake, removing the client round trip and the privacy leak; Must-Staple in the certificate turns a missing staple into a hard failure, but it is rarely used.

The industry’s practical answer has been short lifetimes: Let’s Encrypt certificates last 90 days (with 6-day certificates being introduced), and the browser-CA forum has agreed to reduce the maximum public certificate lifetime to 47 days by 2029. A key that is only valid for days limits the damage of a leak without depending on a check that fails open. Browsers meanwhile push aggregated revocation data (Chrome’s CRLSets, Firefox’s CRLite) rather than querying per site.

  • CRL: signed list, fetched by the client, stale by design.
  • OCSP: per-certificate query, privacy leak, soft-fails when blocked — so an on-path attacker can suppress it.
  • OCSP stapling: server includes the response; Must-Staple makes its absence fatal.
  • Short-lived certificates make revocation nearly moot: the window is days, not a year.

Getting certificates: ACME and automation

Node.js

Before 2015 a certificate meant a purchase, a manual CSR, an email validation and a person pasting files onto a server once a year — and forgetting to, which is why expired certificates were the most common TLS outage. Let’s Encrypt made issuance free and the ACME protocol (RFC 8555) made it automatic: the client proves control of the domain by serving a token at /.well-known/acme-challenge/ (HTTP-01) or publishing a _acme-challenge TXT record (DNS-01, the only option for wildcards), and receives a certificate minutes later. Clients such as certbot, acme.sh, Caddy (built in) and Kubernetes’ cert-manager renew at two-thirds of the lifetime without human involvement.

Every publicly trusted certificate is also logged to Certificate Transparency logs before browsers accept it — the SCTs in the extensions above — so a misissued certificate for your domain is publicly visible; monitoring CT for your names is how you find out a CA or a colleague issued one you did not expect.

The remaining operational work is making renewal *observable*: an alert on days-to-expiry (from an external probe, not from the box that is supposed to renew) catches the case where the automation is broken and nobody noticed — a renewed certificate that was never reloaded into the running process is the modern form of the old outage.

Read what the server actually presented — the first step in any certificate incident
1import tls from 'node:tls'
2
3const socket = tls.connect({ host: 'api.example.com', port: 443, servername: 'api.example.com' }, () => {
4 const cert = socket.getPeerCertificate(true) // true → include the issuer chain
5 console.log(cert.subjectaltname) // 'DNS:api.example.com, DNS:www.example.com'
6 console.log(cert.valid_to) // 'Sep 10 09:14:32 2026 GMT'
7 console.log(cert.issuerCertificate?.subject) // the intermediate the server sent (or the leaf itself if none)
8 console.log(socket.authorized, socket.authorizationError) // false + 'CERT_HAS_EXPIRED' etc.
9 socket.end()
10})

The classic failures

Almost every certificate incident is one of six shapes, and each has a recognisable error string. Learn the strings; they tell you which check failed and therefore where to look.

Failure → what the client says → cause
FailureTypical errorCause and fix
ExpiredChrome ERR_CERT_DATE_INVALID; curl certificate has expired; Node CERT_HAS_EXPIREDRenewal did not run, or ran but the process never reloaded the file. Alert on expiry from outside.
Hostname mismatchChrome ERR_CERT_COMMON_NAME_INVALID; curl subject alternative name does not match; Node ERR_TLS_CERT_ALTNAME_INVALIDConnected to a name not in the SANs: bare domain vs www, wildcard depth, connecting by IP, SNI not sent so the default cert was served.
Missing intermediatecurl unable to get local issuer certificate; Java PKIX path building failed; browsers often succeedServer sends only the leaf. Concatenate leaf + intermediate(s) in the served chain (fullchain.pem).
Wrong system clockEverything looks "not yet valid" or "expired"Embedded devices, VMs resumed from snapshot, containers with a broken clock. Check date before blaming the CA.
Self-signed in developmentself-signed certificate / DEPTH_ZERO_SELF_SIGNED_CERTAdd the dev CA to the trust store (mkcert), never disable verification globally.
Corporate inspection proxyBrowser works; pip, npm, Docker and Go tools fail with unknown issuerThe proxy re-signs every site with its own CA, pushed to the OS store; tools with their own bundle (certifi, Java) do not have it. Add the proxy CA to those bundles.

Key points

  • A certificate is a signed binding of hostname(s) to a public key with a validity window; only SANs count for hostname matching.
  • The client verifies leaf → intermediate → root, where the root must already be in its trust store; servers send the leaf and intermediates, never the root.
  • Different clients consult different trust stores (OS, Mozilla, Java, certifi), which is why the browser and your script can disagree.
  • Wildcards match one label; IPs need IP: SANs; SNI decides which certificate a shared server presents.
  • Revocation via CRL/OCSP soft-fails and is easily suppressed; stapling helps, short-lived certificates help more.
  • ACME made issuance and renewal automatic; the remaining failure is renewal that silently stopped, so alert on expiry from outside.
  • Six failure shapes cover nearly every incident: expired, mismatch, missing intermediate, bad clock, self-signed, inspection proxy.

Why does this exist?

Mechanisms are answers to constraints. Open each question before reading the answer.

▸Why a chain instead of one signature from a root?

Roots must live offline and change rarely because every client ships them; signing millions of leaves needs an online key. Intermediates are the online, revocable, replaceable layer between the two.

▸Why does the server send the intermediates instead of the client fetching them?

Because the client should not need extra network round trips (or a plaintext HTTP fetch) in the middle of establishing a secure channel. AIA fetching exists as a browser fallback, which is exactly why a missing intermediate "works in Chrome" and fails everywhere else.

▸Why did the industry move to short-lived certificates rather than fixing revocation?

Every revocation check either adds latency and a privacy leak (OCSP) or fails open when blocked. Short validity bounds the damage of a leaked key without a runtime check, and automation made short lifetimes operationally free.

▸Why does `mkcert` or a dev CA beat disabling verification?

Disabling verification is usually a global switch that survives into staging and production configs; a local root trusted only by your machine keeps the same code path as production and fails loudly if the wrong certificate is served.

Certificate chain

Certificate chain validation
The client checks the leaf against the name it asked for, the clock, the chain of signatures back to a root it already trusts, and revocation. Break something and read what the browser and curl say.
Break
Client
Educational model
CN=engineer-atlas.devserved by the server
issuer CN=Atlas R3
SAN engineer-atlas.dev, www.engineer-atlas.dev
valid 2026-06-01 → 2026-08-30
↑ signed by
CN=Atlas R3served by the server
issuer CN=Atlas Root X1
valid 2024-03-01 → 2029-03-01
↑ signed by
CN=Atlas Root X1OS / browser trust store
issuer CN=Atlas Root X1 (self)
valid 2015-01-01 → 2035-01-01
  1. 0. Server presents its chainok
    2 certificate(s) in the Certificate message: CN=engineer-atlas.dev → CN=Atlas R3
  2. 1. Hostname matches a SAN?
  3. 2. Every certificate valid at the system clock?
  4. 3. Signatures verify up to a trusted root?
  5. 4. Not revoked (OCSP stapling)?
$ openssl s_client -connect engineer-atlas.dev:443 -servername engineer-atlas.dev </dev/null
Certificate chain
 0 s:CN=engineer-atlas.dev
   i:CN=Atlas R3
 1 s:CN=Atlas R3
   i:CN=Atlas Root X1
---
Verify return code: 0 (ok)
1/6 · Server presents its chain

How it fails

What the failure looks like from inside real software.
Reference · show
  • The certificate was renewed on disk but nginx/HAProxy/the Node process was never reloaded; probes from outside show the old expiry while the box says it is fine.
  • A new microservice fails with unable to get local issuer certificate while browsers load the same host — the served chain lacks the intermediate.
  • Mobile app with certificate pinning breaks when the CA rotates its intermediate; pin to your own key or to the root, and always ship a backup pin.
  • Internal CA root distributed to laptops but not to the CI runners, the Docker base image or the Java keystore; only some clients can talk to internal services.
  • Wildcard *.example.com deployed for api.v2.example.com; the extra label does not match.
  • A device with a dead RTC boots with the clock at 1970 or 2000 and rejects every certificate as not yet valid.

Check yourself

Answer out loud or on paper first, then compare. These come from the interview questions linked to this lesson.

  1. When your browser connects to a site over HTTPS, how does it decide that the server’s certificate is trustworthy? What can make that check fail even though the certificate is genuine?

    Show a strong answer

    A certificate is a signed statement: *this public key belongs to these names, valid between these dates, according to this issuer*. The client does not trust the statement because it is well-formed; it trusts it because it can build a path from it to a root it already holds. The server sends its leaf and the intermediate(s); the root is *not* sent — it must already be in the client’s trust store (the OS store, or the browser’s own, e.g. Mozilla’s for Firefox and the Chrome Root Program). For each link the client verifies the signature with the issuer’s public key, checks the issuer is allowed to issue (basicConstraints: CA, path length, key usage), and stops when it reaches a trusted root. See Certificates and the Chain of Trust.

    Then the leaf itself: the requested hostname must match a Subject Alternative Name (browsers ignore the Common Name); the current time must fall between notBefore and notAfter; the extended key usage must include server authentication; the signature algorithm and key size must be acceptable (SHA-1 and RSA-1024 are rejected); and the certificate must not be revoked — checked via OCSP, an OCSP response stapled by the server, or the browser’s own summary (CRLSets in Chrome, CRLite in Firefox). Chrome and Safari also require proof the certificate was logged in Certificate Transparency logs. Finally the handshake proves the server holds the *private* key: CertificateVerify in TLS 1.3, or the key exchange itself in 1.2 (The TLS Handshake). A stolen certificate without the key is useless.

    A genuine certificate fails in ways that are all about the *client’s* view. Missing intermediate: the server sends only the leaf; browsers often recover by fetching the issuer from the AIA URL or from cache, so the site "works in Chrome" while curl, Java, Python and Go fail with unable to get local issuer certificate. Unknown root: a corporate or private CA not installed on this machine, or a *new* public root missing from an old trust store — when Let’s Encrypt’s cross-sign from DST Root CA X3 expired in 2021, old Android devices and old OpenSSL 1.0 clients rejected perfectly valid chains. Clock skew: a device with the wrong date sees "not yet valid" or "expired". Hostname mismatch: the right certificate on the wrong vhost, a missing SNI so the default certificate is presented, or api.example.com reached via an IP address. Expired: the most common outage of all — Let’s Encrypt certificates last 90 days, and automation that silently stops renewing shows up exactly 90 days later.

    Full interview question, with follow-ups and red flags →
  2. Walk me through a TLS handshake. What does each side learn, how many round trips does it cost, and what changed between TLS 1.2 and TLS 1.3?

    Show a strong answer

    A handshake has to do three things before a byte of HTTP flows: authenticate the server (prove the public key in its certificate belongs to the name the client asked for — see Certificates and the Chain of Trust), agree on a shared secret that no observer can derive, and negotiate algorithms (key exchange, signature, symmetric cipher) plus extras such as the application protocol via ALPN (h2, http/1.1) and the hostname via SNI so one IP can serve many certificates. Everything before the shared secret exists is in the clear.

    TLS 1.2 takes two round trips. ClientHello (versions, cipher suites, random, SNI, ALPN) → ServerHello + Certificate + ServerKeyExchange (its ephemeral ECDHE public value, signed with the certificate’s key) + ServerHelloDone → ClientKeyExchange (the client’s ECDHE value) + ChangeCipherSpec + Finished → server ChangeCipherSpec + Finished. Both sides derive the same secret from the ECDHE exchange; the Finished messages are MACs over the whole transcript, so any tampering with the negotiation is detected. 1.2 also allowed RSA key exchange (client encrypts a secret to the server’s public key), which has no forward secrecy — compromise the key later, decrypt every recorded session.

    TLS 1.3 takes one round trip because the client *guesses*: its ClientHello already carries a key_share for a likely group (usually X25519). The server replies with ServerHello + its own key_share, and from that point everything — EncryptedExtensions, Certificate, CertificateVerify (a signature over the transcript proving possession of the private key), Finished — is already encrypted. The client sends Finished and application data in the same flight. If the guess was wrong the server sends HelloRetryRequest and it costs a second round trip. 1.3 also removed RSA key exchange, static DH, renegotiation, compression and every non-AEAD cipher, so the negotiation surface is small enough that downgrade tricks have little to attack. With a resumption PSK, 1.3 can send 0-RTT data in the first flight — replayable, so only for idempotent requests.

    The cost compounds with TCP: one RTT for the handshake (The Three-Way Handshake), plus one (1.3) or two (1.2), so a cold HTTPS request across a 150 ms path spends 300–450 ms before the first HTTP byte. That is why keep-alive, session resumption and TLS termination close to the user matter more than the cipher choice. Failures are legible: an alert such as handshake_failure (no common cipher/version) or protocol_version, a certificate alert after the Certificate message (client rejected it), a hostname mismatch when SNI was missing and the server presented a default certificate, or a silent hang when a middlebox drops something it does not understand. See The TLS Handshake and TLS Debugging: Why the Certificate Is "Invalid".

    Full interview question, with follow-ups and red flags →
  3. Your API works in Chrome but every Python client fails with CERTIFICATE_VERIFY_FAILED. First hypothesis?

    Show a strong answer

    The server is not sending the intermediate certificate; Chrome fetches it via AIA or has it cached, Python does not. Check with openssl s_client -showcerts.

    Full interview question, with follow-ups and red flags →