Repository navigation
PKCS7: reject ANY-typed eContent with trailing bytes after the first element - #11963
night1rider wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Critical ASN.1 ANY parsing flaws can allow verification to succeed while returning bytes not covered by the verified digest.
2 open issues
What changed in this PR
This PR tightens wolfCrypt’s PKCS#7 signed-attribute verification so legacy ANY-typed eContent returns only the element value covered by the messageDigest.
Changes:
- Adds a whole-content span check to reject trailing bytes, including when a precomputed hash is supplied.
- Strips the ANY element’s tag and length after successful verification.
- Adds regression cases for value extraction and trailing-data rejection, including streaming input.
| File | Description |
|---|---|
wolfcrypt/src/pkcs7.c |
Validates ANY content spans and returns the element value. |
tests/api/test_pkcs7.h |
Registers the new regression test in pkcs7_sd. |
tests/api/test_pkcs7.c |
Tests ordinary, precomputed-hash, and streaming verification paths. |
Review effort: Balanced
|
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11963
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-bugs
Not reviewed (no scan target covers them): tests/api/test_pkcs7.h
Coverage: 2 of 2 in-scope changed file(s) opened by the reviewer
Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
Review tier: Lite
6e8d017 to
41462ae
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11963
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-bugs
Not reviewed (no scan target covers them): tests/api/test_pkcs7.h
Coverage: 1 of 2 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_pkcs7.c
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Lite
Fenrir's latest completed scan found no issues; clearing the prior automated change request.
d5f3470 to
6c8b1f3
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Successful ANY verification still exposes tag-and-length bytes instead of value-only content, and the documentation omits the input-buffer lifetime requirement for aliased content.
2 open issues
1 resolved since last review
Review effort: Balanced
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11963
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/pkcs7.h, tests/api/test_pkcs7.h
Coverage: 1 of 2 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_pkcs7.c
Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
Review tier: Lite
6c8b1f3 to
4935cba
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11963
Scan targets checked: wolfssl-bugs
Unchanged since last review (not re-run): wolfcrypt-src, wolfcrypt-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/pkcs7.h, tests/api/test_pkcs7.h
Coverage: 0 of 1 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_pkcs7.c
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Lite
Fenrir's latest completed scan found no issues; clearing the prior automated change request.
There was a problem hiding this comment.
🟡 Changes recommended
Split header/footer verification can accept a shortened ANY element with a matching digest without validating its declared span, leaving a critical verification bypass.
1 open issue
2 resolved since last review
Review effort: Balanced
893944e to
8bfb6e3
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11963
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/pkcs7.h, tests/api/test_pkcs7.h, tests/api/test_tsp.h
Coverage: 3 of 4 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_pkcs7.c
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Lite
b28fb68 to
930aada
Compare
A legacy PKCS#7 ANY-typed eContent (non-OCTET STRING, e.g. a SEQUENCE) must be a single DER element spanning the whole content; a message with unsigned bytes appended after that element is now rejected with ASN_PARSE_E instead of verifying and returning the appended bytes as content. contentIsPkcs7Type is reset per verify so a reused object parses each message afresh.
930aada to
19d5e7c
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11963
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/pkcs7.h, doc/dox_comments/header_files/tsp.h, tests/api/test_pkcs7.h, tests/api/test_tsp.h
Coverage: 2 of 6 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_pkcs7.c, tests/unit-mcdc/test_pkcs7_arg_whitebox.c, tests/unit-mcdc/test_pkcs7_whitebox.c, wolfcrypt/src/tsp.c
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Lite



Legacy PKCS#7 ANY-typed eContent (a non-OCTET STRING element, e.g. a SEQUENCE as RFC 2315 permits) must be a single DER element spanning the whole content. Before this change, a message with extra bytes appended after that element could verify and return the appended bytes as content, even though the messageDigest only covers the first element's value.
This change adds a span check in the signed-attributes verification path: the ANY element must be a single DER element covering the whole eContent, otherwise verification fails with ASN_PARSE_E. Rejected forms are trailing bytes after the element, an indefinite length, and a high-tag-number identifier. The check runs before the precomputed-hash branch, so it applies to both wc_PKCS7_VerifySignedData and wc_PKCS7_VerifySignedData_ex.
pkcs7->content for an ANY-typed eContent reports the whole DER element (contentSz includes the tag and length octets); the CMS OCTET STRING case is unchanged and reports the value only. contentIsPkcs7Type is reset per verify so a reused object parses each message afresh.
Documentation for wc_PKCS7_VerifySignedData is updated to describe the reported content form, the scope of the rejection, and the content lifetime. Tests cover value extraction, trailing-data rejection on both entry points, long-form and non-minimal lengths, streaming input, and the minimal 2-byte element.
How to run the new test:
./configure --enable-all make -j"$(nproc)" ./tests/unit.test --group pkcs7_sd