Sub topic 9
HTTPS and TLS
This chapter assumes you can read an HTTP request and response, and that you know a TCP connection carries those messages. HTTPS is HTTP sent through a TLS-protected channel on top of that connection.
What TLS protects
Plain HTTP travels as readable text. Anyone on the path, such as a shared Wi-Fi router or an ISP, can read it or change it. TLS (Transport Layer Security) gives a connection three properties:
- Confidentiality: the traffic is encrypted, so observers see only scrambled bytes.
- Integrity: any change to the data in transit is detected.
- Authentication: the client checks that it is talking to the real server for the host name, not an impostor.
TLS does not hide which host you connect to, because DNS lookups and the server name in the handshake can still be visible. It also does not make a site trustworthy. It only proves you reached the server that holds a valid certificate for that name.
Where TLS fits
HTTP messages are unchanged under HTTPS. The browser opens a TCP connection, runs the TLS handshake, and then sends ordinary HTTP inside the encrypted channel. The default port is 443, not 80.
The handshake in steps
- The client sends a ClientHello listing the TLS versions and cipher suites it supports. It also includes the host name it wants (Server Name Indication), so one IP address can serve many sites.
- The server picks a version and cipher suite and sends its certificate.
- The client verifies the certificate (see below).
- Both sides use a key exchange to agree on a shared secret that an eavesdropper cannot compute. They derive session keys from it.
- Each side sends a Finished message. From then on, data is encrypted with fast symmetric keys.
TLS 1.3 completes this in one round trip. TLS 1.2 needs two.
Certificates and trust
A certificate binds a public key to a host name. A certificate authority (CA) signs it. Your browser or operating system ships with a list of trusted CA root certificates. The server usually sends an intermediate certificate too, which links its own certificate to a trusted root.
The browser checks that:
- the signature chain leads to a trusted root,
- the current date is inside the validity period,
- the host name in the URL matches a name in the certificate,
- the certificate has not been revoked.
If any check fails, the browser shows a warning and stops the connection.
Inspecting it with curl
curl -v https://example.com/The verbose output shows the negotiated TLS version, the cipher suite, the certificate subject and issuer, and the line SSL certificate verify ok. Then the normal HTTP request and response follow.
Common errors
| Symptom | Likely cause |
|---|---|
| Certificate expired | The certificate was not renewed before its end date. |
| Name mismatch | The certificate does not list the host name you requested. |
| Unknown issuer | The server did not send its intermediate certificate, or the CA is not trusted. |
| Mixed content blocked | An HTTPS page tried to load a script or image over plain HTTP. |
Exercise
A page at https://shop.example loads a script from http://cdn.example/app.js. What happens, and why does the browser behave this way?
Show answer
The browser blocks the script as mixed content. An attacker could alter the unencrypted script in transit, and that script would run with full access to the secure page. This would defeat the integrity and confidentiality that TLS gives the rest of the page.