Sub topic 7
Securing the Connection with TLS
This chapter assumes you know what a TCP connection is (the previous chapter) and can read basic HTTP messages. After the TCP handshake, the browser has a reliable byte stream to the server. For an https:// URL, it now runs a TLS handshake over that stream before sending any HTTP data.
What TLS provides
TLS (Transport Layer Security) gives a connection three properties:
- Confidentiality: traffic is encrypted, so network observers cannot read it.
- Integrity: tampering with data in transit is detected.
- Authentication: the browser verifies it is talking to the real owner of the host name.
TLS does not hide the host name from everyone. The IP address is visible, and the name is usually visible in the handshake through SNI (Server Name Indication), unless Encrypted Client Hello is in use.
The handshake in TLS 1.3
TLS 1.3 needs one round trip before application data can flow. It uses asymmetric cryptography to agree on a shared secret, then switches to faster symmetric encryption for the data.
- ClientHello. The browser lists the TLS versions and cipher suites it supports, sends its half of a key exchange, and includes the host name in SNI. SNI lets one IP address host many sites.
- ServerHello. The server picks a cipher suite and sends its half of the key exchange. Both sides now compute the same session keys without ever sending them.
- Certificate. The server sends its certificate and proves it holds the matching private key by signing the handshake.
- Finished. Each side confirms the handshake was not altered. Encrypted HTTP traffic starts.
TLS 1.2 needs two round trips. A resumed session in TLS 1.3 can send data even sooner (0-RTT), with a replay risk that limits it to safe requests.
Verifying the certificate
A certificate binds a public key to a name. The browser checks that:
- The host name from the URL appears in the certificate's Subject Alternative Name list.
- The current date falls inside the validity period.
- The certificate chains up to a root certificate authority (CA) in the browser's or operating system's trust store. The server usually sends intermediate certificates too.
- The certificate has not been revoked, and where required, appears in Certificate Transparency logs.
If any check fails, the browser shows a full-page warning instead of loading the site.
Common errors
| Symptom | Likely cause |
|---|---|
| Name mismatch error | Certificate does not list the host name you typed, such as `example.com` versus `www.example.com` |
| Certificate expired | Renewal was missed |
| Untrusted authority | Self-signed certificate, or the server omitted an intermediate certificate |
| Protocol or cipher error | Client and server share no TLS version or cipher suite |
| Wrong clock warning | The client's clock is outside the validity period |
HSTS and the first request
If a site has sent a Strict-Transport-Security header, the browser remembers to use HTTPS for it, as covered in the cache and HSTS chapter. A first visit typed as http:// can still be intercepted before the redirect to HTTPS, so sites can also join the browser's preload list.
Observing TLS
You can see the handshake with curl. Look for the TLS lines, the protocol version, and the certificate details.
curl -v https://example.com/ -o /dev/null 2>&1 | grep -E "TLS|subject|issuer|expire"In the browser, the Security tab or the padlock menu shows the certificate, its issuer and its validity dates. The Network panel's timing breakdown has a separate "SSL" segment for this stage.
Exercise
A user types https://example.com and sees a name mismatch error, although the certificate is valid and unexpired. Which certificate check most likely failed, and why does TLS 1.3 handshake data sent after ServerHello stay encrypted?
Show answer
The host name check failed: example.com is not in the certificate's Subject Alternative Name list. After ServerHello both sides have derived the same session keys from the key exchange, so the rest of the handshake, including the certificate, and all later traffic is encrypted with those keys.