Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 1 of 6 · Concept · 15 min · revision 2

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

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.

  1. 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 in server_name (this is SNI, Server Name Indication), the application protocols it can speak in ALPN (Application-Layer Protocol Negotiation, for example h2 and http/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.
  2. 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.
  3. 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.
  4. 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.

Terminal · create the folder, a lab certificate and a test server
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
Python · tls-hello/hello_client.py
"""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)
Terminal
python hello_client.py
Expected output
library : 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.

Terminal · same server, a name the certificate does not list
python hello_client.py hello.example.com
Expected output
refused : 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.

Terminal
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.example even though the path /orders/1234 is 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.com to whoever controls that domain. The padlock then shows that you reached examp1e-shop.com securely, 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

Practice check · 3 questions

What TLS 1.3 does and does not give you

Choose the best answer for each scenario.

Q1. You recorded a year of TLS 1.3 traffic to a server that only used ECDHE key exchange. Today its certificate's private key is stolen. What can the thief now do?
Q2. A client offers key shares for X25519MLKEM768 and x25519. The ServerHello answers with an x25519 key share. What does that mean for the session?
Q3. Users land on `examp1e-shop.com`, a phishing copy of `example-shop.com`, and their browser shows a valid padlock. What does that padlock actually confirm?
Practice only: not graded, not saved, not evidence.

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

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

10 questions · about 8 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check