Security

What Is a TLS Certificate? What's Inside One and How It Works

A TLS certificate is a small signed file that binds a domain name to a public key, so a browser can confirm it is talking to the real server before it sends anything private. Servers present it at the start of every HTTPS connection, and the client checks the signature, the dates and the name.

You can read any site's certificate yourself. This command downloads one and prints its contents:

openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null | openssl x509 -noout -text

What a TLS certificate does

Encryption alone is not enough. If you encrypt traffic to the wrong server, you have a private conversation with an attacker. A certificate solves the identity half of the problem: it says "this public key belongs to example.com", and a certificate authority (CA) the client already trusts has signed that statement.

The certificate carries a public key, not a secret. The matching private key stays on the server. During the handshake the server proves it holds that private key, and the two sides use that to set up the keys that encrypt the session. The steps are covered in the TLS handshake explained.

"SSL certificate" is the same thing under an older name. The file format is X.509, and it is the same whichever TLS version carries it. If the naming confuses you, SSL vs TLS explains where it came from.

What is inside a TLS certificate

RFC 5280 defines the X.509 certificate profile used on the web. Its to-be-signed part (the TBSCertificate) contains these fields:

FieldWhat it holds
versionThe X.509 version. RFC 5280 says that when extensions are used, as expected in its profile, the version "MUST be 3" (stored as the value 2).
serialNumberA number that identifies this certificate among those the issuer has signed.
signatureThe algorithm the issuer used to sign.
issuerThe name of the CA that signed the certificate.
validityThe start and end dates (notBefore and notAfter).
subjectWho the certificate is for.
subjectPublicKeyInfoThe public key and its algorithm.
extensionsExtra fields, such as the subject alternative name, key usage and basic constraints.

After those fields comes the CA's signature over all of them. Change one byte of the certificate and the signature no longer verifies.

Which domains a certificate covers: the SAN

The domain names live in the subject alternative name (SAN) extension, not in the subject. RFC 9525 says to check DNS names only through the subjectAltName extension, and states that the Common Name "MUST NOT be used to identify a service because it is not strongly typed". Older certificates often repeat the main domain in the Common Name, and you may still see that, but clients rely on the SAN.

One certificate can list several names, including a wildcard such as *.example.com. If you visit a name that is not in the SAN list, the client reports a hostname mismatch even when the certificate is otherwise valid.

How to read a certificate with OpenSSL

The OpenSSL documentation lists -text (print the certificate in text form), -noout (suppress the encoded output), -ext (print chosen extensions) and -enddate (print the notAfter date). To save a server's certificate to a file first:

openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null | openssl x509 -out site.pem

Then look at specific parts of it:

openssl x509 -in site.pem -noout -ext subjectAltName
openssl x509 -in site.pem -noout -enddate
openssl x509 -in site.pem -noout -fingerprint

Example output (your values will differ):

X509v3 Subject Alternative Name:
    DNS:example.com, DNS:www.example.com
notAfter=Jan 15 23:59:59 2027 GMT
sha1 Fingerprint=AB:CD:...:EF

Without a digest option, -fingerprint uses SHA1, per the OpenSSL documentation. A fingerprint is a hash of the whole certificate, which is handy for checking that two copies are identical. For a fuller walk-through, including browser steps, see how to check an SSL certificate.

How a client decides to trust one

A client accepts a certificate only if all of these hold:

  1. The signature chain leads to a root CA certificate the client already trusts. What a certificate authority is covers roots, intermediates and the chain.
  2. Every signature in the chain verifies.
  3. The current date falls between notBefore and notAfter for every certificate in the chain.
  4. The hostname you asked for appears in the SAN list.

Fail any one and you get a warning page or an error. The usual messages are an expired certificate, an untrusted issuer, and a name mismatch.

Types of certificate and what they change

Certificates differ in how much the CA checked before signing. Domain-validated certificates prove control of the domain. Organisation-validated and extended-validation certificates add checks on the organisation behind it. The encryption is the same in all of them, because it comes from the key and the TLS settings, not from the price.

They also differ in what they cover. A single-name certificate lists one hostname. A multi-domain certificate lists several in the SAN. A wildcard certificate covers one label of subdomains. A wildcard for *.example.com does not cover example.com itself unless that name is listed too.

The files you will meet

When you set up a server, you usually handle three things: the certificate, any intermediate certificates, and the private key. Many servers want the certificate and intermediates in one file, and the private key in another. Keep the private key out of version control, tickets and chat. If it leaks, the certificate must be replaced, because anyone with the key can impersonate the site.

A certificate signing request (CSR) is what you send a CA to get a certificate. It contains your public key and the names you want, signed with your private key. The CA never sees the private key.

If a certificate error appears

Check the cheap causes first. Compare the expiry date with today's date, then compare the names in the SAN with the address you typed. If both are fine, run the openssl s_client command above and read the last line, Verify return code. A code other than 0 (ok) names the failure, and a missing intermediate certificate on the server is a common reason that one client fails while another works.

Frequently asked questions

Is a TLS certificate the same as an SSL certificate?
Yes. Both names refer to the same X.509 certificate. 'SSL certificate' is the older name, kept from the days of the SSL protocol. The certificate works with whichever TLS version the server and client negotiate, so there is no separate product to buy.
Does a TLS certificate contain the private key?
No. A certificate holds only the public key, plus the identity and a signature. The matching private key stays on the server and is never sent to clients. Anyone can download a site's certificate; only the server can prove it owns the key.
Which field says which domain a certificate covers?
The subject alternative name (SAN) extension. RFC 9525 says clients check the server identity against the subjectAltName entries and must not use the Common Name for this. A certificate can list many names in its SAN extension.
What happens when a TLS certificate expires?
Clients reject it. Browsers show a full-page warning, and tools such as openssl report 'certificate has expired'. The connection could still be encrypted, but the client can no longer trust that the key belongs to the site, so it refuses by default. Renew and install a new certificate.

Sources