Course contents

02. Networking and Internet Lesson 6 of 10

HTTPS and TLS

Walk through a TLS 1.3 handshake, certificate chain checks, resumption and 0-RTT replay risks, then see where terminating TLS saves server capacity.

16 minIntermediate12 steps
Loading the interactive simulation…
Loading the knowledge check…

Summary

  • TLS adds confidentiality, integrity and server authentication to HTTP.
  • TLS 1.3 sends the key share in the ClientHello, so a full handshake costs one round trip; ephemeral keys give forward secrecy.
  • Certificates are trusted through a signature chain to a root already on the device, plus a hostname match.
  • Resumption skips certificate work; 0-RTT removes the round trip but early data can be replayed, so only accept it for idempotent requests.
  • Terminating TLS at the balancer centralises keys and crypto; re-encrypting on pooled connections is cheap.
Deep diveHow it works, trade-offs, failure modes, misconceptions and the interview angle.

What it is

HTTPS is HTTP sent inside a TLS (Transport Layer Security) connection. TLS sits between TCP (or QUIC) and the application and provides three guarantees: confidentiality (an observer cannot read the bytes), integrity (changes are detected) and authentication (the client knows which server it is talking to; optionally the server also authenticates the client, called mutual TLS). TLS 1.3 (RFC 8446) is the current version; TLS 1.2 is still widely supported, older versions are deprecated.

Why it exists

Traffic crosses networks you do not control: Wi-Fi hotspots, ISPs, transit providers. Without TLS any of them can read passwords and cookies or inject content into pages. Browsers mark plain HTTP as insecure, only speak HTTP/2 and HTTP/3 over TLS, and restrict many features (service workers, geolocation, camera) to secure contexts.

How it works

Handshake (TLS 1.3, full). After the TCP handshake:

  1. The client sends ClientHello: supported versions and cipher suites, the server name (SNI), application protocols (ALPN, e.g. h2) and a key share for its preferred key-exchange group.
  2. The server replies with ServerHello (its key share). From here on everything is encrypted: EncryptedExtensions, Certificate, CertificateVerify (a signature over the handshake with the certificate’s private key) and Finished.
  3. The client verifies the certificate, sends its Finished, and can send application data in the same flight.

That is one round trip before the first request, versus two for TLS 1.2. If the server does not support the client’s guessed group it answers with HelloRetryRequest, costing an extra round trip.

Key exchange. The key shares are ephemeral (EC)DHE values, so each connection derives fresh keys that are discarded afterwards: forward secrecy. Since 2024–2025 major browsers and CDNs use the hybrid group X25519MLKEM768, which combines X25519 with the post-quantum ML-KEM (FIPS 203), protecting recorded traffic against future quantum attacks on the key exchange. Bulk data is then encrypted with an AEAD cipher (AES-GCM or ChaCha20-Poly1305).

Certificate verification. The server sends its leaf certificate plus intermediates. The client checks that each certificate is signed by the next, that the chain ends at a root in its local trust store, that the leaf’s Subject Alternative Name matches the hostname, that it is within its validity period and that it carries Certificate Transparency proofs. CertificateVerify proves the server holds the private key. Revocation is increasingly handled by lists pushed to clients ahead of time (Firefox’s CRLite, Chrome’s CRLSets); live OCSP is being retired (Let’s Encrypt shut down its OCSP service in 2025). The CA/Browser Forum’s ballot SC-081 reduces the maximum certificate lifetime to 200 days from March 2026, 100 days from March 2027 and 47 days from March 2029, which makes automated renewal (ACME) mandatory in practice.

Resumption. After a handshake the server can issue session tickets. A later ClientHello presents one as a pre-shared key (PSK), normally together with a fresh key share (psk_dhe_ke) to keep forward secrecy. The server skips sending and signing the certificate. Still one round trip, but less CPU and fewer bytes.

0-RTT early data. With a PSK, the client may send application data in its first flight, encrypted with a key derived only from the PSK. The server can answer immediately, so the first response arrives after one round trip in total. Early data has no protection against replay: an attacker who records the flight can resend it. Servers therefore limit it to idempotent requests, may keep single-use tickets or replay caches (hard across many servers), and TLS terminators forward early requests with Early-Data: 1 so the origin can reply 425 Too Early (RFC 8470), after which the client retries once the handshake completes.

What stays visible. IP addresses, timing and sizes, and — unless Encrypted Client Hello (ECH) is used — the SNI hostname. DNS lookups are visible too unless DNS is encrypted.

When to use it

Always, for anything that crosses a network you do not fully control, and increasingly inside data centres as well (zero-trust networking, service meshes with mTLS). Use HSTS so browsers never try plain HTTP for your domain.

When not to

There is hardly a case for plaintext on the public internet. Inside a trusted, isolated network segment, some teams still terminate at the edge and run plain HTTP internally for simplicity and debuggability; that is a risk decision, not a performance necessity. 0-RTT specifically should stay off for endpoints with side effects unless replay is handled.

Trade-offs

Choice You gain You pay
Terminate TLS on each app server End-to-end encryption, simple balancer Crypto on app CPUs, private keys on every server, renewals everywhere
Terminate at load balancer / edge Central certificates, L7 routing, app capacity freed Plaintext inside unless re-encrypted; the balancer holds the keys
Re-encrypt to backends (mTLS) Encryption and service identity inside Internal PKI to run; small CPU cost on pooled connections
TLS passthrough (route by SNI) End-to-end encryption, keys only on backends No HTTP-level routing, retries or header logic at the balancer
Enable 0-RTT One round trip less for repeat visitors Replay risk; must restrict to idempotent requests

Alternatives

  • QUIC / HTTP/3 integrates TLS 1.3 into the transport: transport and crypto handshake share one round trip (see the HTTP/2 and HTTP/3 lesson).
  • Mutual TLS instead of bearer tokens for service-to-service identity.
  • Application-layer encryption (e.g. encrypting fields end to end) when intermediaries that terminate TLS must not see the data.

Failure modes

  • Expired certificates remain one of the most common causes of outages; shorter lifetimes make manual renewal untenable.
  • Incomplete chains: a server that omits the intermediate works in browsers that cached it and fails elsewhere.
  • Clock skew on clients makes valid certificates look expired or not yet valid.
  • Handshake storms: after a balancer restart or failover, every client reconnects and performs full handshakes at once; session tickets that survive restarts (shared ticket keys) soften this.
  • 0-RTT replay of non-idempotent requests.
  • Ticket key management: session-ticket encryption keys that are never rotated weaken forward secrecy for resumed sessions.

In production

Automate issuance and renewal with ACME, alert on certificate expiry well ahead, serve complete chains, and prefer ECDSA certificates (smaller and faster to verify than RSA) where clients allow. Terminate TLS at the edge or balancer for public traffic, re-encrypt internally if your threat model includes the internal network, and keep backend connections pooled. Rotate session-ticket keys and share them across the fleet behind one name. Enable HSTS (and consider preloading). Allow 0-RTT only for idempotent routes and honour Early-Data / 425 at the origin.

Common misconceptions

  • “HTTPS hides which site I visit.” The IP address and usually the SNI are visible; only ECH and encrypted DNS hide the hostname.
  • “TLS is slow.” TLS 1.3 adds one round trip on a new connection and almost nothing on a reused one; symmetric encryption is cheap on modern CPUs.
  • “The certificate encrypts the traffic.” The certificate key only signs; traffic keys come from the ephemeral key exchange.
  • “0-RTT is a free speed-up.” Early data can be replayed.
  • “The browser asks the CA on every connection.” Verification is local against the trust store.

Interview angle

Expect to explain where TLS terminates in your design and why: at the CDN or load balancer for public traffic, with re-encryption or mTLS internally if required. Be ready to count round trips (TCP + TLS 1.3 + request = 3 RTT on a cold connection; QUIC saves one), to explain certificate verification in two sentences, and to point out that 0-RTT data is replayable. Mentioning certificate automation, shrinking lifetimes and handshake storms after failover shows operational experience.

Model assumptions

Steps 1–8 are a scripted illustration, not a simulation: every packet is placed by hand to show the order of messages. One-way latency is 10 ms between browser and Wi-Fi and 10 ms between Wi-Fi and the site (a 40 ms round trip); the TCP handshake before TLS is not shown, and multiple TLS records in one flight are drawn as a single packet. The trust-store check is drawn as a 2 ms local lookup. Steps 9–11 are simulated: two app servers with 4 workers each and a lognormal service time (cv 0.5) of 20 ms of application work; terminating TLS on the app servers adds an illustrative 8 ms per request (an average over full handshakes for new connections and record encryption), re-encryption on pooled connections adds 1 ms. The balancer’s crypto work is modelled only as 1 ms of extra latency, not as limited capacity. Arrivals are Poisson. Numbers show behaviour and orders of magnitude, not benchmarks.

The lesson as textEvery step of the simulation, written out.
  1. 1. Everyone on the path can read it

    *Scripted illustration.* The user logs in over plain http://. The request crosses the café Wi-Fi, the café’s ISP and several routers before it reaches the site. Every one of them sees the password in clear text and could change the response, for example inject a script.

    HTTPS fixes three things at once: confidentiality (nobody on the path can read), integrity (nobody can modify without detection) and authentication (the browser knows it is really talking to shop.example.com).

    Scene: A plaintext login request travels from the browser through the café Wi-Fi to shop.example.com and back. The Wi-Fi node can read the password.

    Key idea: Without TLS, every network hop is a potential eavesdropper and editor.

  2. 2. The TLS 1.3 handshake: one round trip

    *Scripted.* After the TCP connection is open, the browser sends a ClientHello: supported versions and ciphers, the server name (SNI), ALPN (h2) and, already, its key share. The server answers with one flight: ServerHello with its own key share, then — already encrypted — its certificate, a CertificateVerify signature and Finished.

    After one round trip (40 ms here) the browser sends its Finished together with the first request, GET /. The answer arrives one round trip later. TLS 1.2 needed two round trips before the request could go out.

    Scene: ClientHello goes from the browser to the site; the server’s hello, certificate and Finished come back in one flight. After one 40 ms round trip the browser sends Finished with GET /, and the response arrives about 90 ms after the start.

    Key idea: TLS 1.3 sends the key share in the first message, so the handshake costs one round trip.

  3. 3. Agree on a key in public

    *Scripted.* The two key shares are public values of an ephemeral (EC)DHE exchange. In 2026 browsers and major servers default to a hybrid group, X25519MLKEM768: classic X25519 combined with a post-quantum ML-KEM key exchange, so recorded traffic stays safe even against a future quantum computer.

    The Wi-Fi sees both shares but cannot compute the shared secret. Because the keys are thrown away after the connection, stealing the server’s certificate key later does not decrypt recorded sessions (forward secrecy). Note what stays visible: IP addresses, the server name in the ClientHello (unless Encrypted Client Hello is used) and traffic sizes and timing.

    Scene: The browser’s and the server’s key shares (tokens) pass through the Wi-Fi in both directions. Encrypted request and response follow; the Wi-Fi cannot read them.

    Key idea: Ephemeral key exchange gives a fresh secret per connection; the certificate key only signs, it does not encrypt.

  4. 4. Is this really shop.example.com?

    *Scripted.* The server sends a chain: its leaf certificate and an intermediate. The browser checks it locally, against the root certificates in its own trust store: each certificate is signed by the next, the chain ends at a trusted root, the leaf’s Subject Alternative Name matches shop.example.com, it is within its validity dates and carries Certificate Transparency proofs. CertificateVerify proves the server holds the leaf’s private key.

    No network call to the CA is needed. Revocation is mostly checked from lists the browser downloads in advance (CRLite, CRLSets); online OCSP is being phased out. Certificates are also getting shorter: the CA/Browser Forum caps lifetimes at 200 days from March 2026, falling to 47 days by 2029, so renewal must be automated (ACME).

    Scene: The certificate chain arrives at the browser, which checks it against its local trust store in a few milliseconds, then sends Finished to the server.

    Key idea: Trust comes from a signature chain to a root the client already has, plus a hostname match.

  5. 5. An attacker in the middle

    *Scripted.* Now the Wi-Fi is a rogue hotspot. It answers the ClientHello itself and presents a certificate for shop.example.com. But it cannot get one signed by a trusted CA for a domain it does not control, and it cannot produce a valid CertificateVerify for the real certificate without the server’s private key.

    The chain check fails, the browser sends a TLS alert and aborts. Nothing reaches the real site. (To stop an attacker from simply keeping the user on plain HTTP, sites send HSTS so browsers always use HTTPS.)

    Scene: The rogue hotspot answers the ClientHello with a fake certificate. The browser’s trust-store check fails and it sends an alert to the hotspot. No packet reaches shop.example.com.

    Key idea: TLS authentication turns a silent interception into a visible, failed connection.

  6. 6. Coming back: session resumption

    *Scripted.* Back on the café’s honest Wi-Fi. After the first handshake the server gave the browser a session ticket. On the next connection the ClientHello carries it as a pre-shared key (plus a fresh key share, so forward secrecy is kept).

    The server accepts it and skips the certificate: no chain to send, no signature to compute, no verification on the client. It is still one round trip, but smaller and cheaper for both CPUs, which matters for servers handling many new connections.

    Scene: The browser resumes with a session ticket. The server answers without sending a certificate and the browser does not consult its trust store. The request still goes out after one round trip.

    Key idea: Resumption skips certificate transfer and verification; it still costs one round trip.

  7. 7. 0-RTT: send the request with the hello

    *Scripted.* With a ticket, the browser can go further: encrypt GET / with the pre-shared key and send it as early data in the same flight as the ClientHello. The server can process it immediately, so the response comes back after one round trip in total instead of two.

    That saves 40 ms here, and much more on a long-distance or mobile link. But early data has a catch.

    Scene: The browser sends the ClientHello and the GET together. The server forwards the request to App 1 right away and the response reaches the browser after one round trip, about 47 ms.

    Key idea: 0-RTT puts the first request in the first flight: the whole exchange takes one round trip.

  8. 8. Early data can be replayed

    *Scripted.* Early data is encrypted, but it is not protected against replay: it is sent before the server has contributed anything fresh to the keys. An attacker who records the first flight can send the same bytes again. Here the early request is POST /orders, and the copy places the order a second time. The attacker cannot read or change it, but the duplicate is real.

    The defences: accept 0-RTT only for safe, idempotent requests (GET without side effects); have the TLS terminator mark forwarded early requests (Early-Data: 1) so the origin can answer 425 Too Early for anything risky; single-use tickets and anti-replay caches help, but are hard to make airtight across a distributed fleet.

    Scene: The browser sends a POST as early data and App 1 places the order. The Wi-Fi then replays the recorded flight; the server accepts it again and App 1 places the same order a second time.

    Key idea: 0-RTT data may arrive twice. Only allow it for requests that are safe to repeat.

  9. 9. Who terminates TLS?

    *Simulated from here.* Behind shop.example.com sit a load balancer and two app servers. Many browsers now send 240 requests per second. First setup: the balancer passes TCP through untouched (layer 4) and each app server terminates TLS itself.

    Handshakes for new connections and record encryption then cost app-server time: here an illustrative 8 ms per request on top of 20 ms of real work. Both servers run about 80% busy and requests start to queue. Every server also needs the certificate and private key, and renewing it means touching every server.

    Scene: Browsers send 240 requests per second through a layer-4 load balancer to two app servers that each terminate TLS. Both are about 80% busy and requests queue.

    Key idea: Terminating TLS on every app server spends their capacity on crypto and spreads private keys across the fleet.

  10. 10. Terminate TLS at the load balancer

    Move TLS to the balancer (layer 7). It holds the certificate, does the handshakes (often with hardware acceleration) and forwards plain HTTP to the app servers over long-lived connections. The balancer’s own work is modelled here only as 1 ms of extra latency; a real one needs capacity for it too.

    The app servers drop back to 20 ms per request: utilisation falls to about 60% and P95 drops. One place to renew certificates, and the balancer can now read HTTP: route by path, add headers, apply rate limits and the 0-RTT rules from before.

    Scene: The load balancer now terminates TLS and forwards plain HTTP. App 1 and App 2 are about 60% busy and P95 latency is lower than before.

    Key idea: Terminating TLS at the edge or balancer centralises keys and crypto and frees app capacity.

  11. 11. Plaintext inside, or re-encrypt?

    Plain HTTP behind the balancer means anyone inside the network can read traffic. Many organisations now re-encrypt to the backends (often mutual TLS issued by an internal CA or a service mesh), following a zero-trust model.

    It costs less than it sounds: balancer-to-backend connections are long-lived and pooled, so full handshakes are rare and most of the cost is cheap symmetric encryption, here an illustrative 1 ms per request. Utilisation rises only a little. The other option, TLS passthrough with routing by SNI, keeps end-to-end encryption but gives up layer-7 features at the balancer.

    Scene: The load balancer re-encrypts traffic to the app servers over pooled connections. App servers are slightly busier than with plain HTTP inside, but far less than when they did full TLS.

    Key idea: Re-encrypting on pooled backend connections is cheap; full handshakes per request are what cost.

  12. 12. What HTTPS gives you, and what it costs

    TLS 1.3 gives confidentiality, integrity and server authentication for one round trip on a new connection; resumption makes repeat handshakes cheap and 0-RTT removes the round trip for requests that are safe to replay.

    Operationally: automate certificate renewal (lifetimes are shrinking), terminate TLS where it is cheapest to manage (edge or balancer), decide deliberately whether traffic inside is encrypted, and keep 0-RTT limited to idempotent requests.

    Scene: Browsers send 240 requests per second to a TLS-terminating load balancer that re-encrypts to two app servers, both moderately busy.

    Key idea: Authenticate with certificates, encrypt with ephemeral keys, terminate where keys are easy to manage.