The TLS handshake: what each step actually does
The TLS handshake is the exchange of messages that opens every TLS connection, before your request is sent. It is the first stage of how TLS works: the two sides agree on a protocol version and algorithms, the server proves it holds the private key for the name you asked for, and both derive the same keys without sending the keys themselves [1].
- Encrypted from
- the first message after the ServerHello, in TLS 1.3 [1]
- Proof of the private key
- the CertificateVerify signature in TLS 1.3; in TLS 1.2 with ephemeral Diffie-Hellman, the signed ServerKeyExchange [1] [2]
- Ends with
- a Finished message from each side, computed over the whole exchange [1]
What has to be settled, and why in this order
RFC 9846 splits the TLS 1.3 handshake into three phases, and each one needs the one before it [1].
Key exchange. The client and server pick the protocol version and algorithms and establish shared keying material. The ClientHello and the ServerHello travel in the clear, because no key exists yet. Everything after this phase is encrypted.
Server parameters. The server sends the remaining settings, such as which application protocol to speak and whether it wants a certificate from the client.
Authentication. The server proves its identity, and both sides confirm that they hold the same keys and saw the same messages.
Step by step in TLS 1.3
The current version, TLS 1.3, completes a full handshake in one round trip [1]:
ClientHello. The client lists the versions and cipher suites it supports, the name it wants in the SNI extension, and a key share for the group it expects the server to pick [1] [4].
ServerHello. The server picks a version and a cipher suite and sends its own key share. From here both sides compute the same handshake keys, and every later message is encrypted.
EncryptedExtensions. Settings the server agreed to that the keys do not depend on, such as the application protocol negotiated by ALPN.
Certificate and CertificateVerify. The server's certificate chain, then a signature over the handshake so far, made with the certificate's private key.
Finished, from the server. A MAC over the whole handshake, keyed from the shared secret.
Finished, from the client. The same check in the other direction. The client may send its first request right after it [1].
What the messages look like on the wire
Here is a TLS 1.3 handshake with a test server of ours, printed by openssl s_client -msg; >>> is what the client sent, <<< what it received [8]:
>>> TLS 1.3, Handshake [length 0134], ClientHello
<<< TLS 1.3, Handshake [length 007a], ServerHello
<<< TLS 1.3, Handshake [length 0006], EncryptedExtensions
<<< TLS 1.3, Handshake [length 0391], Certificate
<<< TLS 1.3, Handshake [length 004f], CertificateVerify
<<< TLS 1.3, Handshake [length 0034], Finished
>>> TLS 1.3, ChangeCipherSpec [length 0001]
>>> TLS 1.3, Handshake [length 0034], FinishedThe -trace output of the same run shows three more details [8]:
The version field says TLS 1.2. The ClientHello carries
client_version=0x303 (TLS 1.2), and the real offer, TLS 1.3 and TLS 1.2, sits in thesupported_versionsextension. RFC 9846 fixes the old field at 0x0303 because servers mishandled higher values [1].Encrypted messages are labelled as application data. From EncryptedExtensions on, every record that carries a handshake message has the outer type
ApplicationData (23); the real type is inside the encryption, as RFC 9846 §5.2 requires [1].ChangeCipherSpec has no job here. TLS 1.3 removed the message. Implementations send a dummy one so that middleboxes built for TLS 1.2 let the connection through (RFC 9846, appendix E.4). With
-no_middlebox, our client sent an empty session ID and no ChangeCipherSpec; the server still sent its own, which the RFC allows [1] [8].
A resumed handshake skips the certificate
This is session resumption. After a full handshake, the server can send NewSessionTicket messages, and a later connection can offer the ticket as a pre-shared key. If the server accepts it, it sends neither Certificate nor CertificateVerify. Our second connection loaded the ticket with -sess_in: -msg showed ClientHello, ServerHello, EncryptedExtensions and the two Finished messages, and s_client printed Reused, TLSv1.3 [8]. With a ticket, the client can also send early data in its first flight, with weaker security properties for that data, replay among them [1].
The client opens with what it can do
The ClientHello is an offer. RFC 9846 §4.2.1 lists four sets of options in it [1]:
the cipher suites the client supports;
the key exchange groups it supports (
supported_groups) and key shares for some of them (key_share);the signature algorithms it can accept (
signature_algorithms);pre-shared keys from earlier connections (
pre_shared_key), if it has any.
It also names the host. One address can serve more than one site, so the client puts the hostname in the server_name extension, and the server can use it to choose the certificate to present [4]. In our trace it also carried supported_versions and a key_share for X25519 [8]. The hostname travels unencrypted.
The key share is a guess: material for the group the client expects the server to accept, sent before the server has said anything. When the guess is right, TLS 1.3 finishes in one round trip.
When the client guesses the wrong group
If the server picks a group the client sent no share for, it answers with a HelloRetryRequest that names that group, and the client sends a second ClientHello [1]. The retry costs an extra round trip. We offered X25519 and P-384 with a share for X25519 only, to a server limited to P-384 [8]:
>>> TLS 1.3, Handshake [length 0124], ClientHello
<<< TLS 1.3, Handshake [length 0058], ServerHello
>>> TLS 1.3, ChangeCipherSpec [length 0001]
>>> TLS 1.3, Handshake [length 0165], ClientHello
<<< TLS 1.3, Handshake [length 00bb], ServerHelloOpenSSL labels the HelloRetryRequest as a ServerHello. RFC 9846 §4.2.3 gives the two the same structure and marks the retry with a fixed random value, the SHA-256 of "HelloRetryRequest" [1]. Our first ServerHello began with it: CF21AD74 E59A6111 [8].
The server answers with what it chose
The ServerHello is a set of decisions. It names the version and cipher suite the server selected and carries its own key share, in a group the client offered. Each side then computes the shared secret from its own private value and the other's share, so the secret itself is not sent and a recording gives an observer nothing to decrypt with. In TLS 1.3 every public-key key exchange works this way, which is why a stolen server key does not expose past sessions: the property called forward secrecy [1].
If the server finds nothing acceptable in the offer, it ends the handshake here with an alert [1]. No certificate has been sent at this point, so a failure at this stage comes with no warning about identity. The alerts themselves, and what to do about each, are on the SSL handshake failed page in the errors section.
The server proves the name is its own
Two things happen here.
The certificate is presented. It states which names it covers, who issued it and until when it is valid. Anyone who connects receives it, so on its own it proves nothing. What a certificate contains is covered under certificates.
The server proves it holds the matching private key. In TLS 1.3 this is the CertificateVerify message: a signature over a hash of every handshake message up to and including the certificate, with the context string "TLS 1.3, server CertificateVerify" [1]. A copied certificate cannot produce it, because the signature needs the private key, and the hash covers this connection's random values and key shares.
TLS 1.2 has no CertificateVerify from the server. With ephemeral Diffie-Hellman, the server signs its key exchange parameters in the ServerKeyExchange message instead [2]; our TLS 1.2 run below shows ServerKeyExchange and no CertificateVerify [8]. The client then checks the chain, the names and the dates, and stops with a browser warning if any check fails.
Both sides confirm they agree
The handshake ends with each side's Finished message: a MAC over the whole handshake, computed with a key derived from the shared secret [1]. The receiver computes the same value. If it differs, the receiver terminates the connection.
This does two jobs. It confirms that both sides derived the same keys, and it detects any change to the earlier messages, since an altered message changes the value. That protects against an attacker in the path who edits the offer to push both sides onto weaker terms than they support.
TLS 1.3 adds a second guard against a forced older version. A TLS 1.3 server that negotiates TLS 1.2 must end its ServerHello random with the bytes 44 4F 57 4E 47 52 44 01, ASCII "DOWNGRD", and a TLS 1.3 client that sees them must abort [1]. Our server allows both versions; asked for TLS 1.2 only, it sent [8]:
random_bytes (len=28): 76AB9013179F4056C3DF2EC2B2A7447FD0C90487444F574E47524401
0000000 D O W N G R D 001The same server limited to TLS 1.2 ended the random with 0C2209D33D1FFB48, no marker [8].
Where TLS 1.2 and TLS 1.3 differ
A full TLS 1.2 handshake needs two full protocol rounds, four flights, before the client may send application data [3]. Our TLS 1.2 run [8]:
>>> TLS 1.2, Handshake [length 00cb], ClientHello
<<< TLS 1.2, Handshake [length 0041], ServerHello
<<< TLS 1.2, Handshake [length 038c], Certificate
<<< TLS 1.2, Handshake [length 0072], ServerKeyExchange
<<< TLS 1.2, Handshake [length 0004], ServerHelloDone
>>> TLS 1.2, Handshake [length 0025], ClientKeyExchange
>>> TLS 1.2, ChangeCipherSpec [length 0001]
>>> TLS 1.2, Handshake [length 0010], Finished
<<< TLS 1.2, Handshake [length 00ba], NewSessionTicket
<<< TLS 1.2, Handshake [length 0010], FinishedThe certificate and the key exchange travel unencrypted: Finished is the first message protected with the negotiated keys. ChangeCipherSpec does real work here. It tells the receiver that the following records are protected with those keys [2].
| TLS 1.3 | TLS 1.2 | |
|---|---|---|
| Round trips before the request | one | two |
| First encrypted handshake message | EncryptedExtensions | Finished |
| Server's proof of the private key | CertificateVerify | signed ServerKeyExchange, with ephemeral Diffie-Hellman |
| Version chosen through | supported_versions extension | version field of the hellos |
| ChangeCipherSpec | dummy, for middleboxes | switches to the new keys |
Some explanations still describe the client encrypting a premaster secret with the public key from the server's certificate. That is static RSA key exchange, defined for TLS 1.2 and removed in TLS 1.3 [1] [2]. Which versions to enable, and what else changed between them, is on how TLS 1.2 and TLS 1.3 compare.
How to watch a handshake
OpenSSL and curl both print the handshake as it happens [6] [7]:
$ openssl s_client -connect example.com:443 -servername example.com -msg </dev/null
$ curl -v https://example.com/ -o /dev/null-msg prints each handshake message by name, from the ClientHello to each Finished message, as in the outputs above; -trace adds the fields inside them. In curl's verbose output, lines starting with * are curl's own notes, and the TLS handshake appears as lines like these, from our test server [7] [8]:
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):The last message in the output shows where an exchange stopped.
On Bridge CDN
On Bridge CDN, TLS is terminated at the edge [9]. A visitor's handshake runs with the edge, not with your server, so these commands against a hostname served through Bridge CDN show the edge's side of the exchange.
FAQ
What is the TLS handshake?
The TLS handshake is the exchange that runs before any of your data is sent. The two sides agree on a protocol version and cipher suite, each derives the same keys from exchanged key shares, and the server proves it holds the private key for the name requested.
What are the steps of the TLS handshake?
In TLS 1.3: ClientHello, ServerHello, EncryptedExtensions, the server's Certificate and CertificateVerify, then a Finished message from each side. It takes one round trip; TLS 1.2 needs two.
Is the SSL handshake the same as the TLS handshake?
Yes. SSL is the name of the protocol TLS replaced, and people still say it out of habit. SSL 3.0, the last SSL version, must not be used, so the handshake a client and server run is a TLS handshake. [5]
Why does a handshake fail with no certificate warning?
Because it failed before the server sent a certificate. If the two sides share no acceptable version, cipher suite or key exchange group, the server ends the exchange instead of answering with a ServerHello.
Are the keys sent over the connection?
No. Each side sends a key share, and both compute the same secret from them, so the secret itself does not travel.
Sources
RFC 9846, TLS 1.3 (obsoletes RFC 8446 and RFC 5246): §1.3, §2, §4.2, §4.3, §4.4.1, §4.5, §4.7.1, §5.2, appendix E.4.
RFC 5246, TLS 1.2: §7.1, §7.3, §7.4.
RFC 7918, TLS False Start: §1.
RFC 6066, TLS Extensions: §3 (server_name).
RFC 7568, Deprecating Secure Sockets Layer Version 3.0: abstract, §3.
OpenSSL 3.0 manual: openssl-s_client (-msg, -trace, -servername, -sess_in, -sess_out, -no_middlebox).
curl man page: -v, --verbose.
Our runs: OpenSSL 3.0.13 and curl 8.5.0 on Linux, localhost, an example.com test certificate from our own lab root.
Bridge SSL, home page FAQ: What happens on my server?