Lesson 4 of 7 · 9 min read
How TLS 1.3 Works
In this lesson
TL;DR: In TLS 1.3 (RFC 8446, revised in July 2026 as RFC 9846) the client sends a key share in its first message, the server answers with its own, and both derive fresh session keys from an ephemeral Diffie-Hellman exchange, which gives forward secrecy. The server sends its certificate and a CertificateVerify signature over the handshake transcript, proving it holds the certificate's private key. Both sides send Finished messages, MACs over the whole transcript, so any tampering with the negotiation is detected. Application data then flows under AES-GCM or ChaCha20-Poly1305. One round trip, and no legacy options to downgrade to.
Before you read
Pick an answer before you read further. The lesson below explains it, and guessing first, right or wrong, helps the explanation stay with you.
1An attacker obtains a copy of a website's certificate (the public certificate file, not the private key). Can they impersonate the site over TLS?
What TLS has to achieve
A client connecting to a server across a network it does not control needs three things:
- Confidentiality: nobody on the path can read the traffic.
- Integrity: nobody can change it undetected.
- Server authentication: the client is talking to the real server, not an impostor.
TLS 1.3, published as RFC 8446 in 2018 and revised as RFC 9846 in July 2026 (still TLS 1.3, not a new version), achieves all three in one round trip and removed the options that made earlier versions fragile: RSA key transport (no forward secrecy), static Diffie-Hellman, CBC-mode ciphers, compression and renegotiation.
The handshake, message by message
Client
Browser or service
Server
Holds cert private key
Client to Server
1
1. ClientHello: key share, cipher suites, SNI
A fresh ephemeral public key (for example X25519), the AEAD cipher suites it supports, and the server name it wants. Sent in the clear.
What each piece protects against:
| Message | Protects against |
|---|---|
| Ephemeral key shares | Passive eavesdropping, and later decryption if a long-term key is stolen (forward secrecy) |
| Certificate, validated against trusted roots | Connecting to a server that cannot present a certificate for this name from a trusted CA |
| CertificateVerify | An attacker replaying a stolen certificate without its private key |
| Finished messages | Tampering with the handshake, including forcing weaker options |
| AEAD record protection | Reading or modifying application data |
If the client's key share uses a group the server does not support, the server sends a HelloRetryRequest naming one it does, costing one extra round trip.
Inside the key schedule
TLS 1.3 never uses the Diffie-Hellman output directly. It feeds it through HKDF in three stages, deriving a separate secret for each purpose with a text label, so a key used for one job can never be mistaken for another.
- 1
1 · Early secret
from the resumption PSK, or zeros
- Binder keys prove the client holds the PSK
- c e traffic: keys for 0-RTT early data
No fresh Diffie-Hellman yet: early data is not forward secret
derived, then add DHE - 2
2 · Handshake secret
mixes in the (EC)DHE shared secret
- c hs traffic and s hs traffic
- Encrypt the certificate and the rest of the handshake
Certificates travel encrypted in TLS 1.3
derived - 3
3 · Main secret
derived after the handshake keys
- c ap traffic and s ap traffic for application data
- exp master for exporters, res master for future resumption
KeyUpdate ratchets traffic keys forward with traffic upd
Before key exchange
With a resumption PSK, the client can derive early-data keys immediately, which is why 0-RTT exists and why it lacks forward secrecy.
The labels are worth recognising (c hs traffic, s ap traffic, res master) because they appear in key-log files used to decrypt captures during debugging. RFC 9846 renamed the secrets to drop "master" from their names, while keeping the original label strings on the wire for compatibility.
Version fields and downgrade protection
TLS 1.3 hides its own version number from middleboxes that broke when it changed. The legacy_version field in ClientHello and ServerHello is fixed at 0x0303, the number for TLS 1.2, and the real version is negotiated in the supported_versions extension. To stop an attacker forcing a 1.3-capable client and server down to 1.2, a TLS 1.3 server that ends up negotiating 1.2 writes a fixed sentinel, the ASCII bytes "DOWNGRD" followed by 01, into the last 8 bytes of its random value. The random is signed in the handshake, so the attacker cannot remove it, and a 1.3-capable client that sees it aborts. A HelloRetryRequest, by contrast, is recognised by a different fixed random: the SHA-256 hash of the string "HelloRetryRequest".
Cipher suites and usage limits
TLS 1.3 defines five cipher suites, each naming an AEAD and a hash for HKDF: TLS_AES_128_GCM_SHA256 (mandatory to implement), TLS_AES_256_GCM_SHA384, TLS_CHACHA20_POLY1305_SHA256, and two CCM suites used mainly on constrained devices. Key exchange and signature algorithms are negotiated separately, which is why the list is short.
Keys also wear out. The RFC limits AES-GCM to 2^24.5 full-size records under one set of keys, and RFC 9846 makes updating keys before the limit a requirement. A full-size record carries 2^14 bytes, so one key set covers about 2^38.5 bytes, roughly 389 GB, before a KeyUpdate message must ratchet the traffic keys forward. Short web connections never get close; long-lived tunnels, replication links and gRPC streams can.
0-RTT and its catch
A client that has connected before can resume with a pre-shared key and send data in its very first flight, called 0-RTT or early data. It saves a round trip, but early data can be replayed: an attacker who captures it can send it again. Servers should accept 0-RTT only for requests that are safe to repeat, such as plain reads, and never for actions like payments.
The details that make this an engineering decision rather than a slogan:
- No forward secrecy for early data. It is encrypted with keys derived from the resumption secret alone, before any fresh Diffie-Hellman, so whoever later obtains that secret (or the server's session-ticket encryption key) can decrypt it.
- Replay windows. Session tickets may live for at most 7 days (604,800 seconds). The RFC describes anti-replay options, single-use tickets, recording ClientHellos and freshness checks with windows on the order of ten seconds, but none prevents replay across servers that do not share state.
- HTTP's answer. RFC 8470 lets a CDN or proxy forward early data with an
Early-Data: 1header, and lets the origin respond425 Too Earlyto make the client retry after the handshake completes. Accept early data only for idempotent methods, and enforce it at the edge. - Resumption without fresh key exchange. A resumption mode that uses the PSK alone (no new Diffie-Hellman) has the same weakness as early data for the whole session. Prefer the mode that adds a fresh key share, and rotate ticket-encryption keys frequently.
Encrypted Client Hello
Without ECH, the server name travels in plaintext in the ClientHello, which lets any network observer, and any censor, see which site on a shared IP a user is visiting. Encrypted Client Hello, standardised as RFC 9849 in March 2026, splits the ClientHello in two. The real ("inner") ClientHello, including the true server name, is encrypted with HPKE to a public key the server publishes, usually in a DNS HTTPS record. The visible ("outer") ClientHello carries only a shared public_name, such as the CDN's name. Clients that do not have a real config send fake "GREASE" ECH extensions, so the presence of ECH does not single out its users. If the server rejects the config, it returns fresh retry_configs authenticated for the public name, and the client retries once; it must never fall back to sending the real name in plaintext. ECH protects the name, not the destination address: a site with its own dedicated IP is still identifiable.
Post-quantum key exchange
An attacker who records TLS traffic today can decrypt it later if they ever break the key exchange, which is the "harvest now, decrypt later" threat a large quantum computer would create for elliptic-curve Diffie-Hellman. The response is a hybrid key exchange: run X25519 and ML-KEM-768 (the lattice-based key encapsulation mechanism NIST standardised as FIPS 203 in August 2024) together, and derive keys from both shared secrets, so the connection stays secure unless both are broken.
| Property | X25519 alone | X25519MLKEM768 hybrid |
|---|---|---|
| Client key share | 32 bytes | 1,216 bytes (1,184 for ML-KEM plus 32) |
| Server key share | 32 bytes | 1,120 bytes (1,088 for ML-KEM plus 32) |
| Protects recorded traffic against a future quantum adversary | No | Yes, if ML-KEM holds |
| TLS codepoint | 0x001D | 0x11EC |
The hybrid group is defined in RFC 10024 (August 2026), but deployment ran ahead of the RFC: Chrome switched its default from an early Kyber draft to ML-KEM in Chrome 131, and Apple enabled X25519MLKEM768 by default for TLS 1.3 in iOS 26's networking frameworks. Two caveats belong in an interview answer. Certificates and handshake signatures are still classical, which matters for live impersonation by a future quantum attacker, not for recorded traffic. And the larger ClientHello no longer fits in a single packet, which has broken some middleboxes that assumed it would.
Mutual TLS
Normally only the server authenticates. In mutual TLS (mTLS) the server also requests a certificate from the client, and the client proves possession of its private key in the same way. Service meshes and internal APIs use mTLS so each service has a cryptographic identity. The trust model differs from the public web: you usually run your own internal certificate authority and decide which identities may call which services, which still requires authorization on top.
What TLS does not protect
TLS is often treated as "security done". It is a channel protection, and engineers should know its edges:
- The endpoints. A compromised server or client sees plaintext. TLS protects data between them.
- Data at rest. Once received, data is stored however the application stores it.
- Authorization. TLS tells the server the connection is encrypted and, with mTLS, who the client is. It does not decide what that client may do.
- Metadata. IP addresses, timing and sizes are visible. The server name in the ClientHello is visible unless Encrypted Client Hello is in use.
- Bad validation. Code that disables certificate checks (
verify=False, "accept all certificates") keeps encryption but loses authentication, so any interceptor can impersonate the server.
That last item matters for AI integrations. Agent frameworks, notebooks and internal tools that call model APIs or tool servers with verification switched off "to make it work" are open to interception on any network the attacker can reach.
Worked example: a latency and byte budget
A client is 80 ms round-trip from a server.
| Scenario | Time until the request is sent | Notes |
|---|---|---|
| TCP plus full TLS 1.3 handshake | 160 ms | One RTT for TCP, one for TLS |
| QUIC (HTTP/3) with TLS 1.3 | 80 ms | Transport and cryptographic handshakes combined |
| Client guessed the wrong key-share group | +80 ms | HelloRetryRequest adds a round trip |
| TLS 1.3 resumption with 0-RTT | 0 ms after TCP | Request rides the first flight, replayable |
Now add the post-quantum share: the ClientHello grows by about 1,184 bytes, so it spans two TCP segments instead of one. On a healthy path that costs almost nothing; on paths with middleboxes that expect a one-packet ClientHello, connections fail outright, which is why browsers rolled the change out gradually and kept the ability to disable it by policy.
For a long-lived AES-GCM connection, budget the 389 GB per-key-set limit: a replication link moving 1 GB a minute reaches it in about six and a half hours, so the implementation must send KeyUpdate on schedule.
Misconceptions interviewers listen for
- "TLS 1.3 hides which site I visit." Only with ECH; and even then, not the destination IP.
- "An observer sees the server certificate." In TLS 1.3 it is encrypted under the handshake keys, although anyone can fetch it by connecting.
- "0-RTT is just a faster handshake." It is replayable and not forward secret.
- "The post-quantum hybrid makes TLS quantum-safe." It protects the key exchange against recorded-traffic attacks; authentication is still classical.
- "RFC 9846 is TLS 1.4." It revises TLS 1.3.
- "Every resumed session has forward secrecy." Not in PSK-only mode, which depends on the ticket key.
What if · interview follow-ups
Hold your answer as the constraints change
You run TLS termination for a payments company: a CDN in front of web and API traffic, session resumption enabled, and long-lived connections between data centres. The interviewer changes one condition at a time.
Start here
What if the server's certificate private key leaks tomorrow?
Which keys protected yesterday's sessions?
Past full handshakes stay confidential, because their traffic keys came from ephemeral Diffie-Hellman shares that were discarded. The attacker can impersonate the server until the certificate expires or clients stop trusting it, and revocation reaches clients slowly, so reissue immediately, revoke, and rely on short certificate lifetimes to bound the window.
Carry it forwardForward secrecy protects the past; certificate lifetime and revocation decide the future.
Weak answerSaying all recorded traffic is now decryptable.
Constraint changes
What if the session-ticket encryption key leaks instead?
Which data was protected only by keys derived from tickets?
0-RTT early data, and any sessions resumed in PSK-only mode without a fresh key share, become decryptable for the tickets that key protected. Rotate ticket keys frequently, keep them out of long-term storage, prefer resumption with a fresh Diffie-Hellman share, and treat a ticket-key leak as an incident affecting recent sessions.
Carry it forwardResumption secrets are long-term keys in disguise; rotate them like keys.
Weak answerAssuming forward secrecy covers every resumed connection.
Constraint changes
What if product wants 0-RTT on the payments API to cut latency?
What can an attacker who captures the first flight do?
Replay it, possibly to another server that has not seen it. Accept early data only for idempotent requests: mark it at the CDN with Early-Data: 1, have the origin answer 425 Too Early for anything that changes state, and require idempotency keys on payment requests regardless. The latency win belongs to reads, not transfers.
Carry it forward0-RTT is safe only where replay is harmless; enforce that at the edge and the origin.
Weak answerEnabling 0-RTT globally because TLS encrypts it.
Constraint changes
What if an adversary is recording traffic now and may have a quantum computer in ten years?
Which part of the handshake would they break first?
Elliptic-curve key exchange would fall, exposing recorded sessions. Enable the X25519MLKEM768 hybrid on the CDN and on inter-data-centre links so recorded traffic stays safe unless ML-KEM is also broken, then find flows still on classical-only groups, such as old clients, internal services, VPNs and SSH, and prioritise those carrying secrets with a long life. Authentication can migrate later, because it only matters at connection time.
Carry it forwardFix key exchange first for harvest-now-decrypt-later; signatures matter only for live attacks.
Weak answerDeclaring nothing can be done until post-quantum certificates exist.
Constraint changes
What if the data-centre replication link stays up for weeks on one AES-GCM connection?
How much data may one key set protect?
About 2^24.5 full-size records, roughly 389 GB, after which the security margin degrades; RFC 9846 requires updating keys before the limit. Confirm the TLS library sends KeyUpdate automatically on long connections, or cycle connections on a schedule well inside the limit, and monitor for libraries that silently do neither.
Carry it forwardAEAD keys have usage limits; long-lived connections must ratchet keys.
Weak answerAssuming a key is good for the life of the connection.
Now defend it
As the defender, what TLS telemetry would you watch at the edge?
Negotiated protocol versions and groups per client population, so classical-only and TLS 1.2 clients are visible; rates of HelloRetryRequest and handshake failures after enabling the hybrid; volume of accepted early data and 425 responses per route; ticket-key rotation age; and certificate expiry and issuance events for every name you serve.
Primary references
- RFC 9846: the July 2026 revision of TLS 1.3, accessed 6 November 2026.
- RFC 9525: TLS service identity verification, accessed 6 November 2026.
How this shows up in interviews
"Walk me through a TLS handshake" is a staple. The strong answer goes beyond the message names: it says what each step defends against, explains forward secrecy, names CertificateVerify as the proof of key possession, and lists what TLS does not cover. Follow-ups test depth: 0-RTT replay, how certificate validation can fail, and how mutual TLS changes the trust model.
Say it in 30 seconds: "The client sends an ephemeral key share, the server replies with its own, and both derive session keys from ECDHE, which gives forward secrecy. The server sends its certificate and a CertificateVerify signature over the transcript, proving it holds the private key for that name, and both sides send Finished MACs so tampering with the negotiation is caught. Then data flows under AES-GCM. It's one round trip. TLS protects the channel, not the endpoints, the data at rest or authorization."
Check yourself
Say or write your answer first, then reveal. Explaining it from memory, in your own words, is the skill an interviewer is checking.
1Why does TLS 1.3 sign the whole handshake transcript in CertificateVerify rather than just signing the server's key share?
2A team says their agent's calls to an internal tool server are secure because they use HTTPS, but the client is configured to skip certificate verification. What is actually protected?
3How does a TLS 1.3 client detect that an attacker forced the connection down to TLS 1.2?
4Why is 0-RTT early data not forward secret?
5What does Encrypted Client Hello hide, and what does it not?