Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 3 of 6 · Concept · 20 min · revision 2

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

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: notBefore and notAfter. 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 digitalSignature for a TLS server or keyCertSign and cRLSign for a CA.
  • Extended Key Usage (EKU): the purposes, such as serverAuth (TLS server) and clientAuth (TLS client).
  • Basic Constraints: CA:TRUE or CA:FALSE, and for a CA an optional pathlen, 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.

Terminal · build a three-level chain (OpenSSL 3.0.2)
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 *.crt
Expected output
issuing.crt
root.crt
shop.crt
Terminal · read the fields that decide trust
openssl x509 -in shop.crt -noout -subject -issuer \
  -ext basicConstraints,keyUsage,extendedKeyUsage,subjectAltName
Expected output
subject=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.test
Terminal · serial, validity and the key identifiers
openssl x509 -in shop.crt -noout -serial -dates \
  -ext subjectKeyIdentifier,authorityKeyIdentifier
openssl x509 -in issuing.crt -noout -ext subjectKeyIdentifier
Illustrative output (serials, dates and keys differ)
serial=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:C4

The 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.

Terminal
openssl verify -CAfile root.crt shop.crt
openssl verify -show_chain -CAfile root.crt -untrusted issuing.crt shop.crt
Expected output
CN = 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 CA

Error 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:

  1. Signatures: each certificate must verify with the public key of the next one up, ending at the trust anchor.
  2. 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.test covers exactly one label: api.shop.test, but not shop.test or a.b.shop.test.
  3. Validity: the current time must lie inside every certificate's validity window. A wrong client clock breaks this check, too.
  4. Usage: the leaf's EKU must allow the purpose (serverAuth for a server), and each CA certificate must have CA:TRUE and the keyCertSign key usage.
  5. Path length: a CA's pathlen limits how many CA certificates may follow it in the chain.
  6. Revocation, if the client checks it (next section).

Each rule has its own error code, so openssl verify tells you which one failed.

Terminal · rule 2: the CN is ignored, only the SAN counts
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.crt
Expected output
CN = www.shop.test
error 62 at 0 depth lookup: hostname mismatch
error shop.crt: verification failed
shop.crt: OK
Terminal · rules 4 and 3: wrong purpose, then 120 days on
openssl 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.crt
Expected output
CN = 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 failed

For 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.

Terminal · rule 5: a CA below a pathlen:0 CA
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 ..
Expected output
CN = Demo Issuing CA
error 25 at 2 depth lookup: path length constraint exceeded
error x.crt: verification failed

05. 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

Practice check · 3 questions

Chains, constraints and revocation

Choose the best answer.

Q1. A server sends its leaf, its intermediate and its root. Which certificate does the client actually rely on to trust the chain?
Q2. An issuing CA has `pathlen:0`. A team uses it to sign a CA certificate for its own sub-CA and issues leaves from that sub-CA. What happens?
Q3. Why did Let's Encrypt shut down its OCSP service and move to CRLs only?
Practice only: not graded, not saved, not evidence.

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

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

10 questions · about 8 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check