1
CS 161, Summer 2026 @ UC Berkeley
Slides credit: Nick Weaver, Nicholas Ngai, Peyrin Kao, Henry Corrigan-Gibbs, Jonah Bedouch
TLS
Lecture 17 (Transport 5)
Layer 4.5
Lecture 17, CS 161, Summer 2026
TLS
TLS at Layer 4.5
Recall: Many attacks exist at lower layers.
TLS (Transport Layer Security) is a protocol for secure communication on top of those layers.
TLS is built on top of TCP (Layer 4).
TLS provides security to Layer 7 applications.
Physical
Data Link
Network
Transport
Secure Transport
4.5
4
3
2
1
(TLS, SSL)
(TCP, UDP)
(IP)
(Ethernet)
(Optical fiber, copper)
Application
7
(DNS, HTTP)
SSL was an older version of the protocol.
TLS is labeled 4.5 because 5 and 6 already exist (and are now obsolete).
Goals of TLS
Confidentiality: Ensure that attackers cannot read your traffic.
Integrity: Ensure that attackers cannot tamper with your traffic.
Authentication: Ensure that the user is talking to the legitimate website.
TLS Handshake
Lecture 17, CS 161, Summer 2026
TLS
TLS Handshake Step 1: Exchange Hellos
An underlying TCP connection has already been formed, so we can use the bytestream abstraction.
The client sends ClientHello with:
The server sends ServerHello with:
RC and RS are randomly chosen for every handshake.
Client
Server
ClientHello
ServerHello
TLS Handshake Step 2: Certificate
The server sends its certificate.
The client verifies the signature in the certificate.
Client
Server
ClientHello
ServerHello
Certificate
TLS Handshake Step 3: Premaster Secret
The server and client derive a shared secret called the premaster secret (PS).
The server signs its half of the key exchange, sending both ga mod p and the signature.
Client
Server
ClientHello
ServerHello
Certificate
ga mod p, signed by SKserver
gb mod p
TLS Handshake Step 4: Derive Symmetric Keys
The server and client each derive symmetric keys from RC, RS, and PS.
The keys are derived with a pseudorandom function.
Client
Server
ClientHello
ServerHello
Certificate
ga mod p, signed by SKserver
gb mod p
Derive keys
Derive keys
TLS Handshake Step 5: Exchange MACs
The client sends a MAC on all the messages sent/received in the handshake so far.
Similarly, the server sends a MAC on all messages so far, and the client verifies it.
Any tampering on the earlier handshake steps will be detected here.
Client
Server
ClientHello
ServerHello
Certificate
ga mod p, signed by SKserver
gb mod p
Derive keys
Derive keys
MAC(KS, steps 1–4)
MAC(KC, steps 1–4)
TLS Handshake Step 6: Send Messages
The client and server can now securely exchange messages.
Data is secured with an AEAD (authenticated encryption with additional data) scheme,�e.g. AES-GCM.
Each message has a unique record number to prevent replay attacks.
Client
Server
ClientHello
ServerHello
Certificate
ga mod p, signed by SKserver
gb mod p
Derive keys
Derive keys
MAC(KS, steps 1–4)
MAC(KC, steps 1–4)
AES-GCM(KS, data2)
AES-GCM(KC, data1)
TLS Security Goals
Lecture 17, CS 161, Summer 2026
TLS
TLS Security Goals: Talking to the Legitimate Server
How can we be sure that we are talking to the legitimate server?
An attacker impersonating the server would not have the server's private key (assuming they have not compromised the server).
Client
Server
ClientHello
ServerHello
Certificate
ga mod p, signed by SKserver
gb mod p
Derive keys
Derive keys
MAC(KS, steps 1–4)
MAC(KC, steps 1–4)
AES-GCM(KS, data2)
AES-GCM(KC, data1)
TLS Security Goals: Replay Attacks
Preventing replays from past connections:
Preventing replays from current connection:
MAC(KS, steps 1–4)
MAC(KC, steps 1–4)
Client
Server
ClientHello
ServerHello
Certificate
ga mod p, signed by SKserver
gb mod p
AES-GCM(KS, data2)
AES-GCM(KC, data1)
Derive keys
Derive keys
Legacy Designs
Lecture 17, CS 161, Summer 2026
TLS
TLS 1.3 Changes
TLS 1.3 (2018) is the latest version of the protocol.
Security upgrade: Removed support for weaker, insecure algorithms.
Performance upgrade: Rearranged steps to allow the handshake to finish faster.
Legacy Premaster Secret Scheme: RSA
The server proves its identity by decrypting the premaster secret.
The shared secret is PS (directly chosen by the client, secured with RSA).
Older versions of TLS used RSA encryption instead of Diffie-Hellman key exchange.
Client generates Premaster Secret (PS), and encrypts it with server's public key.
The server proves its identity by signing its half of the key exchange.
The shared secret is PS = gab mod p (secured with DHE).
Client
Server
ga mod p, signed by SKserver
gb mod p
Client
Server
Enc(PKserver, PS)
DHE (modern)
RSA (legacy)
Forward Secrecy
Recall forward secrecy: If an eavesdropper records an encrypted connection now and learns the secret values later, they cannot decrypt the recorded connection.
Does not provide forward secrecy: Attacker can steal SKserver later and use it to decrypt the recorded PS.
Provides forward secrecy: a, b, PS discarded after each connection.
Values sent during handshake cannot be used to re-derive PS.
Client
Server
ga mod p, signed by SKserver
gb mod p
Client
Server
Enc(PKserver, PS)
DHE (modern)
RSA (legacy)
Optimizing Handshake
Rearranging the steps allows the handshake to complete in one fewer round-trip.
Client must guess which algorithm the server will choose before seeing ServerHello.
Client
Server
ClientHello
ServerHello
Certificate
ga mod p, signed by SKserver
gb mod p
MAC(KS, steps 1–4)
MAC(KC, steps 1–4)
Client
Server
ClientHello
ServerHello
Certificate
ga mod p, signed by SKserver
gb mod p
MAC(KS, steps 1–4)
MAC(KC, steps 1–4)
Old: 2 round-trips
New: 1 round-trip
AES-GCM(KC, data1)
AES-GCM(KC, data1)
1
2
1
Client can send data1 alongside its MAC of handshake.
TLS Certificates
Lecture 17, CS 161, Summer 2026
TLS
Public-Key Infrastructure
One tricky question: Who signs certificates for the servers?
Recall: Certificates require trusting root certificate authorities (root CAs).
Unknown Certificate Authority
Using TLS
Lecture 17, CS 161, Summer 2026
TLS
TLS Stops Lower-Level Attacks
TLS defends against many lower-level network attacks.
Applications can run on TLS-over-TCP, or on plain TCP.
Encouraging TLS Use: Browsers and CAs
On the web, HTTPS (over TLS) only offers security if websites actually use it.
To encourage more HTTPS adoption, browsers show warnings or refuse to load HTTP websites.
In 2015, Let's Encrypt (now the world's largest CA) started offering free certificates, to further incentivize HTTPS adoption.
If a website doesn't support HTTPS, browsers often show a "Not Secure" warning to the user.
Encouraging TLS Use: HSTS
HTTP Strict Transport Security (HSTS) is an HTTP response from servers that says:�"I don't accept plain HTTP requests, only HTTPS ones."
A client seeing this response is redirected to using HTTPS.
Client
Server
GET http://www.google.com
Nope. Ask for https://www.google.com instead.
Encouraging TLS Use: Downgrade Attacks
SSL Stripping: Trick the user into using plain HTTP, by blocking the HSTS redirect.
Client
Server
GET http://www.google.com
Secure HTTPS response
MITM Attacker
Plain HTTP response
GET https://www.google.com
Encouraging TLS Use: Preventing Downgrade Attacks
SSL Stripping is a downgrade attack: User is tricked into using older, insecure code.
Defenses: Minimize the use of plain HTTP.
Client
Server
GET http://www.google.com
Secure HTTPS response
MITM Attacker
Plain HTTP response
GET https://www.google.com
TLS Adoption Over Time
The End...or Not?
TLS sounds great – everyone between our browser and the website can be a MITM, and they still can't interfere with our connection.
What's the catch?