TLS and HTTPS: certificates without the mystery
Read a real certificate chain, see what the TLS handshake proves, recognise the four certificate errors that cause real outages, and how Let's Encrypt and mTLS fit in.
By the end of this lesson you'll be able to
0 of 4 completeVerified lab: openssl s_client and curl against github.com and the badssl.com test sites. The output
shown is real.
Code walkthrough: issuing a certificate with Let's Encrypt and setting up mTLS (they need a public
domain or a service mesh).
Cloud lab: none needed.
More outages come from expired and mismatched certificates than from attacks. Once you can read a certificate, these problems take minutes, not hours.
What TLS protects
TLS sits between TCP and HTTP and gives you three things: encryption (nobody on the path can read it), integrity (nobody can change it unnoticed) and authentication (you're really talking to github.com). The third is what certificates are for, and it's the part that breaks.
Leaf, intermediate, root
$ echo | openssl s_client -connect github.com:443 -servername github.com 0 s:CN=github.com i:C=GB, O=Sectigo Limited, CN=Sectigo Public Server Authentication CA DV E36 1 s:C=GB, O=Sectigo Limited, CN=Sectigo Public Server Authentication CA DV E36 i:C=GB, O=Sectigo Limited, CN=Sectigo Public Server Authentication Root E46 ... Protocol: TLSv1.3 Verify return code: 0 (ok) $ echo | openssl s_client -connect github.com:443 -servername github.com 2>/dev/null | openssl x509 -noout -subject -issuer -dates -ext subjectAltName subject=CN=github.com issuer=C=GB, O=Sectigo Limited, CN=Sectigo Public Server Authentication CA DV E36 notBefore=Oct 30 00:00:00 2026 GMT notAfter=Jan 27 23:59:59 2027 GMT X509v3 Subject Alternative Name: DNS:github.com, DNS:www.github.com
echo | openssl s_client -connect github.com:443 -servername github.comechoprint text|pipe: send output to the next command
(Trimmed.) s: is the subject, i: who signed it. The leaf is valid for under three months, and only for the names
in its SAN list. Your machine trusts it because each signature leads up to a root in its trust store.
The handshake
$ curl -sv https://github.com -o /dev/null 2>&1 | grep -E 'SSL connection|ALPN|expire date' * ALPN: curl offers h2,http/1.1 * SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256 / x25519 / id-ecPublicKey * ALPN: server accepted h2 * expire date: Jan 27 23:59:59 2027 GMT
curl -sv https://github.com -o /dev/null 2>&1 | grep -E 'SSL connection|ALPN|expire date'curlmake an HTTP request-owrite the body to this file2>&1send errors to the same place as output|pipe: send output to the next commandgrepfind lines that match a pattern
TLS 1.3 needs one round trip after TCP's handshake. The client sends the site name (SNI) in the clear so the server can pick the right certificate; that's how one IP serves certificates for thousands of names. ALPN agrees on HTTP/2 at the same time.
Four errors you will meet
$ curl -sS https://expired.badssl.com -o /dev/null curl: (60) SSL certificate OpenSSL verify result: certificate has expired (10) $ curl -sS https://wrong.host.badssl.com -o /dev/null curl: (60) SSL: no alternative certificate subject name matches target hostname 'wrong.host.badssl.com' $ curl -sS https://self-signed.badssl.com -o /dev/null curl: (60) SSL certificate OpenSSL verify result: self-signed certificate (18) $ curl -sS https://untrusted-root.badssl.com -o /dev/null curl: (60) SSL certificate OpenSSL verify result: self-signed certificate in certificate chain (19)
curl -sS https://expired.badssl.com -o /dev/nullcurlmake an HTTP request-owrite the body to this file
Read the reason, not just "SSL error". The most common in real life is expired, so monitor expiry: Prometheus'
blackbox exporter exposes probe_ssl_earliest_cert_expiry, and an alert at 14 days left catches failed renewals.
Certificates from Let's Encrypt
Let's Encrypt issues free certificates to anyone who can prove control of a name, using the ACME protocol.
Certificates last 90 days on purpose, so renewal has to be automated: certbot on a server, cert-manager in
Kubernetes, or let AWS Certificate Manager issue and renew certificates for your load balancers. The DNS-01
challenge (a TXT record instead of a file) works for wildcard names and servers that aren't public.
Mutual TLS
Normal HTTPS proves only the server's identity. With mutual TLS (mTLS) the client presents a certificate too, so the server knows exactly which service is calling. It's how service meshes such as Istio and Linkerd secure traffic between Pods, with certificates issued and rotated automatically by an internal CA.
Audit certificates you depend on
For three HTTPS sites your work depends on, record the issuer, expiry date, SAN names and TLS version. Then work out the days left for each and decide which one would need attention first.
~/certs.txtReveal one safe solution
$ for h in github.com example.com www.cloudflare.com; do echo "== $h" echo | openssl s_client -connect $h:443 -servername $h 2>/dev/null \ | openssl x509 -noout -issuer -enddate -ext subjectAltName end=$(echo | openssl s_client -connect $h:443 -servername $h 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2) echo "days left: $(( ($(date -d "$end" +%s) - $(date +%s)) / 86400 ))" done > ~/certs.txt
for h in github.com example.com www.cloudflare.com; doforloop over a listdostart of what the loop runs each time
Anything under 30 days on a certificate that should auto-renew is worth checking today.
Try it yourself
0 of 5 steps doneRun each task in your own account or terminal, then tick it off.
Quick check
curl says "no alternative certificate subject name matches target hostname". What is wrong?
Official reading for this lesson
Or get every quiz answer right and it completes itself.
Something unclear, wrong or out of date in this lesson? Tell me, and I'll fix it.