TLS Handshake Sequence Explained

The TLS handshake is a cryptographic protocol used to securely establish an encrypted connection between a client (like a browser) and a server (like a web API).

This handshake negotiates everything needed to protect communication: encryption keys, supported algorithms, authentication, and integrity checking.


TLS Handshake Flow

StepDescription
ClientHelloClient initiates handshake, offering TLS version, supported cipher suites, random nonce, and extensions like SNI or ALPN.
ServerHelloServer responds with chosen cipher suite, version, and its own nonce.
CertificateServer sends its X.509 certificate to prove identity.
[Optional] CertificateRequestServer may request a certificate from the client (used in mutual TLS).
ServerHelloDoneIndicates server is done with its part of the handshake.
[Optional] CertificateClient sends certificate if requested.
ClientKeyExchangeClient sends the premaster secret (e.g., RSA-encrypted or ECDHE public key).
[Optional] CertificateVerifyClient proves possession of the private key.
ChangeCipherSpecClient and server signal that future messages will be encrypted.
FinishedEach party sends an encrypted message digest of the handshake.
Secure Channel EstablishedSymmetric encryption is now active for all future communication.

Key Concepts

ConceptExplanation
Cipher SuiteDefines which algorithms will be used for encryption, key exchange, and MAC.
Random NoncesRandom values from both sides, used to derive shared session keys.
Pre-Master SecretA value generated by the client, sent to the server and used to derive the symmetric keys.
Certificate (X.509)Server’s digital certificate, proving its identity and containing the public key.

TLS Handshake Sequence Diagram

Tedi


What Happens After the Handshake?

  • A shared symmetric key is derived from the exchanged data.
  • All future communication is encrypted, authenticated, and tamper-proof.
  • The handshake is relatively expensive; session reuse or TLS 1.3 can reduce round trips.

How to Inspect a TLS Handshake

Run this from your terminal to observe a real handshake:

openssl s_client -connect example.com:443