Certificates and chains: how a client decides to trust a server
The X.509 fields that matter (subject, issuer, serial, validity, SAN, key usage, extended key usage, basic constraints, key identifiers), how a client builds a chain to a trust anchor, the validation rules it applies, and how revocation works with CRLs, OCSP, stapling and short-lived certificates, all inspected with openssl on a chain you generate.
Contentsand lesson path
On this page
- Why it matters
- What is inside a certificate
- Building a chain to a trust anchor
- The validation rules
- Revocation: CRL, OCSP, stapling and short lifetimes
- Check your understanding
- Apply it
- Review prompt
Lessons of TLS & PKI
- What TLS gives you: confidentiality, integrity and authentication Concept · 15 min
- Lab: the TLS 1.3 handshake on the wire, with SNI, ALPN and HTTP/2 vs HTTP/3 Lab · 25 min
- Certificates and chains: how a client decides to trust a server Concept · 20 min
- Lab: a two-tier private CA (offline root, issuing CA), server and client certificates, and mutual TLS Lab · 30 min
- Operating PKI: ACME automation as lifetimes shrink, revocation availability and CA compromise plans Worked example · 25 min
- Check: debug five broken TLS endpoints with openssl s_client Knowledge check · 10 questions
What you will learn
- Explain X.509 certificates, chains of trust, validation rules (names, validity, key usage) and revocation, and inspect them with openssl.
01. Why it matters
Most TLS outages are not cryptography failures. They are certificate failures: a certificate expired on a Sunday, a server forgot to send its intermediate, a new host name was never added to the certificate, or a client certificate was issued with the wrong key usage. Each one produces a cryptic error such as unable to get local issuer certificate. Once you know how a client decides to trust a certificate, those errors become a short list of things to check.
In this lesson you generate a small three-level chain with openssl, read its fields, and break validation on purpose in five different ways.
02. What is inside a certificate
An X.509 certificate, profiled for the internet in RFC 5280, is a signed statement: "this public key belongs to this subject, for these purposes, during this time". The issuer signs it with its own private key. The fields you will read most often:
- Subject and Issuer: distinguished names (DNs) of the holder and of the CA that signed it. A root CA is self-signed, so its subject equals its issuer.
- Serial number: unique per issuer. Revocation lists identify certificates by issuer and serial.
- Validity:
notBeforeandnotAfter. Outside this window the certificate is invalid, whatever else is right. - Subject Alternative Name (SAN): the DNS names and IP addresses the certificate is for. This, not the subject's CN (common name), is what clients match.
- Key Usage (KU): what the key may do, such as
digitalSignaturefor a TLS server orkeyCertSignandcRLSignfor a CA. - Extended Key Usage (EKU): the purposes, such as
serverAuth(TLS server) andclientAuth(TLS client). - Basic Constraints:
CA:TRUEorCA:FALSE, and for a CA an optionalpathlen, the number of CA levels allowed below it. - Subject and Authority Key Identifier (SKI, AKI): short identifiers of the certificate's own key and of the issuer's key. They let software find the right issuer quickly, for example when a CA has renewed its certificate.
Build a chain to look at, running every block of this lesson in the same terminal (later blocks reuse $EC): a root CA, an issuing CA (also called an intermediate) signed by the root with pathlen:0, and a server certificate signed by the issuing CA. The server certificate has a deliberate mistake: its CN is www.shop.test, but its SAN lists only shop.test and api.shop.test.
mkdir chain-demo && cd chain-demo
EC="-newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes"
openssl req -x509 $EC -keyout root.key -out root.crt -days 3650 \
-subj "/CN=Demo Root CA" -addext "basicConstraints=critical,CA:TRUE" \
-addext "keyUsage=critical,keyCertSign,cRLSign" 2>/dev/null
openssl req -new $EC -keyout issuing.key -out issuing.csr \
-subj "/CN=Demo Issuing CA" 2>/dev/null
printf '%s\n' "basicConstraints=critical,CA:TRUE,pathlen:0" \
"keyUsage=critical,keyCertSign,cRLSign" \
"subjectKeyIdentifier=hash" "authorityKeyIdentifier=keyid" > issuing.ext
openssl x509 -req -in issuing.csr -CA root.crt -CAkey root.key -days 1825 \
-extfile issuing.ext -out issuing.crt 2>/dev/null
openssl req -new $EC -keyout shop.key -out shop.csr -subj "/CN=www.shop.test" \
2>/dev/null
printf '%s\n' "basicConstraints=critical,CA:FALSE" \
"keyUsage=critical,digitalSignature" "extendedKeyUsage=serverAuth" \
"subjectAltName=DNS:shop.test,DNS:api.shop.test" \
"subjectKeyIdentifier=hash" "authorityKeyIdentifier=keyid" > shop.ext
openssl x509 -req -in shop.csr -CA issuing.crt -CAkey issuing.key -days 90 \
-extfile shop.ext -out shop.crt 2>/dev/null
ls *.crtissuing.crt
root.crt
shop.crtopenssl x509 -in shop.crt -noout -subject -issuer \
-ext basicConstraints,keyUsage,extendedKeyUsage,subjectAltNamesubject=CN = www.shop.test
issuer=CN = Demo Issuing CA
X509v3 Basic Constraints: critical
CA:FALSE
X509v3 Key Usage: critical
Digital Signature
X509v3 Extended Key Usage:
TLS Web Server Authentication
X509v3 Subject Alternative Name:
DNS:shop.test, DNS:api.shop.testopenssl x509 -in shop.crt -noout -serial -dates \
-ext subjectKeyIdentifier,authorityKeyIdentifier
openssl x509 -in issuing.crt -noout -ext subjectKeyIdentifierserial=21C74F92079D1B31873BEFF5EDFDF5F70305A142
notBefore=Nov 15 18:55:26 2026 GMT
notAfter=Feb 13 18:55:26 2027 GMT
X509v3 Subject Key Identifier:
C6:7D:E7:29:4F:78:D4:47:D5:E6:7E:3B:83:26:C1:47:C9:16:DB:B1
X509v3 Authority Key Identifier:
6B:57:FD:A7:AF:BA:90:D3:C2:1B:FA:8C:C6:3F:3D:18:6C:EF:A2:C4
X509v3 Subject Key Identifier:
6B:57:FD:A7:AF:BA:90:D3:C2:1B:FA:8C:C6:3F:3D:18:6C:EF:A2:C4The server certificate's Authority Key Identifier equals the issuing CA's Subject Key Identifier. That is the link a client follows from one certificate to the next. openssl x509 -in shop.crt -noout -text prints every field at once if you want the full picture.
03. Building a chain to a trust anchor
A client does not trust a certificate because the server sent it. It trusts a certificate when it can build a chain: leaf signed by an intermediate, intermediate signed by a root, and that root present in its own trust store (the list of root certificates the operating system, browser or application ships with). The root is the trust anchor. A root that the server sends adds nothing: anyone can make a self-signed certificate with any name, so only the client's own copy counts.
That is why a server must send its leaf and its intermediates. Roots are in the trust store; intermediates usually are not. openssl verify shows what happens when the intermediate is missing. -CAfile is the trust store, and -untrusted gives extra certificates that may be used to build the chain but are not trusted by themselves.
openssl verify -CAfile root.crt shop.crt
openssl verify -show_chain -CAfile root.crt -untrusted issuing.crt shop.crtCN = www.shop.test
error 20 at 0 depth lookup: unable to get local issuer certificate
error shop.crt: verification failed
shop.crt: OK
Chain:
depth=0: CN = www.shop.test (untrusted)
depth=1: CN = Demo Issuing CA (untrusted)
depth=2: CN = Demo Root CAError 20, unable to get local issuer certificate, means "I cannot find who signed this". It is the same error code that openssl s_client and many other clients report against a server that sends only its leaf. Browsers often hide the problem: they may already hold the intermediate from another site, or fetch it from the URL in the certificate's Authority Information Access (AIA) extension. API clients, mobile apps and curl usually do neither, so they fail while the browser works. The fix is to configure the server with the full chain file, leaf first.
04. The validation rules
Once a chain exists, the client checks each certificate in it. The main rules:
- Signatures: each certificate must verify with the public key of the next one up, ending at the trust anchor.
- Name: the host name the client asked for must match a DNS entry in the leaf's SAN (or an IP entry, for an IP address). RFC 9525, which replaced RFC 6125 in 2023, says the CN must not be used to identify a service. A wildcard such as
*.shop.testcovers exactly one label:api.shop.test, but notshop.testora.b.shop.test. - Validity: the current time must lie inside every certificate's validity window. A wrong client clock breaks this check, too.
- Usage: the leaf's EKU must allow the purpose (
serverAuthfor a server), and each CA certificate must haveCA:TRUEand thekeyCertSignkey usage. - Path length: a CA's
pathlenlimits how many CA certificates may follow it in the chain. - Revocation, if the client checks it (next section).
Each rule has its own error code, so openssl verify tells you which one failed.
openssl verify -CAfile root.crt -untrusted issuing.crt \
-verify_hostname www.shop.test shop.crt
openssl verify -CAfile root.crt -untrusted issuing.crt \
-verify_hostname api.shop.test shop.crtCN = www.shop.test
error 62 at 0 depth lookup: hostname mismatch
error shop.crt: verification failed
shop.crt: OKopenssl verify -CAfile root.crt -untrusted issuing.crt -purpose sslclient shop.crt
openssl verify -CAfile root.crt -untrusted issuing.crt \
-attime "$(date -d '+120 days' +%s)" shop.crtCN = www.shop.test
error 26 at 0 depth lookup: unsupported certificate purpose
error shop.crt: verification failed
CN = www.shop.test
error 10 at 0 depth lookup: certificate has expired
error shop.crt: verification failedFor rule 5, let the issuing CA sign another CA, which then signs a leaf. Nothing stops openssl x509 -req from signing it; the constraint is enforced by whoever verifies the chain. That is also how CA mistakes are contained in practice.
openssl req -new $EC -keyout sub.key -out sub.csr -subj "/CN=Unapproved Sub CA" \
2>/dev/null
openssl x509 -req -in sub.csr -CA issuing.crt -CAkey issuing.key -days 30 \
-extfile issuing.ext -out sub.crt 2>/dev/null
openssl req -new $EC -keyout x.key -out x.csr -subj "/CN=x.shop.test" 2>/dev/null
openssl x509 -req -in x.csr -CA sub.crt -CAkey sub.key -days 30 -extfile shop.ext \
-out x.crt 2>/dev/null
cat issuing.crt sub.crt > two-cas.pem
openssl verify -CAfile root.crt -untrusted two-cas.pem x.crt
cd ..CN = Demo Issuing CA
error 25 at 2 depth lookup: path length constraint exceeded
error x.crt: verification failed05. Revocation: CRL, OCSP, stapling and short lifetimes
A certificate can need withdrawing before notAfter, for example because its key leaked. Revocation is how a CA says so. There are two classic mechanisms.
A CRL (certificate revocation list, RFC 5280) is a file signed by the CA that lists revoked serial numbers. It has a thisUpdate time and a nextUpdate time; a client may cache it until nextUpdate, and a new one must be published before then. The certificate's CRL Distribution Points (CDP) extension says where to download it. You will issue and use a CRL in lesson 4.
OCSP (Online Certificate Status Protocol, RFC 6960) lets a client ask a CA responder about one certificate and get a signed "good" or "revoked" answer. It is small, but it is an online dependency on every connection, and it tells the CA which site each user visits. Most clients therefore soft-fail: if the responder does not answer, they continue. An attacker who can block the responder then defeats the check. OCSP stapling lets the server fetch the answer and attach it to its handshake, which removes the privacy and latency problems, but RFC 9325 notes that an on-path attacker can simply leave the staple out unless the client insists on it.
Public web PKI has moved away from online OCSP. The CA/Browser Forum made OCSP optional for CAs and CRLs mandatory (ballot SC-063). Let's Encrypt turned its OCSP service off in August 2025 and publishes CRLs only. Browsers do not download CRLs one by one: Chrome pushes a curated set of revocations called CRLSets, and Firefox has used CRLite, a compressed set of all revocations, by default since version 137 in 2025.
The third mechanism is to make certificates expire quickly. Under the Baseline Requirements a certificate valid for 7 days or less is "short-lived": it need not point to a CRL, and the CA may choose not to support revoking it. Let's Encrypt offers such a 160-hour profile. A stolen key is then useful for days, not months, without any client needing to check anything. Lesson 5 covers the shrinking lifetimes of ordinary public certificates.
06. Check your understanding
07. Apply it
The practice project needs a server certificate with correct SANs. Before you build it in lesson 4, inspect two real ones: a site you use and a service you run. Run openssl s_client -connect <host>:443 -servername <host> -showcerts < /dev/null, save each certificate from the output to a file, and read it with openssl x509 -noout -ext subjectAltName,extendedKeyUsage,crlDistributionPoints. Note how many certificates the server sends, which names the leaf covers, its lifetime, and whether it points to a CRL.
08. Review prompt
Without looking back, write the six validation rules from memory and the error you would expect when each one fails. Explain why a server-sent root adds no trust, why browsers sometimes accept a server that forgets its intermediate while curl does not, and what a client can do when an OCSP responder does not answer. Finish with one reason short-lived certificates reduce the need for revocation checks.
References
- RFC 5280: Internet X.509 PKI Certificate and CRL Profile
- RFC 9525: Service Identity in TLS
- RFC 6960: X.509 Internet PKI Online Certificate Status Protocol (OCSP)
- RFC 9325: Recommendations for Secure Use of TLS and DTLS, section 7.5
- CA/Browser Forum Baseline Requirements for TLS Server Certificates
- Let's Encrypt: OCSP Service Has Reached End of Life (August 2025)
- Mozilla Hacks: CRLite in Firefox
- OpenSSL 3.0 manual: openssl-verify
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
10 questions · about 8 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.