TLS, HTTPS & PKI
The cryptography behind HTTPS (symmetric, asymmetric, hashes, MACs, signatures, key exchange), certificates and chains of trust, the TLS 1.2 and 1.3 handshakes, forward secrecy, session resumption and 0-RTT, SNI and ECH, mTLS, certificate pinning, HSTS, and how TLS terminates at load balancers.
Crypto building blocks
| Primitive | What it gives | Examples |
|---|---|---|
| Symmetric encryption | confidentiality with one shared key; fast | AES-128/256-GCM, ChaCha20-Poly1305 |
| Asymmetric encryption / key exchange | agree on a secret over an open channel | (EC)DHE: X25519; ML-KEM hybrids (post-quantum) |
| Digital signatures | prove who signed; integrity | RSA-PSS, ECDSA, Ed25519 |
| Hash | fixed-size fingerprint; collision-resistant | SHA-256, SHA-384 |
| MAC / AEAD tag | integrity + authenticity with a shared key | HMAC-SHA256, GCM tag |
| KDF | derive keys from a secret | HKDF |
Diffie-Hellman in one paragraph
Both sides pick secret random numbers a and b, exchange public values g^a and g^b, and each computes g^(ab) — a shared secret an eavesdropper (who only saw g^a and g^b) can't feasibly compute. Elliptic-curve DH (X25519) does the same with smaller keys. Without authentication DH is vulnerable to man-in-the-middle, which is why the server signs the handshake with its certified key.
Certificates and PKI
| Concept | Notes |
|---|---|
| DV / OV / EV certificates | domain-validated (automated, e.g. Let's Encrypt) vs organisation-validated vs extended validation; browsers no longer highlight EV |
| SAN | Subject Alternative Names: the domains the certificate covers; wildcards *.example.com match one label |
| Validity | publicly trusted TLS certificates are being shortened by CA/Browser Forum rules (from 398 days toward 47 days by 2029) → automate renewal |
| ACME | protocol for automated issuance/renewal (Let's Encrypt, cert-manager in Kubernetes) |
| Revocation | CRLs, OCSP, OCSP stapling; Let's Encrypt ended OCSP in 2025 in favour of short lifetimes + CRLs |
| Certificate Transparency | every public certificate is logged; monitor CT logs for your domains |
The TLS 1.3 handshake
TLS 1.2 vs 1.3
| TLS 1.2 | TLS 1.3 | |
|---|---|---|
| Full handshake | 2 RTT | 1 RTT |
| Resumption | session IDs/tickets (1 RTT) | PSK (1 RTT) or 0-RTT |
| Key exchange | RSA or (EC)DHE | (EC)DHE only → forward secrecy always |
| Cipher suites | many, including weak (CBC, RC4, SHA-1) | 5 AEAD suites |
| Certificate visible on the wire | yes | encrypted |
0-RTT caveat: early data can be replayed by an attacker, so servers should accept only idempotent requests (GETs) in 0-RTT.
SNI, ALPN and ECH
- SNI (Server Name Indication): the client says which hostname it wants in ClientHello, so one IP can host many certificates (essential for CDNs and shared load balancers). Sent in clear text unless…
- ECH (Encrypted Client Hello): encrypts the inner ClientHello (including SNI) using a key published in DNS (HTTPS record).
- ALPN: negotiates the application protocol (
h2,http/1.1) during the handshake; HTTP/3 is advertised viaAlt-Svc/DNS.
mTLS
HSTS, pinning and other hardening
| Measure | Purpose |
|---|---|
Strict-Transport-Security (+ preload) | never use HTTP; prevents SSL stripping |
| Redirect HTTP → HTTPS (301/308) | initial upgrade |
| Modern config (TLS 1.2+ only, AEAD ciphers) | remove weak crypto (tools: Mozilla SSL config, SSL Labs) |
| OCSP stapling / short-lived certs | faster, privacy-friendly revocation |
| Certificate pinning | mobile apps pin a key; powerful but risky (bricking on rotation) — pin intermediates/backup keys |
| CAA records | restrict which CAs may issue for your domain |
| Post-quantum hybrid key exchange | X25519 + ML-KEM, enabled by default in modern browsers and CDNs to defeat "harvest now, decrypt later" |
TLS in system designs
# inspect a server's certificate chain and negotiated protocol
openssl s_client -connect api.example.com:443 -servername api.example.com -alpn h2 </dev/null
curl -vI https://api.example.com 2>&1 | grep -E "SSL|TLS|ALPN|subject|expire"
Interview questions
Answer out loud first, then open the model answer. Mark a question confident only when you could explain it to an interviewer without notes.