Why TLS Exists
TCP delivers bytes reliably to an address; it says nothing about who is reading them, who is changing them, or whether the address is the server you meant — TLS is the layer that adds confidentiality, integrity and authenticated identity on top of a transport that has none.
The problem
93.184.216.34:443. Every hop can read the bytes, rewrite them, or answer in the server’s place. TCP will happily deliver the forgery in order and without loss. What has to be added, and where?What TCP does not promise
TCP: A Reliable Ordered Byte Stream over an Unreliable Network gives you a byte stream that arrives complete and in order — and that is the entire contract. The bytes are plaintext on every link. The peer is whoever answered the SYN at that IP and port, and ARP and Neighbor Discovery: From an IP to a Local MAC, DNS: Why Names Need a Distributed Database and Internet Routing: Autonomous Systems and BGP each offer a way to make the wrong machine answer. Nothing in the segment lets the receiver tell "the server sent this" from "someone on the path sent this".
The threat model TLS was designed for has two attackers. The passive eavesdropper copies traffic and reads it: a rogue access point, a tap at an ISP, a compromised router. The active man-in-the-middle sits on the path and rewrites: it can inject a script into an HTML page, change an account number in a form post, or terminate the TCP connection itself and open its own to the real server, relaying both directions while reading everything.
The coffee-shop Wi-Fi is the canonical example because every attack is cheap there: the attacker shares your broadcast domain, can win the ARP race for the gateway’s IP, can hand out its own DNS server via DHCP, and sees every frame you send. The same attacks exist at ISP and nation-state scale; the café just makes them a laptop’s work.
- Passive: read credentials, session cookies, API keys, the content of every page. Defeated by encryption.
- Active: modify responses, downgrade to a weaker protocol, impersonate the server. Defeated by integrity protection plus server authentication.
- TCP checksums and sequence numbers protect against *accidents* (bit flips, reordering), not against an adversary who recomputes them.
Deriving the four properties
Start from the attacks and each property falls out. Against reading: confidentiality — encrypt the application bytes with a symmetric cipher such as AES-GCM or ChaCha20-Poly1305, which run at gigabytes per second with hardware support. Against rewriting: integrity — every record carries an authentication tag computed with the session key; a modified record fails to verify and the connection is torn down. Modern suites combine both in one AEAD construction (authenticated encryption with associated data), so there is no separate MAC step.
Encryption is useless if the key was agreed with the attacker, which forces authentication: the server proves it holds the private key matching a public key that a trusted third party has bound to its hostname — that binding is a Certificates and the Chain of Trust. And symmetric ciphers need both ends to hold the same secret while never sending it in the clear, which forces key agreement: an asymmetric exchange (ephemeral elliptic-curve Diffie-Hellman in every modern configuration) that lets two parties derive the same secret over a public channel.
The split between asymmetric and symmetric is a performance decision, not an aesthetic one. An X25519 key agreement costs on the order of 50–100 µs of CPU; an RSA-2048 signature verification tens of microseconds; encrypting a 16 kB record with AES-GCM under AES-NI costs a few microseconds. You do the expensive asymmetric work once per connection in the The TLS Handshake and the cheap symmetric work on every byte.
| Attack | Property needed | Mechanism (TLS 1.3) |
|---|---|---|
| Read traffic on the path | Confidentiality | Symmetric AEAD cipher (AES-128/256-GCM, ChaCha20-Poly1305) under a per-connection key |
| Modify or inject records | Integrity | AEAD authentication tag on every record; failed verification aborts the connection |
| Impersonate the server | Authentication | X.509 certificate chain to a trusted root plus a signature over the handshake (CertificateVerify) |
| Learn the key by watching key exchange | Key agreement | Ephemeral ECDHE (X25519, P-256) — the shared secret is never transmitted |
| Record now, decrypt after stealing the server key | Forward secrecy | Ephemeral keys discarded after the handshake; static RSA key exchange removed in 1.3 |
Where TLS sits
TLS is a layer between transport and application. It takes a reliable byte stream from TCP, splits application data into records of at most 16 kB plaintext, encrypts and tags each one, and hands the peer the same byte stream it was given. The application protocol above does not change: HTTPS is ordinary HTTP written into a TLS session on port 443. The same is true of SMTP submission on 465, IMAP on 993, the PostgreSQL wire protocol with sslmode=require, gRPC (which mandates h2 over TLS in most deployments), and MQTT on 8883.
Because TLS needs an ordered stream it cannot run directly over UDP: Datagrams and the Contract You Choose; the datagram variant is DTLS, and QUIC instead embeds the TLS 1.3 handshake inside its own transport — see HTTP/3 and QUIC. Some protocols start plaintext and upgrade in-band (STARTTLS for SMTP on 587, PostgreSQL’s SSLRequest message), which is where downgrade attacks live: an active attacker strips the offer to upgrade and the client, unless configured to require TLS, continues in the clear.
- Application protocolHTTP/1.1, HTTP/2, SMTP, PostgreSQL, gRPC — unchanged by TLS↓
- TLS record layerRecords ≤ 16 kB; each encrypted and authenticated with the session key↓
- TCPReliable ordered byte stream; TLS assumes this and cannot run over UDP↓
- IPAddresses and routing — all still visible to the path
What TLS does not protect
TLS protects the content of the connection, not its existence. The path still sees both IP addresses, the port, packet sizes and timing — enough to fingerprint which site or even which page is being visited. The SNI field in the Client Hello carries the hostname in plaintext so a shared server can pick a certificate; Encrypted Client Hello (ECH) is the fix and is deployed by some large CDNs and browsers but is far from universal. DNS lookups are separate and plaintext unless the resolver speaks DNS-over-HTTPS or DNS-over-TLS.
It also does not protect against a compromised endpoint (malware on the client reads the page after decryption), a misissued certificate (a CA that signs a certificate for a hostname it should not — Certificate Transparency exists to make that detectable), or a client that has been told to trust an extra root, which is exactly how corporate inspection proxies decrypt traffic legitimately and how malware does so illegitimately.
Versions matter. SSL 2/3, TLS 1.0 and 1.1 are deprecated and disabled in current browsers; TLS 1.2 is the floor and TLS 1.3 (RFC 8446, 2018) is the default. Statements about "what TLS does" in the rest of this module are made for 1.3 unless marked, with 1.2 differences called out, because the handshake shape, the set of cipher suites and the resumption mechanism all changed between them.
- Visible despite TLS: server IP, port, SNI hostname (unless ECH), sizes, timing, DNS queries (unless DoH/DoT).
- Not addressed by TLS at all: endpoint compromise, CA misissuance, application-level bugs (XSS, injection).
http://on a public network means every property in the table above is absent. HSTS tells the browser never to try.
Key points
- TCP guarantees delivery, not secrecy or identity; any hop on the path can read or rewrite a plaintext stream.
- Confidentiality (symmetric AEAD), integrity (authentication tag), authentication (certificate + signature) and key agreement (ephemeral ECDHE) each answer one specific attack.
- Asymmetric cryptography is used once per connection to agree a key; symmetric cryptography is used on every byte because it is orders of magnitude faster.
- TLS sits between TCP and the application protocol; HTTPS is unmodified HTTP inside a TLS session, and the same applies to SMTP, database and RPC protocols.
- TLS does not hide addresses, sizes, timing or (usually) the SNI hostname, and it does not help against a compromised endpoint or a misissued certificate.
- Version and cipher suite change the details; TLS 1.3 is the default and TLS 1.2 the floor.
Why does this exist?
Mechanisms are answers to constraints. Open each question before reading the answer.
▸Why not just encrypt at the IP layer for everything?
IPsec exists and does exactly that, but it is configured per host or per tunnel by administrators, not per connection by applications. TLS lets an application decide it needs protection and prove the identity of a specific service, which is what HTTPS needs: the browser must know it reached bank.example, not merely that the packets were encrypted to *some* peer.
▸Why does TLS need certificates when it already has encryption?
Key agreement over a public channel resists eavesdropping but not impersonation: an active attacker can run the agreement with both sides and hold two keys. Authentication ties the agreed key to a proven identity, and a certificate is the portable, verifiable form of "this public key belongs to this hostname".
▸Why use two kinds of cryptography instead of one?
Asymmetric operations cost tens to hundreds of microseconds each and would cap a server at a few thousand kilobytes per second; symmetric AEAD costs nanoseconds per byte. Using asymmetric crypto to agree a symmetric key gives the security of the former at the throughput of the latter.
▸Why is forward secrecy a separate property?
Without it, an attacker who records traffic today and steals the server’s long-term private key next year can decrypt everything recorded. Ephemeral per-connection keys that are discarded after the handshake make stolen long-term keys useless against old captures — which is why TLS 1.3 removed the non-ephemeral RSA key exchange entirely.
How it fails
What the failure looks like from inside real software.
- Plain
http://API calls from a mobile app: credentials and session tokens are readable by anyone on the same Wi-Fi; the fix is TLS plus certificate validation actually left enabled. - A client that "works" only because it disabled verification (
verify=False,NODE_TLS_REJECT_UNAUTHORIZED=0,-k): it is encrypted to whoever answers, which is precisely the man-in-the-middle case TLS exists to prevent. - STARTTLS downgrade: an SMTP client configured to "use TLS if offered" is silently kept in plaintext by an on-path attacker who strips the
STARTTLScapability. - Believing TLS hides which sites are visited: SNI and destination IP are visible to the network operator and to any middlebox doing SNI-based filtering.
- Terminating TLS at a load balancer and forwarding plaintext across a shared network segment because "it is internal" — the threat model reappears inside the data centre.