Public Key Infrastructure

Public Key Infrastructure (PKI)

One-liner: Framework of policies, hardware, software, and processes that manage digital certificates and public-key encryption.

🎯 What Is It?

Public Key Infrastructure (PKI) is the foundation of secure digital communications. It enables encryption, digital signatures, and authentication using asymmetric cryptography (public/private key pairs). PKI is essential for HTTPS, email encryption, code signing, and device authentication.

🏽️ PKI Components

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    Certificate Authority (CA)  β”‚  ← Root of trust
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚
             β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
             β”‚                        β”‚
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”
     β”‚  Registration   β”‚      β”‚  CRL/OCSP β”‚
     β”‚   Authority (RA) β”‚      β”‚  Repository  β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”
     β”‚  End Entities   β”‚  ← Users, servers, devices
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

1. Certificate Authority (CA)

Trusted entity that issues and manages digital certificates.

Functions:

Types:

2. Registration Authority (RA)

Verifies identity before CA issues certificate.

Functions:

3. Certificate Repository

Publicly accessible database of certificates and CRLs.

Contains:

4. End Entities

Users, devices, or systems that request and use certificates.

Examples:

πŸ“œ Digital Certificate Structure

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  X.509 Certificate          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Version: 3                  β”‚
β”‚ Serial Number: 123456       β”‚
β”‚ Signature Algorithm: SHA256 β”‚
β”‚ Issuer: CN=DigiCert CA      β”‚
β”‚ Valid From: 2024-01-01      β”‚
β”‚ Valid To: 2025-01-01        β”‚
β”‚ Subject: CN=example.com     β”‚
β”‚ Public Key: RSA 2048-bit    β”‚
β”‚ Extensions:                 β”‚
β”‚   - Key Usage               β”‚
β”‚   - Subject Alternative Nameβ”‚
β”‚   - CRL Distribution Points β”‚
β”‚ Signature: <CA signature>   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Fields:

πŸ”„ Certificate Lifecycle

1. Key Generation

User generates key pair:
  - Private key (kept secret)
  - Public key (sent in certificate request)

2. Certificate Request (CSR)

# Generate CSR
openssl req -new -newkey rsa:2048 -nodes \
  -keyout private.key \
  -out request.csr \
  -subj "/CN=example.com"

3. Identity Verification

RA/CA verifies requestor identity (domain ownership, organization, etc.).

4. Certificate Issuance

CA signs certificate with its private key and issues it.

5. Certificate Deployment

Certificate installed on server/device.

6. Certificate Validation

Clients verify certificate by:

7. Key Rotation

Periodically renew certificates before expiration.

8. Key Revocation

If compromised, CA revokes certificate via CRL or OCSP.

9. Key Destruction

Securely delete private key when no longer needed.

🎯 Common PKI Use Cases

1. HTTPS/TLS (Web Security)

Browser β†’ Connects to https://example.com
       β†’ Server presents certificate
       β†’ Browser validates certificate
       β†’ Encrypted connection established

2. Email Encryption (S/MIME)

3. Code Signing

4. VPN Authentication

5. Document Signing

6. Device Authentication

πŸ”’ Trust Hierarchy

        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚   Root CA       β”‚  ← Self-signed
        β”‚ (DigiCert)     β”‚     (Trusted by browsers)
        β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”
        β”‚ Intermediate  β”‚  ← Signed by Root CA
        β”‚     CA        β”‚
        β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
               β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”
        β”‚ End-Entity    β”‚  ← example.com certificate
        β”‚  Certificate  β”‚     (Signed by Intermediate)
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Browser trusts Root CA β†’ Validates entire chain

Why Intermediate CAs?

⚠️ PKI Security Threats

1. Compromised Private Key

If private key stolen β†’ attacker can impersonate owner.

Mitigation:

2. Man-in-the-Middle (MitM)

Attacker intercepts and presents fake certificate.

Mitigation:

3. Compromised CA

If CA compromised, attacker can issue fraudulent certificates.

Real-world: DigiNotar (2011), Comodo (2011)

Mitigation:

4. Certificate Expiration

Expired certificates break services.

Mitigation:

πŸ“Š PKI Standards

🎭 Example: Checking a Certificate

# View website certificate
openssl s_client -connect example.com:443 -showcerts

# View local certificate file
openssl x509 -in certificate.crt -text -noout

# Verify certificate chain
openssl verify -CAfile ca-bundle.crt certificate.crt

# Check certificate expiration
openssl x509 -in certificate.crt -noout -enddate

🎀 Interview Angles

Q: What is PKI and why is it important?

Q: How does certificate validation work?

Process:

  1. Client receives certificate from server
  2. Verifies certificate signature using CA's public key
  3. Checks validity period (not expired)
  4. Checks revocation status (CRL or OCSP)
  5. Validates entire chain up to trusted root CA
  6. If all checks pass β†’ trust established

Q: What happens if a certificate is compromised?

STAR Example:
Situation: Server's private key was exposed in a data breach.
Task: Prevent attacker from impersonating the server.
Action: