How HTTPS Really Starts: TCP, TLS and the Cipher Suite, Step by Step

There is no “HTTP handshake”

HTTP itself has no handshake: it is a plain request/response protocol. What people call the HTTP handshake is everything that has to happen before the browser can send its first GET over HTTPS.

When you type https://example.com, four things happen in order:

  1. DNS resolves example.com to an IP address. There is no handshake here.
  2. TCP 3-way handshake opens a reliable connection to port 443. Cost: 1 round trip (RTT).
  3. TLS handshake agrees on algorithms, authenticates the server and derives encryption keys. Cost: 2 RTT in TLS 1.2, 1 RTT in TLS 1.3.
  4. HTTP finally sends the request and receives the response, inside encrypted TLS records.

So with TLS 1.2 a browser waits 3 round trips before the first byte of HTTP leaves the machine; with TLS 1.3 it waits 2. On a 100 ms mobile link that difference is a tenth of a second on every new connection.

Throughout this article we follow one concrete connection: a browser talking to example.com, which has an RSA-2048 certificate and ends up negotiating the cipher suite TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256. Press play below and watch every packet move, step by step, for both TLS 1.2 and TLS 1.3.

Step 1: the TCP 3-way handshake

TCP must open a connection before TLS can say anything. Each side picks a random Initial Sequence Number (ISN) and confirms the other’s, so both know where the byte stream starts.

# Direction Packet Example values Meaning
1 Client → Server SYN seq=1000 “I want to connect; my bytes start at 1000.” Options: MSS, window scale, SACK.
2 Server → Client SYN-ACK seq=5000, ack=1001 “Got your 1000; mine start at 5000.”
3 Client → Server ACK ack=5001 “Got your 5000.” Connection is ESTABLISHED.

After one round trip there is a reliable pipe, but nothing in it is encrypted and no cipher suite exists yet.

Security note: a SYN flood sends step 1 millions of times and never sends step 3, filling the server’s half-open connection table. Servers defend with SYN cookies, which encode the connection state in the server’s ISN instead of storing it.

Step 2: the TLS 1.2 handshake (ECDHE_RSA)

The TLS handshake answers three questions in two round trips: which algorithms to use, whether the server is genuine, and which keys to encrypt with.

2a. ClientHello: the client offers

The client lists everything it supports, in its own order of preference. Nothing is chosen yet. A typical offer:

Field Example values offered
Cipher suites TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_128_CBC_SHA
supported_groups (curves) x25519, secp256r1, secp384r1
signature_algorithms ecdsa_secp256r1_sha256, rsa_pss_rsae_sha256, rsa_pkcs1_sha256
Other client_random (32 bytes), SNI = example.com, ALPN = h2, http/1.1

SNI travels in plaintext, so anyone on the path can see which site you are visiting. Encrypted Client Hello (ECH) is the fix.

2b. ServerHello: the server chooses

The server compares the client’s list with its own configuration and usually applies its own preference order:

Offered suite Server decision Why
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 Rejected Needs an ECDSA certificate; this server has RSA
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 Chosen Supported and the server’s first preference
TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 Supported Lower preference
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 Supported Lower preference
TLS_RSA_WITH_AES_128_CBC_SHA Rejected Disabled: no forward secrecy, CBC mode

The server also picks curve x25519 and signature scheme rsa_pss_rsae_sha256, and sends its own 32-byte server_random.

2c. The rest of the server’s flight

  1. Certificate: the X.509 chain, i.e. the leaf certificate for example.com (with an RSA-2048 public key) plus the intermediate CA. The root is not sent; the client already has it.
  2. ServerKeyExchange: the server generates a fresh x25519 key pair (private a, public A), sends A, and signs client_random ‖ server_random ‖ curve ‖ A with its RSA private key.
  3. ServerHelloDone: “your turn”.

2d. The client’s flight

  1. The client runs the certificate validation sub-process (next section). If any check fails, the handshake stops here.
  2. ClientKeyExchange: the client generates its own x25519 pair (private b, public B) and sends B.
  3. Both sides now derive the same keys locally; nothing is sent (see the cipher suite section).
  4. ChangeCipherSpec: “everything I send from now on is encrypted”.
  5. Finished (encrypted): a keyed hash of every handshake message so far.

2e. The server’s final flight

The server sends its own ChangeCipherSpec and encrypted Finished. If both Finished messages verify, both sides saw the same handshake. Any tampering, such as an attacker stripping strong suites from the ClientHello, makes the hashes differ and the connection aborts.

The certificate validation sub-process

Before the client sends anything secret, it checks locally that it is really talking to example.com. It does not “ask the CA”; it verifies a chain of signatures up to a root it already trusts. Every check must pass.

  1. Build the chain: example.com → Example Intermediate CA → Example Root CA.
  2. Leaf signature: verify the leaf certificate’s signature with the intermediate CA’s public key.
  3. Intermediate signature: verify the intermediate’s signature with the root CA’s public key.
  4. Trust anchor: the root must already be in the browser or OS trust store.
  5. Hostname: example.com must match a Subject Alternative Name (SAN) entry. Modern browsers ignore the CN.
  6. Validity: notBefore ≤ now ≤ notAfter.
  7. Key usage: digitalSignature allowed, Extended Key Usage includes serverAuth, and the leaf is not a CA (CA:FALSE).
  8. Revocation and transparency: a stapled OCSP response says “good”, and Certificate Transparency SCTs are present.
  9. Proof of private key: the RSA signature on ServerKeyExchange verifies with the leaf’s public key. This proves the server holds the private key, not just a copy of a public certificate.

If any check fails, the client sends a fatal alert such as bad_certificate, unknown_ca or certificate_expired, closes the connection, and the browser shows “Your connection is not private”.

AppSec note: code that skips these checks is one of the most common TLS findings: a trust-all TrustManager in Java or Android, verify=False in Python requests, rejectUnauthorized: false in Node.js, InsecureSkipVerify: true in Go. The traffic is still encrypted, but to whoever is in the middle.

Decoding TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256

A TLS 1.2 cipher suite name is five separate algorithms glued together, each with one job. Here is what each part does in our connection, and when.

Part Job Where it is used
ECDHE Key exchange: agree on a shared secret without sending it ServerKeyExchange, ClientKeyExchange, key derivation
RSA Authentication: prove the server is example.com Certificate, ServerKeyExchange signature, validation
AES_128 Bulk encryption of the actual data Finished messages and all HTTP traffic
GCM AEAD mode: encryption and integrity in one operation Every encrypted record
SHA256 PRF hash: key derivation and handshake integrity Key derivation, Finished messages

ECDHE: Elliptic-Curve Diffie-Hellman, Ephemeral

  • The server picks a random private key a and sends public A = a·G (G is the x25519 base point).
  • The client picks private b and sends public B = b·G.
  • The client computes b·A, the server computes a·B. Both equal a·b·G: the 32-byte premaster secret.
  • An eavesdropper sees only A and B; recovering a or b from them is computationally infeasible.
  • “Ephemeral” means a and b are discarded after the session. Stealing the server’s RSA key later cannot decrypt recorded traffic: this is forward secrecy.

RSA: authentication only

  • The certificate carries the server’s RSA-2048 public key.
  • The server signs its ECDHE public key A (plus both randoms) with its RSA private key, so a man-in-the-middle cannot substitute their own A.
  • The client verifies that signature with the certificate’s public key.
  • In an ECDHE_RSA suite, RSA only signs. It does not encrypt the premaster secret. That was the old TLS_RSA_WITH_... key exchange, which has no forward secrecy and was removed in TLS 1.3.

SHA256: turning one secret into many keys

The TLS 1.2 PRF is HMAC-SHA256 applied repeatedly. It stretches the premaster secret into everything else:

master_secret = PRF(premaster, "master secret", client_random ‖ server_random)   → 48 bytes
key_block     = PRF(master_secret, "key expansion", server_random ‖ client_random)

The key_block is then sliced in order:

Slice Size Used for
client_write_key 16 bytes AES-128 key, client → server
server_write_key 16 bytes AES-128 key, server → client
client_write_IV 4 bytes GCM implicit nonce salt, client side
server_write_IV 4 bytes GCM implicit nonce salt, server side

There are no MAC keys: GCM authenticates records itself. SHA-256 is also used in Finished: verify_data = PRF(master_secret, “client finished”, SHA-256(all handshake messages)), truncated to 12 bytes.

AES_128 and GCM: protecting every record

  • Each direction encrypts with its own 16-byte AES key.
  • GCM runs AES in counter mode and computes a GHASH authentication tag over the ciphertext and the record header.
  • Nonce (12 bytes) = 4-byte write_IV salt + 8-byte explicit value sent with each record.
  • Each record carries a 16-byte tag. If a single bit is changed in transit, the tag fails, the receiver sends bad_record_mac, and the connection is killed.

Two common misreadings: the SHA256 at the end of a GCM suite is not a record MAC (GCM already authenticates), and the hash used inside the RSA signature comes from signature_algorithms, not from the suite name.

Step 3: HTTP over TLS

Only now does HTTP begin. The browser sends GET /index.html HTTP/1.1 with Host: example.com, cookies and any Authorization header, all inside TLS records of type 23 (application_data) encrypted with AES-128-GCM.

What a network observer can still see: the server IP, the SNI (in TLS 1.2 and in TLS 1.3 without ECH), packet sizes and timing. What they cannot see: the URL path, headers, cookies and bodies.

The response, HTTP/1.1 200 OK plus the HTML, comes back encrypted with the server’s key. If ALPN negotiated h2, these are HTTP/2 frames instead, but the protection is identical.

AppSec note: the response should include Strict-Transport-Security: max-age=31536000; includeSubDomains. HSTS tells the browser to use HTTPS for every future visit, which blocks SSL-stripping attacks that downgrade the very first request to plain HTTP.

TLS 1.3: the same job in one round trip

TLS 1.3 (RFC 8446) cuts the handshake to 1 RTT with one trick: the client guesses the key exchange group and sends its public key inside the ClientHello, as a key_share. The server can then answer with its own key and start encrypting immediately.

  1. ClientHello + key_share: suites TLS_AES_128_GCM_SHA256, TLS_AES_256_GCM_SHA384, TLS_CHACHA20_POLY1305_SHA256; groups X25519MLKEM768 (hybrid post-quantum), x25519, secp256r1; key shares for the first two.
  2. ServerHello + key_share: chooses TLS_AES_128_GCM_SHA256 and x25519 (in this example the server has no post-quantum support), and sends its public key.
  3. Both sides derive handshake keys with HKDF-SHA256. From here on, everything is encrypted.
  4. EncryptedExtensions, Certificate and CertificateVerify (an RSA-PSS signature over the SHA-256 transcript hash), then server Finished.
  5. The client runs the same validation sub-process, with CertificateVerify as the proof of key, then sends its Finished and the HTTP request together.
TLS 1.2 TLS 1.3
Handshake round trips 2 1 (0 on resumption)
Suite name contains key exchange, auth, cipher, mode, hash cipher, mode, hash only
Key exchange ECDHE or static RSA (EC)DHE only: forward secrecy always
Certificate on the wire Plaintext Encrypted
Ciphers allowed Includes CBC, RC4, 3DES in old configs AEAD only (AES-GCM, ChaCha20-Poly1305)
Removed messages — ServerKeyExchange, ChangeCipherSpec, ClientKeyExchange

Key exchange and authentication left the suite name because they are now negotiated through the supported_groups, key_share and signature_algorithms extensions.

0-RTT caveat: on resumption, a client can send early data in its very first flight. That data can be replayed by an attacker, so servers should only accept it for idempotent requests such as GET.

AppSec takeaways: what to check and how

Finding Risk How to test
Certificate validation disabled in code Trivial man-in-the-middle Code review / SAST for trust-all managers, verify=False, InsecureSkipVerify; Burp proxy with an untrusted CA
TLS 1.0 / 1.1 or SSLv3 still enabled Known protocol attacks, compliance failure testssl.sh example.com, sslyze
Weak or non-forward-secret suites (TLS_RSA_*, CBC-SHA1, 3DES, RC4) Downgrade, decryption of recorded traffic nmap --script ssl-enum-ciphers -p 443 example.com
Missing HSTS SSL stripping on first visit curl -sI https://example.com and look for Strict-Transport-Security
Hostname or chain errors Users trained to click through warnings openssl s_client -connect example.com:443 -servername example.com
0-RTT accepted for state-changing requests Replay of POSTs Review server early-data configuration

To watch a real handshake yourself:

# Full TLS 1.2 or 1.3 handshake, certificate chain and negotiated suite
openssl s_client -connect example.com:443 -servername example.com -tls1_2
openssl s_client -connect example.com:443 -servername example.com -tls1_3

# TCP + TLS + HTTP in one trace
curl -v https://example.com

In Wireshark, filter tcp.port == 443 to see SYN / SYN-ACK / ACK, then tls.handshake to expand the ClientHello and read the offered suites and SNI.

Common misconceptions

  • “The client contacts the CA to verify the certificate.” No. It verifies signatures locally against its trust store; only revocation checks (OCSP or CRL) may touch the network, and OCSP stapling usually avoids even that.
  • “The server encrypts the signature with its private key.” It signs; the client verifies. Signing and encryption are different operations, even with RSA.
  • “The certificate is in the ServerHello.” In TLS 1.2, ServerHello, Certificate, ServerKeyExchange and ServerHelloDone are four separate messages sent in one flight.
  • “RSA key exchange is the most common.” Not for years. ECDHE is the norm, and static RSA key exchange does not exist in TLS 1.3.
  • “SHA256 in the suite is the HMAC.” For GCM suites it is the PRF/HKDF hash. GCM provides integrity itself.

SSL and TLS versions

Protocol Published Status
SSL 1.0 Never published —
SSL 2.0 1995 Prohibited 2011 (RFC 6176)
SSL 3.0 1996 Deprecated 2015 (RFC 7568)
TLS 1.0 1999 Deprecated 2021 (RFC 8996)
TLS 1.1 2006 Deprecated 2021 (RFC 8996)
TLS 1.2 2008 (RFC 5246) Supported; prefer TLS 1.3
TLS 1.3 2018 (RFC 8446) Current

References

5 1 vote
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted