Skip to main content
Cryptography Basics
CHAPTER 10

Public Key Infrastructure (PKI)

Updated: May 15, 2026
20 min read

# CHAPTER 10

Public Key Infrastructure (PKI)

1. Introduction

In the TLS handshake, a web server sends your browser a Digital Certificate containing its Public Key. But what stops a hacker from creating a fake certificate that says "I am Google," giving you their *own* Public Key, and intercepting your search history? The answer lies in trust. We need a system that rigorously verifies identities before handing out certificates. This system is the Public Key Infrastructure (PKI). In this chapter, we will explore Certificate Authorities, the Chain of Trust, and the lifecycle of digital certificates.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Define Public Key Infrastructure (PKI).
  • Understand the role of a Certificate Authority (CA).
  • Explain the concept of the "Chain of Trust."
  • Differentiate between a Root CA and an Intermediate CA.
  • Understand the risks of Self-Signed Certificates.

3. Beginner-Friendly Explanation

Imagine getting a passport.
  • If you write your own name on a piece of cardboard and say "I am Alice," border security will laugh at you. This is a Self-Signed Certificate. It proves nothing.
  • Instead, you go to a government passport office. You show them your birth certificate and utility bills.
  • The government verifies your identity and issues you a Passport.
  • When you travel, border security doesn't know you, but they trust the government. Because the government stamped your passport, they trust you.
  • In the digital world, the government office is the Certificate Authority (CA), and your passport is your Digital Certificate.

4. What is a Certificate Authority (CA)?

A Certificate Authority (like DigiCert, Let's Encrypt, or GoDaddy) is a globally trusted organization. Their job is to verify that a person or company actually owns a specific domain name (like amazon.com) before issuing them a Digital Certificate for that domain. When the CA issues the certificate, they use their own highly-guarded Private Key to place a Digital Signature on it.

5. The Chain of Trust

How does your browser know which CAs to trust? When you install Chrome, Firefox, or Windows, the operating system comes pre-installed with a "Root Store"—a list of about 100 highly trusted Root CAs. The trust flows downwards:
  1. 1. Root CA: The ultimate authority. Their Private Keys are locked in physical bank vaults offline. They sign the certificates of the Intermediate CAs.
  1. 2. Intermediate CA: The middle-managers. They do the daily work of issuing certificates to websites.
  1. 3. End-Entity Certificate (The Website): This is the certificate amazon.com sends your browser.
When your browser receives amazon.com's certificate, it checks the signature. It sees the signature belongs to an Intermediate CA. It then checks the Intermediate CA's signature, tracing it all the way up the chain until it reaches a Root CA that it has trusted since the day your computer was manufactured. This is the Chain of Trust.

6. Certificate Revocation

What happens if a company's web server is hacked and their Private Key is stolen? The hackers could use the stolen key and the valid certificate to set up a fake website. The company must immediately tell the CA to Revoke the certificate (cancel the passport). Browsers check if a certificate is revoked using two methods:
  • CRL (Certificate Revocation List): A giant list of bad certificates downloaded by the browser. (Inefficient).
  • OCSP (Online Certificate Status Protocol): The browser pings the CA in real-time asking, "Is this specific certificate still valid?"

7. Mini Project: Create a Self-Signed Certificate

Developers often create Self-Signed certificates to test HTTPS on their local machines before buying a real one from a CA. Let's create one using OpenSSL.

Step-by-Step Walkthrough:

  1. 1. Generate a Private Key and a Self-Signed Certificate simultaneously:
``bash openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes `
  1. 2. Fill out the Prompts: It will ask for your Country, State, and Common Name (Domain). You can type anything (e.g., localhost).
  1. 3. The Result: You now have a key.pem (Private Key) and cert.pem (Your self-signed passport).
  1. 4. The Catch: If you install this on a web server and visit it in Chrome, Chrome will throw a massive red warning: ERRCERTAUTHORITYINVALID. Chrome is saying: *"This passport was signed by you, not a recognized CA. I do not trust you."*

8. Real-World Scenarios

In 2011, a Dutch Certificate Authority named DigiNotar was hacked. The attackers managed to breach the CA's internal network and access the CA's Private Key. The hackers used this key to issue themselves fraudulent, but mathematically valid, certificates for
google.com. They used these fake certificates to perform Man-in-the-Middle attacks on Iranian citizens, intercepting their Gmail communications. Because the Root CA was compromised, the entire Chain of Trust collapsed. When the breach was discovered, Apple, Microsoft, and Google permanently deleted DigiNotar from their Root Stores, instantly destroying the company's business model.

9. Best Practices

  • Automated Lifecycle Management: Certificates expire (usually after 1 year, or 90 days for Let's Encrypt). If a certificate expires, the website immediately goes offline for all users. Organizations must automate certificate renewal (using protocols like ACME) to prevent catastrophic, human-error outages.
Setting up an internal, private Certificate Authority (a Private PKI) is standard practice for large enterprises to secure internal communications. However, IT administrators must manually install the Private Root CA onto every employee's computer. This grants the IT department the technical capability to intercept and decrypt employee HTTPS traffic.

11. Exercises

  1. 1. Explain the purpose of the "Chain of Trust." Why don't Root CAs issue certificates directly to end-user websites?
  1. 2. Describe the difference between a Certificate Authority (CA) and a Certificate Revocation List (CRL).

12. FAQs

Q: Why do browsers warn me against Self-Signed Certificates? A: Because there is no independent third party verifying identity. A hacker can easily generate a self-signed certificate for
bank.com. If your browser didn't warn you, you would connect to the hacker's server, establishing a perfectly encrypted connection directly to the criminal.

13. Interview Questions

  • Q: Describe the architecture of Public Key Infrastructure (PKI). Detail the hierarchical relationship between a Root CA, an Intermediate CA, and an End-Entity certificate.
  • Q: A user is receiving an ERRCERTDATEINVALID` error when visiting your application. Explain the root cause of this issue and the PKI lifecycle management failure it represents.

14. Summary

In Chapter 10, we solved the problem of digital trust. We defined Public Key Infrastructure (PKI) as the ecosystem that binds public keys to real-world identities. We learned that Certificate Authorities (CAs) act as digital passport offices, utilizing Digital Signatures to create an unbreakable Chain of Trust originating from a pre-installed Root Store. Finally, we explored the risks of expired or compromised certificates, emphasizing the necessity of robust certificate lifecycle management.

15. Next Chapter Recommendation

TLS and PKI secure web traffic. But what about securing remote server administration, or creating private networks over the internet? Proceed to Chapter 11: Secure Communication Protocols.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·