Skip to content

Fix PKCS7 streamed SignedData dropping content#10904

Merged
Frauschi merged 1 commit into
wolfSSL:masterfrom
aidangarske:fix/pkcs7-stream-signed-content
Jul 15, 2026
Merged

Fix PKCS7 streamed SignedData dropping content#10904
Frauschi merged 1 commit into
wolfSSL:masterfrom
aidangarske:fix/pkcs7-stream-signed-content

Conversation

@aidangarske

Copy link
Copy Markdown
Member

wc_PKCS7_EncodeContentStreamHelper() initializes ret to BAD_FUNC_ARG and, in the WC_CIPHER_NONE case, only assigns it inside if (esd->contentDigestSet != 1). When the caller passes a precomputed hash to wc_PKCS7_EncodeSignedData_ex(), contentDigestSet is 1, so that branch is skipped, ret keeps BAD_FUNC_ARG, and the if (ret == 0) block that writes the content never runs. PKCS7_EncodeSigned() does not check the return value, so encoding reports success while emitting a bundle with an empty eContent.

Found with wolfssl-examples pkcs7/signedData-stream, which failed verification with ASN_PARSE_E (-140). OpenSSL rejected the same bundle with CMS Verification failure, confirming the bundle was malformed rather than wolfSSL being strict.

With the fix the bundle grows by the 32 bytes that were missing (2 byte OCTET STRING header plus 30 bytes of content), and it verifies with both wolfSSL and openssl cms -verify.

testwolfcrypt and tests/unit.test pass.

Copilot AI review requested due to automatic review settings July 14, 2026 22:02

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.

Pull request overview

Fixes a logic error in PKCS7 streamed SignedData encoding where wc_PKCS7_EncodeContentStreamHelper() could leave ret as BAD_FUNC_ARG in the WC_CIPHER_NONE path when the content digest was precomputed (or when esd is NULL), preventing the eContent bytes from being written despite overall encoding succeeding.

Changes:

  • Ensure wc_PKCS7_EncodeContentStreamHelper() returns success (ret = 0) for WC_CIPHER_NONE when no hashing update is needed (contentDigestSet == 1) or when esd is not provided.
  • As a result, the if (ret == 0) block that emits the OCTET STRING header and content now runs correctly in these cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@aidangarske aidangarske self-assigned this Jul 14, 2026
@Frauschi

Copy link
Copy Markdown
Contributor

Jenkins retest this please

@Frauschi Frauschi 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.

LGTM

@Frauschi
Frauschi merged commit c327ea3 into wolfSSL:master Jul 15, 2026
339 checks passed
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.

4 participants