TLS 1.3 HANDSHAKE

One round trip to a secure channel

L218 MINSECURITY
PREDICT

Mallory intercepts the connection and runs the handshake with her own key and a certificate she made for bank.example. Which client check fails?

The client sends ClientHello with a key share. The server answers with its own key share, so both now hold a handshake secret, as in Diffie-Hellman. Everything after that is encrypted: the certificate chain, a CertificateVerify signing the transcript with the certificate’s key, and a Finished MAC. The client checks them, sends its own Finished, and can send data after one round trip.

The key exchange gives you secrecy with whoever answered. The certificate check is the step that says who answered. If the hostname, dates or signatures are wrong, the client must abort before sending a single byte of application data.

▶ SIMULATION
CLIENT · verifies certs
state: idle
key_share x25519: — · secret: —
PATH
direct
transcript hash: —
round trips: 0
SERVER bank.example
version: — · key_share: —
secret: —
groups: x25519, secp256r1
certificate chain—
client trustsAtlas Root CA · today is day 500
last—
✓ the client never sends application data to an unauthenticated server
SCHEDULE
01[CLIENT]client verifies certificates (default)
02[CLIENT]ClientHello: versions, groups, key_share, random
03[SERVER]ServerHello + key_share (or HelloRetryRequest); client checks for a downgrade
04[SERVER]{EncryptedExtensions, Certificate, CertificateVerify, Finished}
05[CLIENT]client checks certificate, CertificateVerify, Finished
06[CLIENT]{Finished}; both derive application keys
07[CLIENT]client sends GET /account with its session cookie
Start of handshake scenario. 7 steps.
TLS 1.3 full handshake (RFC 8446), 1 RTT

Client                                         Server
ClientHello  supported_versions, key_share(g^a) ─────▶
             (wrong group? ◀── HelloRetryRequest, +1 RTT)
        ◀──── ServerHello  key_share(g^b)
              [handshake keys from g^ab]
        ◀──── {EncryptedExtensions}
        ◀──── {Certificate}        chain: leaf ← intermediate
        ◀──── {CertificateVerify}  sig over transcript, leaf key
        ◀──── {Finished}           MAC over transcript
client checks, in this order, aborting on any failure:
  1. not downgraded: TLS 1.2 + "DOWNGRD\x01" in ServerHello.random → illegal_parameter
  2. certificate: hostname in SAN, every cert in date, each signed by the
     next, chain ends at a root in the trust store → bad_certificate /
     certificate_expired / unknown_ca
  3. CertificateVerify: transcript signed by the key IN that certificate
  4. Finished: MAC matches
{Finished} ─────▶
[application keys]  ═══ application data ═══

Why the certificate check is the one that matters against a MITM:
an attacker can run steps 3 and 4 perfectly with her own key.
Only step 2 ties that key to the name "bank.example".

Watch the client’s check list and the invariant strip. SKIP VERIFY + MITM is the only run that sends the cookie to someone unauthenticated. Every other attack ends with an alert and 0 bytes sent: a forged certificate, an expired one, and a downgrade caught by the sentinel. HELLO RETRY shows the one legitimate way the handshake costs a second round trip.

BREAK IT NOT YET

This client has certificate verification turned off, and against the real server everything works. Inject one fault at a point where the session cookie goes to a server that is not authenticated.

GOAL: application data reaches a peer whose certificate does not verify

FIX IT NOT YET

Implement the client's certificate check. chain[0] is the leaf, each next entry should be its issuer, and the last one must be issued by a root in roots. Reject a wrong hostname (match san entries exactly, or a *. wildcard for exactly one leftmost label), any certificate outside notBefore..notAfter, a non-CA issuer, and any signature that fails cert.verifySignature(issuerKey). Return { ok, reason }.

Mental model:

TLS is Diffie-Hellman plus proof of identity. The key exchange makes a secret with whoever answered. The certificate chain, walked to a root you already trust and matched against the hostname, is what makes “whoever” mean “bank.example”. If any check fails, the client hangs up before sending data. A client that skips the check is encrypting to strangers.

IN PRODUCTION

Every HTTPS client and server. The bugs show up as verify=False, InsecureSkipVerify: true, NODE_TLS_REJECT_UNAUTHORIZED=0, outages when a certificate expires, and corporate proxies that add their own root to the trust store. Certificate pinning narrows which roots a mobile app will accept.

IN INTERVIEWS

“What happens when you type https:// into a browser?” Walk through ClientHello and key_share, ServerHello, the encrypted certificate, CertificateVerify and Finished. Say that 1.3 does this in one round trip, why ephemeral keys give forward secrecy, and that the certificate check, not the encryption, is what stops a man in the middle.

RECALL CARDS Tap to flip. They join your review deck when you mark the lesson complete.

USED IN

Chapters that build on this lesson.

NEXT: BUFFER OVERFLOW →