On-ramp · Lesson 07
TLS proves you reached a name, not that the name is honest
The agent connects to https://crm.acme.example. The padlock is there; the call is encrypted. Another host, crm-acme.example.net, has an equally valid certificate. TLS did its job in both cases. It told the client the server holds a key a certificate authority vouched for under that name.
What the handshake gives
TLS (RFC 8446, 2018) puts three properties on a TCP connection:
- Confidentiality: a network observer sees addresses and sizes, not the bytes.
- Integrity: bytes cannot be changed in flight undetected.
- Server authentication: the server proves it holds the private key for a certificate naming it, and that certificate chains to a root the client trusts (RFC 5280, 2008).
The client checks that the name it meant to reach is in the certificate (RFC 9525, 2023). Here it is on a local socket, with a certificate for crm.acme.example and a client that trusts only that certificate.
Make a throwaway certificate, then save t.py beside it:
openssl req -x509 -newkey rsa:2048 -nodes -keyout k.pem -out c.pem -days 1 \
-subj "/CN=crm.acme.example" -addext "subjectAltName=DNS:crm.acme.example"
import socket, ssl, threading
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ctx.load_cert_chain("c.pem", "k.pem")
srv = socket.socket(); srv.bind(("127.0.0.1", 8443)); srv.listen()
def serve():
while True:
conn, _ = srv.accept()
try:
ctx.wrap_socket(conn, server_side=True).sendall(b"hello")
except Exception:
pass
threading.Thread(target=serve, daemon=True).start()
client = ssl.create_default_context(cafile="c.pem") # trusts only this certificate
for name in ("crm.acme.example", "cal.acme.example"):
try:
with socket.create_connection(("127.0.0.1", 8443)) as raw, \
client.wrap_socket(raw, server_hostname=name) as s:
print(name, "->", s.version(), s.recv(5))
except ssl.SSLCertVerificationError as e:
print(name, "->", e.verify_message)
It prints:
crm.acme.example -> TLSv1.3 b'hello'
cal.acme.example -> Hostname mismatch, certificate is not valid for 'cal.acme.example'.
The same server, the same address, the same bytes: the verdict turns on the name the client asked for. A client that connects by IP address, or turns off hostname checking (verify=False, -k), has encrypted a conversation with nobody in particular.
What it does not give
| Looks like TLS means | It actually means |
|---|---|
| "the server is trustworthy" | a CA vouched that the key holder controls the name |
| "the content is safe" | nothing about the content: a prompt injection arrives encrypted and intact |
| "the client is who it says" | by default, nothing: only the server proved itself (mutual TLS adds the client: the server requests a certificate, RFC 8446, section 4.3.2) |
| "nobody sees the traffic" | the endpoints and any proxy that terminates the connection see it |
A gateway that terminates TLS and re-encrypts to the upstream is a man in the middle by design: it holds a certificate its clients trust, so it can read every byte. That is what lets it inspect a tool call, and also why the keys of that gateway are among the most valuable in the deployment.
SNI: the name travels before the encryption
The client's first message carries the server name indication (RFC 6066) so one address can serve many certificates. It is in clear text in the classic handshake, which is how a network control can allow crm.acme.example and block another name without breaking encryption, and how a client can lie in it while sending a different Host header inside. A gateway that routes on SNI and decides on Host has a parser differential of lesson 1's kind, between two layers.
Expert: pinning and the cost of a check
A client can pin the key or certificate it expects, so a mis-issued certificate from a trusted CA fails. Pinning moves risk to rotation: a pinned key that is replaced without warning takes every client down. Revocation checks (CRLs, RFC 5280; OCSP) fail soft in many clients, because failing hard turns an unreachable CA into an outage for every site that uses it. Short-lived certificates reduce the problem to waiting for expiry.
Check yourself
- An agent's HTTP library has
verify=False"for the lab". Which of the three properties does that remove, and is the traffic still encrypted? - A prompt injection reaches the model over a TLS-protected page fetch. Which of the three properties held for the injected text, and which component from lessons 6 and 7 is placed to inspect it?
- Your gateway terminates TLS. What must be true of how it reaches the CRM for "the CRM's log shows the gateway" to be a property you can rely on?
Answers
- Server authentication: no chain check and no name check. The traffic is still encrypted and integrity-protected, but with whoever answered, so anyone on the path can terminate it, read and change everything, and re-encrypt: "a conversation with nobody in particular".
- All three: the text arrived confidential, unaltered and from the server the client named. TLS says nothing about content. The component placed to inspect it is a proxy that terminates TLS, such as the gateway acting as a reverse proxy (lesson 6), a man in the middle by design that reads the plaintext.
- The gateway-to-CRM connection must authenticate the gateway, and be the only way in. By default TLS proves only the server, so the CRM needs mutual TLS with the gateway's client certificate (RFC 8446, section 4.3.2) or a network on which nothing else can reach it; and the gateway must verify the CRM's certificate in turn. Otherwise "the gateway" in the log is just whoever connected.