Skip to content

Clear the extension list when removing the last extension - #3344

Draft
nebeid wants to merge 4 commits into
aws:mainfrom
nebeid:sweep-x509-delete-last-ext
Draft

Clear the extension list when removing the last extension#3344
nebeid wants to merge 4 commits into
aws:mainfrom
nebeid:sweep-x509-delete-last-ext

Conversation

@nebeid

@nebeid nebeid commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Description of changes:

Cherry-picks three BoringSSL commits in the x509 area:

1. 40e035a9e: "Clear the extension list when removing the last extension"

Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension — a present-but-empty extensions list is invalid DER. A new static delete_ext helper in crypto/x509/x509_ext.c frees the list and nulls the pointer when the last extension is deleted, so re-encoding omits the field. Applied to X509_delete_ext, X509_CRL_delete_ext, and X509_REVOKED_delete_ext. Adds a DeleteLastExtension test covering all three paths.

2. dba32d768: "Refresh basic constraints test certificates"

The six basic_constraints_*.pem test certs were generated by an old Go whose encoder emitted exactly the present-but-empty extensions field fixed above (go.dev/cl/399827). Certificates taken verbatim from upstream (upstream reran make_basic_constraints.go); our previous copies were byte-identical to upstream's pre-refresh ones.

3. f3230c304: "Test verifying signatures over 'unusual' TBSCertificates"

Adds 7 test certificates with legal-but-unusual or accepted-but-noncanonical TBS encodings (unique IDs, explicit v1, NULL sigalg params, empty extension list, inverted RDN order) plus the generator and key, verifying that signature verification uses the cached TBSCertificate bytes.

A fourth commit updates generated-src/ for the new test data (tests/check_generated_src.sh passes).

Adaptations for AWS-LC:

Testing:

Built with cmake/ninja (clang, Release); full X509Test suite passes (106 tests).

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

davidben and others added 4 commits July 10, 2026 14:17
Cherry-picked from BoringSSL 40e035a9e5d721b3b7c15c46259d782ffe7d9e96.

The extensions list in a certificate, CRL, and CRL entry is defined as:

... extensions      [3]  EXPLICIT Extensions OPTIONAL ...
... crlEntryExtensions      Extensions OPTIONAL ...
... crlExtensions           [0]  EXPLICIT Extensions OPTIONAL ...

Extensions  ::=  SEQUENCE SIZE (1..MAX) OF Extension

This means that a present but empty extensions list is actually invalid.
Rather, if you have no extensions to encode, you are meant to omit the
list altogether. Fix the delete_ext functions to handle this correctly.

Adapted for AWS-LC:
- crypto/x509/x509_ext.c is a C file (upstream's is C++), so nullptr
  becomes NULL in the new delete_ext helper
- Test added at the end of x509_test.cc after AWS-LC-only tests
- Fixed two upstream test nits: the "second extension" round now adds
  ext2 (upstream created ext2 but never used it), and a comment typo
  ("but not list at all" -> "but no list at all")

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Cherry-picked from BoringSSL dba32d768e2b48359f17ed2f094347f6a1dfc7f4.

Older versions of Go did not encode extension-less certificates
correctly. See https://go-review.googlesource.com/c/go/+/399827

Rerun the script now that the bug is fixed.

Adapted for AWS-LC:
- None. The six certificates are taken verbatim from the upstream
  commit (upstream reran crypto/x509/test/make_basic_constraints.go);
  they were not regenerated locally. Our previous copies were
  byte-identical to upstream's pre-refresh ones.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Cherry-picked from BoringSSL f3230c304a6e77b78d43e52b3ab4da013272d318.

Test that, signatures over unusual TBSCertificates are verified
correctly. This tests that encoding is correctly round-tripped through
the parser to the verifier.

In principle, this should never happen because a DER parser will only
accept the canonical encoding of an object. However, it is possible for
encoding to not round-trip if we accept any BER inputs, or our in-memory
representation does not capture the full range of abstract
TBSCertificate values.

X509 objects cache the encoded TBSCertificate, so all encoding
variations should be captured. This test tries to exercise the cache's
effects on signature verification.

Adapted for AWS-LC:
- Rewrote the "cache is barely load-bearing" paragraph of the test
  comment: unlike BoringSSL, AWS-LC supports BER inputs in the ASN1
  macro parsers for OpenSSL compatibility (see PRs aws#2306 and aws#2310),
  so verification must use the cached TBSCertificate bytes
- Registered the new test PEMs in sources.cmake (upstream uses
  gen/sources.*)
- Added .c_str() for GetTestData() results; AWS-LC's CertFromPEM and
  PrivateKeyFromPEM take const char*

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov-commenter

codecov-commenter commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.72340% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.19%. Comparing base (c2f5a00) to head (81c031e).
⚠️ Report is 82 commits behind head on main.

Files with missing lines Patch % Lines
crypto/x509/x509_ext.c 62.96% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3344      +/-   ##
==========================================
+ Coverage   78.16%   78.19%   +0.02%     
==========================================
  Files         693      693              
  Lines      123954   123982      +28     
  Branches    17212    17215       +3     
==========================================
+ Hits        96892    96948      +56     
+ Misses      26141    26113      -28     
  Partials      921      921              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

3 participants