Skip to content

PKCS#7 fixes#10203

Open
Frauschi wants to merge 8 commits intowolfSSL:masterfrom
Frauschi:pkcs7_fixes
Open

PKCS#7 fixes#10203
Frauschi wants to merge 8 commits intowolfSSL:masterfrom
Frauschi:pkcs7_fixes

Conversation

@Frauschi
Copy link
Copy Markdown
Contributor

Fixes for various issues found in PKCS#7 code.

Fixes zd21593, F-2683, F-2684, F-2686, F-1552, F-1990, F-2681, F-2685, F-1991, F-1992, F-2679, F-2680. Also fixes a regression when building with --enable-all and NO_PKCS7_STREAM.

Copy link
Copy Markdown

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

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #10203

Scan targets checked: wolfcrypt-api_misuse, wolfcrypt-bugs, wolfcrypt-compliance, wolfcrypt-concurrency, wolfcrypt-consttime, wolfcrypt-defaults, wolfcrypt-mutation, wolfcrypt-portability, wolfcrypt-proptest, wolfcrypt-src, wolfcrypt-zeroize

Findings: 5
5 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Findings are non-blocking.

Comment thread wolfcrypt/src/pkcs7.c
Comment thread wolfcrypt/src/pkcs7.c
Comment thread wolfcrypt/src/pkcs7.c
Comment thread wolfcrypt/src/pkcs7.c
Comment thread wolfcrypt/src/pkcs7.c
@Frauschi Frauschi self-assigned this Apr 13, 2026
@Frauschi Frauschi force-pushed the pkcs7_fixes branch 2 times, most recently from 52b6384 to f381fda Compare April 14, 2026 16:10
@Frauschi
Copy link
Copy Markdown
Contributor Author

Jenkins retest this please

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 15, 2026

MemBrowse Memory Report

No memory changes detected for:

@Frauschi
Copy link
Copy Markdown
Contributor Author

Jenkins retest this please

@Frauschi Frauschi assigned wolfSSL-Bot and unassigned Frauschi Apr 16, 2026
Comment thread wolfcrypt/src/pkcs7.c

/* free any buffers that may be allocated */
if (pkcs7->stream->aad != NULL && pkcs7->stream->aadSz > 0)
ForceZero(pkcs7->stream->aad, pkcs7->stream->aadSz);
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.

Since we are adding ForceZeros then we should put in wc_MemZero_Add calls in constructor.
If memory is dynamic then it will be checked in the free, otherwise you need a wc_MemZero_Check() in the destructor.

Comment thread wolfcrypt/src/pkcs7.c
}

if (ret != 0) {
ForceZero(secret, secretSz);
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.

Add a wc_MemZero_Add after malloc.

Comment thread wolfcrypt/src/pkcs7.c
* whether RSA PKCS#1 v1.5 padding was valid. */
{
byte haveSrc = ctMaskGTE(realLen, 1);
uintptr_t srcVal =
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.

Old compilers may not know unitptr_t.

Comment thread wolfcrypt/src/pkcs7.c
* instead of src[j] to avoid out-of-bounds
* access. The result is masked to zero by
* inBounds anyway. */
word32 safeJ = j & (word32)(0x00U - (word32)(
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.

The pattern I use is to increment safeJ if it doesn't take us out of bounds.
Same result but cleaner I think.

Comment thread wolfcrypt/src/pkcs7.c
* and real paths. Downstream decryption uses
* blockKeySz from the content algorithm, not this
* value, so the extra bytes are harmless. */
*decryptedKeySz = (word32)sizeof(fakeKey);
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.

This seems wrong.
Where does it hurt to use the real value?

Comment thread wolfcrypt/src/pkcs7.c
ForceZero(realPad, sizeof(realPad));
}
ForceZero(fakeKey, sizeof(fakeKey));
ForceZero(encryptedKey, (word32)encryptedKeySz);
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.

Why ForceZero the encrypted key?

Comment thread wolfcrypt/src/pkcs7.c
wc_FreeRng(rng);
}
if (ret != 0) {
ForceZero(seed, sizeof(seed));
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.

seed doesn't contain anything at this point

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