fix(pilot-ca): validate IsCA and BasicConstraints in loadRoot (PILOT-139)#5
Conversation
Add TestLoadRoot_NotCA: generates a self-signed leaf-like cert (IsCA=false), writes it as root.crt, and asserts loadRoot returns an error. Currently fails — loadRoot does not validate IsCA.
…139) loadRoot parses root.crt and uses it as signing root for issueBeacon without checking that the certificate is a CA. A swapped root.crt (self-signed non-CA) would silently produce invalid cert chains rejected by compliant TLS verifiers. Add two guards after x509.ParseCertificate: - !crt.IsCA → error - !crt.BasicConstraintsValid → error Fixes PILOT-139.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
📋 PR Status —
|
🔍 Change Walkthrough —
|
What
loadRoot() parses root.crt and uses it as a signing root for issueBeacon without checking that the certificate is a CA. If root.crt is swapped with a self-signed non-CA cert, issueBeacon silently produces invalid cert chains that get rejected by spec-compliant TLS verifiers.
Fix
Added two guards in loadRoot() after
x509.ParseCertificate:!crt.IsCA→ error: "root.crt: certificate is not a CA (IsCA=false)"!crt.BasicConstraintsValid→ error: "root.crt: basic constraints missing or invalid"Verification
go build ./...✅go vet ./...✅go test ./...✅ (all 23 tests pass, including new TestLoadRoot_NotCA)Files changed
main.go— +6 lines in loadRoot()zz_load_test.go— +60 lines (TestLoadRoot_NotCA: non-CA cert → rejected)Closes PILOT-139