TLS Lecture 2 · The TLS 1.3 Handshake, Step by Step

The core of TLS, rebuilt top-down: the three goals of the handshake (authentication, key agreement, safe negotiation), the three TLS 1.3 flights traced message by message against a real connection to chase.com, Diffie-Hellman computed by hand and the post-quantum X25519MLKEM768 hybrid, how HKDF folds the transcript into the keys so that CertificateVerify and Finished catch any edit, why TLS 1.2 was slower, leaked certificates and lacked forward secrecy, how downgrades, the Debian randomness failure and handshake floods were defeated, and the record layer's AEAD with a sequence-numbered nonce.

Subject: Computer Security · 74 slides · code lesson

Open the interactive version of this deck

What this lesson covers

The lesson, slide by slide

1. The TLS 1.3 Handshake, Step by Step

Title

Computer Security — TLS Lecture 2

Two strangers on a hostile network get one round trip to trust each other and agree on a key

2. Part 1 — What the handshake is for

Section

Three questions before your password goes anywhere

3. What you will be able to do

Objectives

This is the core of TLS. We go top-down: first what the handshake has to achieve, then the round trip at a high level, then the Diffie-Hellman trick inside it, then each message in detail, and finally why the older TLS 1.2 design was worse and how the record layer protects the data afterwards.

Security I, Lecture 3: TLS and the Web PKI slide s-div-hs

4. Warm-up: what must TLS guarantee?

Warm-up

The last lesson listed three things an attacker who owns the network can do to your traffic.

Discussion prompt

Name the three dangers, and the guarantee TLS gives against each one. Which of the three guarantees did the last lesson say was the hard part?

Hint: Read, change, pretend.

Answer:

Eavesdrop, answered by confidentiality. Tamper, answered by integrity. Impersonate, answered by authentication.

Confidentiality and integrity come from authenticated encryption, which you already know. Authentication, knowing who is really at the other end, is the hard part. The handshake is where TLS earns it, and also where it agrees on the key that the encryption will use.

5. Three questions before your password goes anywhere

Concept

You and Chase have never met, and the attacker from the threat model sits in the middle. Before a single byte of your data is sent, the handshake has to answer three questions.

questiongoalwhat goes wrong without it
Who are you, really?authenticationyou encrypt perfectly, to the attacker
Which key do we share?key agreementthe attacker copies the key as it crosses the wire
Did anyone change what we agreed on?safe negotiationthe attacker forces a weak, breakable option

Keep this table in view. Every message in the handshake exists to answer one of these rows, and at the end of the lesson we check each row off.

Security I, Lecture 3: TLS and the Web PKI slide s-hs-why

6. Goal 1: are you really chase.com?

Concept

You type chase.com and expect the bank. But the attacker controls the network, including DNS, so it answers the lookup with its own address and serves a copy of the Chase login page that looks exactly right.

Figure (svg): You connect with perfect AES to the attacker, who shows a fake Chase page and relays to the real chase.com

Notice what this means: perfect encryption with the fake site would not help at all, because the party at the other end of the encrypted connection is the attacker. Your password arrives safely, at the wrong place. So the handshake has to check who is on the other end before anything else matters.

Security I, Lecture 3: TLS and the Web PKI slide s-hs-goal-1

7. Is strong encryption enough on its own?

Counterexample

A classmate says: if my connection uses AES-256, nobody can steal my password, whatever else happens.

Discussion prompt

Describe one situation where the connection really does use AES-256 and the password is still stolen. What was missing?

Hint: Who holds the other end of the AES key?

Answer:

The fake airport Wi-Fi from the last lesson: you connect, with AES-256, to a server the attacker runs. The encryption works perfectly between you and the attacker, who reads your password and forwards you to the real site.

What was missing is authentication of the other end. Encryption answers who can read this on the way. It never answers who is at the end of the pipe. That is a separate guarantee and needs a separate mechanism: in TLS, the certificate and a signature.

8. Goal 2: how do two strangers agree on a secret key?

Concept

Everything after the handshake is AES, and AES needs the same key at both ends. You and Chase have never met, and if one side simply sends a key across, the attacker copies it on the way.

approachwhat the attacker seesresult
send the key in the clearthe keybroken immediately
lock the key with the server's RSA key (TLS 1.2)the locked keysafe today, exposed if the RSA key ever leaks
build the key from public pieces (Diffie-Hellman)both piecesstill cannot build the key

The goal is the third row: both sides build the same key out of pieces sent in public, where the attacker sees every piece and still cannot build it. That is use 3 from the public-key lecture, and this lesson shows exactly how it works.

Security I, Lecture 3: TLS and the Web PKI slide s-hs-goal-2

9. Background: every client and server supports different options

Concept

TLS is not one fixed recipe. Each connection uses an option: a protocol version plus a cipher suite, the set of algorithms. Every client and every server supports its own list, and Chase supports several because its customers are not all on new devices.

clientbest version it speakswhat the connection uses
a new ChromeTLS 1.3TLS 1.3
an Android phone from 2014TLS 1.2TLS 1.2
an old card reader in a storeTLS 1.0TLS 1.0, if the server still allows it

So every connection begins with a negotiation: find the best option both sides share. That negotiation is exactly what the attacker goes after, two slides from now.

Security I, Lecture 3: TLS and the Web PKI slide s-hs-goal-3-bg

10. Read a TLS 1.3 cipher suite name

Matching

The connection to chase.com used the cipher suite TLS_AES_256_GCM_SHA384. Each part of the name is one choice.

Match the pairs

  • p1. AES_256
  • p2. GCM
  • p3. SHA384
  • p4. TLS
  • q1. the block cipher and its key size, 256 bits
  • q2. the authenticated mode: counter mode plus a built-in MAC
  • q3. the hash used for the transcript and inside HKDF
  • q4. the protocol family the suite belongs to

Why: A TLS 1.3 suite names only the record protection (an AEAD cipher) and the hash for the key schedule. The key exchange and the signature algorithm are negotiated separately, through the supported groups and signature algorithms lists. TLS 1.2 suite names were longer because they also packed in the key exchange.

11. Goal 3: did anyone change what we agreed on?

Concept

Your browser and Chase should settle on the strongest option they share. But the list of options travels over the network in the clear, so the attacker can delete the strong ones, which is exactly the SSL 2.0 attack from the history.

Figure (svg): The browser offers TLS 1.3, 1.2 and 1.0; the attacker deletes 1.3 and 1.2; Chase receives only 1.0 and picks it

Chase sees only the weak option and honestly picks it, and nobody notices. The fix cannot be to hide the list, because the server must read it before any key exists. Instead, the handshake must end with both sides confirming that they saw exactly the same messages.

Security I, Lecture 3: TLS and the Web PKI slide s-hs-goal-3

12. An edited menu, with no final check

Prediction

Imagine a handshake with no step at the end where both sides compare what they saw. The attacker removes every strong option from the browser's offer.

Predict first

What happens?

  • The connection uses the weak option, and neither side notices anything wrong
  • The server notices the offer was edited and refuses
  • The browser notices its offer was edited and refuses
  • The connection fails because the options do not match

Correct: The connection uses the weak option, and neither side notices anything wrong

Why: Each side only sees its own half. The browser knows what it sent; the server knows what it received; nothing compares the two. The server picks the best option it was shown and the browser accepts a valid choice. Only a final check over the whole conversation, which TLS calls Finished, turns this silent downgrade into a failed handshake.

13. Which handshake goal stops this attack?

Sorting

Sort each attack to the goal that defeats it.

Sort into buckets

Authentication, key agreement, or safe negotiation?

authentication
A fake Wi-Fi hotspot serves a copy of the bank's login page; A DNS reply points chase.com at the attacker's server
key agreement
An eavesdropper records the key as it is sent across
safe negotiation
A man in the middle deletes TLS 1.3 from the browser's offer; An attacker removes the strong cipher suites so only a 40-bit one is left
auth
The danger is talking to the wrong party; only proof of who is at the other end stops it.
kex
The danger is the key itself being seen; building it from public pieces stops it.
neg
The danger is a quiet edit of the opening offer; confirming both sides saw the same messages stops it.

14. Part 2 — The whole handshake in one round trip

Section

Three flights, then the details of the two hellos

15. The whole handshake, one message at a time

Concept

Before anything is sent, each side picks a fresh random secret, a for you and b for Chase, and turns it into a public key half, A and B. The handshake is then three flights, drawn on the next slide.

Flight 1 says here is what I support, and my half A. Chase now has both halves and runs what we will call a mystery box that turns them into an AES key. Flight 2 answers with the choice and Chase's half B, in the clear, and then, already encrypted with the new key, the Certificate, CertificateVerify and Finished. You run the same box and get the same key, which never crossed the wire. Flight 3 is your Finished, and your data can go right behind it.

Security I, Lecture 3: TLS and the Web PKI slide s-hs-trip

16. Trace the handshake flight by flight

Worked example

Write the handshake out as a transcript, the way a protocol analyser would show it. Braces mark messages encrypted with the handshake key.

Figure (svg): TLS 1.3 sequence: ClientHello with A in the clear; ServerHello with B in the clear, then Certificate, CertificateVerify and Finished encrypted; then the client's Finished and data

flight 1  client -> server   ClientHello
                             (versions, cipher suites, random, key share A, server name)
flight 2  server -> client   ServerHello (choice, random, key share B)
          ---- both sides now derive handshake keys ----
                             {EncryptedExtensions} {Certificate}
                             {CertificateVerify} {Finished}
flight 3  client -> server   {Finished}  then  {application data}

{ } = encrypted with the handshake key
flightdirectioncontentsprotected by
1client to serverClientHello with key share Anothing yet; checked later by Finished
2aserver to clientServerHello with key share Bnothing yet; checked later by Finished
2bserver to clientCertificate, CertificateVerify, FinishedAES-GCM with the handshake key
3client to serverFinished, then application dataAES-GCM with handshake, then traffic keys

Count the round trips

Why: Flights 1 and 2 are one round trip. The client has the key as soon as flight 2 arrives, so its first data travels with flight 3.

Verify: against RFC 8446

Why: Section 2 of the standard draws the same picture: ClientHello with key_share, ServerHello with key_share, then EncryptedExtensions, Certificate, CertificateVerify and Finished under handshake keys, and the client's Finished.

RFC 8446 — The Transport Layer Security (TLS) Protocol Version 1.3 section 2, Protocol Overview

17. Put the TLS 1.3 handshake in order

Ranking

Order the events from the moment you press Enter until your first request leaves.

Put in order

  1. Your browser picks a secret a and computes A
  2. ClientHello carries the options and A
  3. ServerHello carries Chase's choice and B
  4. Chase sends Certificate and CertificateVerify, encrypted
  5. Chase sends Finished, encrypted
  6. Your browser sends Finished, then the HTTP request

Why: The client commits to a key share before hearing from the server, which is what makes one round trip possible. Everything the server sends after ServerHello is already encrypted, and the client's Finished closes the handshake with its data right behind it.

18. Why is the clear part signed instead of encrypted?

Socratic

Flight 1 and the start of flight 2 travel in the clear, so the attacker can read A and B.

Discussion prompt

Try to encrypt the hellos. Which key could you use at that moment? And is reading A and B actually a problem, or is something else the real danger?

Hint: Integrity or secrecy: which one does a public key half need?

Answer:

There is no usable key. The AES key is made from A and B, so it does not exist yet. Chase's RSA public key arrives only in flight 2, inside the certificate, and locking secrets with RSA is the old TLS 1.2 design with its own problems.

Reading A and B is harmless: seeing A = 8 and B = 19 does not give the key, because you still need a or b, which never leave the two machines. The real danger is a swap: if the attacker replaces A with its own value, the two sides would compute different things. What is needed is integrity, not secrecy, and a signature provides it. CertificateVerify is Chase signing a fingerprint of every message so far, A and B included.

Security I, Lecture 3: TLS and the Web PKI slide s-hs-why-sign

19. ClientHello: hello, here is what I support

Concept

ClientHello is not encrypted, so anyone on the path can read it. Tampering with it is caught later, by Finished. It carries four things.

fieldexamplewhy it is there
server name (SNI)www.chase.comone machine may host many sites; the server needs the name before any key exists
the menuTLS 1.3, TLS 1.2; AES-256-GCM, ChaCha20-Poly1305, ...versions and cipher suites, strongest first
client random32 fresh random bytesno two handshakes are alike, so nothing can be replayed
key share Aa public number for a named groupyour half of the key, sent before hearing anything back

Hold on to the key share. A few slides from now we see how two public halves become one shared key.

Security I, Lecture 3: TLS and the Web PKI slide s-msg-ch

20. ServerHello: this is what we will use

Concept

ServerHello is the answer. Chase picks one option from your menu, adds its own random bytes, and sends its key half B. B is a one-time public value: Chase made it from a fresh secret b and throws b away after this connection.

$ openssl s_client -connect www.chase.com:443 -servername www.chase.com
...
New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384
Protocol: TLSv1.3
Negotiated TLS1.3 group: X25519MLKEM768
Peer signature type: rsa_pss_rsae_sha256
Server public key is 2048 bit
Verification: OK
line of outputwhat it tells you
TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384the version and record cipher Chase chose from the menu
Negotiated TLS1.3 group: X25519MLKEM768the kind of key share in the two hellos
Peer signature type: rsa_pss_rsae_sha256how CertificateVerify was signed: RSA-PSS with SHA-256
Server public key is 2048 bitChase's long-term RSA key, from the certificate

Do not confuse B with Chase's long-term public key. B changes on every connection and only builds the shared key. The long-term 2048-bit RSA key proves who Chase is, and it comes right behind, inside the encrypted Certificate. This output is real: it was captured on 15 October 2026.

Security I, Lecture 3: TLS and the Web PKI slide s-msg-sh

openssl s_client -connect www.chase.com:443, run with OpenSSL 3.5.6 on 2026-10-15

21. Read a connection like an engineer

Fill the middle

A colleague pastes this from openssl s_client against an internal API. Fill in what each line tells you.

Fill in the blanks

New, TLSv1.3, Cipher is TLS_CHACHA20_POLY1305_SHA256
# record cipher: ChaCha20-Poly1305
# transcript hash: SHA-256
Negotiated TLS1.3 group: x25519
# key share kind: X25519
Peer signature type: ecdsa_secp256r1_sha256
# long-term key: ECDSA

Why: The suite gives the AEAD cipher, ChaCha20-Poly1305, and the hash, SHA-256. The group line gives the ephemeral key share, X25519 elliptic-curve Diffie-Hellman. The signature type shows the server's long-term key is an ECDSA key on the P-256 curve rather than RSA. The ephemeral share and the long-term key are two different keys with two different jobs.

22. Detour — Diffie-Hellman

Section

How two strangers agree on a secret in public

23. Detour: how can two strangers agree on a secret in public?

Step zero

Step out of TLS for a few slides, because the key halves A and B only make sense once you see this trick on its own. Forget browsers. Alice and Bob have never met, everything they say travels in public, and Eve hears all of it.

Discussion prompt

Before seeing any protocol: what would a solution need? Think about what kind of operation would let each side mix a private ingredient into a public message, and still let both arrive at the same result.

Hint: Think of mixing paint: easy to mix, hard to un-mix.

Answer:

Each side needs a secret it never sends, a public message that hides that secret, and a way to combine its own secret with the other side's public message so that both combinations land on the same value.

It sounds impossible, and for a long time people assumed it was. In 1976 Diffie and Hellman showed that exponentiation modulo a prime has exactly these properties: easy to compute forwards, hard to undo, and the order of two exponents does not matter.

Security I, Lecture 3: TLS and the Web PKI slide s-dh-detour

24. Diffie-Hellman, precisely: the protocol and the reason it works

Concept

The public setup is a large prime p and a base g. Everyone, Eve included, knows both. Then four steps.

stepAliceBob
pick a secretrandom a, keptrandom b, kept
send a public valueA = g to the a, mod pB = g to the b, mod p
combineK = B to the a, mod pK = A to the b, mod p
why they agreeg to the b, to the a, is g to the abg to the a, to the b, is g to the ab

Taking remainders mod p at any point does not change the final remainder, so the exponent rules survive. Eve knows p, g, A and B. To get K she needs a, which means solving A = g to the a mod p for a. That is the discrete logarithm problem, and for a 2048-bit p nobody knows a fast method.

Alice and Bob are fast because of square and multiply, the same trick as RSA: g to the 15 is g to the 8 times g to the 4 times g squared times g, three squarings and three multiplications instead of fourteen.

Security I, Lecture 3: TLS and the Web PKI slide s-dh-math

25. The same exchange with numbers

Worked example

Public setup p = 23 and g = 5. Alice picks a = 6, Bob picks b = 15. Every power is built from a short table of squares, exactly as a computer would do it.

p = 23, g = 5          # public setup
a = 6,  b = 15         # secrets, never sent

square:   5^1 = 5   5^2 = 2   5^4 = 4   5^8 = 16      (all mod 23)
A = 5^6  = 5^4 * 5^2           = 4 * 2          = 8
B = 5^15 = 5^8 * 5^4 * 5^2 * 5 = 16 * 4 * 2 * 5 = 640 = 19

Alice:  B^a = 19^6 = 19^4 * 19^2 = 3 * 16 = 48 = 2
Bob:    A^b = 8^15 = 8^8 * 8^4 * 8^2 * 8 = 4 * 2 * 18 * 8 = 1152 = 2
power5 mod 2319 mod 238 mod 23
15198
221618
4432
81694

Figure (svg): Alice sends 8 and computes 19 to the 6 = 2; Bob sends 19 and computes 8 to the 15 = 2; Eve sees 23, 5, 8 and 19 only

Combine

Why: Alice raises Bob's 19 to her 6 and gets 2. Bob raises Alice's 8 to his 15 and gets 2. Both are 5 to the 90 mod 23.

Verify: in Python

Why: pow(5, 6, 23) is 8, pow(5, 15, 23) is 19, pow(19, 6, 23) is 2, pow(8, 15, 23) is 2, and pow(5, 90, 23) is 2.

Security I, Lecture 3: TLS and the Web PKI slide s-dh-numbers

26. Your turn: a Diffie-Hellman exchange

Faded example

Same public setup, p = 23 and g = 5, so you can reuse the table of squares: 5, 2, 4, 16. Now Alice picks a = 4 and Bob picks b = 9.

Fill in the blanks

A = 5^4 mod 23 = 4
B = 5^9 = 5^8 * 5 mod 23 = 11
Alice: B^4 mod 23 = 13
Bob: A^9 mod 23 = 13

Why: A = 4 straight from the table. B = 16 times 5 = 80 = 3 times 23 + 11, so 11. Alice computes 11 squared = 121 = 6 mod 23, then 6 squared = 36 = 13. Bob computes 4 to the 9 = 4 to the 8 times 4 = 9 times 4 = 36 = 13. Both get 13, which is 5 to the 36 mod 23, and Eve saw only 4 and 11.

27. What can Eve do with what she saw?

Two truths and a lie

Eve recorded the public setup 23 and 5 and the two public values 8 and 19.

Eliminate the wrong options

Which statement is the myth?

  • e1. At this toy size Eve can find a = 6 by trying exponents until 5 to the a gives 8
  • e2. Multiplying A and B gives Eve the key, because 8 times 19 mod 23 equals the shared secret
  • e3. If Eve can change A on the wire, she can end up sharing a key with Bob instead of Alice

Survives elimination: e2

Why: A times B is g to the (a + b), not g to the ab. Here 8 times 19 = 152 = 14 mod 23, not 2. Combining the two public values never produces the shared key; you need one of the secret exponents. The real weakness of plain Diffie-Hellman is active substitution, not passive observation.

28. Back to TLS: Diffie-Hellman lives inside the hellos

Concept

Back to Chase. You are Alice and Chase is Bob. Your key half A rides in ClientHello, Chase's key half B rides in ServerHello, and the secrets a and b never leave the two machines.

Figure (svg): You keep a and send A in ClientHello; Chase keeps b and sends B in ServerHello; both compute g to the ab

You compute B to the a, Chase computes A to the b, and both get g to the ab, the shared secret, which goes into the mystery box on the next slides. Notice why this fits in one round trip: you made A before hearing anything from Chase.

Security I, Lecture 3: TLS and the Web PKI slide s-dh-back

29. Which g and p? TLS 1.3 allows only a short, fixed list

Concept

In TLS 1.3, g and p are never invented per connection and never sent. The standard allows a short fixed list of named groups, and ClientHello lists the names the browser supports.

familynamed groupsnotes
finite-field DH (this lesson's math)ffdhe2048, ffdhe3072, ffdhe4096, ffdhe6144, ffdhe8192g = 2 and one fixed prime per size, from RFC 7919
elliptic-curve DHx25519, x448, secp256r1, secp384r1, secp521r1same idea, different math, much smaller numbers
post-quantum hybridX25519MLKEM768X25519 plus ML-KEM-768; offered by current browsers
ffdhe2048 prime (RFC 7919), g = 2, 2048 bits:
FFFFFFFF FFFFFFFF ADF85458 A2BB4A9A AFDC5620 273D3CF1 ...
... 1B2EFFA8 86B42386 1285C97F FFFFFFFF FFFFFFFF

To keep one round trip, the browser already sends a key share for its best guess. If the server prefers a group the browser did not send a share for, it answers with HelloRetryRequest and the handshake costs one extra round trip.

Security I, Lecture 3: TLS and the Web PKI slide s-dh-groups

RFC 7919 — Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS (ffdhe groups) appendix A.1, ffdhe2048

RFC 8446 — The Transport Layer Security (TLS) Protocol Version 1.3 section 4.2.7, Supported Groups

30. Chase picked X25519MLKEM768. Why add a second algorithm?

Real world

The original lecture's connection reported plain X25519. The same command on 15 October 2026 reported X25519MLKEM768: X25519 combined with ML-KEM-768, a lattice-based key-encapsulation scheme standardised by NIST in 2024.

Discussion prompt

X25519 is not broken today. What threat is the hybrid defending against, and why does it make sense to deploy it before a large quantum computer exists?

Hint: Recordings last much longer than connections.

Answer:

The threat is harvest now, decrypt later. An attacker can record encrypted traffic today and keep it. If a large quantum computer is ever built, Shor's algorithm solves the elliptic-curve discrete logarithm, recovers the X25519 secret from the recording, and decrypts traffic that was meant to stay private for decades.

The hybrid feeds both secrets into the key schedule: the shared secret is the ML-KEM secret followed by the X25519 secret. An attacker must break both. If ML-KEM turns out to have a flaw, X25519 still protects you; if quantum computers arrive, ML-KEM still protects you. The cost is size: the client's key share grows from 32 bytes to 1216 bytes.

31. Part 3 — From shared secret to keys, and proof of identity

Section

HKDF, then Certificate, CertificateVerify and Finished

32. Opening the mystery box: from the shared secret to AES keys

Concept

The mystery box is called HKDF, and it is built from HMAC, the keyed hash from the crypto lecture, used as a blender. These values are computed on each side and never sent.

Figure (svg): Three inputs, the shared secret, a SHA-384 transcript hash of the hellos, and a label, go into HKDF; out come a key and IV for each direction and the Finished keys

inputwhat it iswhy it is there
shared secretg to the ab from Diffie-Hellmanonly you and Chase know it
transcript hashSHA-384 of exactly the ClientHello and ServerHello each side sawbinds the keys to the conversation
labela name such as c hs traffic or s hs traffica different output for each use

Out comes, per label, a value: for traffic from you to Chase a 32-byte AES-256 key and a 12-byte IV, and the same pair for the other direction. After Finished, the same box runs again with a hash of the whole handshake to make the keys for your data.

Security I, Lecture 3: TLS and the Web PKI slide s-msg-kdf

RFC 5869 — HMAC-based Extract-and-Expand Key Derivation Function (HKDF) HKDF-Extract and HKDF-Expand

33. The transcript is in the key: change one word and see

Worked example

Here is the same shape as the TLS 1.3 key schedule, shrunk to toy inputs: extract from the shared secret 2, hash the two hellos, and expand with a label. Run it twice: once on the honest hellos, once on a ClientHello where the attacker deleted TLS 1.3 from the menu.

import hashlib, hmac
def handshake_key(shared, client_hello, server_hello):
    prk = hmac.new(bytes(48), shared, hashlib.sha384).digest()       # extract
    th  = hashlib.sha384(client_hello + server_hello).digest()       # transcript
    return hmac.new(prk, b"c hs traffic" + th, hashlib.sha384).digest()[:8]

handshake_key(b"\x02", b"ClientHello: TLS1.3,TLS1.2 | A=8", b"ServerHello: TLS1.3 | B=19")
handshake_key(b"\x02", b"ClientHello: TLS1.2 | A=8",        b"ServerHello: TLS1.3 | B=19")
runClientHello offeredtranscript hash startshandshake key starts
honestTLS1.3, TLS1.2c235c0c6170e6eff366554e39ce653e4
edited on the wireTLS1.218f4e1c209af5d6778f5371bbe06968b
same edit, seen by both sidesTLS1.2 on both sidesidentical on bothidentical on both

Figure (svg): Honest run: transcript hash c235c0c6, key 366554e3; edited run: transcript hash 18f4e1c2, key 78f5371b

Read the result

Why: Chase hashes the ClientHello it received, you hash the one you sent. After the edit they differ, so the two sides derive different keys, and Chase's first encrypted message fails its AES-GCM check on your side.

Verify: the last row

Why: the attack only goes unnoticed if both sides hashed the same bytes, which means the attacker did not edit anything.

RFC 8446 — The Transport Layer Security (TLS) Protocol Version 1.3 section 7.1, Key Schedule

34. The attacker swaps A for its own value

Prediction

The attacker replaces your key share A with its own A-star in ClientHello, hoping to share a key with Chase.

Predict first

In TLS 1.3, where does the handshake fail first?

  • Your browser cannot decrypt Chase's first encrypted message
  • Chase rejects ClientHello immediately
  • Nothing fails until your HTTP request arrives
  • The certificate check fails

Correct: Your browser cannot decrypt Chase's first encrypted message

Why: Chase builds its keys from A-star and a transcript containing A-star. You build yours from B with your own a and a transcript containing A. The keys differ, so the very first encrypted message from Chase, EncryptedExtensions, fails its AES-GCM tag check on your side and you hang up. CertificateVerify and Finished would also have caught it, but the mismatch shows up first.

35. Certificate: Chase shows its ID card

Concept

The certificate is an ID card for a public key. It travels encrypted with the handshake key, and it is signed by the certificate authority. These are the real values chase.com sent on 15 October 2026.

fieldvalue from chase.commeaning
subjectCN = www.chase.com, O = JPMorgan Chase and Co.whose key this is
names it is valid forwww.chase.com, beta.chase.comthe hostnames the browser will match
public keyRSA, 2048 bits, e = 65537like the RSA recap, much bigger; Chase keeps d
validity29 Dec 2025 to 5 Jan 2027IDs expire
issuerDigiCert EV RSA CA G2who checked Chase and signed the card
chainDigiCert EV RSA CA G2, signed by DigiCert Global Root G2the root your browser already trusts

The issuer's signature is use 2 from the public-key lecture: anyone can verify it, and only DigiCert could have made it. The next lesson opens the certificate up properly.

Security I, Lecture 3: TLS and the Web PKI slide s-msg-cert

openssl s_client -connect www.chase.com:443, run with OpenSSL 3.5.6 on 2026-10-15

36. Does your browser call the CA during the handshake?

Socratic

DigiCert is a certificate authority, a company whose job is to check who owns a website and sign certificates for it.

Discussion prompt

To know who Chase is, does your browser have to contact DigiCert while the handshake is running? If not, where does it get what it needs to check the signature?

Hint: Whose public key verifies DigiCert's signature, and when did your browser get it?

Answer:

No. The CA did its work months ago: Chase proved it controls chase.com, and DigiCert signed the certificate then.

Long before that, your browser or operating system shipped with the public keys of the root CAs, roughly 150 of them. During the handshake Chase hands over the signed certificate and the intermediate, and your browser checks the signatures locally, up to a root it already has. No phone call and no extra round trip. The one exception is revocation checking, covered in the next lesson.

Security I, Lecture 3: TLS and the Web PKI slide s-msg-ca

37. CertificateVerify: proof that the ID really belongs to Chase

Concept

The certificate alone proves nothing, because it is public: anyone can download Chase's certificate and replay it, like a photocopy of someone's passport. So Chase adds CertificateVerify: it signs a hash of all the handshake messages so far with its private key.

Figure (svg): The real Chase has the certificate and the private key, so CertificateVerify passes; the attacker has only the certificate, so it fails

You check the signature with the public key printed on the certificate. The real Chase passes. The attacker has the certificate but not the private key, so it cannot produce the signature. For chase.com the signature type was rsa_pss_rsae_sha256: RSA-PSS, the padded signature scheme from the public-key lecture.

Security I, Lecture 3: TLS and the Web PKI slide s-msg-cv

38. Replay yesterday's CertificateVerify?

Counterexample

An attacker recorded a complete, valid handshake with chase.com yesterday, including Chase's genuine CertificateVerify signature.

Discussion prompt

Today the attacker pretends to be Chase and replays that recorded signature to you. Why does it fail?

Hint: What exactly did Chase sign?

Answer:

The signature covers a hash of today's handshake messages, which include your fresh client random and today's key shares. Yesterday's signature was over yesterday's transcript, so it does not verify against today's hash.

This is why both hellos carry 32 random bytes: no two transcripts are ever the same, so a signature cannot be reused. Without fresh randomness, one recorded signature would let anyone impersonate the server forever.

39. Finished: both sides compare a summary of everything

Concept

Finished closes the loop on goal 3. Each side takes a hash of every handshake message it saw and computes an HMAC over it, with a Finished key from HKDF.

finished_key = HKDF-Expand-Label(server_handshake_traffic_secret, "finished", "", 48)
verify_data  = HMAC-SHA384(finished_key, Hash(ClientHello ... CertificateVerify))
caseserver's Finishedclient's check
nothing touchedHMAC over the same transcriptmatches: continue
menu edited in ClientHelloHMAC over a different ClientHellomismatch: hang up
attacker tries to fix the HMACneeds the Finished keyimpossible: the key comes from the shared secret

Now replay the SSL 2.0 attack: the attacker edited the menu. Chase saw a different ClientHello, so its HMAC is different, and the attacker cannot fix it because it does not have the key. Both sides hang up. The downgrade is caught.

Security I, Lecture 3: TLS and the Web PKI slide s-msg-fin

RFC 8446 — The Transport Layer Security (TLS) Protocol Version 1.3 section 4.4.4, Finished

40. Which message catches it?

Discrimination

Each problem is caught by a different part of the handshake.

Sort into buckets

Certificate, CertificateVerify, or Finished?

Certificate (and its chain)
The server's key belongs to evil.example, not chase.com; A certificate signed by no CA the browser trusts
CertificateVerify
Someone replays Chase's real certificate without Chase's private key; A signature recorded in yesterday's handshake is resent today
Finished
The cipher list in ClientHello was shortened on the way
cert
The certificate binds a key to a name and must chain to a trusted root; a wrong name or an untrusted issuer fails here.
cv
Only the holder of the private key can sign this transcript; copies and replays fail.
fin
Both sides' HMAC over everything they saw must agree; any edit to the handshake fails here. CertificateVerify also covers the hellos, so it would catch the edit too.

41. Part 4 — Why TLS 1.3 works

Section

Each goal, checked off

42. Why TLS 1.3 works (1 of 3): the certificate proves it is Chase

Concept

Goal 1 comes down to two pieces that only the real Chase has together.

piecewho has itwhat it proves
a certificate for chase.com signed by a trusted CAanyone (it is public)this public key belongs to chase.com
a CertificateVerify over this transcriptonly the holder of the private keythe party on this connection holds that key

Put together, the other end must be Chase. An attacker has neither piece: no CA will sign its key as chase.com, and it does not have Chase's private key.

Security I, Lecture 3: TLS and the Web PKI slide s-hs-why-1

43. Why TLS 1.3 works (2 of 3): only A and B are shared, never a or b

Concept

Goal 2 in one sentence: only A and B are ever shared, never a or b. You build the key from B and your a, Chase builds it from A and its b.

valuewhere it livesseen by the attacker?
A and Bin the two hellosyes
ayour machine, deleted after the handshakenever
bChase's machine, deleted after the handshakenever
g to the ab and the AES keyscomputed on both sidesnever

Every way to the key needs a or b, and those never leave the two machines and are deleted right after the handshake. That deletion is what later gives forward secrecy.

Security I, Lecture 3: TLS and the Web PKI slide s-hs-why-2

44. Why TLS 1.3 works (3 of 3): the messages are hashed into the key

Concept

Goal 3: every message is hashed, and that hash is mixed into the key. If nobody touched anything, both sides hash the same messages and get the same key. If the attacker changes even one message, say deletes a strong option, the two sides hash different messages and end up with different keys.

Three overlapping checks over the same transcript. An attacker would have to defeat all three, which needs the shared secret or Chase's private key.

Security I, Lecture 3: TLS and the Web PKI slide s-hs-why-3

45. Match each goal to its mechanism

Matching

Check off the table from the start of the lesson.

Match the pairs

  • g1. authentication
  • g2. key agreement
  • g3. safe negotiation
  • g4. no replay of old handshakes
  • m1. a CA-signed certificate plus CertificateVerify
  • m2. ephemeral Diffie-Hellman key shares in the hellos
  • m3. the transcript hash in the keys, and Finished
  • m4. fresh client and server randoms in every transcript

Why: Each goal from Part 1 has its own mechanism, and all of them work on the same transcript. Signatures prove identity, Diffie-Hellman builds the key from public pieces, the hash of everything seen detects edits, and fresh randoms make every transcript unique.

46. The secure-handshake recipe

Pattern

Strip away the message names and every good key-exchange protocol follows the same five steps.

  1. Each side contributes a fresh ephemeral key share and fresh randomness
  2. Derive keys from the shared secret and a hash of everything sent so far
  3. The server signs that same transcript with a long-term key that a certificate vouches for
  4. Both sides send a MAC over the transcript and check the other's
  5. Delete the ephemeral secrets as soon as the keys exist

SSH, Signal's X3DH and the Noise framework used by WireGuard are built on the same ideas. When you review a homemade protocol, check for each line: a missing one is usually the bug.

47. Checkpoint: catching the SSL 2.0 attack

Check

Solve it on paper before you click.

Check your understanding

An attacker edits ClientHello to remove every cipher suite except a weak one, and the server, which still supports that suite, picks it. In TLS 1.3, what stops the attack?

  • A. ClientHello is encrypted, so the attacker cannot edit it
  • B. The two sides hash different ClientHellos, so the keys, CertificateVerify and Finished all disagree (correct)
  • C. The CA refuses to sign certificates for servers that support weak suites
  • D. Nothing: TLS 1.3 is vulnerable to this attack

Answer: B

Why: The attacker can edit ClientHello because it is in the clear, but the edit changes the transcript. The server derives keys from, signs, and computes Finished over the edited ClientHello; the client uses the original. Every check disagrees and the handshake fails. TLS 1.3 also removed the weak suites altogether.

Why A tempts people
ClientHello is sent in the clear: no key exists yet when it is sent.
Why C tempts people
CAs certify names and keys; they know nothing about which cipher suites a server enables.
Why D tempts people
This is exactly the attack the transcript hash and Finished were designed to stop.

48. Part 5 — What TLS 1.2 did worse

Section

Same goals, an older design, three problems

49. Before TLS 1.3: the TLS 1.2 handshake

Concept

Compare the old TLS 1.2 handshake, in its common RSA key-transport form, drawn the same way. Flight 1, ClientHello, is as before. Flight 2 comes back with the choice and the certificate, and nothing is encrypted yet, so anyone on the path reads both.

Figure (svg): TLS 1.2 sequence: ClientHello; ServerHello and Certificate in the clear; client sends an RSA-locked secret and Finished; server sends Finished

In flight 3 the client invents the secret itself and sends it locked with Chase's RSA public key, which is use 1 from the public-key lecture, followed by Finished. Chase unlocks it with its private key, both sides run the mystery box, and flight 4 is Chase's Finished. That is two full round trips before your first byte, and the whole session hangs on one RSA padlock.

Security I, Lecture 3: TLS and the Web PKI slide s-hs-12

50. Problem 1: TLS 1.2 is slow to start

Concept

Draw time going down, with 100 milliseconds per round trip, which is normal for a phone talking to a faraway server. Both versions start with TCP setup, one round trip.

Figure (svg): TLS 1.2 needs TCP setup plus two handshake round trips, first byte at 300 ms; TLS 1.3 needs TCP setup plus one, first byte at 200 ms

TLS 1.2TLS 1.3
TCP setup1 round trip1 round trip
handshake before data2 round trips1 round trip
first byte of data at300 ms200 ms

TLS 1.3 is faster because the key halves ride along with the very first two messages. A third less waiting on every new connection, and a page opens several.

Security I, Lecture 3: TLS and the Web PKI slide s-hs-12-slow

51. A slower network

Estimation

A user on a satellite link has a 600 ms round trip. Count TCP setup plus the handshake, as on the last slide.

Predict first

How much sooner does the first byte of data leave with TLS 1.3 than with TLS 1.2?

  • About 100 ms
  • About 300 ms
  • About 600 ms
  • About 1200 ms

Correct: About 600 ms

Why: TLS 1.2 needs three round trips before data (TCP plus two), which is 1800 ms. TLS 1.3 needs two (TCP plus one), which is 1200 ms. The saving is exactly one round trip, 600 ms, on every new connection. The slower the network, the more the saved round trip matters.

52. Problem 2: TLS 1.2 shows your certificate to everyone

Concept

Look at flight 2 through the eyes of the eavesdropper at the cafe. In TLS 1.2 the certificate is in the clear, so it reads the name and the owner: you are talking to JPMorgan Chase. That matters more when the site is a clinic or a political group.

what the eavesdropper readsTLS 1.2TLS 1.3TLS 1.3 with ECH
server name in ClientHelloyesyesno
the certificateyesno: it is encryptedno
the page contentsnonono

In TLS 1.3 the key already exists when the certificate is sent, so it travels inside the encrypted part. One leak remains: the site name in ClientHello, because the server needs it before any key exists. Encrypted ClientHello, ECH, which hides it by encrypting the inner hello to a key the server publishes in DNS, is being rolled out now.

Security I, Lecture 3: TLS and the Web PKI slide s-hs-12-clear

IETF draft-ietf-tls-esni — TLS Encrypted Client Hello

53. Problem 3: one stolen key unlocks years of old traffic

Concept

In TLS 1.2 with RSA, the session secret travels locked with Chase's long-term RSA key. So an attacker can record encrypted traffic and simply wait.

Figure (svg): TLS 1.2: the leaked RSA key opens the recorded secret and all old traffic; TLS 1.3: the recording holds only A and B, and a and b were deleted, so old traffic stays locked

In 2014, Heartbleed let attackers read memory from OpenSSL servers, including private keys. With the key, the padlock on a recorded secret opens, and the secret opens every byte of that old session. In TLS 1.3 the recording only holds the public halves A and B. The private key never locked anything; it only signs. The one-time secrets a and b were deleted after the handshake, so even with the leaked key, old traffic stays locked. This property is called forward secrecy.

Security I, Lecture 3: TLS and the Web PKI slide s-hs-12-fs

The Heartbleed Bug (CVE-2014-0160)

54. Heartbleed and a recording from 2013

Commit first

An agency recorded a server's TLS traffic throughout 2013. In April 2014 it obtains the server's private RSA key through Heartbleed. Half the recorded sessions used RSA key transport; the other half used ephemeral Diffie-Hellman (ECDHE) with the same RSA key for signing.

Predict first

Which recorded sessions can the agency now decrypt?

  • Only the RSA key-transport sessions
  • Only the ephemeral Diffie-Hellman sessions
  • Both halves
  • Neither half

Correct: Only the RSA key-transport sessions

Why: In key transport the session secret was encrypted under the RSA key, so the stolen key decrypts it from the recording. In the ECDHE sessions the RSA key only signed; the session secret came from ephemeral values that were deleted, so the recording plus the RSA key is not enough. The stolen key does let the agency impersonate the server from now on, until the certificate is revoked or expires.

55. TLS 1.3 fixes all of it

Comparison

Fill in the scorecard from the last three slides and the history lesson.

Comparison matrix

TLS 1.2 (RSA key transport)TLS 1.3
round trips before data21
certificate visible to eavesdroppersyesno, it is encrypted
a leaked long-term key exposes old recordingsyesno: forward secrecy
weak options left to downgrade tomany: export ciphers, RC4, static RSAnone: deleted

Speed, privacy, the past, and nothing to downgrade to. That is why the handshake we walked through looks the way it does.

56. Part 6 — When the system around the math fails

Section

Randomness, downgrade and cost

57. The whole handshake rests on good randomness: Debian, 2006 to 2008

Concept

Every secret in the handshake comes from the random number generator: the server's long-term key, the ephemeral a and b, and the two randoms. In 2006 a Debian developer silenced a memory-checker warning by removing one line from OpenSSL's random generator.

/* OpenSSL md_rand.c, ssleay_rand_add(): the line Debian removed in 2006 */
MD_Update(&m, buf, j);   /* purify complains */
what changedconsequence
entropy stopped being mixed into the poolthe seed was essentially the process ID
process IDs on Linux ran up to 32,768at most 32,768 possible key streams per key type and size
every key made on Debian and Ubuntu from 2006 to 2008SSH, OpenVPN, DNSSEC and TLS keys drawn from a tiny set

Anyone could regenerate the whole set of possible keys and recognise a weak one. The fix was not only patching OpenSSL: every affected key had to be thrown away and regenerated, and blacklists of the weak keys were shipped. The cryptography is only as good as the randomness underneath it, and randomness is the easiest thing to get quietly wrong.

Security I, Lecture 3: TLS and the Web PKI slide s-rng-debian

Debian Security Advisory DSA-1571-1 — openssl: predictable random number generator (2008)

58. How strong was a Debian key?

Estimation

A 2048-bit RSA key is meant to be about as hard to break as a 112-bit symmetric key. On an affected Debian system, the generator could only produce one of 32,768 streams.

Predict first

Roughly how many bits of security did such a key really have?

  • About 15 bits
  • About 56 bits
  • About 112 bits
  • About 2048 bits

Correct: About 15 bits

Why: 32,768 is 2 to the 15, so there were only about 15 bits of uncertainty, however long the key looked. A laptop can enumerate 32,768 candidates in seconds. Key length measures the size of the space a key could come from only if the generator can actually reach all of it.

59. The attacker cannot break TLS 1.3, so it tries to drag you to something older

Concept

Backward compatibility is the hole. As long as a strong client will also speak a weak protocol, an attacker who edits the opening messages can try to force the weak one. ClientHello is in the clear, so editing it is easy.

Figure (svg): The attacker rewrites ClientHello to offer only an old option; a server that still allows it picks it; in TLS 1.3 the transcript check over both hellos fails

attackyearwhat it forced
SSL 2.0 cipher stripping1995 onward40-bit export ciphers
POODLE2014a fallback to SSL 3.0, then its unchecked padding
FREAK2015512-bit export RSA, factorable in hours
Logjam2015512-bit export Diffie-Hellman

The common root: strong endpoints kept speaking weak protocols, and the negotiation that chose between them was not fully protected.

Security I, Lecture 3: TLS and the Web PKI slide s-downgrade

60. The fix: make the negotiation part of what gets signed

Concept

TLS 1.3 defends in three layers. First and most important, the transcript is authenticated: the server's signature and both Finished MACs cover every handshake message, so an edited ClientHello makes the handshake fail.

Second, a belt-and-braces sentinel for the case where the attacker pushes a 1.3-capable pair down to TLS 1.2, whose own protection is weaker. A server that supports 1.3 but is negotiating an older version stamps a fixed pattern into the end of its random, which the TLS 1.2 handshake signs. A genuine 1.3 client that sees the pattern treats it as a downgrade and quits.

ServerHello.random (32 bytes), last 8 bytes when a TLS 1.3 server
is negotiated down:

  to TLS 1.2:          44 4F 57 4E 47 52 44 01
  to TLS 1.1 or below: 44 4F 57 4E 47 52 44 00
layerwhat it stops
transcript in the signature and Finishedany edit to a TLS 1.3 handshake
downgrade sentinel in ServerHello.randombeing pushed from 1.3 down to 1.2 or older
weak primitives deletedexport ciphers, static RSA, SSL 3.0, RC4, MD5: nothing weak to roll back to

The reusable lesson: authenticate the negotiation itself, not just the data that follows it.

Security I, Lecture 3: TLS and the Web PKI slide s-downgrade-fix

RFC 8446 — The Transport Layer Security (TLS) Protocol Version 1.3 section 4.1.3, downgrade protection

61. Decode the downgrade sentinel

Fill the middle

The sentinel bytes are ASCII. Decode them using the table: 44 = D, 47 = G, 4E = N, 4F = O, 52 = R, 57 = W.

Fill in the blanks

44 4F 57 4E 47 52 44 -> DOWNGRD
last byte 01 -> negotiated down to TLS 1.2
last byte 00 -> negotiated down to TLS 1.1 or below

Why: The seven bytes spell DOWNGRD. A TLS 1.3 server writes DOWNGRD followed by 01 when it ends up speaking TLS 1.2 and DOWNGRD followed by 00 for TLS 1.1 or older. Because the random is covered by the older version's signature, the attacker cannot remove the pattern, and a 1.3 client that sees it aborts.

62. Trap: my server supports TLS 1.3, so downgrade attacks cannot touch it

Trap

The trap

A common belief: once a server enables TLS 1.3, its connections are as strong as TLS 1.3, whatever else it still allows.

Supporting the strong version is not the same as refusing the weak ones. FREAK and Logjam hit servers whose best option was fine; they still accepted 512-bit export options for compatibility, and that was enough.

The fix

A connection is only as strong as the weakest option both ends will accept. Turn off what you do not need: no SSL 3.0, no TLS 1.0 or 1.1, no export or RC4 suites, no static RSA key exchange. Keep TLS 1.2 only with forward-secret AEAD suites, and let the TLS 1.3 transcript check and the downgrade sentinel do the rest.

settingsafe choice
protocol versionsTLS 1.2 and 1.3 only
TLS 1.2 key exchangeECDHE only
TLS 1.2 ciphersAES-GCM or ChaCha20-Poly1305 only

Security I, Lecture 3: TLS and the Web PKI slide s-hist-pattern

63. A different weakness: the handshake's cost falls on the server

Concept

Confidentiality and integrity are not the only things that can fail: availability can too. The handshake deliberately puts heavy public-key work on the server, which makes it asymmetric in cost. Establishing a connection can cost the server around fifteen times the client's work, and renegotiating on an existing connection used to let one client repeat the expensive part without even opening new connections.

where the cost goesclientserver
key shareone ephemeral keyone ephemeral key
signatureverify (cheap for RSA)sign with the private key (expensive)
many handshakes from few machinessmall total costCPU can saturate

Tools that open handshakes in a loop showed a handful of machines could saturate a large server. The defences are about cost and rate, not cryptography, which is working exactly as designed: TLS 1.3 removed renegotiation entirely.

Security I, Lecture 3: TLS and the Web PKI slide s-dos

64. Defending against handshake floods

Trade off

Each defence moves cost or limits rate. Fill in what each one costs you.

Comparison matrix

defencehow it helpstrade-off
rate-limit new handshakes per client addresscaps how much work one source can demandshared addresses (NAT, campus) can be throttled unfairly
session resumption (PSK tickets)returning clients skip the expensive signaturethe ticket key must be protected and rotated
disable renegotiation (built into TLS 1.3)one connection can no longer redo the handshake repeatedlyold clients relying on it may break
ECDSA certificate instead of RSAsigning is much cheaper for the serververy old clients may not support it

None of these touch the cipher. They change who pays for the expensive step, or how often anyone can ask for it.

65. Part 7 — The record layer

Section

The handshake handed us keys; now protect every byte

66. Every record is one AEAD box: encrypted and authenticated together

Concept

Once the handshake has produced traffic keys, protecting the data is exactly the authenticated encryption from the crypto lecture, applied record by record. This part is deliberately short.

Figure (svg): The header as associated data, the plaintext, a nonce built from IV xor sequence number, and the traffic key go into AES-256-GCM; out come ciphertext and a tag; a bad tag drops the record

Each fragment of application data, up to 16 kilobytes, is sealed with an AEAD cipher, AES-GCM or ChaCha20-Poly1305, using a traffic key from the handshake. The record header is fed in as associated data so it cannot be altered. The output is ciphertext plus a 16-byte tag. If the tag does not check out on the other side, the record is dropped and the connection closed. There is no new cryptography here, which is the point.

Security I, Lecture 3: TLS and the Web PKI slide s-div-record

Security I, Lecture 3: TLS and the Web PKI slide s-record

67. The sequence number is hidden inside the nonce

Worked example

Neither side sends the sequence number. Both count records, starting from 0 after each key change, and fold the count into the nonce. Here is the per-record nonce for a toy static IV.

static IV  = a1 b2 c3 d4 e5 f6 07 18 29 3a 4b 5c   # 12 bytes from HKDF
nonce(seq) = IV xor seq, seq written as a 12-byte big-endian number

seq 0  ->  a1 b2 c3 d4 e5 f6 07 18 29 3a 4b 5c
seq 1  ->  a1 b2 c3 d4 e5 f6 07 18 29 3a 4b 5d
seq 2  ->  a1 b2 c3 d4 e5 f6 07 18 29 3a 4b 5e
seq 3  ->  a1 b2 c3 d4 e5 f6 07 18 29 3a 4b 5f
recordseqlast nonce bytehow
first05c5c xor 00
second15d5c xor 01
third25e5c xor 02
fourth35f5c xor 03

Figure (svg): Record 1 uses sequence 0 and nonce ending 5c, record 2 uses 1 and 5d; a replayed record 1 arriving third is checked with nonce ending 5e and fails

Why this matters

Why: Every record gets a different nonce, so AES-GCM's nonce never repeats under one key, and the nonce also fixes the record's position in the stream.

Verify: against RFC 8446

Why: section 5.3: the 64-bit sequence number is padded on the left to the IV length and XORed with the static IV to form the per-record nonce.

RFC 8446 — The Transport Layer Security (TLS) Protocol Version 1.3 section 5.3, Per-Record Nonce

68. The sequence number stops the attacks AEAD alone would miss

Concept

Sealing each record independently is not enough. An attacker who cannot read or forge a record can still play with the stream: reorder records, replay one, or cut the stream short.

attack on the streamwhat happens in TLS
replay an old recordthe receiver expects the next sequence number, so the nonce is wrong and the tag fails
swap two recordsboth arrive with the wrong sequence number and both tags fail
drop a record in the middleevery later record is one position off and fails
cut the stream shortno close_notify alert arrived, so the receiver knows the end was not genuine

Confidentiality and integrity per record, plus ordering across records: the channel delivers exactly the bytes that were sent, in order, once. What the channel cannot tell you is whether the name on the certificate deserved your trust, which is the next lesson.

Security I, Lecture 3: TLS and the Web PKI slide s-record-order

69. Which mechanism stops it?

Sorting

Sort each attempt by the part of the record layer that defeats it.

Sort into buckets

AEAD tag, sequence number in the nonce, or close_notify?

AEAD tag
Flipping one bit of a record's ciphertext; Changing the length field in a record header
sequence number in the nonce
Sending yesterday's 'transfer 100 dollars' record again; Delivering record 7 before record 6
close_notify
Cutting the connection right before the last record of a page
tag
Any change to the ciphertext or to the header (the associated data) makes the tag check fail.
seq
The record itself is genuine, but it is in the wrong position, so the receiver uses a different nonce and the tag fails.
close
Nothing was altered; the stream just ended early, and only an authenticated end-of-stream alert reveals that.

70. Draw the whole connection

Connect it up

Put the entire lesson on one page.

Draw it

Draw the client and server as two vertical lines. Add the three TLS 1.3 flights, marking each message as clear or encrypted. Beside each message write which goal it serves (authentication, key agreement, safe negotiation). Show where a and b are created and deleted, where HKDF runs, and where the record layer takes over. Finally, circle the one value whose theft would let someone impersonate the server, and explain why stealing it does not decrypt recorded traffic.

A good diagram shows A and B in the clear, everything from Certificate onward encrypted, the transcript feeding HKDF, CertificateVerify and Finished, a and b deleted after key derivation, and the long-term private key used only to sign.

71. Checkpoint: forward secrecy

Check

Solve it on paper before you click.

Check your understanding

Which design gives forward secrecy?

  • A. The client encrypts a random session secret under the server's long-term RSA key
  • B. Both sides use fresh Diffie-Hellman secrets per connection, delete them after deriving keys, and the server signs the transcript with its long-term key (correct)
  • C. The server uses a 4096-bit RSA key instead of a 2048-bit one
  • D. The server reuses the same Diffie-Hellman secret b for every connection for a year

Answer: B

Why: Forward secrecy means a future theft of the long-term key does not expose past sessions. That requires the session secret to depend on values that no longer exist, the deleted ephemeral a and b, and the long-term key to be used only for signing.

Why A tempts people
This is TLS 1.2 RSA key transport: the long-term key decrypts every recorded session secret.
Why C tempts people
A bigger key is harder to factor, but if it is stolen it still decrypts everything it ever locked.
Why D tempts people
A static b is effectively a long-term key: stealing it exposes every session that used it.

72. Checkpoint: where the handshake fails

Check

Solve it on paper before you click.

Check your understanding

An attacker with a valid copy of chase.com's certificate, but not Chase's private key, intercepts your TLS 1.3 connection and sends its own key share B. What happens?

  • A. The handshake succeeds, because the certificate is genuine
  • B. The attacker cannot produce a CertificateVerify signature that checks against the certificate's public key, so your browser aborts (correct)
  • C. The browser contacts DigiCert, which reports the attacker
  • D. The connection works but falls back to TLS 1.2

Answer: B

Why: The certificate is public, so having it proves nothing. CertificateVerify must be a signature over this transcript, including the attacker's B, made with the private key matching the certificate. Without Chase's private key the attacker cannot produce it, and the browser aborts.

Why A tempts people
A certificate is like a photocopied passport: it must be paired with proof of holding the private key.
Why C tempts people
The browser checks signatures locally; it does not phone the CA during the handshake.
Why D tempts people
Nothing here triggers a fallback, and a 1.3 client would detect a forced fallback through the sentinel.

73. Exit ticket

Exit ticket

One question on the central idea.

Predict first

Why do the key halves A and B travel in the clear without any harm?

  • Because building the key from them needs a or b, which never leave the two machines, and the transcript signature stops anyone swapping them
  • Because they are encrypted with the server's RSA key
  • Because the attacker cannot see the first two messages
  • Because A and B change every second

Correct: Because building the key from them needs a or b, which never leave the two machines, and the transcript signature stops anyone swapping them

Why: Secrecy of A and B is never needed: the discrete logarithm problem keeps a and b hidden even though A and B are public. What is needed is integrity, that they arrive unchanged, and the transcript hash in the keys, CertificateVerify and Finished provide it.

74. What you can do now

Recap

The single thread: meet once, carefully. Each side sends a fresh key half in the clear, the key is built from secrets that never travel, the server signs everything said so far, both sides check a MAC over it, and then the record layer seals every byte with AEAD and a counted nonce.

you needTLS 1.3 uses
a shared key from public piecesephemeral Diffie-Hellman, today X25519 or X25519MLKEM768
proof of the server's identitya CA-signed certificate plus CertificateVerify
proof that nothing was editedthe transcript hash in the keys, and Finished
protection for the dataAEAD records with nonce = IV xor sequence number

Security I, Lecture 3: TLS and the Web PKI slide s-hs-compare

RFC 8446 — The Transport Layer Security (TLS) Protocol Version 1.3

Sources

  1. Security I, Lecture 3: TLS and the Web PKI
  2. RFC 8446 — The Transport Layer Security (TLS) Protocol Version 1.3
  3. RFC 5869 — HMAC-based Extract-and-Expand Key Derivation Function (HKDF)
  4. RFC 7919 — Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS (ffdhe groups)
  5. RFC 7748 — Elliptic Curves for Security (X25519 and X448)
  6. IETF draft-ietf-tls-ecdhe-mlkem — Post-quantum hybrid ECDHE-MLKEM key agreement for TLS 1.3 (X25519MLKEM768)
  7. IETF draft-ietf-tls-esni — TLS Encrypted Client Hello
  8. Debian Security Advisory DSA-1571-1 — openssl: predictable random number generator (2008)
  9. The Heartbleed Bug (CVE-2014-0160)
  10. openssl s_client -connect www.chase.com:443, run with OpenSSL 3.5.6 on 2026-10-15 — Live connection made while preparing this lesson; the protocol, cipher suite, group, signature type and certificate chain are copied from its output

Want this taught 1-on-1? Alexander tutors Computer Security — $55/session, free consultation.

Book on Wyzant · Text (657) 465-8108