Sub topic 2
Certificate authorities and the chain of trust
This chapter assumes you know what a TLS handshake does and that a server presents an X.509 certificate during it. It also assumes you can run openssl commands in a shell. Here you will learn why a browser accepts a certificate from a server it has never contacted, and what breaks when the pieces of that decision are missing.
Why a certificate needs a signer
A certificate binds a public key to a name, such as example.com. Anyone can generate a key pair and write a certificate claiming that name, so the claim alone proves nothing. The client needs a third party it already trusts to vouch for the binding. That third party is a certificate authority (CA). The CA signs the certificate with its own private key, and the client checks the signature with the CA's public key.
This moves the problem one step back: how does the client know the CA's public key is genuine? The answer is a chain. Each certificate is signed by the one above it, and the chain ends at a certificate the client already holds.
The three kinds of certificate in a chain
| Kind | Signed by | Typical lifetime | Where it lives |
|---|---|---|---|
| Root certificate | Itself (self-signed) | 10 to 25 years | Client trust store |
| Intermediate certificate | A root or another intermediate | Several years | Sent by the server |
| Leaf (end-entity) certificate | An intermediate | 90 days for Let's Encrypt | Sent by the server |
- Root certificates are the trust anchors. Operating systems and browsers ship a list of them, called the trust store. A root is trusted because it is in that list, not because anything signed it.
- Intermediate certificates exist so that the root's private key can stay offline. The CA keeps the root key in a hardened, rarely used environment and uses intermediates for day-to-day signing. If an intermediate key is compromised, the CA can revoke that intermediate without replacing the root in every device.
- Leaf certificates are the ones you install on your server. A leaf cannot sign other certificates. Its Basic Constraints extension says
CA:FALSE.
For Let's Encrypt, the root is ISRG Root X1, run by the Internet Security Research Group. Your leaf is signed by an intermediate with a name like R10 or R11 (RSA) or E5 or E6 (ECDSA). Let's Encrypt rotates these intermediates over time, so don't hard-code their names anywhere.
How a client validates the chain
When nginx presents its certificates, the client does the following:
- It reads the leaf and finds the issuer name and the Authority Key Identifier, a hash that points to the signer's key.
- It looks for a certificate whose Subject Key Identifier matches. The server normally supplies this intermediate in the handshake. If the client's trust store holds it, the client can use that copy.
- It verifies the leaf's signature using the intermediate's public key.
- It repeats the process for the intermediate, moving up until it reaches a certificate in its trust store.
- It checks every certificate on the path: validity dates, Basic Constraints, and key usage.
- It confirms that the leaf's Subject Alternative Name (SAN) list contains the host name it was asked to connect to.
If any step fails, the client rejects the connection. Browsers show a warning page. curl fails with an error such as unable to get local issuer certificate.
Trust flows only upward from the trust store. The server does not need to send the root, because a client that doesn't already have it would have no reason to trust a copy sent over the same connection. Sending it only wastes bytes in every handshake.
What the server must send
The server is responsible for sending the leaf and every intermediate. The root is left out. This is the main reason Certbot gives you separate files, which a later chapter covers in detail:
cert.pemcontains only the leaf.chain.pemcontains only the intermediate(s).fullchain.pemcontains the leaf followed by the intermediate(s).
In nginx you almost always want fullchain.pem as the ssl_certificate. If you use cert.pem alone, many clients can't build the path. Desktop browsers sometimes hide the mistake because they cache intermediates from other sites or fetch missing ones through the Authority Information Access extension. Mobile apps, curl, Java, and monitoring tools typically do not, so the failure appears only for some clients.
Inspecting a chain with openssl
Connect to a live site and print the chain that the server sends:
echo | openssl s_client -connect example.com:443 -servername example.com -showcerts 2>/dev/null \
| sed -n '/^Certificate chain/,/^---/p'You should see numbered entries. Entry 0 is the leaf and entry 1 is the intermediate. For each entry, s: is the subject and i: is the issuer. The issuer of entry 0 should match the subject of entry 1. If only one entry appears, the server sends the leaf without its intermediate.
You can also verify the chain locally against your system's trust store. The following command uses the files from a Certbot installation:
sudo openssl verify \
-untrusted /etc/letsencrypt/live/example.com/chain.pem \
/etc/letsencrypt/live/example.com/cert.pemA successful run prints cert.pem: OK. The -untrusted option supplies intermediates that are used to build the path but are not trusted by themselves. The trust anchor comes from the system store. On Debian and Ubuntu, that store is built by the ca-certificates package into /etc/ssl/certs/.
Now run the same command without the -untrusted option. It should fail with unable to get local issuer certificate, which is the error a client reports when a server forgets to send its intermediate.
Where trust comes from, and how it is lost
Trust stores are controlled by a few organizations: Mozilla, Apple, Microsoft, and Google. A CA gets into the store by meeting their audit and operational requirements. A CA can also be removed from the store if it breaks those rules. Several CAs have been distrusted in the past for misissuing certificates.
Three things can end the usefulness of a chain:
- Expiry. Every certificate in the chain has its own validity period, and a client rejects the path if any one has expired. The leaf is the one you renew. CA certificates are rotated by the CA.
- Revocation. A CA can declare a certificate invalid before it expires, for example after a key compromise. Clients learn about this through certificate revocation lists (CRLs) or the Online Certificate Status Protocol (OCSP). Let's Encrypt has ended its OCSP service and now publishes CRLs. Your server needs no revocation configuration. Short 90-day lifetimes limit how long a stolen certificate stays useful.
- Removal of a root. If a root leaves the trust store, or an old device never receives the new root, clients on that device reject the chain.
The last case caused a well-known incident. Until 2021, Let's Encrypt chains reached older Android devices through a cross-signature from another root, DST Root CA X3. That root expired on 30 September 2021, and some old clients, mostly devices that cannot update their trust stores, began rejecting certificates that other clients accepted. A cross-signed intermediate is the same key certified by two different issuers, which lets a young root gain compatibility before it is widely distributed. The incident shows that a chain failure can be specific to certain client populations. A server can look healthy from a modern browser and still fail for other clients.
Common errors
| Symptom | Likely cause | Check |
|---|---|---|
| `unable to get local issuer certificate` from `curl` | Server sends the leaf without the intermediate | Use `fullchain.pem`; list the chain with `-showcerts` |
| Works in Chrome, fails in Java or on mobile | Same missing intermediate, hidden by browser caching | Count the entries in the chain |
| `certificate has expired` | The leaf, or an old chain served from cached config | Compare the `notAfter` date; reload nginx |
| `Hostname mismatch` | Name not in the SAN list | `openssl x509 -noout -ext subjectAltName` |
| Only very old devices fail | Device lacks the current root | Update the device or its trust store |
Self-signed certificates and private CAs
A self-signed certificate is one where the issuer and the subject are the same. It is a root with no chain above it. Public clients reject it because it isn't in any trust store. Organizations that run an internal CA solve this by installing their own root on their machines. The mechanism is the same as the public one, with a trust store you control. For a public web server, use a public CA such as Let's Encrypt.
Exercise
You install a certificate on nginx using cert.pem as the ssl_certificate. Chrome on your laptop loads the site without warnings, but curl on a fresh server reports unable to get local issuer certificate. What is wrong, how can you confirm it with openssl, and what is the fix?
Show answer
The server sends only the leaf certificate and omits the intermediate. Chrome may have the intermediate cached or may fetch it, so it hides the problem. curl has the root in its trust store but cannot build the path from the leaf to it. Confirm by running echo | openssl s_client -connect example.com:443 -servername example.com -showcerts and noting that the chain contains only entry 0. Fix it by pointing ssl_certificate at fullchain.pem, then run sudo nginx -t && sudo systemctl reload nginx.
Exercise
Why does a server not need to send the root certificate in the handshake?
Show answer
A client trusts a root only because it is already in the client's trust store. A copy sent over the connection adds no trust, since an attacker could send a fake root just as easily. Sending it only increases handshake size.