Lesson 8 of 14 · 10 min · HTTP, TLS and traffic management

HTTPS and TLS: encryption, certificates and trust

Covers: OpenSSL 3.0 and curl 8.5 on Ubuntu 24.04. Updated 13 Nov 2026. Part of the DevOps Engineer roadmap.

What you will learn

  • What problem TLS solves and what HTTPS is
  • The TLS handshake in plain steps
  • Certificates, certificate authorities and the chain of trust
  • Inspecting certificates with openssl s_client and curl
  • Let's Encrypt and automatic renewal; common certificate errors; TLS termination

In simple words

HTTP alone is a postcard: anyone carrying it can read it. HTTPS puts the message in a sealed envelope and also proves who the sender is. TLS is the technology that does the sealing. This lesson explains it in plain steps, and why the browser's padlock needs a certificate.

Words to know

  • Encryption: scrambling data so that only the intended receiver can read it.
  • TLS: the protocol that encrypts a connection. HTTPS is HTTP running inside TLS.
  • Certificate: a website's digital identity card, signed by an authority that browsers trust.
  • Certificate authority (CA): an organisation that checks who owns a site and signs its certificate.

What TLS gives you

Without encryption, anyone on the path (café Wi-Fi, an ISP, a compromised router) can read and change HTTP traffic. TLS (Transport Layer Security; "SSL" is its obsolete predecessor) wraps a TCP connection and provides three guarantees:

  1. Confidentiality: the data is encrypted.
  2. Integrity: tampering is detected.
  3. Authentication: the client can verify it is talking to the real server (and optionally the server verifies the client).

HTTPS = HTTP over TLS, on port 443. Today there is no good reason for a site to serve HTTP only; browsers mark it "not secure" and many features need HTTPS.

How the handshake works (TLS 1.3)

Simplified:

  1. ClientHello: the client lists the TLS versions and ciphers it supports, sends a random value, a key share, and the server name (SNI) it wants (example.com), so one IP can host many certificates.
  2. ServerHello: the server picks the version and cipher, sends its own key share, and its certificate chain, with a signature proving it holds the certificate's private key.
  3. Key agreement: both sides compute the same session keys from the key shares (Diffie-Hellman), which never cross the network.
  4. The client verifies the certificate (details below). If it fails, the browser shows a warning.
  5. From now on, application data (the HTTP request) is encrypted with fast symmetric keys.

TLS 1.3 needs one round trip (TLS 1.2 needs two), and supports session resumption to skip work on reconnect. Prefer TLS 1.2 or 1.3; versions 1.0 and 1.1 are deprecated.

Asymmetric cryptography (certificates, signatures, key exchange) is used briefly to set up the connection; symmetric cryptography (AES, ChaCha20) protects the bulk of the data because it is much faster.

Certificates and trust

A certificate binds a name to a public key and is signed by a certificate authority (CA). It contains: the subject (domain names, in the Subject Alternative Name list), the public key, the issuer, and a validity period (notBefore, notAfter).

Your browser or OS ships a trust store of root CAs. A server sends its certificate plus the intermediate certificates, forming a chain: leaf (your domain) → intermediate CA → root CA. The client checks each signature up to a root it trusts, that the name matches the host it connected to, that today's date is within the validity period, and that the certificate is not revoked.

The real certificate of a public site, inspected with OpenSSL:

echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
  | grep -E "Protocol|Cipher is|Verification|subject=|issuer="
subject=CN = example.com
issuer=C = US, O = SSL Corporation, CN = Cloudflare TLS Issuing ECC CA 3
Verification: OK
New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384

and its dates:

echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
  | openssl x509 -noout -subject -dates
subject=CN = example.com
notBefore=Sep 26 22:49:11 2026 GMT
notAfter=Dec 25 22:56:35 2026 GMT

The certificate is valid for 90 days, typical for automatically renewed certificates. -servername sets SNI; without it a server hosting many sites may return the wrong certificate. curl reports the verification result too: curl -sI https://example.com -o /dev/null -w '%{ssl_verify_result}' printed 0 (success).

Free certificates: Let's Encrypt and ACME

Let's Encrypt issues free certificates, automatically, using the ACME protocol: the client proves control of the domain (by serving a token over HTTP, HTTP-01, or by adding a DNS record, DNS-01, which also allows wildcard certificates). Tools: certbot, acme.sh, Caddy (built in), cert-manager in Kubernetes, and cloud services (AWS Certificate Manager, issued free for use with its load balancers). Certificates last 90 days or less, so renewal must be automatic and monitored.

Self-signed certificates and private CAs

A self-signed certificate is its own signer; nobody trusts it by default. Fine for local development or internal services where you add your own CA to the trust store (mkcert helps locally). We tried it: an nginx server with a self-signed certificate made curl fail with exit code 60 (certificate problem), while curl -k (skip verification) worked and reported verify result 18 (self-signed certificate). Never tell users to click through warnings for a public site.

TLS termination

Who decrypts the traffic?

  • Termination at the load balancer or reverse proxy: clients speak TLS to the proxy, which forwards plain HTTP to backends over the private network. Simple; certificates are managed in one place. Add X-Forwarded-Proto: https so the app knows the original scheme.
  • Pass-through (layer 4): the proxy forwards the encrypted bytes; the backend holds the certificate. End-to-end encryption, but no HTTP-level routing.
  • Re-encryption: terminate, inspect, then encrypt again to the backend. Common where policy requires encryption inside the network.
  • mTLS (mutual TLS): both sides present certificates. Used between services (service meshes) and for API clients.

Common certificate problems

Browser or tool message Cause Fix
expired certificate not renewed renew; add expiry monitoring and alerts at 30/14/7 days
name mismatch (ERR_CERT_COMMON_NAME_INVALID) the host name is not in the certificate's SAN list issue a certificate covering that name
unknown authority / unable to get local issuer missing intermediate certificate in the server's chain, or a private CA serve the full chain (fullchain.pem)
self-signed no trusted CA use a real CA, or trust your CA on clients
clock errors client or server time is wrong fix time sync (NTP)
handshake failure / no shared cipher incompatible TLS versions or ciphers check server TLS config and client age

Certificate expiry is one of the most common causes of "sudden" outages, and one of the easiest to prevent: check it with a script (openssl x509 -checkend 1209600 returns failure if the certificate expires within 14 days) or a monitoring probe.

HSTS and redirects

Serve HTTP only to redirect to HTTPS (301). Add HSTS (Strict-Transport-Security: max-age=31536000) so browsers refuse to use HTTP for your domain afterwards. Be sure HTTPS works for every subdomain before enabling includeSubDomains.

Common mistakes

  • Letting certificates expire with no monitoring.
  • Serving only the leaf certificate (missing intermediates).
  • Committing private keys to Git or sharing them in chat. Anyone with the key can impersonate your server. Keys belong in secret stores, with file mode 600.
  • Testing without SNI and getting the wrong certificate.
  • Disabling verification (curl -k, verify=False) "to make it work", and leaving it in production.
  • Mixed content: an HTTPS page loading HTTP resources.

Try it yourself

  1. Use openssl s_client to print the issuer, subject and expiry of three websites you use. Which CAs issued them?
  2. Compute how many days remain: echo | openssl s_client -connect HOST:443 -servername HOST 2>/dev/null | openssl x509 -noout -enddate.
  3. Create a self-signed certificate with openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem -days 30 -subj "/CN=localhost", serve it from nginx and see what curl and curl -k say.
  4. Write a script that exits non-zero if a host's certificate expires within 14 days.

Check yourself

What three guarantees does TLS provide?

Confidentiality (encryption), integrity (tamper detection) and authentication (the server, and optionally the client, proves its identity).

What is the role of a certificate authority?

It verifies control of a domain (or identity) and signs a certificate binding that name to a public key. Clients trust the CA's root certificate, so they trust what it signs.

What is SNI and why does it matter?

Server Name Indication: the client names the host it wants in the ClientHello, so a server with many sites on one IP can present the right certificate.

Users get "unable to verify the first certificate" but the browser works. What is the likely issue?

The server sends only the leaf certificate without the intermediate chain. Some browsers fetch the missing intermediate, but other clients such as curl, Java and API clients fail. Serve the full chain.

Interview questions

Explain the TLS handshake.

The client sends supported versions/ciphers and a key share (and SNI); the server replies with its choice, key share and certificate; the client validates the certificate chain, name and dates; both derive session keys; then data flows encrypted with symmetric keys.

Where would you terminate TLS in a typical cloud setup and why?

At the load balancer or ingress: one place to manage certificates and TLS policy, offloads CPU from backends, and enables HTTP-aware routing. Re-encrypt to the backend if policy requires encryption in transit inside the network.

How do you avoid certificate expiry outages?

Automatic issuance and renewal (ACME/cert-manager/ACM), monitoring of expiry dates with alerts well ahead, and a documented manual renewal procedure.

Summary

  • TLS encrypts, protects integrity and authenticates; HTTPS is HTTP over TLS on port 443.
  • A server proves identity with a certificate chain that clients validate against their trust store: name, dates, signatures.
  • Use free automated certificates (Let's Encrypt/ACME, ACM), serve the full chain, and monitor expiry.
  • Know termination patterns (terminate, pass-through, re-encrypt, mTLS) and the usual certificate errors.

Going deeper

See how much of this you can explain

A free mock interview asks you new questions on Networking for DevOps for DevOps Engineer and scores every answer, with what to fix.