The TLS handshake is the process by which a client and a server establish a secure, encrypted connection: they agree on a protocol version and cipher suite, authenticate the server (and optionally the client) using certificates, and exchange key material so that both sides derive the same session keys. Once the handshake completes, all application data is encrypted and integrity-protected.
Background: What TLS Is and Why the Handshake Matters
TLS (Transport Layer Security) is the cryptographic protocol that secures most of the internet's traffic—HTTPS, secure email, messaging apps, and VPNs. It sits between the application layer (e.g., HTTP) and the transport layer (TCP), encrypting data before it leaves the sender and decrypting it at the receiver. The handshake is the critical first phase: it negotiates the rules of engagement and establishes the shared secrets that make encryption possible. Without a secure handshake, an attacker could intercept or alter traffic, so the handshake is designed to provide confidentiality, integrity, and authentication.
TLS has evolved through versions: SSL 2.0 and 3.0 (now deprecated), TLS 1.0 and 1.1 (also deprecated), TLS 1.2 (still widely used), and TLS 1.3 (the current standard, faster and more secure). The handshake differs between versions; this article focuses on the modern TLS 1.2 and 1.3 handshakes, noting key differences.
Step-by-Step: The TLS 1.2 Handshake
The TLS 1.2 handshake typically involves two round trips before application data can flow. Here is the sequence:
- ClientHello: The client sends a message containing its supported TLS version, a list of cipher suites (combinations of key exchange, encryption, and MAC algorithms), a random byte string (client random), and optionally extensions such as SNI (Server Name Indication) to indicate which hostname it wants.
- ServerHello: The server responds with the chosen TLS version and cipher suite, its own random byte string (server random), and any extensions.
- Certificate: The server sends its digital certificate (or chain) to prove its identity. The client verifies the certificate against trusted root CAs, checks the hostname, and validates the signature.
- ServerKeyExchange (optional): If the chosen cipher suite uses ephemeral Diffie-Hellman (DHE or ECDHE), the server sends its key exchange parameters here, signed with its private key.
- ServerHelloDone: The server indicates it has finished its part of the handshake.
- ClientKeyExchange: The client sends its key exchange contribution—either an encrypted pre-master secret (for RSA key exchange) or its Diffie-Hellman public value.
- ChangeCipherSpec (client): The client signals that subsequent messages will be encrypted with the negotiated keys.
- Finished (client): The client sends a MAC over the handshake transcript, encrypted, to verify the handshake integrity.
- ChangeCipherSpec (server): The server signals the same.
- Finished (server): The server sends its encrypted Finished message.
After these steps, both parties have derived the same session keys (using the pre-master secret and the client/server randoms via a pseudorandom function) and can exchange encrypted application data.
How TLS 1.3 Simplifies and Speeds Up the Handshake
TLS 1.3 reduces the handshake to a single round trip (1-RTT) for a new connection and supports 0-RTT resumption for repeat connections. It removes legacy features like RSA key exchange and static Diffie-Hellman, mandating forward secrecy through ephemeral key exchange (typically ECDHE). The handshake flow is condensed:
- ClientHello: Includes key share (client's ephemeral public key), supported cipher suites, and other extensions.
- ServerHello: Includes server's key share, chosen cipher suite, and encrypted extensions.
- Encrypted handshake messages: The server sends its certificate, CertificateVerify (signature over transcript), and Finished—all encrypted. The client responds with its Finished.
Because the server's certificate is sent after keys are established, it is encrypted, improving privacy. TLS 1.3 also simplifies cipher suite negotiation to a small set of AEAD (Authenticated Encryption with Associated Data) algorithms.
Key Exchange and Forward Secrecy
Key exchange is how the client and server agree on a shared secret over an insecure channel. In older TLS versions, RSA key exchange was common: the client encrypts a pre-master secret with the server's public key. However, this lacks forward secrecy—if the server's private key is later compromised, past sessions can be decrypted. Modern practice favors ephemeral Diffie-Hellman (DHE or ECDHE), where both parties generate temporary key pairs; the shared secret is derived from these and discarded after the session. Forward secrecy ensures that compromising long-term keys does not compromise past session keys. TLS 1.3 requires forward secrecy for all non-PSK handshakes.
Authentication: Certificates and the Chain of Trust
During the handshake, the server presents a certificate issued by a Certificate Authority (CA). The client validates it by:
- Checking the certificate's digital signature against the CA's public key (which is in the client's trust store).
- Verifying the certificate chain up to a trusted root.
- Checking the certificate's validity period and revocation status (via CRL or OCSP).
- Confirming the hostname matches the certificate's subject or Subject Alternative Name (SAN).
If any check fails, the client aborts the handshake. Client authentication is optional: the server can request a client certificate, which the client sends and the server verifies similarly.
Common Problems and Misconceptions
Handshake failures are common and often stem from misconfiguration or outdated software. Typical issues include:
- Certificate errors: Expired, self-signed, or hostname-mismatched certificates cause browsers to warn or block.
- Protocol mismatch: If client and server do not share a common TLS version or cipher suite, the handshake fails. For example, a server that only supports TLS 1.2 will reject a client that only offers TLS 1.3.
- SNI issues: Virtual hosting relies on SNI; if the client omits it or the server misconfigures it, the wrong certificate may be presented.
- Firewall or middlebox interference: Some network devices block or alter handshake messages, especially for older protocols.
A common misconception is that the handshake encrypts the entire conversation from the start. In reality, the initial ClientHello and ServerHello are sent in plaintext (though TLS 1.3 encrypts more of the handshake). Another misconception is that TLS provides end-to-end encryption regardless of endpoints; it only secures the connection between client and server—if either endpoint is compromised, the data is exposed.
Frequently Asked Questions
What is the difference between TLS and SSL?
SSL (Secure Sockets Layer) is the predecessor to TLS. SSL 3.0 was deprecated in 2015; TLS 1.2 and 1.3 are the current secure versions. People often say "SSL" colloquially, but modern secure connections use TLS.
Does the TLS handshake happen on every HTTPS request?
No. The handshake occurs once per connection. HTTPS can reuse an existing TLS connection for multiple HTTP requests (HTTP keep-alive), and TLS session resumption (via session IDs or tickets) allows a abbreviated handshake for new connections, reducing overhead.
Is the TLS handshake encrypted?
In TLS 1.2, the initial messages (ClientHello, ServerHello, Certificate) are plaintext; only after ChangeCipherSpec does encryption begin. In TLS 1.3, most of the handshake after ServerHello is encrypted, including the server's certificate, providing better privacy.
What is 0-RTT and is it safe?
0-RTT (zero round-trip time) is a TLS 1.3 feature that allows a client to send application data in the first flight using a pre-shared key from a previous session. It reduces latency but has replay risks: an attacker could replay the early data. It should be used only for idempotent requests (e.g., GET) and with caution.
Why does my browser show a certificate warning?
Certificate warnings occur when the certificate is expired, self-signed, issued for a different hostname, or not trusted by the client's root store. They indicate a potential security risk; do not proceed unless you understand the cause.
Can the TLS handshake be intercepted?
The handshake is designed to resist interception: an active attacker cannot forge the server's certificate without being detected (assuming a trusted CA). However, if the client's trust store is compromised or the attacker can install a rogue CA, interception (e.g., by corporate proxies) is possible.