Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

How to read a TLS certificate

After this lesson: I can read the names, issuer, lifetime and chain of a TLS certificate with OpenSSL.

65 min lesson6 commandsCertificate automation lab: ACME, short-lived TLS certificates and automatic renewal with a private CA

What is inside a TLS certificate?

A TLS certificate is a signed file that ties a website's name to a public key. Your browser reads one every time it shows a padlock.

Public certificates now last at most 200 days, and soon 47. A short life means you read them more often, so learn to read one quickly.

By the end of this lesson

Note

I can read the names, issuer, lifetime and chain of a TLS certificate with OpenSSL.

Key words

WordWhat it meansExample
Certificatea signed file tying names to a public key
Subject alternative name (SAN)the list of names a certificate is valid forDNS:shop
Issuerthe CA that signed the certificate
Validitythe time between notBefore and notAfter
Chainthe certificate, its intermediates and a trusted root
OpenSSLa command line tool that reads and checks certificates

The cells students fill in are left blank in this preview.

A certificate is fields plus a signature

The subject says who it is for. The subject alternative name lists the names a browser will accept, and browsers use only this list. The issuer names the CA that signed it.

notBefore and notAfter bound its life. The public key is what the server proves it holds. The CA's signature covers all of it, so no field can change unnoticed.

Worked example: the fields of one certificate

FieldValue in a made-up certificateWhat it tells you
SubjectCN = books.riverside.exampleWho it was issued to
Subject alternative nameDNS:books.riverside.example, DNS:*.books.riverside.exampleEvery name it is valid for
IssuerCN = Example Trust Issuing CA 2Which CA signed it
notBeforeMar 2 08:30:00 2029 GMTNot valid before this
notAfterApr 18 08:29:59 2029 GMTNot valid after this, 46 days later

The cells students fill in are left blank in this preview.

Fetch the shop's certificate and chain

Command
docker exec python python3 steps/fetch.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

What the fetch printed

The script connected to shop on port 443 with TLSv1.3 and checked the certificate against the lab's root. It printed the server sent 2 certificates, then saved the first to shop.pem and the second to chain.pem.

The shop got this certificate by itself over ACME, which the next lessons open up. Now read it.

Read the subject and the issuer

Command
docker exec python openssl x509 -in shop.pem -noout -subject -issuer

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Read the names it is valid for

Command
docker exec python openssl x509 -in shop.pem -noout -ext subjectAltName

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

What the two Runs print

LineWhat it means
subject=Empty: the web server asked for names only
issuer=O = Lab Private CA, CN = Lab Private CA Intermediate CASigned by the lab's intermediate, not the root
X509v3 Subject Alternative Name: criticalThe name list, marked critical because the subject is empty
DNS:shopThe one name this certificate is valid for

The cells students fill in are left blank in this preview.

A common mistake

Warning

Many people think the subject's common name decides which site a certificate is for. Browsers ignore it and check only the subject alternative name. Read the name list first, as the shop's empty subject shows.

Read the validity dates

Command
docker exec python openssl x509 -in shop.pem -noout -dates

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

This certificate lives for one day

The Run prints notBefore= and notAfter= with your own dates, which differ for every copy. They are always 24 hours and one minute apart. The CA starts each certificate a minute early, so a clock running slightly behind still accepts it.

A day is short on purpose. A public certificate will soon last 47 days, and this lab shows the same habits at a faster pace.

A chain links your certificate to a root

A browser trusts a short list of root certificates. A root signs an intermediate, and the intermediate signs your certificate.

The server sends its own certificate and the intermediate. It never needs to send the root, because the browser already has it. If the intermediate is missing, many clients fail.

Read the intermediate the server sent

Command
docker exec python openssl x509 -in chain.pem -noout -subject -issuer

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Check the chain against the root

Command
docker exec python openssl verify -CAfile /ca/certs/root_ca.crt -untrusted chain.pem shop.pem

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

About this lab and its source: Certificate automation lab: ACME, short-lived TLS certificates and automatic renewal with a private CA

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.