The problem certificates solve
You have a public key that claims to be www.example.com. How do you know?
Anyone can make a key pair and say so. A certificate answers this: a
trusted third party, the Certificate Authority (CA), signs a statement
“this public key belongs to this name”. You trust the CA, so you trust the
binding.
Think of a passport. Anyone can print a card that says “I am Alice”. A passport is believable because a government you already trust issued it after checking who you are, and it is hard to forge. A certificate is the same idea for a key: the CA checked the requester, then signed a small document containing the name and the public key. Because the CA’s signature cannot be forged, any computer that trusts the CA can believe the name-to-key link without ever having met the owner.
That is also why the CA’s own private key is the most valuable secret in the whole system: whoever holds it can issue a passport for anyone.
PKI (Public Key Infrastructure) is the people, software and rules around that: creating CAs, issuing, distributing trust, renewing and revoking.
| Term | Meaning |
|---|---|
| CA | Signs certificates |
| Root CA | Top of a hierarchy; its certificate is self-signed and installed as trusted |
| Intermediate (issuing) CA | Signed by the root; issues the end certificates, so the root key can stay offline |
| RA | Registration Authority: checks the request is legitimate, then asks the CA to sign |
| End-entity / leaf | The server, device or user certificate |
| Trust store | The list of root CAs a system trusts (OS, browser, Java, container image) |
| Relying party | Whoever checks a certificate |
Trust flows downward along a chain. Your computer ships with a short list of roots it trusts. The root signs an intermediate, the intermediate signs the server’s certificate, and the client walks back up the signatures until it reaches a root it already trusts: server certificate → intermediate → root. Roots are kept offline and used rarely because a stolen root key would be a catastrophe; intermediates do the daily work, and if one is compromised you retire it without replacing the root on every device.
Build a tiny PKI
We will build the real thing: a root, an intermediate, and a web certificate. Do this once; later pages reuse the files.
1. The root CA
$ openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-384 -out root.key
$ openssl req -x509 -new -key root.key -sha384 -days 3650 \
-subj "/O=Example Corp/CN=Example Root CA" \
-addext "basicConstraints=critical,CA:TRUE" \
-addext "keyUsage=critical,keyCertSign,cRLSign" \
-addext "subjectKeyIdentifier=hash" \
-out root.crt
What each option does:
genpkey ... P-384: the root’s private key. It lives for ten years and signs everything below it, so it gets the larger curve (see the previous page).-x509: instead of a certificate request, produce a finished certificate, self-signed. Subject and issuer are the same, and it is signed with its own key. Nobody vouches for a root, so it is trusted only because someone chose to put it in a trust store.-days 3650: valid for about ten years.-subj: the name the certificate carries (organisation and common name).basicConstraints=critical,CA:TRUE: this certificate is allowed to be a CA. critical means “a program that does not understand this field must reject the certificate”, so a client cannot accidentally ignore it.keyUsage=critical,keyCertSign,cRLSign: the key may only sign certificates and revocation lists, not, say, run a TLS server. Restricting what a key can do limits the damage if it is misused.subjectKeyIdentifier=hash: a short ID for this key, so a verifier can pick the right issuer when a CA has several keys.
2. The intermediate CA
The intermediate makes a CSR (certificate signing request: “please sign my public key”), and the root signs it.
$ openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out int.key
$ openssl req -new -key int.key -subj "/O=Example Corp/CN=Example Issuing CA" -out int.csr
$ cat > int.ext <<'EOF'
basicConstraints=critical,CA:TRUE,pathlen:0
keyUsage=critical,keyCertSign,cRLSign
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid
crlDistributionPoints=URI:http://pki.example.com/int.crl
EOF
$ openssl x509 -req -in int.csr -CA root.crt -CAkey root.key -CAcreateserial \
-days 1825 -sha384 -extfile int.ext -out int.crt
A few things differ from the root:
- The intermediate makes its own key and a CSR, and the root signs it. The root’s private key is used only for this one action, which is why it can stay offline.
pathlen:0says: this CA may issue end certificates but not more CAs. If this intermediate is ever compromised, the attacker cannot make a hidden sub-CA below it.authorityKeyIdentifierrecords which key signed it (the root’s key ID), and pairs with the root’ssubjectKeyIdentifier. This is how a verifier finds the right issuer quickly.crlDistributionPointstells clients where to download the list of revoked certificates (see Revocation, below).-sha384: the hash that is signed. It matches the root’s P-384 key.
3. A web server certificate
Generate the key and CSR on the server. The private key never leaves it. Only the CSR travels to the CA.
$ openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out web.key
$ openssl req -new -key web.key -subj "/CN=www.example.com" \
-addext "subjectAltName=DNS:www.example.com,DNS:example.com" -out web.csr
$ openssl req -in web.csr -noout -verify
Certificate request self-signature verify OK
A CSR contains the public key, the requested name and a signature made with the matching private key. That signature is the proof of possession: it shows the requester really holds the private key, rather than having copied someone else’s public key. The CA verifies it before signing.
Note the subjectAltName (SAN) in the request. A certificate’s job is to say “this key belongs to these names”, and modern clients look at the SAN list, not the old Common Name field. If you forget the SAN the browser will reject an otherwise valid certificate.
Now the CA signs, with the profile it decides (not what the CSR asks for):
$ cat > web.ext <<'EOF'
basicConstraints=critical,CA:FALSE
keyUsage=critical,digitalSignature
extendedKeyUsage=serverAuth,clientAuth
subjectAltName=DNS:www.example.com,DNS:example.com
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid
EOF
$ openssl x509 -req -in web.csr -CA int.crt -CAkey int.key -CAcreateserial \
-days 90 -sha256 -extfile web.ext -out web.crt
What the CA chose to put in the web certificate:
CA:FALSE: this is a leaf, it can never sign other certificates.keyUsage=digitalSignature: the key is used to sign the TLS handshake (that is all an elliptic-curve key needs for TLS).extendedKeyUsage=serverAuth,clientAuth: the allowed purposes.serverAuthlets it act as a TLS server andclientAuthas a TLS client (mutual TLS, below). A certificate meant only for servers should list onlyserverAuth.-days 90: short lived. A stolen 90-day certificate is useful to an attacker for at most 90 days, and one that renews automatically is a non-event. See Certificate lifetimes below.
CA:TRUE. The CA’s policy decides the extensions; the CSR only
supplies the public key and (checked) names.Read a certificate
$ openssl x509 -in web.crt -noout -text
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
24:4d:56:fc:d6:89:2a:15:0e:ed:d3:c8:67:db:0b:59:e6:40:7a:e4
Signature Algorithm: ecdsa-with-SHA256
Issuer: O=Example Corp, CN=Example Issuing CA
Validity
Not Before: Nov 25 05:50:28 2026 GMT
Not After : Feb 23 05:50:28 2027 GMT
Subject: CN=www.example.com
Subject Public Key Info:
Public Key Algorithm: id-ecPublicKey
Public-Key: (256 bit field, 128 bit security level)
...
X509v3 extensions:
X509v3 Basic Constraints: critical
CA:FALSE
X509v3 Key Usage: critical
Digital Signature
X509v3 Extended Key Usage:
TLS Web Server Authentication, TLS Web Client Authentication
X509v3 Subject Alternative Name:
DNS:www.example.com, DNS:example.com
X509v3 Subject Key Identifier:
4E:53:0D:63:...
X509v3 Authority Key Identifier:
01:40:52:E0:...
Signature Algorithm: ecdsa-with-SHA256
Signature Value:
30:45:02:20:04:7f:...
| Field | What it means | Why you care |
|---|---|---|
| Serial Number | Unique per issuing CA | How you revoke a specific certificate |
| Issuer / Subject | Who signed / who it is for | The chain is built by matching these |
| Validity | Not Before / Not After (UTC) | Expiry causes outages; clock skew causes “not yet valid” |
| Subject Alternative Name | The DNS names, IPs, emails, URIs it is valid for | This is what clients check; the CN is ignored by browsers |
| Basic Constraints | CA:TRUE/FALSE, pathlen | Prevents a leaf from acting as a CA |
| Key Usage / EKU | What the key may be used for (signing, TLS server, TLS client, code signing) | A client-auth-only certificate must not work as a server cert |
| SKI / AKI | Key identifiers | Pick the right issuer when a CA has several keys |
| CRL Distribution Points / AIA | Where to find revocation info and the issuer’s certificate | Revocation checks and chain-fetching |
Two habits make a certificate quick to read. First, find Subject (who it
is for) and Issuer (who signed it); for a root they are identical.
Second, read the extensions as a statement of what the certificate is
allowed to do: if it says CA:FALSE and serverAuth, it is a web-server
certificate and must not be trusted to sign other certificates. Extensions
marked critical must be understood by the client or the certificate is
rejected.
Short-form views for everyday use:
$ openssl x509 -in web.crt -noout -subject -issuer -dates -fingerprint -sha256 -ext subjectAltName
subject=CN=www.example.com
issuer=O=Example Corp, CN=Example Issuing CA
notBefore=Nov 25 05:50:28 2026 GMT
notAfter=Feb 23 05:50:28 2027 GMT
sha256 Fingerprint=F2:19:B1:0C:D6:EA:1E:F1:...
X509v3 Subject Alternative Name:
DNS:www.example.com, DNS:example.com
Under the hood: ASN.1 and DER
You do not need to read ASN.1 daily, but knowing it exists explains many
strange errors. ASN.1 is a language for describing structured data (fields
inside fields). DER is one strict way of writing that data as bytes, so
that the same certificate always produces the same bytes, which is vital
because a signature is calculated over those exact bytes. PEM is DER
wrapped in base64 text so it can be pasted into an email or a config file.
Each line of asn1parse below is one field: d= is how deep it is nested,
l= its length, and cons/prim whether it contains other fields or holds a
value. You can walk it:
$ openssl asn1parse -in web.crt | head -12
0:d=0 hl=4 l= 506 cons: SEQUENCE
4:d=1 hl=4 l= 416 cons: SEQUENCE
8:d=2 hl=2 l= 3 cons: cont [ 0 ]
10:d=3 hl=2 l= 1 prim: INTEGER :02
13:d=2 hl=2 l= 20 prim: INTEGER :244D56FCD6892A150EEDD3C867DB0B59E6407AE4
35:d=2 hl=2 l= 10 cons: SEQUENCE
37:d=3 hl=2 l= 8 prim: OBJECT :ecdsa-with-SHA256
...
The three top-level pieces are always: the to-be-signed data (everything above), the signature algorithm, and the signature.
Verify a chain
A server should send its certificate plus the intermediate, never the root. The client already has the root in its trust store.
$ openssl verify -CAfile root.crt web.crt
CN=www.example.com
error 20 at 0 depth lookup: unable to get local issuer certificate
error web.crt: verification failed
$ openssl verify -CAfile root.crt -untrusted int.crt web.crt
web.crt: OK
The first command fails because the verifier does not have the intermediate.
This is the most common real-world certificate bug: the server forgot to
send the intermediate. Browsers sometimes paper over it; curl, Java, Go and
IoT devices do not.
The first command failed because the verifier started with only the root. It
looked at web.crt, saw “issued by Example Issuing CA”, and had no copy of
that certificate. The second command supplied the intermediate with
-untrusted (“use this to build the chain, but do not trust it on its own”).
The chain then connected: web → intermediate → root, and the root is the one
thing explicitly trusted.
The verifier checks, for each link: the signature is valid, the dates are
valid, the issuer is allowed to sign (CA:TRUE, keyCertSign, path length),
names and usages fit, and the top is in the trust store. If any one check
fails, the whole chain fails.
Does this key belong to this certificate?
A frequent mistake is installing a certificate with a private key that does not belong to it (for example after renewing with a new key). The server then fails to start, with a “key values mismatch” error. To check, compare the public key hash in the certificate with the one derived from the private key. Equal means they match:
$ openssl x509 -in web.crt -pubkey -noout | openssl sha256
SHA2-256(stdin)= bf1db7de15a39e454bf4682edbfd2479cd8b23e6091b1694e37917cd38485b68
$ openssl pkey -in web.key -pubout | openssl sha256
SHA2-256(stdin)= bf1db7de15a39e454bf4682edbfd2479cd8b23e6091b1694e37917cd38485b68
A TLS handshake, live
Start a test server and connect to it. First, a server that sends only its own certificate:
$ openssl s_server -accept 14443 -cert web.crt -key web.key -www -quiet &
$ openssl s_client -connect localhost:14443 -servername www.example.com \
-CAfile root.crt -verify_hostname www.example.com </dev/null
0 s:CN=www.example.com
Verification error: unable to verify the first certificate
Protocol: TLSv1.3
Verify return code: 21 (unable to verify the first certificate)
The client trusts the root but was never given the intermediate: the same
“missing intermediate” bug as above. Now the server also sends the
intermediate (-cert_chain):
$ openssl s_server -accept 14443 -cert web.crt -cert_chain int.crt -key web.key -www -quiet &
$ openssl s_client -connect localhost:14443 -servername www.example.com \
-CAfile root.crt -verify_hostname www.example.com </dev/null
0 s:CN=www.example.com
1 s:O=Example Corp, CN=Example Issuing CA
Verification: OK
Verified peername: www.example.com
Protocol: TLSv1.3
Verify return code: 0 (ok)
Reading the Verify return code line is the quickest way to debug TLS.
(In nginx, Apache and most servers, the “certificate” file must hold the leaf
followed by the intermediates.)
What happened, simplified:
- Client hello. The client says which TLS versions and ciphers it
supports, and sends
-servername(SNI): the name of the site it wants. One server IP can host many sites, so the server needs this to choose the right certificate. - Server sends its certificate chain (leaf, then intermediates).
- The client verifies the chain and the hostname. The chain is checked as described above, and the name it typed must appear in the SAN list. Both must pass, or the client stops.
- Both sides run an ephemeral key exchange (Diffie-Hellman from the previous page). This is what gives forward secrecy: the session secret is never sent, and never derived from the certificate’s key.
- The server proves it holds the private key. It signs the handshake
transcript with the certificate’s private key
(
Peer signature type: ecdsa_secp256r1_sha256). Anyone can present a copy of someone’s public certificate; only the real owner can produce this signature. - Both derive session keys and switch to AES-GCM for the actual data.
That is why a certificate alone is not a credential: it is public. The credential is the private key that can sign step 5. For a deeper look at who does what in this handshake (ECDHE, HKDF, AES-GCM, and the difference between TLS 1.2 and 1.3), see How HTTPS works.
Mutual TLS (mTLS): the server also requires a client certificate, so the connection proves who the client is too. In an ordinary TLS connection only the server is authenticated and the client stays anonymous (a login form follows later); with mTLS, the connection itself proves the identity of both ends, with no passwords. It is used for service-to-service traffic, VPNs, Wi-Fi (EAP-TLS) and device identity.
Certificate lifetimes
How long should a certificate live? Consider what happens if its private key is stolen. For the whole remaining lifetime the thief can impersonate the owner, unless the certificate is revoked, and revocation (below) is unreliable in practice: lists can be stale, and many clients ignore failures. A certificate that lives for five minutes needs no revocation: it expires before an attacker can do much.
So lifetimes keep shrinking. Public TLS certificates are moving to 47 days (CA/Browser Forum schedule ending 2029). For private PKI, short is also best: hours or days for user and workload certificates, 90 days or less for servers.
The catch: nobody can renew hundreds of certificates by hand every few weeks. Short lifetimes only work if issuance is automated; see enrollment protocols. Automation is what turns “expiry” from a 3 a.m. outage into a non-event.
Revocation: taking a certificate back
If a key is stolen, the certificate must stop working before it expires. This is revocation. Think of the hotlist a bank keeps for lost credit cards: the card still looks valid, but the shop checks the list. There are two ways to check, plus two ways of avoiding the problem:
| Method | How | Catch |
|---|---|---|
| CRL | The CA publishes a signed list of revoked serial numbers | Can be large; clients cache it |
| OCSP | Client asks a responder “is serial X good?” | Privacy; responder must be available; “soft-fail” clients ignore errors |
| OCSP stapling | The server attaches a fresh signed OCSP answer to the handshake | Needs server support |
| Short lifetimes | Do not revoke; let it expire in hours | Needs automation |
A CRL is itself a signed file:
$ openssl crl -in int.crl -noout -text | head -9
Certificate Revocation List (CRL):
Version 2 (0x1)
Signature Algorithm: ecdsa-with-SHA256
Issuer: O=Example Corp, CN=Example Issuing CA
Last Update: Nov 25 05:50:39 2026 GMT
Next Update: Dec 2 05:50:39 2026 GMT
CRL extensions:
X509v3 CRL Number:
1
No Revoked Certificates.
To use a CRL, a client downloads the list (the URL is in the certificate’s
crlDistributionPoints extension), verifies its signature, and checks whether
the certificate’s serial number is on it. The list says “next update” so
clients know how long they may cache it. OCSP does the same for one
certificate at a time, in real time. For a deeper comparison see
OCSP vs CRL.
Public vs private PKI
- Public CAs (Let’s Encrypt, DigiCert, …) are in browser trust stores, follow the CA/Browser Forum rules and are logged in Certificate Transparency. Use them for sites on the internet.
- Private CAs, like BastionXP, are trusted only by devices you configure.
Use them for internal services, devices, users, SSH and mTLS. You control
the policy, lifetime and naming, but you must distribute the root to every
client (MDM, Group Policy, config management, or
bxp-cli trust).
CA hierarchy design tips
- Keep the root offline (ideally in an HSM, in a safe) and use it only to sign intermediates, every few years. A key that is never connected to a network cannot be stolen over one. This is the single best protection for the thing that everything else depends on.
- Issue day-to-day certificates from intermediates, one per purpose (servers, users, devices). A compromised intermediate is replaced and only the certificates under it are affected; a compromised root means every device in the company must learn a new root.
- Use name constraints and
pathlento limit what a CA may issue. A name constraint says “this CA may only issue for*.corp.example.com”, so even a stolen department CA could not issue forgoogle.com. - Write down who may request what (a certificate profile): which names, which key types, which lifetime, which usages. A written profile is what lets you review, audit and automate issuance, instead of every request being a one-off decision.
Related articles
- How to create self-signed SSL TLS X.509 certificates using OpenSSL
- Mutual TLS Authentication - Everything you need to know
- Certificate Revocation: OCSP vs CRL — Which One Should Your Enterprise Use?
About BastionXP
BastionXP is a cloud-native private PKI CA and device identity management platform that eliminates passwords and shared secrets by issuing hardware-attested certificates to mobile devices and laptops. Secure access to your Wi-Fi, VPN, and SaaS applications in your enterprise network. Replace legacy SCEP with automated ACME Device Attestation. No shared secrets. Zero credential theft. Learn more about BastionXP →