forked from wolfSSL/wolfssl
save and set PKCS7 isDynamic flag in wc_PKCS7_Init
This commit is contained in:
committed by
David Garske
parent
13b30a6a21
commit
0b3930e24f
91
tests/api.c
91
tests/api.c
@@ -15741,7 +15741,7 @@ static void test_wc_PKCS7_EncodeDecodeEnvelopedData (void)
|
|||||||
static void test_wc_PKCS7_EncodeEncryptedData (void)
|
static void test_wc_PKCS7_EncodeEncryptedData (void)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_PKCS7) && !defined(NO_PKCS7_ENCRYPTED_DATA)
|
#if defined(HAVE_PKCS7) && !defined(NO_PKCS7_ENCRYPTED_DATA)
|
||||||
PKCS7 pkcs7;
|
PKCS7* pkcs7;
|
||||||
byte* tmpBytePtr = NULL;
|
byte* tmpBytePtr = NULL;
|
||||||
byte encrypted[TWOK_BUF];
|
byte encrypted[TWOK_BUF];
|
||||||
byte decoded[TWOK_BUF];
|
byte decoded[TWOK_BUF];
|
||||||
@@ -15808,64 +15808,65 @@ static void test_wc_PKCS7_EncodeEncryptedData (void)
|
|||||||
testSz = sizeof(testVectors) / sizeof(pkcs7EncryptedVector);
|
testSz = sizeof(testVectors) / sizeof(pkcs7EncryptedVector);
|
||||||
|
|
||||||
for (i = 0; i < testSz; i++) {
|
for (i = 0; i < testSz; i++) {
|
||||||
AssertIntEQ(wc_PKCS7_Init(&pkcs7, HEAP_HINT, devId), 0);
|
AssertNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, devId));
|
||||||
pkcs7.content = (byte*)testVectors[i].content;
|
AssertIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, devId), 0);
|
||||||
pkcs7.contentSz = testVectors[i].contentSz;
|
pkcs7->content = (byte*)testVectors[i].content;
|
||||||
pkcs7.contentOID = testVectors[i].contentOID;
|
pkcs7->contentSz = testVectors[i].contentSz;
|
||||||
pkcs7.encryptOID = testVectors[i].encryptOID;
|
pkcs7->contentOID = testVectors[i].contentOID;
|
||||||
pkcs7.encryptionKey = testVectors[i].encryptionKey;
|
pkcs7->encryptOID = testVectors[i].encryptOID;
|
||||||
pkcs7.encryptionKeySz = testVectors[i].encryptionKeySz;
|
pkcs7->encryptionKey = testVectors[i].encryptionKey;
|
||||||
pkcs7.heap = HEAP_HINT;
|
pkcs7->encryptionKeySz = testVectors[i].encryptionKeySz;
|
||||||
|
pkcs7->heap = HEAP_HINT;
|
||||||
|
|
||||||
/* encode encryptedData */
|
/* encode encryptedData */
|
||||||
encryptedSz = wc_PKCS7_EncodeEncryptedData(&pkcs7, encrypted,
|
encryptedSz = wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
|
||||||
sizeof(encrypted));
|
sizeof(encrypted));
|
||||||
AssertIntGT(encryptedSz, 0);
|
AssertIntGT(encryptedSz, 0);
|
||||||
|
|
||||||
/* Decode encryptedData */
|
/* Decode encryptedData */
|
||||||
decodedSz = wc_PKCS7_DecodeEncryptedData(&pkcs7, encrypted, encryptedSz,
|
decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, encryptedSz,
|
||||||
decoded, sizeof(decoded));
|
decoded, sizeof(decoded));
|
||||||
|
|
||||||
AssertIntEQ(XMEMCMP(decoded, data, decodedSz), 0);
|
AssertIntEQ(XMEMCMP(decoded, data, decodedSz), 0);
|
||||||
/* Keep values for last itr. */
|
/* Keep values for last itr. */
|
||||||
if (i < testSz - 1) {
|
if (i < testSz - 1) {
|
||||||
wc_PKCS7_Free(&pkcs7);
|
wc_PKCS7_Free(pkcs7);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(testingFmt, "wc_PKCS7_EncodeEncryptedData()");
|
printf(testingFmt, "wc_PKCS7_EncodeEncryptedData()");
|
||||||
AssertIntEQ(wc_PKCS7_EncodeEncryptedData(NULL, encrypted,
|
AssertIntEQ(wc_PKCS7_EncodeEncryptedData(NULL, encrypted,
|
||||||
sizeof(encrypted)),BAD_FUNC_ARG);
|
sizeof(encrypted)),BAD_FUNC_ARG);
|
||||||
AssertIntEQ(wc_PKCS7_EncodeEncryptedData(&pkcs7, NULL,
|
AssertIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, NULL,
|
||||||
sizeof(encrypted)), BAD_FUNC_ARG);
|
sizeof(encrypted)), BAD_FUNC_ARG);
|
||||||
AssertIntEQ(wc_PKCS7_EncodeEncryptedData(&pkcs7, encrypted,
|
AssertIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
|
||||||
0), BAD_FUNC_ARG);
|
0), BAD_FUNC_ARG);
|
||||||
/* Testing the struct. */
|
/* Testing the struct. */
|
||||||
tmpBytePtr = pkcs7.content;
|
tmpBytePtr = pkcs7->content;
|
||||||
pkcs7.content = NULL;
|
pkcs7->content = NULL;
|
||||||
AssertIntEQ(wc_PKCS7_EncodeEncryptedData(&pkcs7, encrypted,
|
AssertIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
|
||||||
sizeof(encrypted)), BAD_FUNC_ARG);
|
sizeof(encrypted)), BAD_FUNC_ARG);
|
||||||
pkcs7.content = tmpBytePtr;
|
pkcs7->content = tmpBytePtr;
|
||||||
tmpWrd32 = pkcs7.contentSz;
|
tmpWrd32 = pkcs7->contentSz;
|
||||||
pkcs7.contentSz = 0;
|
pkcs7->contentSz = 0;
|
||||||
AssertIntEQ(wc_PKCS7_EncodeEncryptedData(&pkcs7, encrypted,
|
AssertIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
|
||||||
sizeof(encrypted)), BAD_FUNC_ARG);
|
sizeof(encrypted)), BAD_FUNC_ARG);
|
||||||
pkcs7.contentSz = tmpWrd32;
|
pkcs7->contentSz = tmpWrd32;
|
||||||
tmpInt = pkcs7.encryptOID;
|
tmpInt = pkcs7->encryptOID;
|
||||||
pkcs7.encryptOID = 0;
|
pkcs7->encryptOID = 0;
|
||||||
AssertIntEQ(wc_PKCS7_EncodeEncryptedData(&pkcs7, encrypted,
|
AssertIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
|
||||||
sizeof(encrypted)), BAD_FUNC_ARG);
|
sizeof(encrypted)), BAD_FUNC_ARG);
|
||||||
pkcs7.encryptOID = tmpInt;
|
pkcs7->encryptOID = tmpInt;
|
||||||
tmpBytePtr = pkcs7.encryptionKey;
|
tmpBytePtr = pkcs7->encryptionKey;
|
||||||
pkcs7.encryptionKey = NULL;
|
pkcs7->encryptionKey = NULL;
|
||||||
AssertIntEQ(wc_PKCS7_EncodeEncryptedData(&pkcs7, encrypted,
|
AssertIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
|
||||||
sizeof(encrypted)), BAD_FUNC_ARG);
|
sizeof(encrypted)), BAD_FUNC_ARG);
|
||||||
pkcs7.encryptionKey = tmpBytePtr;
|
pkcs7->encryptionKey = tmpBytePtr;
|
||||||
tmpWrd32 = pkcs7.encryptionKeySz;
|
tmpWrd32 = pkcs7->encryptionKeySz;
|
||||||
pkcs7.encryptionKeySz = 0;
|
pkcs7->encryptionKeySz = 0;
|
||||||
AssertIntEQ(wc_PKCS7_EncodeEncryptedData(&pkcs7, encrypted,
|
AssertIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
|
||||||
sizeof(encrypted)), BAD_FUNC_ARG);
|
sizeof(encrypted)), BAD_FUNC_ARG);
|
||||||
pkcs7.encryptionKeySz = tmpWrd32;
|
pkcs7->encryptionKeySz = tmpWrd32;
|
||||||
|
|
||||||
printf(resultFmt, passed);
|
printf(resultFmt, passed);
|
||||||
|
|
||||||
@@ -15873,27 +15874,27 @@ static void test_wc_PKCS7_EncodeEncryptedData (void)
|
|||||||
|
|
||||||
AssertIntEQ(wc_PKCS7_DecodeEncryptedData(NULL, encrypted, encryptedSz,
|
AssertIntEQ(wc_PKCS7_DecodeEncryptedData(NULL, encrypted, encryptedSz,
|
||||||
decoded, sizeof(decoded)), BAD_FUNC_ARG);
|
decoded, sizeof(decoded)), BAD_FUNC_ARG);
|
||||||
AssertIntEQ(wc_PKCS7_DecodeEncryptedData(&pkcs7, NULL, encryptedSz,
|
AssertIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, NULL, encryptedSz,
|
||||||
decoded, sizeof(decoded)), BAD_FUNC_ARG);
|
decoded, sizeof(decoded)), BAD_FUNC_ARG);
|
||||||
AssertIntEQ(wc_PKCS7_DecodeEncryptedData(&pkcs7, encrypted, 0,
|
AssertIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, 0,
|
||||||
decoded, sizeof(decoded)), BAD_FUNC_ARG);
|
decoded, sizeof(decoded)), BAD_FUNC_ARG);
|
||||||
AssertIntEQ(wc_PKCS7_DecodeEncryptedData(&pkcs7, encrypted, encryptedSz,
|
AssertIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, encryptedSz,
|
||||||
NULL, sizeof(decoded)), BAD_FUNC_ARG);
|
NULL, sizeof(decoded)), BAD_FUNC_ARG);
|
||||||
AssertIntEQ(wc_PKCS7_DecodeEncryptedData(&pkcs7, encrypted, encryptedSz,
|
AssertIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, encryptedSz,
|
||||||
decoded, 0), BAD_FUNC_ARG);
|
decoded, 0), BAD_FUNC_ARG);
|
||||||
/* Test struct fields */
|
/* Test struct fields */
|
||||||
|
|
||||||
tmpBytePtr = pkcs7.encryptionKey;
|
tmpBytePtr = pkcs7->encryptionKey;
|
||||||
pkcs7.encryptionKey = NULL;
|
pkcs7->encryptionKey = NULL;
|
||||||
AssertIntEQ(wc_PKCS7_DecodeEncryptedData(&pkcs7, encrypted, encryptedSz,
|
AssertIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, encryptedSz,
|
||||||
decoded, sizeof(decoded)), BAD_FUNC_ARG);
|
decoded, sizeof(decoded)), BAD_FUNC_ARG);
|
||||||
pkcs7.encryptionKey = tmpBytePtr;
|
pkcs7->encryptionKey = tmpBytePtr;
|
||||||
pkcs7.encryptionKeySz = 0;
|
pkcs7->encryptionKeySz = 0;
|
||||||
AssertIntEQ(wc_PKCS7_DecodeEncryptedData(&pkcs7, encrypted, encryptedSz,
|
AssertIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, encryptedSz,
|
||||||
decoded, sizeof(decoded)), BAD_FUNC_ARG);
|
decoded, sizeof(decoded)), BAD_FUNC_ARG);
|
||||||
|
|
||||||
printf(resultFmt, passed);
|
printf(resultFmt, passed);
|
||||||
wc_PKCS7_Free(&pkcs7);
|
wc_PKCS7_Free(pkcs7);
|
||||||
#endif
|
#endif
|
||||||
} /* END test_wc_PKCS7_EncodeEncryptedData() */
|
} /* END test_wc_PKCS7_EncodeEncryptedData() */
|
||||||
|
|
||||||
|
@@ -300,13 +300,17 @@ PKCS7* wc_PKCS7_New(void* heap, int devId)
|
|||||||
*/
|
*/
|
||||||
int wc_PKCS7_Init(PKCS7* pkcs7, void* heap, int devId)
|
int wc_PKCS7_Init(PKCS7* pkcs7, void* heap, int devId)
|
||||||
{
|
{
|
||||||
|
word16 isDynamic;
|
||||||
|
|
||||||
WOLFSSL_ENTER("wc_PKCS7_Init");
|
WOLFSSL_ENTER("wc_PKCS7_Init");
|
||||||
|
|
||||||
if (pkcs7 == NULL) {
|
if (pkcs7 == NULL) {
|
||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isDynamic = pkcs7->isDynamic;
|
||||||
XMEMSET(pkcs7, 0, sizeof(PKCS7));
|
XMEMSET(pkcs7, 0, sizeof(PKCS7));
|
||||||
|
pkcs7->isDynamic = isDynamic;
|
||||||
#ifdef WOLFSSL_HEAP_TEST
|
#ifdef WOLFSSL_HEAP_TEST
|
||||||
pkcs7->heap = (void*)WOLFSSL_HEAP_TEST;
|
pkcs7->heap = (void*)WOLFSSL_HEAP_TEST;
|
||||||
#else
|
#else
|
||||||
@@ -411,7 +415,6 @@ int wc_PKCS7_InitWithCert(PKCS7* pkcs7, byte* derCert, word32 derCertSz)
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
void* heap;
|
void* heap;
|
||||||
int devId;
|
int devId;
|
||||||
word16 isDynamic;
|
|
||||||
Pkcs7Cert* cert;
|
Pkcs7Cert* cert;
|
||||||
Pkcs7Cert* lastCert;
|
Pkcs7Cert* lastCert;
|
||||||
|
|
||||||
@@ -421,11 +424,9 @@ int wc_PKCS7_InitWithCert(PKCS7* pkcs7, byte* derCert, word32 derCertSz)
|
|||||||
|
|
||||||
heap = pkcs7->heap;
|
heap = pkcs7->heap;
|
||||||
devId = pkcs7->devId;
|
devId = pkcs7->devId;
|
||||||
isDynamic = pkcs7->isDynamic;
|
|
||||||
ret = wc_PKCS7_Init(pkcs7, heap, devId);
|
ret = wc_PKCS7_Init(pkcs7, heap, devId);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
return ret;
|
return ret;
|
||||||
pkcs7->isDynamic = isDynamic;
|
|
||||||
|
|
||||||
if (derCert != NULL && derCertSz > 0) {
|
if (derCert != NULL && derCertSz > 0) {
|
||||||
#ifdef WOLFSSL_SMALL_STACK
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
Reference in New Issue
Block a user