Skip to content

Commit 46a2234

Browse files
authored
Merge pull request #9425 from JacobBarthelmeh/pkcs7_stream
with decode enveloped data track total encrypted content size
2 parents 30baf0a + c63ca04 commit 46a2234

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

tests/api/test_pkcs7.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,8 @@ int test_wc_PKCS7_DecodeEnvelopedData_stream(void)
21292129
#ifdef NO_DES3
21302130
ExpectIntEQ(ret, ALGO_ID_E);
21312131
#else
2132-
ExpectIntGT(ret, 0);
2132+
/* expecting the size of ca-cert.pem */
2133+
ExpectIntEQ(ret, 5539);
21332134
#endif
21342135
}
21352136

wolfcrypt/src/pkcs7.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12493,6 +12493,7 @@ int wc_PKCS7_DecodeEnvelopedData(wc_PKCS7* pkcs7, byte* in,
1249312493
}
1249412494

1249512495
#endif
12496+
pkcs7->totalEncryptedContentSz = 0;
1249612497
wc_PKCS7_ChangeState(pkcs7, WC_PKCS7_ENV_5);
1249712498
FALL_THROUGH;
1249812499

@@ -12628,6 +12629,10 @@ int wc_PKCS7_DecodeEnvelopedData(wc_PKCS7* pkcs7, byte* in,
1262812629
/* advance idx past encrypted content */
1262912630
localIdx += (word32)encryptedContentSz;
1263012631

12632+
/* keep track of total encrypted content size */
12633+
pkcs7->totalEncryptedContentSz +=
12634+
(word32)encryptedContentSz;
12635+
1263112636
if (localIdx + ASN_INDEF_END_SZ <= pkiMsgSz) {
1263212637
if (pkiMsg[localIdx] == ASN_EOC &&
1263312638
pkiMsg[localIdx+1] == ASN_EOC) {
@@ -12673,6 +12678,8 @@ int wc_PKCS7_DecodeEnvelopedData(wc_PKCS7* pkcs7, byte* in,
1267312678
} else {
1267412679
pkcs7->cachedEncryptedContentSz =
1267512680
(word32)encryptedContentTotalSz;
12681+
pkcs7->totalEncryptedContentSz =
12682+
(word32)encryptedContentTotalSz;
1267612683
pkcs7->cachedEncryptedContent = (byte*)XMALLOC(
1267712684
pkcs7->cachedEncryptedContentSz, pkcs7->heap,
1267812685
DYNAMIC_TYPE_PKCS7);
@@ -12734,7 +12741,7 @@ int wc_PKCS7_DecodeEnvelopedData(wc_PKCS7* pkcs7, byte* in,
1273412741
pkcs7->cachedEncryptedContentSz = 0;
1273512742
}
1273612743

12737-
ret = encryptedContentSz - padLen;
12744+
ret = (int)pkcs7->totalEncryptedContentSz - padLen;
1273812745
#ifndef NO_PKCS7_STREAM
1273912746
pkcs7->stream->aad = NULL;
1274012747
pkcs7->stream->aadSz = 0;

wolfssl/wolfcrypt/pkcs7.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ struct wc_PKCS7 {
349349
/* used by DecodeEnvelopedData with multiple encrypted contents */
350350
byte* cachedEncryptedContent;
351351
word32 cachedEncryptedContentSz;
352+
word32 totalEncryptedContentSz; /* track encrypted content across octets */
352353
WC_BITFIELD contentCRLF:1; /* have content line endings been converted to CRLF */
353354
WC_BITFIELD contentIsPkcs7Type:1; /* eContent follows PKCS#7 RFC not CMS */
354355
WC_BITFIELD hashParamsAbsent:1;

0 commit comments

Comments
 (0)