The TLS 1.3 Handshake Step by Step
Everything in this course so far meets in one place: the TLS 1.3 handshake (RFC 8446, 2018; republished with clarifications as RFC 9846 in 2026). In one round trip, two parties that share nothing agree on fresh keys with X25519, authenticate the server with a certificate chain and a signature, confirm that nobody tampered with the negotiation, and switch to AES-GCM or ChaCha20-Poly1305. TLS Records and the ClientHello parsed the first message byte by byte; this lesson follows the whole exchange and asks what each step protects against.
The messages
- ClientHello (cleartext): a 32-byte random, the supported cipher suites, signature algorithms and groups, and a key share: the client guesses that the server will accept X25519 and sends its ephemeral public key right away. That guess is why TLS 1.3 needs only one round trip. Extensions include SNI (the host name, in cleartext unless Encrypted Client Hello is used) and ALPN (
h2,http/1.1). - ServerHello (cleartext): the server's random, the chosen suite and its own key share. Both sides now compute the X25519 shared secret and derive handshake traffic keys (The Key Schedule). If the server doesn't support the client's group, it sends a HelloRetryRequest and costs an extra round trip.
- EncryptedExtensions: the rest of the server's choices, now encrypted. Unlike TLS 1.2, the certificate is also encrypted, so a passive observer doesn't see which certificate the server presented (the site name can still leak through SNI).
- Certificate: the leaf and intermediates, validated as in Certificate Chains.
- CertificateVerify: a signature with the certificate's private key over a hash of the whole transcript so far, both key shares included. This is what stops the man in the middle of Diffie–Hellman: an attacker who substituted a key share can't sign the transcript the client saw.
- Finished (server, then client): an HMAC over the transcript with a key derived from the handshake secret. It proves that both sides saw the same messages, so a downgrade (an attacker deleting the strong cipher suites from the ClientHello) is detected.
- Application data flows under application traffic keys. After the handshake the server may send NewSessionTicket messages for resumption.
The lab sends the same messages one at a time, each in the colour of the key that protects it: grey for cleartext, amber for the handshake keys, green for the application keys. The full handshake is 9 messages and the client sends application data after 1 round trip. Switch on HelloRetryRequest and a second ClientHello costs a second round trip (11 messages). PSK resumption drops Certificate and CertificateVerify (7 messages; the server proves itself with the earlier session's key), and PSK + 0-RTT sends a request in purple, under the early key, with the very first flight: 0 round trips, and replayable. Encrypted Client Hello leaves the observer only the outer name public.example.net.
The handshake in the sandbox
The session starts a TLS server on 127.0.0.1:8443 with the lab certificate and prints OpenSSL's message trace (-msg), keeping only the handshake-level lines.
P=$SAMPLES/pki
openssl s_server -accept 127.0.0.1:8443 -cert $P/lab.test.crt -key $P/lab.test.key -quiet >/dev/null 2>&1 &
for i in $(seq 50); do ss -Htln 'sport = :8443' | grep -q . && break; sleep 0.1; done
openssl s_client -connect 127.0.0.1:8443 -servername lab.test -CAfile $P/ca.crt -msg </dev/null 2>&1 \
| grep -E '^(<<<|>>>)' | grep -vE 'RecordHeader|InnerContent'
kill %1>>> TLS 1.3, Handshake [length 0131], ClientHello
<<< TLS 1.3, Handshake [length 007a], ServerHello
<<< TLS 1.3, Handshake [length 0006], EncryptedExtensions
<<< TLS 1.3, Handshake [length 03af], Certificate
<<< TLS 1.3, Handshake [length 0108], CertificateVerify
<<< TLS 1.3, Handshake [length 0034], Finished
>>> TLS 1.3, ChangeCipherSpec [length 0001]
>>> TLS 1.3, Handshake [length 0034], Finished
>>> TLS 1.3, Alert [length 0002], warning close_notify
Reading the lengths (hex, including the 4-byte handshake header):
- ClientHello
0x131= 305 bytes; Certificate0x3af= 943 bytes (one RSA-2048 certificate plus framing). - CertificateVerify
0x108= 264 bytes: 4 header + 2 (signature schemersa_pss_rsae_sha256) + 2 (length) + 256-byte RSA-2048 signature. - Finished
0x34= 52 bytes: 4 header + 48-byte HMAC-SHA-384, because the negotiated suite wasTLS_AES_256_GCM_SHA384. - The client's ChangeCipherSpec is a dummy record for "middlebox compatibility": old firewalls expected it, so TLS 1.3 sends one and ignores it.
close_notifyis the client closing because its input (/dev/null) ended.
What changed from TLS 1.2
| TLS 1.2 | TLS 1.3 |
|---|---|
| RSA key exchange allowed (no forward secrecy) | only (EC)DHE or PSK with (EC)DHE |
| CBC and RC4 suites, MAC-then-encrypt | only AEADs: AES-GCM, ChaCha20-Poly1305, AES-CCM |
| 2 round trips for a full handshake | 1 round trip (0 with resumption and early data) |
| certificate in cleartext | certificate encrypted |
| server signs only the key exchange parameters | server signs the whole transcript |
| renegotiation, compression, custom DH groups | removed |
| dozens of cipher suites | 5 suites (3 in common use) |
Most famous TLS attacks of the 2010s (BEAST, CRIME, Lucky Thirteen, POODLE, FREAK, Logjam, ROBOT, Triple Handshake) target features TLS 1.3 removed. Downgrade to TLS 1.2 is detected too: a TLS 1.3 server that negotiates 1.2 puts a fixed marker in the last 8 bytes of its random, and a 1.3 client that sees it aborts.
Resumption and 0-RTT
A client with a session ticket can resume with a pre-shared key (PSK), ideally combined with a fresh X25519 exchange (psk_dhe_ke) to keep forward secrecy. It may even send 0-RTT early data with the first flight. Early data is encrypted but replayable: an attacker can resend the client's first flight. Servers must accept early data only for idempotent requests (a GET, never a payment) or use anti-replay mechanisms.
How TLS configuration problems are detected
openssl s_client -briefagainst your own servers: protocol version, suite, key exchange group, signature type, verification result.-tls1_2,-tls1_1probes and scanners (testssl.sh, SSL Labs for public sites, Nmapssl-enum-cipherswithin scope) for old protocols, non-AEAD suites, weak groups and missing forward secrecy.- Inspection of 0-RTT settings (
ssl_early_datain nginx) on endpoints with side effects. - Packet captures of your own traffic: ClientHello contents (offered versions, SNI, groups), visible with tshark.
How it is fixed
- Enable TLS 1.3, keep TLS 1.2 only with ECDHE + AEAD suites, disable everything older (RFC 8996 deprecates TLS 1.0 and 1.1).
- Use library defaults (OpenSSL 3, BoringSSL, rustls, Go's crypto/tls) rather than hand-tuned cipher lists; Mozilla's server-side TLS guidelines give ready configurations.
- Keep early data off unless the endpoint is safe to replay.
Pitfalls
- Thinking TLS 1.3 hides the site name: SNI is in cleartext without ECH, and DNS lookups and IP addresses still leak a lot (What TLS Does Not Protect).
- TLS-inspecting middleboxes that break 1.3 or downgrade connections: they must be configured and audited like any other TLS endpoint.
- Disabling certificate verification "because it is internal": the handshake then authenticates nothing.
Practice
1. Which message stops an attacker from substituting their own key share in the ServerHello?
CertificateVerify: the server signs the transcript including both key shares; a substituted share makes the signature fail (and the attacker doesn't have the server's private key to make a new one). Finished then confirms the whole transcript.
2. Why is the Finished message 52 bytes here and not 36?
The suite uses SHA-384, so the HMAC is 48 bytes; with the 4-byte header that is 52 (0x34). A SHA-256 suite would give 32 + 4 = 36.
3. An online shop enables 0-RTT to save latency. Which request types must it refuse in early data?
Anything non-idempotent: checkout, payment, password changes, any POST with side effects. Early data can be replayed by an attacker who recorded it.
Test yourself
Why can TLS 1.3 complete a full handshake in one round trip?
- It skips certificates
- The client sends its key share in the ClientHello
- It uses RSA key exchange
- It caches all keys
What does the server sign in CertificateVerify?
- Only its certificate
- A hash of the handshake transcript so far
- The client's random only
- The application data
Which of these is NOT allowed in TLS 1.3?
- AES-GCM
- ChaCha20-Poly1305
- RSA key exchange
- X25519
What is the main risk of 0-RTT early data?
- It is not encrypted
- It can be replayed
- It disables certificates
- It uses weak ciphers
In the TLS 1.3 lab, which messages disappear with PSK resumption, and why is that safe?
- ClientHello and ServerHello; the ticket replaces them
- Certificate and CertificateVerify; knowing the PSK from the earlier, authenticated session proves the server's identity
- Both Finished messages; the PSK makes them redundant
- Nothing disappears