forked from wolfSSL/wolfssl
fix asn original build, vs warning, and add test cases
This commit is contained in:
100
tests/api.c
100
tests/api.c
@@ -26916,13 +26916,56 @@ static int test_wc_PKCS7_EncodeSignedData(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ExpectIntGT(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz), 0);
|
ExpectIntGT(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz), 0);
|
||||||
|
|
||||||
wc_PKCS7_Free(pkcs7);
|
wc_PKCS7_Free(pkcs7);
|
||||||
pkcs7 = NULL;
|
pkcs7 = NULL;
|
||||||
|
|
||||||
ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
|
ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
|
||||||
ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
|
ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
|
||||||
ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
|
ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
|
||||||
|
|
||||||
|
#ifdef ASN_BER_TO_DER
|
||||||
|
wc_PKCS7_Free(pkcs7);
|
||||||
|
|
||||||
|
/* reinitialize and test setting stream mode */
|
||||||
|
{
|
||||||
|
int signedSz;
|
||||||
|
|
||||||
|
ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
|
||||||
|
ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
|
||||||
|
|
||||||
|
ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
|
||||||
|
|
||||||
|
if (pkcs7 != NULL) {
|
||||||
|
pkcs7->content = data;
|
||||||
|
pkcs7->contentSz = (word32)sizeof(data);
|
||||||
|
pkcs7->privateKey = key;
|
||||||
|
pkcs7->privateKeySz = (word32)sizeof(key);
|
||||||
|
pkcs7->encryptOID = RSAk;
|
||||||
|
#ifdef NO_SHA
|
||||||
|
pkcs7->hashOID = SHA256h;
|
||||||
|
#else
|
||||||
|
pkcs7->hashOID = SHAh;
|
||||||
|
#endif
|
||||||
|
pkcs7->rng = &rng;
|
||||||
|
}
|
||||||
|
ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 0);
|
||||||
|
ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1), 0);
|
||||||
|
ExpectIntEQ(wc_PKCS7_SetStreamMode(NULL, 1), BAD_FUNC_ARG);
|
||||||
|
ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 1);
|
||||||
|
|
||||||
|
ExpectIntGT(signedSz = wc_PKCS7_EncodeSignedData(pkcs7, output,
|
||||||
|
outputSz), 0);
|
||||||
|
wc_PKCS7_Free(pkcs7);
|
||||||
|
pkcs7 = NULL;
|
||||||
|
|
||||||
|
ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
|
||||||
|
ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
|
||||||
|
|
||||||
|
/* use exact signed buffer size since BER encoded */
|
||||||
|
ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, signedSz), 0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Pass in bad args. */
|
/* Pass in bad args. */
|
||||||
ExpectIntEQ(wc_PKCS7_EncodeSignedData(NULL, output, outputSz),
|
ExpectIntEQ(wc_PKCS7_EncodeSignedData(NULL, output, outputSz),
|
||||||
BAD_FUNC_ARG);
|
BAD_FUNC_ARG);
|
||||||
@@ -27953,6 +27996,9 @@ static int test_wc_PKCS7_EncodeDecodeEnvelopedData(void)
|
|||||||
EXPECT_DECLS;
|
EXPECT_DECLS;
|
||||||
#if defined(HAVE_PKCS7)
|
#if defined(HAVE_PKCS7)
|
||||||
PKCS7* pkcs7 = NULL;
|
PKCS7* pkcs7 = NULL;
|
||||||
|
#ifdef ASN_BER_TO_DER
|
||||||
|
int encodedSz;
|
||||||
|
#endif
|
||||||
#ifdef ECC_TIMING_RESISTANT
|
#ifdef ECC_TIMING_RESISTANT
|
||||||
WC_RNG rng;
|
WC_RNG rng;
|
||||||
#endif
|
#endif
|
||||||
@@ -28153,6 +28199,39 @@ static int test_wc_PKCS7_EncodeDecodeEnvelopedData(void)
|
|||||||
|
|
||||||
testSz = (int)sizeof(testVectors)/(int)sizeof(pkcs7EnvelopedVector);
|
testSz = (int)sizeof(testVectors)/(int)sizeof(pkcs7EnvelopedVector);
|
||||||
for (i = 0; i < testSz; i++) {
|
for (i = 0; i < testSz; i++) {
|
||||||
|
#ifdef ASN_BER_TO_DER
|
||||||
|
/* test setting stream mode */
|
||||||
|
ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (testVectors + i)->cert,
|
||||||
|
(word32)(testVectors + i)->certSz), 0);
|
||||||
|
if (pkcs7 != NULL) {
|
||||||
|
#ifdef ECC_TIMING_RESISTANT
|
||||||
|
pkcs7->rng = &rng;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
pkcs7->content = (byte*)(testVectors + i)->content;
|
||||||
|
pkcs7->contentSz = (testVectors + i)->contentSz;
|
||||||
|
pkcs7->contentOID = (testVectors + i)->contentOID;
|
||||||
|
pkcs7->encryptOID = (testVectors + i)->encryptOID;
|
||||||
|
pkcs7->keyWrapOID = (testVectors + i)->keyWrapOID;
|
||||||
|
pkcs7->keyAgreeOID = (testVectors + i)->keyAgreeOID;
|
||||||
|
pkcs7->privateKey = (testVectors + i)->privateKey;
|
||||||
|
pkcs7->privateKeySz = (testVectors + i)->privateKeySz;
|
||||||
|
}
|
||||||
|
ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1), 0);
|
||||||
|
|
||||||
|
ExpectIntGE(encodedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
|
||||||
|
(word32)sizeof(output)), 0);
|
||||||
|
|
||||||
|
decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
|
||||||
|
(word32)encodedSz, decoded, (word32)sizeof(decoded));
|
||||||
|
ExpectIntGE(decodedSz, 0);
|
||||||
|
/* Verify the size of each buffer. */
|
||||||
|
ExpectIntEQ((word32)sizeof(input)/sizeof(char), decodedSz);
|
||||||
|
wc_PKCS7_Free(pkcs7);
|
||||||
|
pkcs7 = NULL;
|
||||||
|
ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
|
||||||
|
#endif
|
||||||
|
|
||||||
ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (testVectors + i)->cert,
|
ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (testVectors + i)->cert,
|
||||||
(word32)(testVectors + i)->certSz), 0);
|
(word32)(testVectors + i)->certSz), 0);
|
||||||
if (pkcs7 != NULL) {
|
if (pkcs7 != NULL) {
|
||||||
@@ -28170,6 +28249,11 @@ static int test_wc_PKCS7_EncodeDecodeEnvelopedData(void)
|
|||||||
pkcs7->privateKeySz = (testVectors + i)->privateKeySz;
|
pkcs7->privateKeySz = (testVectors + i)->privateKeySz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ASN_BER_TO_DER
|
||||||
|
/* test without setting stream mode */
|
||||||
|
ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
ExpectIntGE(wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
|
ExpectIntGE(wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
|
||||||
(word32)sizeof(output)), 0);
|
(word32)sizeof(output)), 0);
|
||||||
|
|
||||||
@@ -28178,6 +28262,7 @@ static int test_wc_PKCS7_EncodeDecodeEnvelopedData(void)
|
|||||||
ExpectIntGE(decodedSz, 0);
|
ExpectIntGE(decodedSz, 0);
|
||||||
/* Verify the size of each buffer. */
|
/* Verify the size of each buffer. */
|
||||||
ExpectIntEQ((word32)sizeof(input)/sizeof(char), decodedSz);
|
ExpectIntEQ((word32)sizeof(input)/sizeof(char), decodedSz);
|
||||||
|
|
||||||
/* Don't free the last time through the loop. */
|
/* Don't free the last time through the loop. */
|
||||||
if (i < testSz - 1) {
|
if (i < testSz - 1) {
|
||||||
wc_PKCS7_Free(pkcs7);
|
wc_PKCS7_Free(pkcs7);
|
||||||
@@ -28871,7 +28956,6 @@ static int test_wc_PKCS7_signed_enveloped(void)
|
|||||||
#ifdef HAVE_AES_CBC
|
#ifdef HAVE_AES_CBC
|
||||||
PKCS7* inner = NULL;
|
PKCS7* inner = NULL;
|
||||||
#endif
|
#endif
|
||||||
void* pt = NULL;
|
|
||||||
WC_RNG rng;
|
WC_RNG rng;
|
||||||
unsigned char key[FOURK_BUF/2];
|
unsigned char key[FOURK_BUF/2];
|
||||||
unsigned char cert[FOURK_BUF/2];
|
unsigned char cert[FOURK_BUF/2];
|
||||||
@@ -28958,17 +29042,13 @@ static int test_wc_PKCS7_signed_enveloped(void)
|
|||||||
pkcs7->rng = &rng;
|
pkcs7->rng = &rng;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set no certs in bundle for this test. Hang on to the pointer though to
|
/* Set no certs in bundle for this test. */
|
||||||
* free it later. */
|
|
||||||
if (pkcs7 != NULL) {
|
if (pkcs7 != NULL) {
|
||||||
pt = (void*)pkcs7->certList;
|
ExpectIntEQ(wc_PKCS7_SetNoCerts(pkcs7, 1), 0);
|
||||||
pkcs7->certList = NULL; /* no certs in bundle */
|
ExpectIntEQ(wc_PKCS7_SetNoCerts(NULL, 1), BAD_FUNC_ARG);
|
||||||
|
ExpectIntEQ(wc_PKCS7_GetNoCerts(pkcs7), 1);
|
||||||
}
|
}
|
||||||
ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, sigSz)), 0);
|
ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, sigSz)), 0);
|
||||||
if (pkcs7 != NULL) {
|
|
||||||
/* restore pointer for PKCS7 free call */
|
|
||||||
pkcs7->certList = (Pkcs7Cert*)pt;
|
|
||||||
}
|
|
||||||
wc_PKCS7_Free(pkcs7);
|
wc_PKCS7_Free(pkcs7);
|
||||||
pkcs7 = NULL;
|
pkcs7 = NULL;
|
||||||
|
|
||||||
|
@@ -15482,7 +15482,7 @@ word32 SetSet(word32 len, byte* output)
|
|||||||
*/
|
*/
|
||||||
word32 SetImplicit(byte tag, byte number, word32 len, byte* output, byte isIndef)
|
word32 SetImplicit(byte tag, byte number, word32 len, byte* output, byte isIndef)
|
||||||
{
|
{
|
||||||
int useIndef = 0;
|
byte useIndef = 0;
|
||||||
|
|
||||||
if ((tag == ASN_OCTET_STRING) && isIndef) {
|
if ((tag == ASN_OCTET_STRING) && isIndef) {
|
||||||
tag = ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC | number;
|
tag = ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC | number;
|
||||||
@@ -36453,7 +36453,7 @@ int EncodeOcspRequest(OcspRequest* req, byte* output, word32 size)
|
|||||||
*/
|
*/
|
||||||
extSz = EncodeOcspRequestExtensions(req, extArray + 2,
|
extSz = EncodeOcspRequestExtensions(req, extArray + 2,
|
||||||
OCSP_NONCE_EXT_SZ);
|
OCSP_NONCE_EXT_SZ);
|
||||||
extSz += SetExplicit(2, extSz, extArray);
|
extSz += SetExplicit(2, extSz, extArray, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
totalSz = algoSz + issuerSz + issuerKeySz + snSz;
|
totalSz = algoSz + issuerSz + issuerKeySz + snSz;
|
||||||
|
@@ -2630,7 +2630,6 @@ static int PKCS7_EncodeSigned(PKCS7* pkcs7, ESD* esd,
|
|||||||
totalSz -= pkcs7->contentSz;
|
totalSz -= pkcs7->contentSz;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
esd->innerSeqSz = SetSequenceEx(totalSz + total2Sz, esd->innerSeq,
|
esd->innerSeqSz = SetSequenceEx(totalSz + total2Sz, esd->innerSeq,
|
||||||
pkcs7->encodeStream);
|
pkcs7->encodeStream);
|
||||||
totalSz += esd->innerSeqSz;
|
totalSz += esd->innerSeqSz;
|
||||||
@@ -2651,7 +2650,6 @@ static int PKCS7_EncodeSigned(PKCS7* pkcs7, ESD* esd,
|
|||||||
if (pkcs7->encodeStream) {
|
if (pkcs7->encodeStream) {
|
||||||
totalSz += ASN_INDEF_END_SZ;
|
totalSz += ASN_INDEF_END_SZ;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* if using header/footer, we are not returning the content */
|
/* if using header/footer, we are not returning the content */
|
||||||
if (output2 && output2Sz) {
|
if (output2 && output2Sz) {
|
||||||
|
Reference in New Issue
Block a user