PKI & Authentication

Every time your browser visits https://bank.com, two things must be true: the traffic is encrypted and you are talking to the real bank, not an imposter. Public Key Infrastructure (PKI) is the machinery that makes the second guarantee possible. Without it, public-key cryptography is wide open to a devastating man-in-the-middle (MITM) attack.

The Key-Authenticity Problem

In a basic public-key exchange, Alice sends her public key to Bob. Nothing stops Mallory from intercepting that transmission and substituting her own public key. Bob now encrypts data that only Mallory can read; Mallory decrypts it, re-encrypts with Alice's real key, and forwards it — neither party notices the interception.

Alice ──(Alice's pub key)──► Mallory ──(Mallory's pub key)──► Bob
Alice ◄──[secret data]◄──── Mallory ◄──[secret data]◄─────── Bob

Fundamental problem: Bob cannot tell whether the public key he received actually belongs to Alice.

Solution: Involve a trusted third party that binds an identity to a public key in a tamper-evident document called a digital certificate, and signs that document with its own private key. Because the certificate cannot be forged, Bob can verify it and learn the true owner of the key.

Digital Certificates and X.509

A digital certificate (standardized as X.509) is a data structure containing:

Field Purpose
Subject Identity being certified (e.g., CN=www.paypal.com)
Subject Public Key The public key that belongs to the subject
Issuer The CA that signed this certificate
Validity Period Not Before / Not After dates
Serial Number Unique identifier assigned by the CA
Signature CA's digital signature over all the above fields

The CA signs the certificate with its private key. Anyone who has the CA's public key can verify the signature, confirming that the binding of identity to public key has not been tampered with.

openssl s_client -showcerts -connect www.paypal.com:443 </dev/null
openssl x509 -in paypal.pem -text -noout     # decode the certificate

Certificate Authorities and the Chain of Trust

A Certificate Authority (CA) is the trusted party that:

  1. Verifies that the applicant controls the domain or identity claimed in the certificate request (Certificate Signing Request, or CSR).
  2. Signs the certificate with its own private key.

CAs are organized in a hierarchy:

Root CA  (self-signed)
  ├── Intermediate CA 1
  │     └── Sub CA ── Domain Owner 1
  └── Intermediate CA 2
        ├── Sub CA 1 ── Domain Owner 2
        └── Sub CA 2 ── Domain Owner 3

This layered design limits risk: root CA private keys are kept offline and almost never used directly; intermediate CAs do day-to-day signing.

Getting a Certificate (the CSR flow)

  1. Generate a key pair (openssl genrsa).
  2. Create a CSR with your identity information (openssl req -new).
  3. Send the CSR to a CA. The CA verifies your identity and signs the certificate.
  4. Install the issued certificate on your server (e.g., Apache SSLCertificateFile).

Certificate Revocation

A certificate may need to be invalidated before it expires (compromised private key, domain change). Two mechanisms:

Mechanism How it works Drawback
CRL (Certificate Revocation List) CA publishes a signed list of revoked serial numbers Clients must download the full list; may be stale
OCSP (Online Certificate Status Protocol) Client queries CA in real time for one certificate's status Adds latency; CA learns browsing patterns
OCSP Stapling Server fetches its own OCSP response and "staples" it to the TLS handshake Solves latency and privacy concerns

How TLS Uses Certificates

During a TLS handshake the server presents its certificate. The client:

  1. Verifies the CA's signature on the certificate.
  2. Walks the certificate chain up to a root CA in its trust store.
  3. Checks validity dates and revocation status.
  4. If everything checks out, uses the server's public key to establish a shared session key.

This is why a compromised CA is catastrophic: a CA that has been subverted can issue fraudulent certificates for any domain, enabling MITM attacks against any site signed by that CA.

Entity Authentication

Authentication is the process of verifying that an entity is who it claims to be. Three classic factors:

Factor Description Examples
Something you know A secret the user memorizes Password, PIN, security question
Something you have A physical object the user possesses Hardware token, smart card, TOTP app
Something you are A biological characteristic Fingerprint, face, iris, voice

Single-factor systems (e.g., password only) are weaker; multi-factor authentication (MFA / 2FA) requires at least two different factor types. Either factor alone is useless without the other.

Passwords and Secure Storage

Passwords are the most common "something you know" factor but are routinely misused.

Storing passwords safely:

Why a fast hash like MD5 or SHA-256 is wrong for passwords:
A GPU array can compute billions of SHA-256 hashes per second. Argon2 (the 2015 Password Hashing Competition winner) lets you tune memory and CPU cost so that each guess takes tens of milliseconds on the attacker's hardware, but verification on your server is still fast enough to be imperceptible.

Password attacks:

Password hygiene rules: use long, randomly generated passwords, never reuse passwords across sites, and consider a password manager.

Multi-Factor Authentication and FIDO/WebAuthn

2FA adds a second factor — typically a time-based one-time password (TOTP) from an authenticator app (Duo, Authy, Google Authenticator), an SMS code, or a hardware security key.

FIDO2 / WebAuthn goes further by using public-key cryptography directly for authentication. The security key or device stores a private key that never leaves the hardware; the server holds only the corresponding public key. Because no shared secret is transmitted, FIDO2 is phishing-resistant by design.

Challenge-response is the underlying pattern: the server sends a random challenge r; the client responds with f(r) (e.g., HMAC-SHA1 of r with the shared or private key). Because each challenge is unique, a replay of the response is useless.

Phishing: The Main Authentication Threat

All of the above mechanisms can be bypassed by phishing — tricking the user into voluntarily submitting credentials to a fake site. A certificate only proves that the server controls the domain; it says nothing about whether the domain is trustworthy. FIDO2/WebAuthn is the strongest defense because the private key response is cryptographically bound to the origin, so a phishing site cannot receive a valid response even if the user enters their PIN.

Key Takeaways

Practice

  1. In the man-in-the-middle attack on a public-key exchange, what does Mallory do after intercepting Alice's public key?
  2. Which of the following fields is present in an X.509 certificate but NOT typically included in a plain RSA public key file?
  3. A root CA's certificate is self-signed. How do browsers and operating systems know to trust it?
  4. An attacker obtains a copy of a password database whose entries are stored as SHA-256(password) with no salt. Which attack becomes dramatically cheaper compared to a properly salted, key-stretched database?
  5. What does OCSP Stapling solve compared to basic OCSP?
  6. A site uses password + SMS code for login (2FA). An attacker sends a convincing phishing email that tricks the victim into entering both factors on a fake site. Which additional technology would have prevented the attacker from using the captured credentials on the real site?
  7. During TLS handshake verification of a server certificate, which step establishes that the certificate was issued by a CA the client trusts?
  8. A developer stores user passwords as bcrypt(salt + password) in the database. A separate team suggests switching to SHA-256(password) because 'SHA-256 is a stronger, more modern hash.' Explain why the developer's current approach is in fact better for password storage.
  9. A company's intermediate CA is compromised and its private key is stolen. Explain what harm the attacker can do and why certificate revocation is essential in this scenario.