Computer Networking › Section H · Security in computer networks › Topic H.6
Securing TCP connections: TLS
Transport Layer Security turns an ordinary TCP connection into one that is private, tamper-evident and connected to the right server. It protects almost all web traffic, and its current version, TLS 1.3, does so in a single round trip.
Where TLS fits
TLS sits between an application and TCP. The application hands data to a TLS library, much as it would write to a socket, and the library encrypts and protects it before passing it to TCP; the receiving library checks and decrypts it. HTTPS is HTTP over TLS, and mail and many other protocols use it too. It grew from Netscape's SSL in the mid-1990s. TLS 1.0 appeared in 1999, TLS 1.2 in 2008 and TLS 1.3 in 2018, as RFC 8446. SSL and TLS 1.0 and 1.1 are deprecated, formally so for TLS since 2021, and should be disabled; current guidance is TLS 1.3, or TLS 1.2 where needed.
What the handshake must achieve
Before any application data flows, the client and server run a handshake with three jobs. First, they agree on algorithms: the client lists the cipher suites it supports and the server picks one. Second, the client authenticates the server, which proves it holds the private key matching a certificate for the name the client asked for; the server can optionally authenticate the client too. Third, they establish shared secret material that Trudy cannot learn, using the Diffie-Hellman method from "Principles of cryptography". Every later protection depends on getting these three right.
From one secret to several keys
Using a single key for everything would be poor practice, so both sides feed the shared secret, together with random values from the handshake, into a key derivation function. In TLS 1.3 this is HKDF, built on HMAC. Out come separate keys for the handshake and for application data, and within each, separate keys and IVs for each direction, client to server and server to client. If one key were ever exposed, the others would stay safe, and a message reflected back to its own sender would not verify, because it was protected with the other direction's key.
Records, sequence numbers and closure
TLS cuts the data stream into records. Each record is encrypted and integrity-protected with an authenticated cipher, such as AES-GCM, so any change is detected. Each side also keeps a record sequence number that is not sent but is mixed into every record's protection, so a record that Trudy deletes, reorders or replays fails to verify. The end of a session is protected too. Trudy could forge a TCP FIN to cut a transfer short, so TLS ends with an authenticated closing alert; a connection that stops without one is treated as possibly truncated, not as complete.
The TLS 1.3 handshake
The client's ClientHello lists supported versions and cipher suites, carries a random value, and includes a key share, its Diffie-Hellman public value. The server's ServerHello picks a suite and returns its own key share. Both can now compute the shared secret, so everything after this is encrypted. The server sends its Certificate, then CertificateVerify, a signature over the whole handshake so far, made with the certificate's private key, then Finished, a MAC over the handshake. The client checks all three and sends its own Finished. Any tampering with the earlier, unencrypted messages makes the signature and MACs fail.
Worked example: connecting to a shop
A browser opens https://shop.example. 1. TCP's three-way handshake completes. 2. The ClientHello offers TLS 1.3, the suites TLS_AES_128_GCM_SHA256 and TLS_CHACHA20_POLY1305_SHA256, and an X25519 key share. 3. The ServerHello picks the AES suite and returns the server's key share; both derive handshake keys. 4. The browser checks the certificate: it names shop.example, is in date, and chains to a trusted root. 5. CertificateVerify proves the server holds the matching private key. 6. Both Finished messages verify. 7. HTTP requests now travel in protected records. Check: authentication came from steps 4 and 5, secrecy from step 3.
Worked example: counting round trips
Suppose the round-trip time (RTT) to a server is 40 ms, and ignore processing time. 1. The TCP handshake costs 1 RTT before the client can send. 2. A TLS 1.3 handshake adds 1 RTT, because key shares travel in the first two messages. 3. The HTTP request and response take 1 more RTT, so the first response arrives after 3 RTT, 120 ms. 4. TLS 1.2 needed 2 RTT for a full handshake, giving 4 RTT, 160 ms. 5. QUIC, described in "Evolution of the transport layer: QUIC", merges the transport and TLS handshakes, giving 2 RTT, 80 ms. Check: 3 × 40 = 120 and 4 × 40 = 160.
Forward secrecy and resumption
In TLS 1.3 both sides generate fresh, ephemeral Diffie-Hellman values for each handshake and discard them afterwards. The server's long-term private key only signs; it never encrypts a session key. So if Trudy records traffic today and steals that key next year, she still cannot decrypt the recording. This is forward secrecy, which the old RSA key transport of earlier versions lacked. A returning client can resume with a pre-shared key from an earlier session and even send data in its first flight, called 0-RTT. That early data can be replayed by an attacker, so it should only carry requests that are safe to repeat.
What TLS 1.3 removed
TLS 1.3 simplified the protocol by deleting options that had caused real attacks. Gone are RSA key transport and static Diffie-Hellman, so every handshake has forward secrecy; CBC-mode and RC4 ciphers; MD5 and SHA-1 in handshake signatures; compression; and renegotiation. Only authenticated ciphers remain, chiefly TLS_AES_128_GCM_SHA256, TLS_AES_256_GCM_SHA384 and TLS_CHACHA20_POLY1305_SHA256. The design also allows new key-exchange groups. Since late 2024, major browsers have offered a hybrid group, X25519MLKEM768, combining classical X25519 with the post-quantum ML-KEM, and as of 2026 much web traffic already uses it.
Common mistakes to avoid
First, thinking TLS protects data on the server; it protects data in transit only. Second, believing the padlock proves a site is honest; it proves the connection reaches the holder of a valid certificate for that name. Third, ignoring certificate warnings, which defeats server authentication. Fourth, assuming 0-RTT data is as safe as other data; it can be replayed. Fifth, thinking a stolen server key exposes recorded TLS 1.3 sessions; forward secrecy prevents that. Sixth, leaving SSL, TLS 1.0 or TLS 1.1 enabled.
Key takeaways
TLS sits between applications and TCP and secures HTTPS and much else; use TLS 1.3, or 1.2 where needed. Its handshake agrees a cipher suite, authenticates the server with a certificate and a signature over the handshake, and sets up a shared secret with ephemeral Diffie-Hellman. HKDF derives separate keys for each direction. Records are encrypted and authenticated, with hidden sequence numbers against reordering and replay, and an authenticated close against truncation. TLS 1.3 takes one round trip, gives forward secrecy, keeps only authenticated ciphers, and now often adds post-quantum hybrid key exchange.
Flashcards
Flashcard
Transport Layer Security, between the application and TCP
Test your understanding
Question 1 of 5
In a TLS 1.3 handshake, which message proves that the server actually holds the private key for its certificate?
Question 2 of 5
The RTT to a server is 50 ms. Ignoring processing time, when does the first HTTP response arrive over TCP with a full TLS 1.3 handshake?
Question 3 of 5
An attacker records a TLS 1.3 session today and steals the server's long-term private key a year later. What can the attacker decrypt?
Question 4 of 5
Why does each side keep a record sequence number that is mixed into each record's protection?
Question 5 of 5
Why should 0-RTT early data carry only requests that are safe to repeat?
