The TLS Handshake
Cryptographic Protocols · Networking & Cryptography track
6 min read
In this module
Every Secure Connection Starts Here
Every time you see a padlock icon in your browser, a TLS handshake has just wrapped up. This handshake is the ceremony that transforms an insecure TCP connection into an encrypted channel. It authenticates the server, negotiates cryptographic parameters, and establishes a shared secret, all before a single byte of application data crosses the wire.
TLS (Transport Layer Security) is what makes HTTPS, secure email, VPNs, and countless other secure communications work. Understanding the handshake matters because every cryptographic concept from the previous modules — symmetric encryption, asymmetric encryption, key exchange, digital signatures, hash functions — converges in this single protocol.
TLS 1.3: The Modern Handshake
TLS 1.3, published in 2018, dramatically simplified the handshake compared to earlier versions. It completes in a single round trip (1-RTT), so encrypted data can flow after just one exchange of messages:
Step 1: Client Hello
The client sends:
- Supported TLS versions
- Supported cipher suites (e.g., AES-256-GCM with SHA-384)
- A key share - the client's ephemeral Diffie-Hellman public value
- A random nonce
Including the key share upfront lets the server compute the shared secret immediately, shaving off a round trip. Earlier TLS versions needed an extra round trip for the key exchange, adding latency to every new connection.
Step 2: Server Hello + Encrypted Extensions
The server responds with:
- The chosen cipher suite
- The server's ephemeral Diffie-Hellman public value (key share)
- EncryptedExtensions: the remaining negotiated settings, such as the ALPN protocol (
h2orhttp/1.1), sent as the first encrypted message - The server's certificate (proving its identity)
- A certificate verify message (signed with the server's private key)
- The server's Finished message (a MAC over the entire handshake)
At this point, both sides can compute the shared secret from the Diffie-Hellman exchange. Everything after the Server Hello is encrypted, even the certificate and extensions (which used to travel in plaintext in earlier TLS versions). That hides the certificate from passive eavesdroppers, but it doesn't hide which site you're visiting: the client still names the server in plaintext in the SNI (Server Name Indication) extension of its Client Hello. Encrypted Client Hello (ECH) is the fix, and browsers and some CDNs have started to deploy it.
Step 3: Client Finished
The client verifies the server's certificate and signature, computes the shared secret, and sends its Finished message. This message is a MAC over the entire handshake transcript, proving that the client saw the same handshake messages as the server.
Now both sides have a shared secret, and all subsequent communication is encrypted with a symmetric cipher derived from that secret.
The TLS 1.3 handshake combines key exchange (ephemeral Diffie-Hellman), server authentication (certificate + signature), and cipher negotiation into a single round trip. After the handshake, all data is encrypted with a symmetric cipher derived from the shared secret. Each component serves a specific security purpose, and the handshake is designed so that no component can be removed without breaking a security guarantee.
Step through the handshake one message at a time. Watch when each side can first derive keys, which messages are already encrypted, and what a passive observer on the wire actually gets to see.
TLS 1.3 full handshake
A first connection: ECDHE key exchange and a certificate, in one round trip. (RFC 8446 section 2)
- Handshake traffic keys from here
- Application traffic keys from here
Nothing sent yet. Step through to watch what each side learns and when encryption starts.
- Early Secret
- Early Secret
What Each Piece Accomplishes
Key exchange (ECDHE): Establishes a shared secret no eavesdropper can compute. The ephemeral keys give you forward secrecy — even if the server's long-term private key leaks years later, past sessions stay safe, because the ephemeral keys were thrown away.
Server certificate: Proves the server's identity. The certificate contains the server's public key and is signed by a Certificate Authority the client trusts. Stops an attacker from impersonating the server.
Certificate Verify: The server signs a hash of the handshake transcript with its private key, proving it actually holds the private key matching the certificate. Without this step, an attacker could just wave around someone else's certificate.
Finished messages: Both sides send a MAC (message authentication code) of the entire handshake transcript. Any tampered handshake message produces a mismatched Finished MAC, and the connection dies.
0-RTT Resumption
For repeat connections, TLS 1.3 supports 0-RTT (zero round trip time) resumption. If the client has connected before and cached a pre-shared key, it can send encrypted application data in its very first message. No waiting on the server.
The catch: 0-RTT data isn't protected against replay attacks. An attacker who captures the first message can resend it, and the server processes the request twice. So 0-RTT should only carry idempotent requests like GET, never POST. Servers also need to be built to handle replayed 0-RTT data safely.
The resumption handshake below uses a pre-shared key from an earlier session, so the server skips Certificate and CertificateVerify entirely. It leaves out the optional early data itself. The key schedule panel still shows where the PSK enters: the Early Secret. 0-RTT data is encrypted with keys derived from that secret, which comes from the PSK alone, before any Diffie-Hellman has happened. That's why it has no forward secrecy.
TLS 1.3 resumption with a PSK
A returning client offers a PSK from an earlier session's NewSessionTicket, with psk_dhe_ke so a fresh ECDHE still runs. No certificate this time. (RFC 8446 section 2.2)
- Handshake traffic keys from here
- Application traffic keys from here
Nothing sent yet. Step through to watch what each side learns and when encryption starts.
- PSK from an earlier session
- Early Secret
- binder_key
Nothing yet
- Early SecretClient knows it.Server doesn't know it.HKDF-Extract(0, PSK)
- binder_keyClient knows it.Server doesn't know it.Derive-Secret(Early Secret, "res binder", "")
- Handshake SecretClient doesn't know it.Server doesn't know it.HKDF-Extract(Derive-Secret(Early Secret, "derived", ""), (EC)DHE)
- client_handshake_traffic_secretClient doesn't know it.Server doesn't know it.Derive-Secret(Handshake Secret, "c hs traffic", ClientHello...ServerHello)
- server_handshake_traffic_secretClient doesn't know it.Server doesn't know it.Derive-Secret(Handshake Secret, "s hs traffic", ClientHello...ServerHello)
- Master SecretClient doesn't know it.Server doesn't know it.HKDF-Extract(Derive-Secret(Handshake Secret, "derived", ""), 0)
- client_application_traffic_secret_0Client doesn't know it.Server doesn't know it.Derive-Secret(Master Secret, "c ap traffic", ClientHello...server Finished)
- server_application_traffic_secret_0Client doesn't know it.Server doesn't know it.Derive-Secret(Master Secret, "s ap traffic", ClientHello...server Finished)
- exporter_master_secretClient doesn't know it.Server doesn't know it.Derive-Secret(Master Secret, "exp master", ClientHello...server Finished)
- resumption_master_secretClient doesn't know it.Server doesn't know it.Derive-Secret(Master Secret, "res master", ClientHello...client Finished)
What TLS 1.3 Removed
TLS 1.3 eliminated many legacy features that caused security problems:
- RSA key exchange (no forward secrecy) - removed
- Static Diffie-Hellman (no forward secrecy) - removed
- CBC mode ciphers (vulnerable to padding oracle attacks) - removed
- RC4 (biased output) - removed
- SHA-1 and MD5 for signatures - removed
- Compression (vulnerable to CRIME attack) - removed
- Renegotiation (complex, attack-prone) - removed
TLS 1.3 only supports AEAD ciphers (AES-GCM, ChaCha20-Poly1305) with ephemeral key exchange (ECDHE). Ruthless pruning. The protocol-level attacks that hit earlier versions (padding oracles, compression oracles, downgrades to weak key exchange) have nothing left to target. Implementation bugs are another matter: Heartbleed lived in OpenSSL's code, and no protocol redesign can rule out the next one.
Observing the Handshake
You can see TLS handshakes in action using tools like Wireshark or the openssl command line:
openssl s_client -connect example.com:443 -tls1_3You'll see the cipher suite negotiated, the certificate chain, and the handshake messages exchanged. Reading these traces fluently makes TLS debugging vastly easier, and it's an invaluable skill for any network engineer or security professional.
The Importance of Getting It Right
The TLS handshake is one of the most scrutinised protocols in computing. Flaws in TLS and its implementations have produced some of the loudest security vulnerabilities in internet history. Heartbleed, POODLE, BEAST, CRIME — every security professional recognises those names. Every step in the handshake exists for a reason, and every piece of data carries a specific security purpose. Strip out or weaken any step and you open the door to attacks cryptographers have spent decades shutting down.