Overview

8 Public Key Infrastructure and X.509 Digital Certificates: know who you are talking to

Public key cryptography secures data, but it doesn’t, by itself, prove who owns a given public key. During initial handshakes, an attacker can swap in their own key and intercept traffic. To bind a public key to an identity, systems rely on X.509 digital certificates and a Public Key Infrastructure (PKI). A certificate packages a public key with identity and operational metadata, allowing clients to decide whether to trust the key they received. Developers mainly need to recognize three core fields: subject (who the certificate is for), issuer (who signed it), and validity (when it’s usable). Subject Alternative Name (SAN) extends identity to include network identifiers—most importantly DNS names for servers—while certificates are distributed in common encodings such as PEM, DER, and PKCS#12.

In practice, developers inspect certificates to verify identity and fit-for-purpose. The subject and SAN fields must match the service being contacted (for example, the requested DNS name), and the key type/parameters (RSA or elliptic curve) must be acceptable for the application’s security profile. Validity enforces time-based use; shorter lifetimes reduce risk because private keys are hard to protect over long periods. Tools like OpenSSL make it straightforward to download, view, and parse certificates without needing to alter application code, and understanding the core formats and fields simplifies troubleshooting across languages, frameworks, and platforms.

Verification hinges on digital signatures and the certificate’s signature algorithm, but trust comes from building a chain of trust from the end-entity certificate through one or more intermediates to a trusted root in the local trust store provided by operating systems and browsers. A common failure—“unable to get local issuer certificate”—usually means the verifier can’t assemble that chain. Successful verification also requires checking dates, intended usage, and SAN matches, and then considering operational risk: even a valid certificate is unsafe if the owner’s private key is compromised. When compromise is discovered, revocation via CRLs or OCSP communicates that loss of trust. The developer’s takeaway is to combine algorithmic checks (signature, chain, dates, name) with risk assessment (CA trust and key hygiene) to confidently know who you are talking to.

Public keys are exchanged over an insecure connection can be modified by a man in the middle attacker. The client needs a way to validate that the public key it received from the server has not been tampered with. Using X.509 digital certificate the client can determine who the public key belongs to.
DigiCert Certificate authority with a full list of certificates of the certificate authority
Details Links for the certificate of the DigiCert TLS Hybrid ECC SHA384 2020 CA1 certificate authority
How trust is established by following the certificate chain to a trusted root certificate authority. Hint read this diagram from the bottom to the top.

Summary

  • X.509 certificates contain a public key and metadata about who owns the key and who issued it.
  • The three key certificate fields developers need to know are Subject (owner identity), Issuer (certificate authority), and Validity (time range).
  • Subject Alternative Name (SAN) extension lists network addresses like DNS names, emails, IP addresses, or URIs.
  • Certificate authorities (CAs) digitally sign certificates to prove authenticity and prevent tampering.
  • Root CAs are self-signed and pre-installed in operating systems, while intermediate CAs create a safer trust hierarchy.
  • Certificate verification follows a chain of trust from end-entity certificate to intermediate CA to trusted root CA.
  • Common certificate formats include PEM (text-based), DER (binary), and PKCS#12 (can store multiple certificates and keys).
  • Certificate validation checks digital signatures, validity dates, and that the CA is trusted.
  • Certificate revocation lists (CRLs) track stolen or compromised certificates that should no longer be trusted.
  • OpenSSL command-line tools can inspect, verify, and create certificates for testing and development.

FAQ

Why can’t I just trust any public key I receive?Because key exchange often happens before a secure channel exists, an attacker could swap in their own public key (man-in-the-middle). X.509 certificates and PKI bind a public key to an identity and let you verify that binding so you know whose key you’re using.
Which X.509 certificate fields matter most to developers?The big three are: - Subject/Subject Alternative Name (SAN): who the key belongs to (DNS, IP, email, URI) - Issuer: which Certificate Authority (CA) created the certificate - Validity: the “notBefore” and “notAfter” time window when the cert is usable
What’s the difference between Subject and SAN, and how are hostnames validated?- Subject identifies the primary entity; historically includes attributes like C, ST, O, CN. - SAN is the authoritative place for identifiers (e.g., DNS names). Clients validate the server by matching the requested hostname to a DNS entry in SAN. Wildcards like *.example.com are allowed. Avoid IPs in SAN because ownership can change and is hard to verify.
How do I download and inspect a website’s certificate with OpenSSL?- Fetch and save the cert: echo | openssl s_client -servername github.com -connect github.com:443 2>/dev/null | openssl x509 > github-cert.pem - View key fields in human-readable form: openssl x509 -in github-cert.pem -noout -text
What does the Signature Algorithm field mean and how is integrity verified?It states the algorithm/hash used to sign the certificate (e.g., ECDSA with SHA-384). Verifiers recompute the signature over the certificate’s data and check it using the issuer CA’s public key. If it matches, the cert hasn’t been tampered with.
What are root and intermediate CAs, and how does the chain of trust work?- Root CA: self-signed, pre-installed in OS/browsers (trust store). - Intermediate CA: issued by a root (or another intermediate); used to sign end-entity certs. A client verifies the end-entity cert → intermediate → root. If the chain links to a trusted root, the certificate is trusted (subject to other checks).
What does “unable to get local issuer certificate” mean, and how do I fix it?It means the verifier can’t find the issuer CA needed to build the chain (often a missing intermediate). Fixes: - Provide the intermediate via -CAfile/-CApath or include the full chain on the server. - Ensure your trust store is up to date. - Use openssl verify -show_chain to see what’s missing.
What do the Validity dates imply, and why prefer short-lived certificates?notBefore is when the cert becomes valid; notAfter is when it expires. Short lifetimes reduce risk from key compromise and operational mistakes. Many ecosystems now favor 90-day or even minutes-long certs (for automated issuance/signing) to limit exposure.
How is revocation handled, and why can’t key theft be auto-detected?Key theft leaves no inherent signal. Owners report compromise to the CA, which then publishes revocation via CRLs or OCSP. Clients consult these to learn a cert’s status. Until reported, a stolen key can be abused.
What are the most common certificate validation failure reasons?- Expired or not yet valid (clock skew) - Hostname mismatch (SAN doesn’t match requested DNS) - Untrusted issuer or missing intermediate(s) - Revoked certificate (CRL/OCSP) - Disallowed Key Usage/Extended Key Usage - Weak/unsupported algorithms or parameters - Self-signed or private CA not added to trust store

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Software Security for Developers ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Software Security for Developers ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Software Security for Developers ebook for free