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:
- Issue certificates
- Revoke compromised certificates
- Maintain certificate directory
- Generate and manage CA's key pair
Types:
- Root CA β Top of trust hierarchy (e.g., DigiCert, Let's Encrypt)
- Intermediate CA β Issued by Root CA, issues end-entity certificates
- Internal CA β Enterprise PKI (Active Directory Certificate Services)
2. Registration Authority (RA)
Verifies identity before CA issues certificate.
Functions:
- Accept certificate requests
- Verify requestor identity
- Approve/reject requests
- Forward approved requests to CA
3. Certificate Repository
Publicly accessible database of certificates and CRLs.
Contains:
- Issued certificates
- Certificate Revocation Lists (CRLs)
- CA public keys
4. End Entities
Users, devices, or systems that request and use certificates.
Examples:
- Web servers (HTTPS)
- Email clients (S/MIME)
- VPN clients
- Code signing (developers)
π 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:
- Subject β Certificate owner (CN=Common Name)
- Issuer β CA that signed certificate
- Public Key β Owner's public key
- Validity Period β Start and expiration dates
- Signature β CA's digital signature (proves authenticity)
π 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:
- Checking CA signature
- Verifying validity period
- Checking revocation status (CRL/OCSP)
- Validating trust chain to root CA
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)
- Encrypt emails using recipient's public key
- Sign emails with sender's private key
3. Code Signing
- Developers sign software with private key
- Users verify authenticity with certificate
4. VPN Authentication
- Certificate-based authentication (better than passwords)
5. Document Signing
- PDF digital signatures
- Legal validity
6. Device Authentication
- IoT devices
- Client certificates (mutual TLS)
π 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?
- Protect Root CA (kept offline)
- If Intermediate compromised, revoke only that CA
- Root CA remains trusted
β οΈ PKI Security Threats
1. Compromised Private Key
If private key stolen β attacker can impersonate owner.
Mitigation:
- Use Hardware Security Module (HSM) for key storage
- Strong access controls
- Immediate revocation if compromised
2. Man-in-the-Middle (MitM)
Attacker intercepts and presents fake certificate.
Mitigation:
- Certificate pinning
- HSTS (HTTP Strict Transport Security)
- Monitor for suspicious certificates (Certificate Transparency logs)
3. Compromised CA
If CA compromised, attacker can issue fraudulent certificates.
Real-world: DigiNotar (2011), Comodo (2011)
Mitigation:
- Certificate Transparency (CT) logs
- Multiple trust anchors
- CA security audits
4. Certificate Expiration
Expired certificates break services.
Mitigation:
- Automated renewal (Let's Encrypt, ACME protocol)
- Monitoring and alerts
π PKI Standards
- X.509 β Certificate format standard
- PKCS (Public Key Cryptography Standards) β RSA Security standards
- CRL β Revoked certificates list
- OCSP (Online Certificate Status Protocol) β Real-time revocation check
- ACME (Automated Certificate Management Environment) β Let's Encrypt protocol
π 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?
- Framework for managing digital certificates and public-key encryption
- Enables secure HTTPS, email encryption, code signing
- Based on asymmetric cryptography (public/private keys)
- Certificate Authority (CA) is root of trust
- Critical for secure digital communications and Authentication
Q: How does certificate validation work?
Process:
- Client receives certificate from server
- Verifies certificate signature using CA's public key
- Checks validity period (not expired)
- Checks revocation status (CRL or OCSP)
- Validates entire chain up to trusted root CA
- 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:
- Immediately contacted CA to revoke certificate
- CA added certificate to CRL and updated OCSP
- Generated new key pair
- Requested new certificate from CA
- Deployed new certificate to server
Result: Revoked certificate no longer trusted by clients; new secure certificate deployed within 4 hours.
π Related Concepts
- Certificate Revocation Lists (CRLs) β Revocation mechanism
- Authentication β Primary use case
- Hardware Security Module (HSM) β Secure key storage
- Key Management Lifecycle (KML) β Full key lifecycle
- Asymmetric key distribution β Key exchange