Skip to content

PKCS7: reject ANY-typed eContent with trailing bytes after the first element - #11963

Open
night1rider wants to merge 1 commit into
wolfSSL:masterfrom
night1rider:pkcs7-econtent-any-digest-span
Open

night1rider wants to merge 1 commit into
wolfSSL:masterfrom
night1rider:pkcs7-econtent-any-digest-span

Conversation

@night1rider

@night1rider night1rider commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

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

@night1rider night1rider self-assigned this Nov 2, 2026
@night1rider
night1rider requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot November 2, 2026 23:38

Copilot AI left a comment

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.

🟡 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

Comment thread wolfcrypt/src/pkcs7.c Resolved
Comment thread wolfcrypt/src/pkcs7.c Resolved
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

gcc-arm-cortex-m4-pkcs7

  • FLASH: .text +128 B (+0.1%, 222,868 B / 262,144 B, total: 85% used)

zephyr-frdm_rw612

  • FLASH: log_const_area -8 B, rodata -8 B, text +1,544 B (+0.5%, 283,992 B / 67,108,864 B, total: 0% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

@night1rider
night1rider force-pushed the pkcs7-econtent-any-digest-span branch from 6e8d017 to 41462ae Compare November 3, 2026 00:34
@night1rider
night1rider requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot November 3, 2026 00:35

Copilot AI left a comment

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.

🟡 Changes recommended

The ANY payload check accepts an unterminated indefinite-length SEQUENCE as empty content, allowing verification to succeed for an invalid DER element.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment thread wolfcrypt/src/pkcs7.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

@wolfSSL-Fenrir-bot
wolfSSL-Fenrir-bot dismissed their stale review November 3, 2026 00:44

Fenrir's latest completed scan found no issues; clearing the prior automated change request.

@night1rider
night1rider force-pushed the pkcs7-econtent-any-digest-span branch 5 times, most recently from d5f3470 to 6c8b1f3 Compare November 4, 2026 07:18
@night1rider
night1rider requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot November 4, 2026 07:37

Copilot AI left a comment

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.

🟡 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

Comment thread doc/dox_comments/header_files/pkcs7.h Resolved
Comment thread wolfcrypt/src/pkcs7.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread tests/api/test_pkcs7.c Resolved
@night1rider night1rider changed the title PKCS7: return only the signed value of an ANY-typed eContent PKCS7: reject ANY-typed eContent with trailing bytes after the first element Nov 4, 2026
@night1rider
night1rider force-pushed the pkcs7-econtent-any-digest-span branch from 6c8b1f3 to 4935cba Compare November 4, 2026 07:58
@night1rider
night1rider requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot November 4, 2026 07:58

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

@wolfSSL-Fenrir-bot
wolfSSL-Fenrir-bot dismissed their stale review November 4, 2026 08:01

Fenrir's latest completed scan found no issues; clearing the prior automated change request.

Copilot AI left a comment

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.

🟡 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

Comment thread wolfcrypt/src/pkcs7.c Resolved
@night1rider
night1rider force-pushed the pkcs7-econtent-any-digest-span branch 2 times, most recently from 893944e to 8bfb6e3 Compare November 4, 2026 18:46
@night1rider
night1rider requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot November 4, 2026 18:52

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

@night1rider
night1rider force-pushed the pkcs7-econtent-any-digest-span branch 2 times, most recently from b28fb68 to 930aada Compare November 4, 2026 22:30
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.
@night1rider
night1rider force-pushed the pkcs7-econtent-any-digest-span branch from 930aada to 19d5e7c Compare November 4, 2026 23:52
@night1rider
night1rider requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot November 4, 2026 23:53

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

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