Topic 027 / Core
TLS and secure communication
Chapter 3.2 · TLS and HTTP
What and why
TCP (→ 25) delivers bytes reliably, but in the clear — anyone on the path can read or alter them. TLS wraps a connection to provide confidentiality (encryption), integrity (tamper detection), and server authentication (via a certificate signed by a trusted certificate authority). Builds on: → 25.
Diagram
ClientHello ──────────────────────────────►
◄────────── ServerHello + certificate
key exchange, both sides derive a shared session key
◄══════════ encrypted application data (HTTP, →28) ══════════►
How it works
- The client opens a connection (TCP, or UDP for QUIC/HTTP-3) and sends a ClientHello proposing protocol and cipher options.
- The server responds with its choice and presents its certificate.
- The client validates the certificate against a trusted certificate-authority chain and checks it matches the hostname being connected to.
- Both sides use a key-exchange step to derive a shared symmetric session key — cheap to use per byte, unlike the asymmetric cryptography used to set it up.
- All further bytes on the connection are encrypted and integrity-checked with that session key.
- A later reconnect to the same server can resume a previous session, skipping the full handshake.
Practical example
(illustrative). The handshake above adds a small, fixed number of round trips before the first byte of actual HTTP data can be sent; a resumed session skips most of that, which is why a second connection to a site you just visited feels faster to establish than the first.
When to use it
- Use when: always, for any traffic crossing a network you don't fully control — which in practice means essentially all internet traffic, and increasingly internal traffic too.
- Avoid when: there is no legitimate case to skip it for traffic leaving a process boundary; the real decision is where to terminate it (→ 29), not whether to use it.
- Failure scenarios: an expired or hostname-mismatched certificate breaks every client at once; clock skew on either side can invalidate an otherwise-correct certificate; a network path that strips TLS down to plaintext if it isn't strictly enforced end to end.
- Simpler alternative: none for anything that matters. Terminating TLS at one shared edge (→ 29) to avoid managing certificates on every backend is an operational simplification, never a reason to skip TLS itself.
Practice
(mechanism kind — trace/predict-then-verify; 15–20 min, no lab services).
Run curl -v against a real HTTPS site. In the output, find where the handshake ends and
encrypted application data begins, and read which certificate authority signed the
presented certificate. Predict first what you expect to see, then verify against the
actual output. Done when prediction and observed handshake agree, or you can explain the
difference.
Key takeaway
TLS turns a plain, readable connection into a confidential,
tamper-evident, server-authenticated one, at the cost of a handshake before the first byte.
Done when you can: point to the exact line in a curl -v trace where the connection
becomes encrypted. Used next in → 28.
References
None — this topic makes no external claims; TLS mechanics are kept at the
conceptual level since no TLS specification is listed in references.md.