SECURITY ENGINEERING · PART 4 · CRYPTOGRAPHY IN PRACTICE · PKI · 52 OF 229

PKI and X.509 Certificates: Chain of Trust Explained

A certificate ties a public key to a name, signed by an authority you already trust. This episode builds a practice certificate authority with OpenSSL and reads a real certificate field by field, then covers the chain of trust, the checks a client performs (we show the exact errors for an unknown issuer and a wrong hostname), revocation, Certificate Transparency, and running an internal PKI.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 9
  9. 10
  10. 11
  11. 12
  12. 13
  13. 14
  14. 15
  15. 16
  16. 17
  17. 18
  18. 19
  19. 20
  20. 21
  21. 22
  22. 23
  23. 24
  24. 25
  25. 26
  26. 27
  27. 28
  28. 29
  29. 30
  30. 31
  31. 32
  32. 33
  33. 34
  34. 35
  35. 36
  36. 37
  37. 38
  38. 39
  39. 40
  40. 41
  41. 42
  42. 43
  43. 44
  44. 45
  45. 46
  46. 47
  47. 48
  48. 49
  49. 50
  50. 51
  51. 52
  52. 53
  53. 54
  54. 55
  55. 56
  56. 57
  57. 58
  58. 59
  59. 60
  60. 61
  61. 62
  62. 63
  63. 64
  64. 106
  65. 107
  66. 108
  67. 109
  68. 110
  69. 111
  70. 112
  71. 113
  72. 114
  73. 115
  74. 116
  75. 117
  76. 118
  77. 119
  78. 120
  79. 121
  80. 122
  81. 123
  82. 124
  83. 125
  84. 126
  85. 127
  86. 128
  87. 129
  88. 130
  89. 131
  90. 132
  91. 133
  92. 134
  93. 135
  94. 136
  95. 137
  96. 138
  97. 139
  98. 140
  99. 141
  100. 142
  101. 143
  102. 144
1 / 14

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • A certificate binds a key to a name
  • chain to a trusted root
  • automate renewal
  • never disable verification

Notes

A certificate

A certificate is a signed statement. It says: this public key belongs to this name. The format is called X five oh nine. Inside are the subject, the DNS names it covers, the public key, the issuer who signed it, the validity dates, what the key may be used for, a serial number, and the issuer's signature over everything. The certificate is public. The matching private key stays on the server and is never part of it.

What is inside (X.509)
  • subject: who it is for subject alternative names: the DNS names it covers
  • the public key
  • issuer: who signed it
  • valid from / valid until key usage and constraints
  • serial number
  • the issuer's signature over all of the above

Chain of trust

Trust works as a chain. At the top is a root certificate authority. It signs its own certificate, its key is kept offline, and its certificate ships inside your operating system and browser: about a hundred and fifty of them. The root signs intermediate authorities, which do the daily issuing. An intermediate signs the server certificate, called the leaf. The server sends the leaf and the intermediates, and your client connects them to a root it already has.

Root, intermediate, leaf
  • root CA: self-signed, kept offline, shipped in your OS and browser trust store
  • intermediate CA: signed by the root; does daily issuing
  • leaf: the server certificate, signed by the intermediate
  • a server sends leaf plus intermediates, not the root

Build one

You can build this yourself in a minute, and you should, once. First we create a practice root: a key and a self-signed certificate. Then, for the server, a new key and a certificate signing request, which contains the name and the public key. Finally the authority signs the request and produces the certificate, valid for ninety days. Notice that the server's private key never went to the authority. Only the request did.

make a CA, sign a certificate
openssl req -x509 -newkey ec ... \
  -keyout ca.key -out ca.crt \
  -subj "/CN=Practice Root CA"
openssl req -newkey ec ... \
  -keyout srv.key -out srv.csr \
  -subj "/CN=shop.example.test"
openssl x509 -req -in srv.csr \
  -CA ca.crt -CAkey ca.key \
  -days 90 -extfile ext.cnf \
  -out srv.crt

Read one

Here is that certificate, read back. The subject and the issuer. Valid from the second of December to the second of March. The subject alternative name, which is the field clients actually match against the hostname. Basic constraints say C A false, so this certificate cannot sign other certificates. Key usage allows digital signatures, and extended key usage says it is for server authentication. The whole file is six hundred and seventy six bytes.

openssl x509 -in srv.crt ...
subject=CN = shop.example.test
issuer=CN = Practice Root CA
notBefore=Dec  2 22:05:59 2026 GMT
notAfter=Mar  2 22:05:59 2027 GMT
Subject Alternative Name:
    DNS:shop.example.test
Basic Constraints: CA:FALSE
Key Usage: Digital Signature
Extended Key Usage:
    TLS Web Server Authentication

What the client checks

When a client receives a certificate it checks several things, and all must pass. Each signature in the chain verifies, ending at a root in its trust store. Today's date is inside the validity period. The hostname it wanted matches a subject alternative name. The usage fields allow this purpose. And the certificate has not been revoked. Separately, during the handshake, the server proves it holds the private key by signing with it.

Validation
  • 1. each signature in the chain verifies, up to a trusted root
  • 2. today is inside the validity dates
  • 3. the hostname matches a subject alternative name
  • 4. usage allows this purpose
  • 5. it is not revoked
  • then the server proves it has the private key

Watch it fail

Here are those checks failing. With our practice root supplied, verification says OK. Without it, the client does not know the issuer: error twenty, unable to get local issuer certificate. That is the classic error for a private authority or a missing intermediate. And when we asked whether the certificate is valid for a different hostname, error sixty two, hostname mismatch. A valid certificate for the wrong name is not valid.

openssl verify
$ openssl verify -CAfile ca.crt srv.crt
srv.crt: OK

$ openssl verify srv.crt
error 20: unable to get local issuer
  certificate

$ ... -verify_hostname evil.example.test
error 62: hostname mismatch

Getting a certificate

To get a public certificate you prove that you control the domain, by publishing a DNS record or serving a file. The ACME protocol automates this, which is how Let's Encrypt, cert-manager and cloud certificate managers issue and renew without people. Lifetimes keep shrinking: ninety days is normal and the industry is moving shorter. That makes automation a requirement. An expired certificate is one of the most common causes of outages.

Issuance today
  • domain validation: prove control via DNS record or an HTTP file
  • ACME automates it: Let's Encrypt, cert-manager, cloud certificate managers
  • lifetimes keep shrinking: 90 days is normal, shorter is coming; automate renewal
  • wildcards: one key, many hosts

Revocation and CT

If a private key leaks, the certificate must be revoked, through revocation lists or the OCSP lookup protocol. In practice, clients check these unreliably, which is the real reason lifetimes are getting shorter. Certificate Transparency is the other safeguard: every public certificate is recorded in public logs. Monitor those logs for your domains, and you will see any certificate issued without your knowledge. A CAA record in DNS says which authorities may issue for you.

After issuance
  • revocation: CRLs (lists) and OCSP (live lookup); both are checked unreliably
  • so: short lifetimes limit the damage of a stolen key
  • Certificate Transparency: every public certificate goes into public logs
  • monitor the logs for your domains (crt.sh)
  • CAA records: who may issue

Internal PKI

Inside a company you usually run a private authority. It issues certificates for internal services, for mutual TLS between services, for devices, and for VPN and Wi-Fi logins. Tools include step-ca, the Vault PKI engine, cloud private authorities and Active Directory Certificate Services. Keep the root key offline or in a hardware module, and issue short-lived certificates automatically. Whoever controls the authority's key can create an identity for anything, so it is a top target.

Private CA
  • for: internal services, mTLS between services, devices, VPN and Wi-Fi logins
  • tools: step-ca, Vault PKI, AWS Private CA, AD CS
  • root key offline or in an HSM
  • issue short-lived certs, automatically
  • the CA key can mint identity for anything: guard it

How attackers abuse it

Attackers aim at trust, not at mathematics. The easiest win is a client with verification switched off, which accepts any certificate. Malware adds a rogue root to a device's trust store, then intercepts everything. Private keys are stolen. Occasionally an authority is compromised and issues certificates for domains it should not. And in Windows networks, misconfigured certificate templates let ordinary users request certificates for administrators.

Attacks on PKI
  • clients with verification turned off (verify=False)
  • a rogue root added to a device trust store
  • stolen private keys
  • a compromised or careless CA issuing for your domain
  • misconfigured AD CS templates that let users request admin certificates
  • forgotten, expired certs

Common mistakes

Mistakes. Certificate verification disabled in code, often added during testing and never removed. Renewals done by hand from a calendar reminder. No monitoring of expiry dates. A server that sends the leaf without its intermediates, which works in some clients and fails in others. One wildcard key copied to every server. Private keys committed to repositories. Internal certificates valid for ten years. And nobody watching the transparency logs.

Avoid these
  • verify=False or -k in code
  • renewals done by hand
  • no expiry monitoring
  • serving the leaf without its intermediates
  • one wildcard key copied to every server
  • private keys in repos
  • long-lived internal certs
  • nobody watching CT logs

Say it like this

In the interview: the browser builds a chain from the server certificate through the intermediates to a root in its trust store, verifying each signature. It checks the validity dates, that the hostname matches a subject alternative name, the key usage, and revocation status. Then the server proves it holds the private key by signing the handshake. I would add that I automate issuance and renewal, and monitor expiry and Certificate Transparency.

In the interview
  • "It builds a chain from the leaf through intermediates to a root in its trust store, verifying each signature. It
  • checks dates, that the name
  • matches a SAN, usage, and revocation. The server proves
  • possession of the private key
  • in the handshake."

Interview questions

Q1What is PKI?

Public key infrastructure: the certificate authorities, certificates, policies and processes that bind public keys to identities and let parties who have never met verify each other. It is the trust foundation of HTTPS, code signing and much of enterprise authentication.

Q2What is an X.509 certificate?

A standard format for a signed document that binds a public key to a subject. It contains the subject and its alternative names, the public key, the issuer, a validity period, usage constraints and the issuer's signature.

Q3What is a certificate chain of trust?

The sequence from a server (leaf) certificate through one or more intermediate CA certificates to a root CA that the client already trusts. Each certificate is signed by the next one up, and the client verifies every link.

Q4What is the difference between a root CA and an intermediate CA?

A root CA is self-signed, present in trust stores and kept offline because its compromise is catastrophic. An intermediate CA is signed by the root and performs day-to-day issuance, so it can be revoked and replaced without changing trust stores.

Q5What is a CSR?

A certificate signing request: a message containing the requested subject names and the public key, signed with the matching private key. It is sent to a CA, which validates the request and returns a certificate. The private key never leaves the requester.

Q6How does certificate revocation work?

A CA can revoke a certificate before expiry by listing it in a certificate revocation list (CRL) or answering OCSP queries. Because clients check these inconsistently, the industry increasingly relies on short certificate lifetimes instead.

Q7What is Certificate Transparency?

A system of public, append-only logs in which CAs must record every publicly trusted certificate. Domain owners can monitor the logs to detect certificates issued for their domains without authorisation.

Q8What does "unable to get local issuer certificate" mean?

The client could not build a chain to a trusted root: either the server did not send the intermediate certificates, or the issuing CA is private and not in the client's trust store. The fix is to serve the full chain or install the CA certificate, never to disable verification.