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
| Word | What it means | Example |
|---|---|---|
| Certificate | a signed file tying names to a public key | |
| Subject alternative name (SAN) | the list of names a certificate is valid for | DNS:shop |
| Issuer | the CA that signed the certificate | |
| Validity | the time between notBefore and notAfter | |
| Chain | the certificate, its intermediates and a trusted root | |
| OpenSSL | a 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
| Field | Value in a made-up certificate | What it tells you |
|---|---|---|
| Subject | CN = books.riverside.example | Who it was issued to |
| Subject alternative name | DNS:books.riverside.example, DNS:*.books.riverside.example | Every name it is valid for |
| Issuer | CN = Example Trust Issuing CA 2 | Which CA signed it |
| notBefore | Mar 2 08:30:00 2029 GMT | Not valid before this |
| notAfter | Apr 18 08:29:59 2029 GMT | Not valid after this, 46 days later |
The cells students fill in are left blank in this preview.
Fetch the shop's certificate and chain
docker exec python python3 steps/fetch.pyShown 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
docker exec python openssl x509 -in shop.pem -noout -subject -issuerShown here, not run. Press Start lab to type it into your own lab’s terminal.
Read the names it is valid for
docker exec python openssl x509 -in shop.pem -noout -ext subjectAltNameShown here, not run. Press Start lab to type it into your own lab’s terminal.
What the two Runs print
| Line | What it means |
|---|---|
| subject= | Empty: the web server asked for names only |
| issuer=O = Lab Private CA, CN = Lab Private CA Intermediate CA | Signed by the lab's intermediate, not the root |
| X509v3 Subject Alternative Name: critical | The name list, marked critical because the subject is empty |
| DNS:shop | The 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
docker exec python openssl x509 -in shop.pem -noout -datesShown 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
docker exec python openssl x509 -in chain.pem -noout -subject -issuerShown here, not run. Press Start lab to type it into your own lab’s terminal.
Check the chain against the root
docker exec python openssl verify -CAfile /ca/certs/root_ca.crt -untrusted chain.pem shop.pemShown here, not run. Press Start lab to type it into your own lab’s terminal.