← All Exercises
Verify a Certificate Chain End to End
intermediatejavascript
Background
Clients fail handshakes for a small number of structural reasons. Encoding those reasons as data turns certificate debugging into a repeatable check.
Problem
Walk a presented chain from leaf to root and report broken links, leaf expiry, and an untrusted root as sorted reason codes.
Input
JSON object: { chain: [{ subject, issuer, expiresInDays }] } ordered leaf → rootOutput
JSON object: { valid: boolean, reasons: string[] }Sample tests
Sample 1
Input: {"chain":[{"subject":"leaf","issuer":"intermediate","expiresInDays":30},{"subject":"intermediate","issuer":"root","expiresInDays":300},{"subject":"root","issuer":"root","expiresInDays":3000}]}Expected: {"valid":true,"reasons":[]}Sample 2
Input: {"chain":[{"subject":"leaf","issuer":"intermediate","expiresInDays":0},{"subject":"intermediate","issuer":"other-root","expiresInDays":300}]}Expected: {"valid":false,"reasons":["expired:leaf","untrusted-root"]}Your solution
Learning objective
Diagnose handshake failures from chain structure rather than guessing at the certificate store.