Computing Foundations › How the Internet Works › Day 19

Day 19: HTTPS and TLS: Encryption on the Wire

Day 19 of 365 — HTTPS and TLS: Encryption on the Wire

After this lesson you will be able to explain how HTTPS secures a web connection — the handshake, the mix of symmetric and public-key encryption, and the certificate chain of trust — and use openssl and curl to inspect any site's certificate and diagnose common TLS errors.

Course
Computing Foundations
Category
How the Internet Works
Reading time
≈ 40 min
Practical time
≈ 30 min
Lesson duration
1h 10m
Last verified
2026-07-12

Hands-on lab for this lesson

Lab files on GitHub: https://github.com/ai-roadmap-365/ai-roadmap-365.github.io/tree/main/labs/sections/computing-foundations/day-019-https-and-tls-encryption-on-the

  1. Get the hands-on files. Clone the labs repository once (you can reuse this clone for every lesson). This works on macOS, Linux, and Windows (PowerShell or WSL):
    git clone https://github.com/ai-roadmap-365/ai-roadmap-365.github.io.git
    cd ai-roadmap-365.github.io
  2. Open this lesson's lab. Move into the directory for this specific day. Every lab lives at the same predictable path — section / subsection / week / day:
    cd labs/sections/computing-foundations/day-019-https-and-tls-encryption-on-the
  3. Read the lab guide. Open `README.md` in that directory. It lists the exact commands, what each does, the expected output, and how to check your work — read it before running anything.
  4. Run it and check your work. Follow the README's "How to run" section: run the example first to see the finished result, then complete the numbered exercises in `starter/`, then run the tests. The tests pass (exit 0) only when your work is correct.
    bash tests/run_tests.sh   # or the test command named in the lab README

You can also open the lab as a local page (works offline, shows the file tree and expected output).

Learning objectives

By the end of this lesson you will be able to:

Prerequisites

Why this matters


The idea in plain language

Diagram: encryption without authentication compared with both together


Historical background

Diagram: TLS 1.2 compared with TLS 1.3


What it is — and what it is not

Diagram: what a valid certificate proves and what it does not

TLS is:

TLS is not:


Why it was created and what problems it solves


How it works

Two kinds of encryption, and why both

Diagram: symmetric encryption compared with public-key cryptography

The handshake

Diagram: the TLS handshake from ClientHello to an encrypted session

  1. ClientHello. “Here are the TLS versions and cipher suites I support, and some random data.” A cipher suite is a named bundle: key agreement, bulk encryption, integrity.

  2. ServerHello and certificate. The server picks a version and suite both support, adds its own random data, and sends its certificate — domain name, public key, expiry date, and the issuing authority’s signature.

  3. Verify the certificate. Signed by a trusted authority? Still within its dates? Does the name match the site you asked for?

  4. Key agreement. Both sides independently derive the same fresh secret, without it ever crossing the wire usably. Only the holder of the private key can complete this — which ties the encryption to the verified identity.

  5. Encrypted session. The slow work is over; every request and response from here uses the fast symmetric key.

The chain of trust

Diagram: the chain of trust from root CA through intermediate to site certificate

HSTS: refusing to fall back


An everyday analogy

Diagram: how an intercepting proxy breaks and remakes a TLS connection

Meeting a stranger who claims to be your bank manager.

The meetingTLS
”Prove who you are”Certificate verification
A passportThe certificate
The government that issued itThe certificate authority
Your belief that the government is realThe trust store
Agreeing a private phrase for laterKey agreement
The rest of the conversation, in that codeSymmetric encryption

Examples in practice

Diagram: the four checks a certificate must pass


Implications: security, privacy, performance, scalability, and cost

Diagram: what is lost when certificate verification is disabled


Alternatives: free, open source, and commercial

Diagram: automated certificate renewal compared with manual renewal

ToolTypeWhat it gives you
Let’s Encrypt + certbotFree, open sourceAutomatic issuance and renewal
CaddyFree, open sourceA web server that obtains and renews certificates itself
openssl s_clientFree, built inThe raw handshake and the whole chain
curl -vFree, built inWhich check failed, in readable English
SSL Labs testFreeA graded report on a public server’s configuration
Commercial CAsPaidOrganisation validation, warranties, support

TermWhat it actually is
SSLTLS’s predecessor; the name survives, the protocol does not
TLSThe protocol that authenticates and encrypts the connection
HTTPSHTTP carried inside TLS
CertificateA signed statement binding a public key to a domain name
CAThe organisation that verifies control and signs
Trust storeThe root certificates your system believes by default
Forward secrecyPast sessions stay safe even if the private key later leaks

When to use it — and when not to

Diagram: how HSTS removes the unprotected first request


The AI connection

Diagram: how certificate transparency logs expose unauthorised certificates


Knowledge check

quiz:
  question: "A site loads fine in your browser but `curl` reports it cannot get the local issuer certificate. What is the most likely cause?"
  options:
    - "The server is not sending its intermediate certificate, and the browser has one cached while curl does not"
    - "The site's certificate has expired and the browser is ignoring the expiry"
    - "The certificate was issued for a different hostname than the one requested"
    - "curl does not support the TLS version the server negotiated"
  answer_index: 0
  explanation: "A server should send its leaf and the intermediate that signed it. Browsers often hold intermediates from previous visits and quietly fill the gap; curl builds the chain only from what it is sent, so an incomplete chain fails there and nowhere else."

Hands-on exercise

Inspect a real certificate, read its chain, and break verification on purpose. Worked through fully in the Day 19 lab directory.

What you are doingCommand
See the whole handshake and chainopenssl s_client -connect example.com:443 -servername example.com
Read the certificate’s fields... | openssl x509 -noout -text
Just the dates... | openssl x509 -noout -dates
Which check failedcurl -v https://expired.badssl.com
Skip verification, and see why not tocurl -k https://self-signed.badssl.com
Check a chain is completecurl -v https://incomplete-chain.badssl.com

Expected output

depth=2 O = Root CA
depth=1 O = Intermediate CA
depth=0 CN = example.com
notBefore=Jun  1 00:00:00 2026 GMT
notAfter=Aug 30 23:59:59 2026 GMT
curl: (60) SSL certificate problem: certificate has expired

Validate your work

Troubleshooting

Common mistakes


Practice assignment


Extension challenge


Quiz

Q1. What are the three protections that TLS provides to an HTTP connection?

  1. Compression, caching, and load balancing
  2. Speed, redundancy, and anonymity
  3. Confidentiality, integrity, and authentication
  4. Encryption, compression, and error correction
Show answer

Answer: C. Confidentiality, integrity, and authentication

TLS provides confidentiality (nobody in the middle can read the data), integrity (nobody can alter it undetected), and authentication (you can be confident the server is genuine). All three are needed together — encryption to an impostor is worthless.

Q2. Why does TLS use public-key cryptography for the handshake but symmetric encryption for the rest of the connection?

  1. Public-key encryption is illegal for bulk data in most countries
  2. Symmetric encryption cannot protect data at all, so it is only used as a backup
  3. Symmetric encryption is more secure than public-key encryption for the handshake
  4. Public-key math sets up a shared secret; symmetric is fast for bulk
Show answer

Answer: D. Public-key math sets up a shared secret; symmetric is fast for bulk

Public-key cryptography solves the problem of two strangers agreeing on a secret over a watched wire, but it is slow. So TLS uses it briefly to bootstrap a shared symmetric key, then switches to fast symmetric encryption for the actual traffic — the best of both.

Q3. What does a Certificate Authority (CA) actually vouch for when it issues a certificate?

  1. That the holder controls the domain named in the certificate
  2. That the website is honest and safe to give your data to
  3. That the website will never be hacked
  4. That the website loads quickly and is well designed
Show answer

Answer: A. That the holder controls the domain named in the certificate

A CA verifies that whoever requested the certificate controls the domain, then signs a certificate binding that domain to a public key. It certifies identity (control of the domain), not the honesty, safety, or quality of the site.

Q4. A browser receives a site (leaf) certificate. How does it decide whether to trust it?

  1. It contacts the website owner by email to confirm
  2. Leaf against intermediate, intermediate against root, root in the store
  3. It trusts any certificate that is not expired, regardless of who signed it
  4. It asks the user to approve every certificate manually
Show answer

Answer: B. Leaf against intermediate, intermediate against root, root in the store

The browser follows the chain of trust upward: each certificate must be validly signed by the one above it, ending at a root CA whose public key is already in the browser or OS trust store. If any link fails, the connection is rejected.

Q5. Which statement about the padlock icon in the address bar is correct?

  1. It guarantees the website is trustworthy and safe to share data with
  2. It means the website cannot be hacked
  3. The connection is encrypted and the domain verified, nothing more
  4. It appears only on websites owned by large companies
Show answer

Answer: C. The connection is encrypted and the domain verified, nothing more

The padlock confirms the connection is encrypted and the certificate for that domain checked out. It says nothing about whether the site is honest or handles your data well — even a scam site can obtain a valid certificate for its own domain.

Q6. What is the purpose of HSTS (HTTP Strict Transport Security)?

  1. It compresses HTTPS traffic to make pages load faster
  2. It lets a site work without any certificate
  3. It replaces certificates with passwords
  4. It tells the browser to use HTTPS only, always
Show answer

Answer: D. It tells the browser to use HTTPS only, always

HSTS is a header a site sends telling the browser to use only HTTPS for that site in future and not to allow clicking through certificate warnings, which prevents an attacker from hijacking an initial unprotected HTTP request.

Q7. What is the relationship between SSL and TLS?

  1. TLS is the modern standard; SSL is its obsolete predecessor
  2. SSL is the modern, secure version and TLS is obsolete
  3. They are competing protocols made by different companies today
  4. They are completely unrelated technologies
Show answer

Answer: A. TLS is the modern standard; SSL is its obsolete predecessor

TLS is the standardized successor to Netscape's SSL. The actual SSL versions are obsolete and insecure, but the name persists in casual usage; when people say "SSL certificate" they almost always mean TLS.

Q8. A service that worked yesterday now shows a certificate error to every visitor, though the code did not change. What is the most likely cause?

  1. The website's content was rewritten
  2. The certificate expired and was not renewed
  3. The visitors all changed browsers at once
  4. HTTP was upgraded to HTTPS overnight
Show answer

Answer: B. The certificate expired and was not renewed

Certificates are valid only within a not-before / not-after window. A very common outage is a certificate quietly expiring because renewal was not automated, which makes every browser reject the connection until it is renewed.

Glossary

HTTPS
HTTP carried inside a TLS-encrypted connection (conventionally on port 443), giving web traffic confidentiality, integrity, and server authentication.
TLS
Transport Layer Security, the protocol that wraps a network connection in encryption and authentication; the modern successor to SSL.
encryption
Scrambling data with a key so that only someone with the right key can turn it back into readable form.
symmetric key
A single shared secret key used to both encrypt and decrypt messages; fast, but both sides must already share the same key.
public-key cryptography
Encryption using a matched public/private key pair so two strangers can establish a secret without pre-sharing one; also called asymmetric encryption, and slower than symmetric.
certificate
A signed digital document that binds a domain name to a public key and carries an expiry date, presented by a server to prove its identity.
Certificate Authority
A trusted organization (CA) that verifies control of a domain and signs certificates for it; browsers ship with a list of trusted CA roots.
chain of trust
The sequence of signatures from a site certificate up through one or more intermediate CAs to a root the browser already trusts; if any link fails, the certificate is rejected.
handshake
The opening exchange of a TLS connection that authenticates the server and agrees a shared symmetric key, after which data is encrypted symmetrically.
HSTS
HTTP Strict Transport Security, a header telling a browser to contact a site only over HTTPS and never allow clicking through its certificate warnings.
cipher
An algorithm used to encrypt and decrypt data; TLS negotiates a cipher suite (a bundle of algorithms for key agreement, bulk encryption, and integrity) during the handshake.
man-in-the-middle attack
An attack in which someone secretly sits between you and a server, reading or altering traffic while both sides believe the line is private; authentication in TLS is designed to prevent it.
root CA
A self-signed Certificate Authority certificate that anchors the chain of trust; its public key is preloaded in the browser or operating system trust store and kept offline for safety.

Sources and further reading


Kept in this browser, no account needed. Your progress page turns the whole record into one link you can bookmark or open on another device.