Skip to content

Test ASN1_TYPE parsing more extensively - #3345

Draft
nebeid wants to merge 1 commit into
aws:mainfrom
nebeid:sweep-asn1-type-tests
Draft

Test ASN1_TYPE parsing more extensively#3345
nebeid wants to merge 1 commit into
aws:mainfrom
nebeid:sweep-asn1-type-tests

Conversation

@nebeid

@nebeid nebeid commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Description of changes:

BoringSSL commit 074b6dad0: "Test ASN1_TYPE parsing more extensively"

Test-only. Expands ASN1Test.ASN1Type in crypto/asn1/asn1_test.cc:

  • More accepted types (INTEGER/ENUMERATED positive and negative, IA5String, UTF8String, BMPString, UniversalString), each checked for ASN1_TYPE_get/type/ASN1_STRING_type consistency, round-tripped through i2d_ASN1_TYPE, and additionally exercised embedded as X509_ALGOR AlgorithmIdentifier parameters
  • A table of invalid encodings that must be rejected, including the CVE-2016-2108-adjacent guards (tag [UNIVERSAL 258] colliding with V_ASN1_NEG_INTEGER, tag-number overflow)
  • Renames InvalidASN1Type to EncodeInvalidASN1Type for clarity

In AWS-LC, ASN1_TYPE is consumed beyond X509_ALGOR — PKCS#7 (d.other, signed attributes), X509_ATTRIBUTE values (CSR/PKCS#8/PKCS#12), and OCSP — so this coverage matters more here than upstream.

Adaptations for AWS-LC:

  • Replaced CBB_add_asn1_element (not in AWS-LC) with CBB_add_asn1 + CBB_add_bytes (identical DER); replaced C++17 std::vector CTAD with explicit std::vector<uint8_t>
  • AWS-LC intentionally accepts BER constructed strings and EOC for OpenSSL/PKCS#7 compatibility (PRs Reinstate indefinite length and [UNIVERSAL 0] support in crypto/asn1 #2306, Reinstate support for constructed strings in crypto/asn1 #2310) and does not validate UTF8String contents. Upstream's test expects these rejected; they are instead pinned as accepted via ExpectParse with a comment noting the intent, so a change in either direction is caught
  • Unknown universal tags ≤ V_ASN1_MAX_UNIVERSAL parse as ASN1_STRING with type == tag in AWS-LC (BoringSSL uses V_ASN1_OTHER); the [UNIVERSAL 128] row asserts our representation

Testing:

Built with cmake/ninja (clang, Release); full ASN1Test suite passes (51 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.

Cherry-picked from BoringSSL 074b6dad0ca0fbb2087b7a85e828c666746bf61a.

We should be able to parse a variety of valid types, and also reject
syntax errors in any types that we recognize. Also double-check that
nothing went wrong in the translation from i2d_ASN1_TYPE to X509_ALGOR.

Adapted for AWS-LC:
- Dropped upstream's claim that X509_ALGOR is "basically the only use
  of ASN1_TYPE in the library": in AWS-LC, ASN1_TYPE is also consumed
  by PKCS#7 (d.other content and signed attributes), X509_ATTRIBUTE
  values (CSR/PKCS#8/PKCS#12 paths), and OCSP, so this test covers
  more surface here than upstream
- Replaced CBB_add_asn1_element (not in AWS-LC) with CBB_add_asn1 +
  CBB_add_bytes, producing identical DER
- Replaced C++17 std::vector CTAD with explicit std::vector<uint8_t>
- AWS-LC intentionally accepts BER constructed strings and EOC for
  OpenSSL/PKCS#7 compatibility (see PRs aws#2306, aws#2310), and does not
  validate UTF8String contents; moved those inputs from the invalid
  table to explicit ExpectParse acceptance pins with a comment noting
  the intent
- Unknown universal tags <= V_ASN1_MAX_UNIVERSAL parse as ASN1_STRING
  with type == tag number (BoringSSL uses V_ASN1_OTHER); adapted the
  [UNIVERSAL 128] row accordingly

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

🔒 Security ReviewView Report

Please review before merging.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.19%. Comparing base (c2f5a00) to head (c3d6eb5).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3345      +/-   ##
==========================================
+ Coverage   78.16%   78.19%   +0.02%     
==========================================
  Files         693      693              
  Lines      123954   123989      +35     
  Branches    17212    17214       +2     
==========================================
+ Hits        96892    96954      +62     
+ Misses      26141    26116      -25     
+ Partials      921      919       -2     

☔ 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