Skip to content

fix: bound BasicConstraints ASN.1 parsing#41

Open
leanthebean wants to merge 1 commit into
base:mainfrom
leanthebean:security/bound-basic-constraints-asn1
Open

fix: bound BasicConstraints ASN.1 parsing#41
leanthebean wants to merge 1 commit into
base:mainfrom
leanthebean:security/bound-basic-constraints-asn1

Conversation

@leanthebean

Copy link
Copy Markdown
Contributor

Summary

Fixes CAT finding 7596fd8c-ca58-496f-81bc-c8e71c2ad57a.

The BasicConstraints verifier previously called firstChildOf on the decoded extension value unconditionally. For an empty BasicConstraints SEQUENCE (30 00), that made the ASN.1 walker parse the next byte outside the BasicConstraints container, and the escaped node could influence the cA / pathLenConstraint decision.

This change:

  • treats an empty BasicConstraints SEQUENCE as cA=false without traversing children;
  • bounds every parsed BasicConstraints child against the extension SEQUENCE end before consuming it;
  • rejects unknown BasicConstraints fields and trailing fields after pathLenConstraint;
  • keeps valid encodings supported: client 30 00, CA 30 03 01 01 ff, and CA with pathLen 30 06 01 01 ff 02 01 00.

Security Impact

This removes the parser-bounds escape from the PKI trust gate. The existing coincidental mitigations still made the finding non-weaponizable against the current AWS Nitro profile, but the verifier no longer relies on adjacent extension ordering or outer signature-algorithm bytes for safety.

Tests

  • forge test --match-path test/CertManager.t.sol -vvv
  • forge test

Comment thread src/CertManager.sol
require(ca == isCA, "isCA must be true for CA certs");

if (certificate[basicConstraintsPtr.header()] == 0x02) {
maxPathLen = int64(uint64(certificate.uintAt(basicConstraintsPtr)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reject zero-length pathLenConstraint before calling uintAt; otherwise an in-bounds 02 00 child still makes uintAt read ptr.content() outside the BasicConstraints SEQUENCE and can accept the malformed INTEGER as 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants