ROOT CAOFFLINECANAME?DATES?CHAIN?REVOKED??1import socket, ssl2host = "example.com"3ctx = ssl.create_default_context()4raw = socket.create_connection((host, 443))5s = ctx.wrap_socket(raw, server_hostname=host)6print(s.getpeercert()["notAfter"])TRUST STORE
Back row: the root CA, the intermediate CA and the serverFront: the Python client, its four checks, your computer and its trust storeTokens: a public key, a signing request, certificates, a revocation query, the padlockAt the back, the root CA (kept offline), the intermediate CA and the example.com server; in front, the Python client, its four checks and your computer with its trust store. The server gets a certificate signed by the intermediate CA, whose own certificate the root signed. In the handshake the server sends both; your computer checks the chain against its trust store, then the name, the dates and revocation, before it trusts the connection. Real chains are sometimes longer (several intermediates) or cross-signed, so a client may find more than one path to a trusted root. The idea is the same: each signature is checked by the next certificate up, ending at a trust anchor.

Why certificates

  1. Your computer wants a private connection to example.com. The server sends a public key, but a key alone carries no name. An impostor could send their own key instead. Your computer needs proof of whose key it is.

Python checks the chain

The classic mistake

What happens

;; step 1/11 · whose-key
public key   lets anyone lock data for, or check
             signatures from, the key's owner
problem      the key does not say who owns it
needed       a trusted statement: this key
             belongs to example.com

The CA names in the figure are generic. Run the code and print s.getpeercert()["issuer"] to see who really issued example.com's certificate; on 2026-11-06 it was a Cloudflare issuing CA and the certificate ran until 25 December 2026. Python's ssl module does not check CRLs or OCSP unless you configure it; browsers use their own revocation methods. Shorter certificate lifetimes (CA/Browser Forum ballot SC-081) limit how long a stolen key stays useful.