fix for PKCS7 decompress

This commit is contained in:
Jacob Barthelmeh
2020-12-03 18:57:25 +07:00
parent 69d642206d
commit fbf56bcf96
4 changed files with 166 additions and 9 deletions

View File

@@ -24622,6 +24622,60 @@ static void test_wc_PKCS7_SetOriDecryptCtx (void)
printf(resultFmt, passed);
#endif
}
static void test_wc_PKCS7_DecodeCompressedData(void)
{
#if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
&& !defined(NO_AES) && defined(HAVE_LIBZ)
PKCS7* pkcs7;
void* heap = NULL;
byte out[3072];
byte *decompressed;
int outSz, decompressedSz;
const char* cert = "./certs/client-cert.pem";
byte* cert_buf = NULL;
size_t cert_sz = 0;
printf(testingFmt, "wc_PKCS7_DecodeCompressedData()");
AssertIntEQ(load_file(cert, &cert_buf, &cert_sz), 0);
AssertNotNull((decompressed =
(byte*)XMALLOC(cert_sz, heap, DYNAMIC_TYPE_TMP_BUFFER)));
decompressedSz = (int)cert_sz;
AssertNotNull((pkcs7 = wc_PKCS7_New(heap, devId)));
pkcs7->content = (byte*)cert;
pkcs7->contentSz = (word32)cert_sz;
pkcs7->contentOID = DATA;
AssertIntGT((outSz = wc_PKCS7_EncodeCompressedData(pkcs7, out,
sizeof(out))), 0);
wc_PKCS7_Free(pkcs7);
/* compressed key should be smaller than when started */
AssertIntLT(outSz, cert_sz);
/* test decompression */
AssertNotNull((pkcs7 = wc_PKCS7_New(heap, devId)));
/* fail case with out buffer too small */
AssertIntLT(wc_PKCS7_DecodeCompressedData(pkcs7, out, outSz,
decompressed, outSz), 0);
/* success case */
AssertIntEQ(wc_PKCS7_DecodeCompressedData(pkcs7, out, outSz,
decompressed, decompressedSz), cert_sz);
AssertIntEQ(XMEMCMP(decompressed, cert, cert_sz), 0);
if (cert_buf)
free(cert_buf);
XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
wc_PKCS7_Free(pkcs7);
printf(resultFmt, passed);
#endif
}
static void test_wc_i2d_PKCS12(void)
{
#if !defined(NO_ASN) && !defined(NO_PWDBASED) && defined(HAVE_PKCS12) \
@@ -39664,6 +39718,7 @@ void ApiTest(void)
test_wc_PKCS7_NoDefaultSignedAttribs();
test_wc_PKCS7_SetOriEncryptCtx();
test_wc_PKCS7_SetOriDecryptCtx();
test_wc_PKCS7_DecodeCompressedData();
test_wc_i2d_PKCS12();