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
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
Section
Three questions before your password goes anywhere
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
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.
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.
| question | goal | what goes wrong without it |
|---|---|---|
| Who are you, really? | authentication | you encrypt perfectly, to the attacker |
| Which key do we share? | key agreement | the attacker copies the key as it crosses the wire |
| Did anyone change what we agreed on? | safe negotiation | the 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
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
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.
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.
| approach | what the attacker sees | result |
|---|---|---|
| send the key in the clear | the key | broken immediately |
| lock the key with the server's RSA key (TLS 1.2) | the locked key | safe today, exposed if the RSA key ever leaks |
| build the key from public pieces (Diffie-Hellman) | both pieces | still 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
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.
| client | best version it speaks | what the connection uses |
|---|---|---|
| a new Chrome | TLS 1.3 | TLS 1.3 |
| an Android phone from 2014 | TLS 1.2 | TLS 1.2 |
| an old card reader in a store | TLS 1.0 | TLS 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
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
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.
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
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?
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.
Sorting
Sort each attack to the goal that defeats it.
Sort into buckets
Authentication, key agreement, or safe negotiation?
Section
Three flights, then the details of the two hellos
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
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| flight | direction | contents | protected by |
|---|---|---|---|
| 1 | client to server | ClientHello with key share A | nothing yet; checked later by Finished |
| 2a | server to client | ServerHello with key share B | nothing yet; checked later by Finished |
| 2b | server to client | Certificate, CertificateVerify, Finished | AES-GCM with the handshake key |
| 3 | client to server | Finished, then application data | AES-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
Ranking
Order the events from the moment you press Enter until your first request leaves.
Put in order
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.
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
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.
| field | example | why it is there |
|---|---|---|
| server name (SNI) | www.chase.com | one machine may host many sites; the server needs the name before any key exists |
| the menu | TLS 1.3, TLS 1.2; AES-256-GCM, ChaCha20-Poly1305, ... | versions and cipher suites, strongest first |
| client random | 32 fresh random bytes | no two handshakes are alike, so nothing can be replayed |
| key share A | a public number for a named group | your 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
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 output | what it tells you |
|---|---|
| TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384 | the version and record cipher Chase chose from the menu |
| Negotiated TLS1.3 group: X25519MLKEM768 | the kind of key share in the two hellos |
| Peer signature type: rsa_pss_rsae_sha256 | how CertificateVerify was signed: RSA-PSS with SHA-256 |
| Server public key is 2048 bit | Chase'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
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.
Section
How 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
Concept
The public setup is a large prime p and a base g. Everyone, Eve included, knows both. Then four steps.
| step | Alice | Bob |
|---|---|---|
| pick a secret | random a, kept | random b, kept |
| send a public value | A = g to the a, mod p | B = g to the b, mod p |
| combine | K = B to the a, mod p | K = A to the b, mod p |
| why they agree | g to the b, to the a, is g to the ab | g 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
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| power | 5 mod 23 | 19 mod 23 | 8 mod 23 |
|---|---|---|---|
| 1 | 5 | 19 | 8 |
| 2 | 2 | 16 | 18 |
| 4 | 4 | 3 | 2 |
| 8 | 16 | 9 | 4 |
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
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.
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?
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.
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
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.
| family | named groups | notes |
|---|---|---|
| finite-field DH (this lesson's math) | ffdhe2048, ffdhe3072, ffdhe4096, ffdhe6144, ffdhe8192 | g = 2 and one fixed prime per size, from RFC 7919 |
| elliptic-curve DH | x25519, x448, secp256r1, secp384r1, secp521r1 | same idea, different math, much smaller numbers |
| post-quantum hybrid | X25519MLKEM768 | X25519 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 FFFFFFFFTo 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
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.
Section
HKDF, then Certificate, CertificateVerify and Finished
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
| input | what it is | why it is there |
|---|---|---|
| shared secret | g to the ab from Diffie-Hellman | only you and Chase know it |
| transcript hash | SHA-384 of exactly the ClientHello and ServerHello each side saw | binds the keys to the conversation |
| label | a name such as c hs traffic or s hs traffic | a 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
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")| run | ClientHello offered | transcript hash starts | handshake key starts |
|---|---|---|---|
| honest | TLS1.3, TLS1.2 | c235c0c6170e6eff | 366554e39ce653e4 |
| edited on the wire | TLS1.2 | 18f4e1c209af5d67 | 78f5371bbe06968b |
| same edit, seen by both sides | TLS1.2 on both sides | identical on both | identical 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
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?
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.
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.
| field | value from chase.com | meaning |
|---|---|---|
| subject | CN = www.chase.com, O = JPMorgan Chase and Co. | whose key this is |
| names it is valid for | www.chase.com, beta.chase.com | the hostnames the browser will match |
| public key | RSA, 2048 bits, e = 65537 | like the RSA recap, much bigger; Chase keeps d |
| validity | 29 Dec 2025 to 5 Jan 2027 | IDs expire |
| issuer | DigiCert EV RSA CA G2 | who checked Chase and signed the card |
| chain | DigiCert EV RSA CA G2, signed by DigiCert Global Root G2 | the 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
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
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
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.
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))| case | server's Finished | client's check |
|---|---|---|
| nothing touched | HMAC over the same transcript | matches: continue |
| menu edited in ClientHello | HMAC over a different ClientHello | mismatch: hang up |
| attacker tries to fix the HMAC | needs the Finished key | impossible: 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
Discrimination
Each problem is caught by a different part of the handshake.
Sort into buckets
Certificate, CertificateVerify, or Finished?
Section
Each goal, checked off
Concept
Goal 1 comes down to two pieces that only the real Chase has together.
| piece | who has it | what it proves |
|---|---|---|
| a certificate for chase.com signed by a trusted CA | anyone (it is public) | this public key belongs to chase.com |
| a CertificateVerify over this transcript | only the holder of the private key | the 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
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.
| value | where it lives | seen by the attacker? |
|---|---|---|
| A and B | in the two hellos | yes |
| a | your machine, deleted after the handshake | never |
| b | Chase's machine, deleted after the handshake | never |
| g to the ab and the AES keys | computed on both sides | never |
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
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
Matching
Check off the table from the start of the lesson.
Match the pairs
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.
Pattern
Strip away the message names and every good key-exchange protocol follows the same five steps.
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.
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?
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.
Section
Same goals, an older design, three problems
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
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.2 | TLS 1.3 | |
|---|---|---|
| TCP setup | 1 round trip | 1 round trip |
| handshake before data | 2 round trips | 1 round trip |
| first byte of data at | 300 ms | 200 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
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?
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.
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 reads | TLS 1.2 | TLS 1.3 | TLS 1.3 with ECH |
|---|---|---|---|
| server name in ClientHello | yes | yes | no |
| the certificate | yes | no: it is encrypted | no |
| the page contents | no | no | no |
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
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
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?
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.
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 data | 2 | 1 |
| certificate visible to eavesdroppers | yes | no, it is encrypted |
| a leaked long-term key exposes old recordings | yes | no: forward secrecy |
| weak options left to downgrade to | many: export ciphers, RC4, static RSA | none: deleted |
Speed, privacy, the past, and nothing to downgrade to. That is why the handshake we walked through looks the way it does.
Section
Randomness, downgrade and cost
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 changed | consequence |
|---|---|
| entropy stopped being mixed into the pool | the seed was essentially the process ID |
| process IDs on Linux ran up to 32,768 | at most 32,768 possible key streams per key type and size |
| every key made on Debian and Ubuntu from 2006 to 2008 | SSH, 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)
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?
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.
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
| attack | year | what it forced |
|---|---|---|
| SSL 2.0 cipher stripping | 1995 onward | 40-bit export ciphers |
| POODLE | 2014 | a fallback to SSL 3.0, then its unchecked padding |
| FREAK | 2015 | 512-bit export RSA, factorable in hours |
| Logjam | 2015 | 512-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
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| layer | what it stops |
|---|---|
| transcript in the signature and Finished | any edit to a TLS 1.3 handshake |
| downgrade sentinel in ServerHello.random | being pushed from 1.3 down to 1.2 or older |
| weak primitives deleted | export 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
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.
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.
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.
| setting | safe choice |
|---|---|
| protocol versions | TLS 1.2 and 1.3 only |
| TLS 1.2 key exchange | ECDHE only |
| TLS 1.2 ciphers | AES-GCM or ChaCha20-Poly1305 only |
Security I, Lecture 3: TLS and the Web PKI slide s-hist-pattern
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 goes | client | server |
|---|---|---|
| key share | one ephemeral key | one ephemeral key |
| signature | verify (cheap for RSA) | sign with the private key (expensive) |
| many handshakes from few machines | small total cost | CPU 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
Trade off
Each defence moves cost or limits rate. Fill in what each one costs you.
Comparison matrix
| defence | how it helps | trade-off |
|---|---|---|
| rate-limit new handshakes per client address | caps how much work one source can demand | shared addresses (NAT, campus) can be throttled unfairly |
| session resumption (PSK tickets) | returning clients skip the expensive signature | the ticket key must be protected and rotated |
| disable renegotiation (built into TLS 1.3) | one connection can no longer redo the handshake repeatedly | old clients relying on it may break |
| ECDSA certificate instead of RSA | signing is much cheaper for the server | very 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.
Section
The handshake handed us keys; now protect every byte
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
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| record | seq | last nonce byte | how |
|---|---|---|---|
| first | 0 | 5c | 5c xor 00 |
| second | 1 | 5d | 5c xor 01 |
| third | 2 | 5e | 5c xor 02 |
| fourth | 3 | 5f | 5c 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
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 stream | what happens in TLS |
|---|---|
| replay an old record | the receiver expects the next sequence number, so the nonce is wrong and the tag fails |
| swap two records | both arrive with the wrong sequence number and both tags fail |
| drop a record in the middle | every later record is one position off and fails |
| cut the stream short | no 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
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?
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.
Check
Solve it on paper before you click.
Check your understanding
Which design gives forward secrecy?
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.
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?
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.
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?
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.
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 need | TLS 1.3 uses |
|---|---|
| a shared key from public pieces | ephemeral Diffie-Hellman, today X25519 or X25519MLKEM768 |
| proof of the server's identity | a CA-signed certificate plus CertificateVerify |
| proof that nothing was edited | the transcript hash in the keys, and Finished |
| protection for the data | AEAD 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
Want this taught 1-on-1? Alexander tutors Computer Security — $55/session, free consultation.