What TLS gives you: confidentiality, integrity and authentication
What a TLS 1.3 connection protects and what it leaves exposed: the one-round-trip handshake with key shares, forward secrecy, Certificate, CertificateVerify and Finished, hybrid post-quantum key exchange, and a small client that prints what a real handshake agreed.
Contentsand lesson path
On this page
- Why it matters
- Three properties, and one optional extra
- The handshake in one round trip
- See what a handshake agreed
- What TLS does not protect
- Check your understanding
- Apply it
- Review prompt
Lessons of TLS & PKI
- What TLS gives you: confidentiality, integrity and authentication Concept · 15 min
- Lab: the TLS 1.3 handshake on the wire, with SNI, ALPN and HTTP/2 vs HTTP/3 Lab · 25 min
- Certificates and chains: how a client decides to trust a server Concept · 20 min
- Lab: a two-tier private CA (offline root, issuing CA), server and client certificates, and mutual TLS Lab · 30 min
- Operating PKI: ACME automation as lifetimes shrink, revocation availability and CA compromise plans Worked example · 25 min
- Check: debug five broken TLS endpoints with openssl s_client Knowledge check · 10 questions
What you will learn
- Explain the TLS 1.3 handshake - key exchange, server authentication, SNI and ALPN - and what TLS does and does not protect.
01. Why it matters
Almost every connection you build or operate runs over TLS (Transport Layer Security): HTTPS, calls between services, database drivers and mail relays. Teams that think "it is encrypted, so it is safe" make two kinds of mistakes. They trust TLS for things it never covered, such as hiding which site a user visits. Or they switch off the part that does the real work, certificate checking, to make an error go away.
This lesson explains the three properties TLS 1.3 gives you, the handshake that produces them, and what it leaves open. You will also run a small Python client against a local server and read what the two sides agreed.
02. Three properties, and one optional extra
TLS 1.3 is defined in RFC 8446. Once the handshake is finished, it gives a connection three properties.
- Confidentiality. Application data is encrypted with keys that only the two endpoints know. A café Wi-Fi router or an internet provider on the path sees ciphertext.
- Integrity. Every record carries an authentication tag. TLS 1.3 only uses AEAD ciphers (authenticated encryption with associated data, for example AES-GCM or ChaCha20-Poly1305), so encryption and tamper detection happen in one step. If an attacker changes, drops or reorders a record, the tag check fails and the connection is closed with an alert.
- Server authentication. The client checks that the server holds the private key for a certificate that a trusted certificate authority (CA) issued for the name the client asked for. Without it, you could have an encrypted conversation with an attacker.
Client authentication is the optional extra. The server can send a CertificateRequest, and the client then proves its own identity with a certificate. This is called mutual TLS (mTLS) and is common between internal services. You will build it in lesson 4.
Server authentication proves that the peer controls a key for a name, not that the name is the one the user meant.
03. The handshake in one round trip
A TLS 1.3 handshake normally needs one round trip before the client can send its request. Here is what each message does, in the order they travel.
- ClientHello (client to server, in clear). The client lists the TLS versions it supports in
supported_versions, the cipher suites, the server name it wants inserver_name(this is SNI, Server Name Indication), the application protocols it can speak in ALPN (Application-Layer Protocol Negotiation, for exampleh2andhttp/1.1), and one or more key shares. A key share is the public half of a fresh, temporary key pair, for example on the curve X25519. - ServerHello (server to client, in clear). The server picks the version and cipher suite and sends its own key share for one of the groups the client offered. Both sides now combine their own private half with the other side's public half. This is ECDHE (elliptic-curve Diffie-Hellman, ephemeral), and both arrive at the same shared secret without ever sending it. If the server supports none of the offered key shares but another group the client listed, it sends a HelloRetryRequest and the client tries again, at the cost of a round trip.
- EncryptedExtensions, Certificate, CertificateVerify, Finished (server to client, already encrypted with keys derived from the shared secret). EncryptedExtensions carries answers that need not be in clear, such as the chosen ALPN protocol. Certificate carries the certificate chain. CertificateVerify is a signature, made with the certificate's private key, over a hash of every handshake message so far. A certificate is public, so anyone can replay it; only the real key holder can produce this signature. Finished is a MAC (a keyed checksum) over the whole handshake, which shows that both sides saw the same messages and derived the same keys.
- Finished (client to server). The client checks the certificate chain and the name, checks the signature, sends its own Finished, and can send application data straight after.
Forward secrecy comes from the word ephemeral. The key pairs behind the key shares are created for one handshake and then thrown away. The certificate key only signs; it never encrypts the session keys. So if someone records your traffic today and steals the certificate key next year, the key does not decrypt the recording. It does let the thief impersonate the server to new clients until the certificate expires or is revoked. TLS 1.2 with "RSA key transport" lacked this property; TLS 1.3 removed that mode.
One caveat concerns the future. A large enough quantum computer could break X25519, so an attacker could decrypt traffic recorded years earlier ("harvest now, decrypt later"). The response is hybrid key exchange. The group X25519MLKEM768 combines X25519 with ML-KEM-768, a post-quantum key encapsulation mechanism standardised by NIST in FIPS 203. The session stays safe as long as either part holds. It was published as RFC 10024 in August 2026. Its key shares are much larger (1,216 bytes from the client instead of 32), and OpenSSL 3.5 and current browsers already offer it by default. It protects confidentiality only: most certificates in 2026 still carry classical ECDSA or RSA signatures. In the lab you will see a client that offers the hybrid group fall back to plain X25519 when the server is older.
04. See what a handshake agreed
You need openssl 3.x (outputs here come from OpenSSL 3.0.2 on Ubuntu 22.04) and uv, whose own build of Python 3.12 has OpenSSL 3.5, so the client output matches even with an older system OpenSSL (--managed-python tells uv to use that build). First create a self-signed lab certificate for the name hello.lab.test and start a test server on port 8440 that offers ALPN h2 and http/1.1.
mkdir tls-hello && cd tls-hello
uv venv --managed-python --python 3.12 .venv && source .venv/bin/activate
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes \
-keyout key.pem -out cert.pem -days 30 -subj "/CN=hello.lab.test" \
-addext "subjectAltName=DNS:hello.lab.test,IP:127.0.0.1" \
-addext "basicConstraints=critical,CA:FALSE" \
-addext "keyUsage=critical,digitalSignature" \
-addext "extendedKeyUsage=serverAuth" 2>/dev/null
openssl s_server -accept 127.0.0.1:8440 -cert cert.pem -key key.pem \
-alpn h2,http/1.1 -www -quiet > server.log 2>&1 &
SERVER_PID=$!
sleep 1"""Connect to a TLS server and print what the handshake agreed."""
import socket
import ssl
import sys
host = sys.argv[1] if len(sys.argv) > 1 else "hello.lab.test"
ctx = ssl.create_default_context(cafile="cert.pem") # trust only the lab cert
ctx.minimum_version = ssl.TLSVersion.TLSv1_3
ctx.set_alpn_protocols(["h2", "http/1.1"])
try:
with socket.create_connection(("127.0.0.1", 8440), timeout=5) as raw:
# server_hostname is sent as SNI and is the name the cert must match
with ctx.wrap_socket(raw, server_hostname=host) as tls:
cert = tls.getpeercert()
print("library :", ssl.OPENSSL_VERSION)
print("version :", tls.version())
print("cipher :", tls.cipher()[0])
print("alpn :", tls.selected_alpn_protocol())
print("subject :", dict(x[0] for x in cert["subject"]))
print("SAN :", cert["subjectAltName"])
except ssl.SSLCertVerificationError as err:
print("refused :", err.verify_message)python hello_client.pylibrary : OpenSSL 3.5.7 9 Jun 2026
version : TLSv1.3
cipher : TLS_AES_256_GCM_SHA384
alpn : h2
subject : {'commonName': 'hello.lab.test'}
SAN : (('DNS', 'hello.lab.test'), ('IP Address', '127.0.0.1'))Each line maps to a handshake decision. TLSv1.3 came from supported_versions. The TLS 1.3 cipher suite names only the AEAD cipher and the hash, because key exchange and signature are negotiated separately. h2 is the server's ALPN choice from the client's list. The subject and SAN (subject alternative name) come from the certificate the client verified. Now ask for a name the certificate does not cover.
python hello_client.py hello.example.comrefused : Hostname mismatch, certificate is not valid for 'hello.example.com'.The server was the same and the encryption would have worked, but the client refused to continue, because it could not confirm it was talking to hello.example.com. This refusal is server authentication doing its job. Stop the server when you are done.
kill $SERVER_PID; cd ..05. What TLS does not protect
TLS protects bytes in transit between two endpoints. Several things fall outside that.
- Metadata. IP addresses and ports sit in the IP and TCP headers, outside TLS. RFC 8446 also says that TLS does not hide the length of the data, so an observer still sees when you talk, how much and how often. Sizes and timing can sometimes reveal which page was loaded.
- The server name. SNI travels in the ClientHello in clear, so the network sees
shop.exampleeven though the path/orders/1234is encrypted. Encrypted Client Hello (ECH, RFC 9849, March 2026) encrypts the real ClientHello with a public key that the server publishes in a DNS HTTPS record. It only helps when server, client and DNS all support it, and an IP address that is not shared with other sites still gives the site away. - The endpoints themselves. If the server is compromised, or malware runs on the laptop, the attacker reads data before encryption or after decryption. TLS ends at the process that holds the keys, so a load balancer that terminates TLS sees everything in clear.
- Data at rest. Logs, backups and database files are not covered. They need their own encryption and access control.
- Lookalike names. A CA will correctly issue a certificate for
examp1e-shop.comto whoever controls that domain. The padlock then shows that you reachedexamp1e-shop.comsecurely, not that it belongs to the shop you meant. - Weak client code. A client that skips certificate or name checks keeps the encryption but loses authentication, so an attacker in the middle can present any certificate.
For any data flow, ask who can see it on the wire, who can see it at each endpoint, and where it is stored. TLS answers only the first question, and only partly.
06. Check your understanding
07. Apply it
The practice project ends with a mutual-TLS service and a decrypted session in Wireshark. Prepare now: pick one service you run or use and write a three-line data-flow note. On the wire: what TLS hides and what metadata stays visible (IPs, SNI, sizes). At each endpoint: where TLS ends, for example on a load balancer, and who can read the data there. At rest: which logs or stores keep the data. In lesson 4 you will add which side authenticates which.
08. Review prompt
Without looking back, draw the TLS 1.3 handshake as two columns. Mark which messages travel in clear and which are encrypted, and say in one sentence what Certificate, CertificateVerify and Finished each prove. Then explain why a stolen certificate key does not decrypt last year's recordings, what hybrid key exchange adds, and name four things an observer can still learn about a TLS connection.
References
- RFC 8446: The Transport Layer Security (TLS) Protocol Version 1.3
- RFC 9325: Recommendations for Secure Use of TLS and DTLS (BCP 195)
- RFC 10024: Post-Quantum Traditional Hybrid Key Agreement Mechanisms for TLS 1.3
- RFC 9849: TLS Encrypted Client Hello
- RFC 6066: TLS Extensions, section 3: Server Name Indication
- Python documentation: ssl, TLS/SSL wrapper for socket objects
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
10 questions · about 8 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.