Networking Fundamentals

Ch.36: TLS, an Overview

By Ayush Arora••6 min read

Inspired by: YouTube

Every chapter so far has assumed the network is just slow or lossy. It also isn't private: anything sent as plain TCP or UDP payload can be read, and tampered with, by anyone sitting on the path between client and server. TLS (Transport Layer Security) is the layer that fixes that. This chapter is the overview: what problems TLS solves and the two encryption techniques it's built from. The handshake itself, and protocols like RSA and Diffie-Hellman, get their own chapters later.


What TLS is for

TLS sits between the application layer and the transport layer, roughly OSI layer 6 (presentation), wrapping whatever the application sends before it hits TCP or UDP. It has three goals:

HTTPS is just this applied to HTTP: HTTPS = HTTP + TLS. Plain HTTP is a valid protocol on its own, it just sends everything as plaintext, so anyone on the path reads it as easily as the destination does. Add a TLS layer underneath and the same HTTP request/response gets encrypted before it goes on the wire.


Two kinds of encryption, two different jobs

TLS doesn't use one encryption technique, it uses two, for two different problems.

Symmetric encryption: fast, but you need the key first

In symmetric encryption, the client and server both hold the same secret key. The client encrypts plaintext with that key, sends the ciphertext, and the server decrypts it with the same key. An attacker who intercepts the ciphertext can't make sense of it without the key.

Symmetric algorithms use comparatively simple operations (XOR-style bit manipulation is the canonical example), which makes them cheap to compute and fast to run. That's the appeal.

The catch: both sides need the same key before any of this works, and the only channel available to share it is the same untrusted network the attacker is watching. Send the secret key in the clear and the attacker just captures it along with everything else, at which point the encryption is worthless. Securely getting a shared secret onto both sides without ever exposing it in transit is the actual hard problem, and symmetric encryption alone can't solve it.

ClientServerPlain textRs 10,000Encryptedavd5267Send over networkEncryptedavd5267Plain textRs 10,000

Both sides hold the same secret key, so whichever side encrypts, the other can decrypt.

Asymmetric encryption: solves the key-sharing problem, at a cost

Asymmetric encryption uses two different keys: a public key and a private key. Data encrypted with one key can only be decrypted with the other. In TLS's use of it, the server generates a public/private key pair and sends the public key to the client (how, in detail, is a later chapter). The client uses that public key to encrypt data; only the server's private key can decrypt it. The public key is, by design, useless for decryption, so it doesn't matter that it traveled over the open network in plain view.

That property is exactly what solves the symmetric-key problem: the client can now encrypt a freshly generated symmetric key with the server's public key and send it over, and only the server's private key can recover it. An eavesdropper sees the encrypted key pass by and can't do anything with it.

The tradeoff is cost. Asymmetric algorithms (RSA and Diffie-Hellman are the two named here, each gets its own chapter) are computationally heavier than symmetric ones. So TLS doesn't use asymmetric encryption for the whole conversation, it uses it once, briefly, to get a symmetric key safely onto both sides. After that, everything switches to the cheap symmetric algorithm.

Server Public KeyServer Private KeyClientServerAnyone can have thisPlain textRs 10,000Encrypted73viuwSend over networkEncrypted73viuwPlain textRs 10,000

The client encrypts with the server's public key; only the server's private key can decrypt it, no one else.


How they combine: the TLS handshake, at a glance

Putting the two together: a TCP connection is opened first, and only after that does the TLS handshake run on top of it. The handshake uses asymmetric encryption to let the client and server agree on a shared symmetric key without ever exposing that key on the wire. Once the handshake completes, both sides hold the same symmetric key and switch to symmetric encryption for the actual application data, HTTP requests and responses included.

TCP handshake        (open the connection)
TLS handshake         (asymmetric encryption -> agree on a shared symmetric key)
Application data      (symmetric encryption, using that shared key)

The full mechanics of that handshake, exactly which messages carry what, are the subject of the next TLS chapter.


Where TLS lives in HTTP/2 vs HTTP/3

This connects back to QUIC: under HTTP/1.1 and HTTP/2, TLS is a separate layer bolted onto TCP, TCP carries the bytes, TLS encrypts them, and the two together produce HTTPS. QUIC, underneath HTTP/3, was designed after encryption became a baseline expectation, so it builds TLS 1.3 directly into the protocol instead of requiring it as an add-on. Either way, the same handshake ideas from this chapter, symmetric encryption for speed, asymmetric encryption to bootstrap the shared key, are what's running.


Summary