Lion Cipher Lab

Validate X.509 Certificate Paths From Scratch (and Break the Naive Ones)

Why it matters

Every TLS handshake your browser makes depends on certificate-path validation being correct, and the history of web PKI is a graveyard of validators that got it subtly wrong — the most famous being the class of bug where a validator forgets to check basicConstraints, letting anyone with a legitimately-issued leaf certificate mint trusted-looking certs for any domain they like. Building the validator yourself, then removing one check at a time and watching a forged victim.com certificate sail through, moves 'validate the chain' from a phrase in a diagram to something you understand at the…

What you'll learn

Steps in this lab

  1. What path validation is, and why we build it to break it
  2. Set up Python and the cryptography library
  3. Generate a 3-cert hierarchy plus the attacker's material
  4. Write the from-scratch validator
  5. Run the honest chain: it should be VALID
  6. The headline bug: skip basicConstraints and impersonate any CA
  7. Three more classic omissions: expiry, anchoring, and pathLen
  8. The judgment call: never ship this in production

Open the full interactive lab →