All Posts

X.509 Certificates: A Deep Dive into How They Work

Your browser trusts Google because of a file called a Certificate. We explain the Chain of Trust, Public Keys, and Revocation.

Abstract AlgorithmsAbstract Algorithms
ยทยท6 min read
Share
Share on X / Twitter
Share on LinkedIn
Copy link

TLDR: An X.509 Certificate is a digital document that binds a Public Key to an Identity (e.g., google.com). It is digitally signed by a trusted Certificate Authority (CA). It prevents attackers from impersonating websites via man-in-the-middle attacks.


๐Ÿ“– The Digital Passport Analogy

Imagine a passport:

  • Identity: Your name and photo โ€” the subject.
  • Authority stamp: The government's seal โ€” the CA's digital signature.
  • Trust: The border officer trusts the government stamp, therefore trusts you.

If you print your own passport on a laser jet, the officer rejects it (self-signed certificate warning). Your browser does the same: if a certificate isn't signed by a recognized authority, it shows a red "Not Secure" error.


๐Ÿ”ข Anatomy of an X.509 Certificate

An X.509 v3 certificate contains:

FieldExamplePurpose
SubjectCN=google.com, O=Google LLCIdentity being certified
IssuerCN=GTS CA 1C3, O=Google Trust ServicesWho signed this?
Public KeyRSA 2048-bit or EC P-256The key being certified
Serial Number0x1A2B3C...Unique ID from the CA
Validity2024-01-01 โ†’ 2025-01-01Active window
Subject Alt Names*.google.com, google.comWildcard/multi-domain support
Key UsageDigital Signature, Key EnciphermentWhich operations this key may perform
SignatureCA's digital signature over all aboveTamper detection

How the signature works:
The CA hashes all fields โ†’ signs the hash with the CA's private key โ†’ embeds the signature in the certificate. Your browser re-hashes the fields, decrypts the signature with the CA's public key, and checks they match. Any tampered field = hash mismatch = invalid.


โš™๏ธ The Chain of Trust: Root โ†’ Intermediate โ†’ Leaf

Your browser doesn't know every website certificate. It pre-installs a curated set of Root CAs (DigiCert, Let's Encrypt, ISRG, GlobalSign) in the OS/browser trust store.

flowchart TD
    Root["Root CA\n(Self-signed; stored in OS/browser trust store)\nPrivate key kept OFFLINE in HSMs"]
    Int["Intermediate CA\n(Signed by Root)\nHandles day-to-day certificate issuance"]
    Leaf["Leaf Certificate\ngoogle.com\n(Signed by Intermediate)"]

    Root -->|signs| Int
    Int -->|signs| Leaf

Validation algorithm:

  1. Is the leaf cert signed by the stated Intermediate CA?
  2. Is the Intermediate CA cert signed by the stated Root CA?
  3. Is the Root CA in the browser's trusted store?
  4. Are all certs within their validity periods?
  5. Has any cert been revoked?

All 5 checks must pass. One failure = connection blocked.

Why three levels?
Root private keys are stored offline in air-gapped HSMs. If they signed every leaf cert directly, a single Root key compromise would invalidate the entire internet's trust. Intermediate CAs handle daily signing; if one is compromised, only its issued certs need revocating โ€” the Root remains intact.


๐Ÿง  Certificate Revocation: CRL and OCSP

Certificates expire naturally, but sometimes they need to be revoked early (private key compromised, company dissolved, mis-issuance):

MechanismHow It WorksWeakness
CRL (Certificate Revocation List)CA publishes a signed list of revoked serial numbers; browser downloads periodicallyLarge lists; can be stale
OCSP (Online Certificate Status Protocol)Browser queries CA's OCSP responder in real-timePrivacy risk (CA learns which sites you visit); latency
OCSP StaplingServer pre-fetches the OCSP response and staples it to the TLS handshakeNo browser โ†’ CA roundtrip; removes privacy leak
CRLite / OneCRLBrowser vendors pre-aggregate revocation data; browser checks locallySmall delay before propagation, but no network cost

Chrome's approach: Chrome doesn't send OCSP requests by default. Instead, it relies on CRLSets โ€” compact bloom-filter-based revocation data pushed by Google automatically. Hard revocations (CA compromise, mass mis-issuance) go through CRLSets and browser vendor channels.


โš–๏ธ Certificate Types and Validation Levels

TypeValidation LevelWhat Was CheckedWhen to Use
DV (Domain Validated)LowApplicant controls the domainPersonal sites, APIs
OV (Organization Validated)MediumCompany name verifiedBusiness websites
EV (Extended Validation)HighFull legal entity verificationBanks, payment pages
Wildcard (*.example.com)AnyOne cert covers all subdomainsMulti-subdomain services
SAN / Multi-domainAnyMultiple domains in one certCDNs, cloud load balancers

Let's Encrypt issues DV certs automatically (free, 90-day validity, renewal via ACME protocol). This transformed certificate adoption โ€” HTTPS was rare in 2015; now it's universal.


๐Ÿ›ก๏ธ Certificate Transparency and mTLS

Certificate Transparency (CT)

Every publicly-trusted CA is required to log every issued certificate to an append-only Certificate Transparency Log. Browsers require proof-of-CT-log-inclusion (an SCT โ€” Signed Certificate Timestamp) in the certificate.

This allows:

  • Domain owners to detect unauthorized certificates issued for their domain.
  • The community to audit and expose mis-issuing CAs.

Real example: In 2017, Symantec was caught mis-issuing thousands of certs. CT logs provided the evidence. Google subsequently distrusted Symantec root CAs.

Mutual TLS (mTLS)

Standard TLS: only the server presents a certificate. Clients are anonymous.
mTLS: Both client and server present certificates; each verifies the other.

Used in:

  • Zero-trust networks (every service identity is cryptographically verified).
  • Service meshes (Istio issues short-lived certs to every pod via SPIFFE/SPIRE).
  • B2B APIs requiring cryptographic client identity (not just API keys).
sequenceDiagram
    participant C as Client (Service A)
    participant S as Server (Service B)
    C->>S: ClientHello + Client Certificate
    S->>C: ServerHello + Server Certificate
    C->>S: Verify Server Cert (CA chain)
    S->>C: Verify Client Cert (CA chain)
    Note over C,S: Mutual identity established
    C->>S: Encrypted data

๐Ÿ“Œ Summary

  • An X.509 certificate binds a public key to an identity via a CA's digital signature.
  • Chain of Trust: Root (offline HSM) โ†’ Intermediate โ†’ Leaf. All three links must validate.
  • Revocation: CRL, OCSP, OCSP Stapling, CRLSets. Stapling is the most practical modern approach.
  • DV/OV/EV indicate how thoroughly the CA verified the applicant's identity.
  • Certificate Transparency forces CAs to log every issuance publicly, enabling mis-issuance detection.
  • mTLS extends certificate verification to both sides โ€” essential for zero-trust service architectures.

๐Ÿ“ Practice Quiz

  1. Why does the chain of trust have an Intermediate CA rather than Root CAs signing leaf certs directly?

    • A) To make certificate issuance faster.
    • B) To keep Root private keys offline. Compromising an Intermediate only requires revoking that CA, not the entire Root.
    • C) Intermediate CAs are cheaper.
      Answer: B
  2. What does Certificate Transparency (CT) accomplish?

    • A) It encrypts certificate contents so only the browser can read them.
    • B) It requires CAs to log every issued certificate to public append-only logs, enabling detection of unauthorized certificates.
    • C) It replaces OCSP for revocation checking.
      Answer: B
  3. Your company runs a service mesh where every microservice must cryptographically prove its identity to peers (not just API key). Which TLS feature enables this?

    • A) SNI (Server Name Indication).
    • B) mTLS โ€” both client and server present and verify certificates.
    • C) HSTS.
      Answer: B

Abstract Algorithms

Written by

Abstract Algorithms

@abstractalgorithms