add test cases and set content oid with decode encrypted data

This commit is contained in:
Jacob Barthelmeh
2021-06-25 21:16:01 +07:00
parent 2b1a6cfb54
commit 5038a27cda
3 changed files with 15 additions and 2 deletions

View File

@@ -25991,6 +25991,7 @@ static void test_wc_PKCS7_DecodeCompressedData(void)
/* test decompression */ /* test decompression */
AssertNotNull((pkcs7 = wc_PKCS7_New(heap, devId))); AssertNotNull((pkcs7 = wc_PKCS7_New(heap, devId)));
AssertIntEQ(pkcs7->contentOID, 0);
/* fail case with out buffer too small */ /* fail case with out buffer too small */
AssertIntLT(wc_PKCS7_DecodeCompressedData(pkcs7, out, outSz, AssertIntLT(wc_PKCS7_DecodeCompressedData(pkcs7, out, outSz,
@@ -25999,6 +26000,7 @@ static void test_wc_PKCS7_DecodeCompressedData(void)
/* success case */ /* success case */
AssertIntEQ(wc_PKCS7_DecodeCompressedData(pkcs7, out, outSz, AssertIntEQ(wc_PKCS7_DecodeCompressedData(pkcs7, out, outSz,
decompressed, decompressedSz), cert_sz); decompressed, decompressedSz), cert_sz);
AssertIntEQ(pkcs7->contentOID, DATA);
AssertIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0); AssertIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0);
XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER); XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
decompressed = NULL; decompressed = NULL;

View File

@@ -12322,6 +12322,10 @@ int wc_PKCS7_DecodeEncryptedData(PKCS7* pkcs7, byte* in, word32 inSz,
pkiMsgSz) < 0) pkiMsgSz) < 0)
ret = ASN_PARSE_E; ret = ASN_PARSE_E;
if (ret == 0) {
pkcs7->contentOID = contentType;
}
if (ret == 0 && (ret = GetAlgoId(pkiMsg, &idx, &encOID, oidBlkType, if (ret == 0 && (ret = GetAlgoId(pkiMsg, &idx, &encOID, oidBlkType,
pkiMsgSz)) < 0) pkiMsgSz)) < 0)
ret = ASN_PARSE_E; ret = ASN_PARSE_E;

View File

@@ -30558,9 +30558,11 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz,
} }
/* decode envelopedData */ /* decode envelopedData */
pkcs7->contentOID = 0;
decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, enveloped, envelopedSz, decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, enveloped, envelopedSz,
decoded, PKCS7_BUF_SIZE); decoded, PKCS7_BUF_SIZE);
if (decodedSz <= 0) { if (pkcs7->contentOID != testVectors[i].contentOID ||
decodedSz <= 0) {
wc_PKCS7_Free(pkcs7); wc_PKCS7_Free(pkcs7);
ERROR_OUT(-12187, out); ERROR_OUT(-12187, out);
} }
@@ -31510,6 +31512,11 @@ static int getFirmwareKey(PKCS7* pkcs7, byte* key, word32 keySz)
envPkcs7->contentOID = FIRMWARE_PKG_DATA; envPkcs7->contentOID = FIRMWARE_PKG_DATA;
ret = wc_PKCS7_DecodeEnvelopedData(envPkcs7, atr, atrSz, ret = wc_PKCS7_DecodeEnvelopedData(envPkcs7, atr, atrSz,
key, keySz); key, keySz);
if (envPkcs7->contentOID != FIRMWARE_PKG_DATA) {
/* the contentOID should have been set to the inner
* FIRMWARE_PKG_DATA content */
ret = BAD_STATE_E;
}
} }
wc_PKCS7_Free(envPkcs7); wc_PKCS7_Free(envPkcs7);
} }
@@ -33245,7 +33252,7 @@ static int pkcs7signed_run_SingleShotVectors(
pkcs7->contentSz, encryptedTmp, pkcs7->contentSz, encryptedTmp,
encryptedTmpSz); encryptedTmpSz);
if (encryptedTmpSz < 0) { if (encryptedTmpSz < 0 || pkcs7->contentOID != COMPRESSED_DATA) {
XFREE(encryptedTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); XFREE(encryptedTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
wc_PKCS7_Free(pkcs7); wc_PKCS7_Free(pkcs7);