@@ -2397,7 +2397,8 @@ static int myCEKwrapFunc(PKCS7* pkcs7, byte* cek, word32 cekSz, byte* keyId,
23972397 HAVE_AES_KEYWRAP */
23982398
23992399
2400- #if defined(HAVE_PKCS7 ) && defined(ASN_BER_TO_DER ) && !defined(NO_RSA )
2400+ #if defined(HAVE_PKCS7 ) && defined(ASN_BER_TO_DER ) && !defined(NO_RSA ) && \
2401+ !defined(NO_PKCS7_STREAM )
24012402#define MAX_TEST_DECODE_SIZE 6000
24022403static int test_wc_PKCS7_DecodeEnvelopedData_stream_decrypt_cb (wc_PKCS7 * pkcs7 ,
24032404 const byte * output , word32 outputSz , void * ctx ) {
@@ -2430,7 +2431,8 @@ static int test_wc_PKCS7_DecodeEnvelopedData_stream_decrypt_cb(wc_PKCS7* pkcs7,
24302431int test_wc_PKCS7_DecodeEnvelopedData_stream (void )
24312432{
24322433 EXPECT_DECLS ;
2433- #if defined(HAVE_PKCS7 ) && defined(ASN_BER_TO_DER ) && !defined(NO_RSA )
2434+ #if defined(HAVE_PKCS7 ) && defined(ASN_BER_TO_DER ) && !defined(NO_RSA ) && \
2435+ !defined(NO_PKCS7_STREAM )
24342436 PKCS7 * pkcs7 = NULL ;
24352437 int ret = 0 ;
24362438 XFILE f = XBADFILE ;
@@ -2579,7 +2581,7 @@ int test_wc_PKCS7_EncodeDecodeEnvelopedData(void)
25792581 EXPECT_DECLS ;
25802582#if defined(HAVE_PKCS7 )
25812583 PKCS7 * pkcs7 = NULL ;
2582- #ifdef ASN_BER_TO_DER
2584+ #if defined( ASN_BER_TO_DER ) && !defined( NO_PKCS7_STREAM )
25832585 int encodedSz = 0 ;
25842586#endif
25852587#ifdef ECC_TIMING_RESISTANT
@@ -2784,7 +2786,7 @@ int test_wc_PKCS7_EncodeDecodeEnvelopedData(void)
27842786
27852787 testSz = (int )sizeof (testVectors )/(int )sizeof (pkcs7EnvelopedVector );
27862788 for (i = 0 ; i < testSz ; i ++ ) {
2787- #ifdef ASN_BER_TO_DER
2789+ #if defined( ASN_BER_TO_DER ) && !defined( NO_PKCS7_STREAM )
27882790 encodeSignedDataStream strm ;
27892791
27902792 /* test setting stream mode, the first one using IO callbacks */
@@ -2950,17 +2952,11 @@ int test_wc_PKCS7_EncodeDecodeEnvelopedData(void)
29502952 pkcs7 -> singleCert = NULL ;
29512953 }
29522954 #ifndef NO_RSA
2953- #if defined(NO_PKCS7_STREAM )
2954- /* when none streaming mode is used and PKCS7 is in bad state buffer error
2955- * is returned from kari parse which gets set to bad func arg */
2956- ExpectIntEQ (wc_PKCS7_DecodeEnvelopedData (pkcs7 , output ,
2957- (word32 )sizeof (output ), decoded , (word32 )sizeof (decoded )),
2958- WC_NO_ERR_TRACE (BAD_FUNC_ARG ));
2959- #else
2955+ /* With corrupted singleCert, decode should fail with a parse error.
2956+ * State is properly reset on error so re-decode starts from scratch. */
29602957 ExpectIntEQ (wc_PKCS7_DecodeEnvelopedData (pkcs7 , output ,
29612958 (word32 )sizeof (output ), decoded , (word32 )sizeof (decoded )),
29622959 WC_NO_ERR_TRACE (ASN_PARSE_E ));
2963- #endif
29642960 #endif /* !NO_RSA */
29652961 if (pkcs7 != NULL ) {
29662962 pkcs7 -> singleCert = tmpBytePtr ;
@@ -3991,7 +3987,8 @@ int test_wc_PKCS7_Degenerate(void)
39913987} /* END test_wc_PKCS7_Degenerate() */
39923988
39933989#if defined(HAVE_PKCS7 ) && !defined(NO_FILESYSTEM ) && \
3994- defined(ASN_BER_TO_DER ) && !defined(NO_DES3 ) && !defined(NO_SHA )
3990+ defined(ASN_BER_TO_DER ) && !defined(NO_DES3 ) && !defined(NO_SHA ) && \
3991+ !defined(NO_PKCS7_STREAM )
39953992static byte berContent [] = {
39963993 0x30 , 0x80 , 0x06 , 0x09 , 0x2A , 0x86 , 0x48 , 0x86 ,
39973994 0xF7 , 0x0D , 0x01 , 0x07 , 0x03 , 0xA0 , 0x80 , 0x30 ,
@@ -4182,7 +4179,7 @@ static byte berContent[] = {
41824179 0x00 , 0x00 , 0x00 , 0x00 , 0x00
41834180};
41844181#endif /* HAVE_PKCS7 && !NO_FILESYSTEM && ASN_BER_TO_DER &&
4185- * !NO_DES3 && !NO_SHA
4182+ * !NO_DES3 && !NO_SHA && !NO_PKCS7_STREAM
41864183 */
41874184
41884185/*
@@ -4197,7 +4194,7 @@ int test_wc_PKCS7_BER(void)
41974194 char fName [] = "./certs/test-ber-exp02-05-2022.p7b" ;
41984195 XFILE f = XBADFILE ;
41994196 byte der [4096 ];
4200- #ifndef NO_DES3
4197+ #if !defined( NO_DES3 ) && !defined( NO_PKCS7_STREAM )
42014198 byte decoded [2048 ];
42024199#endif
42034200 word32 derSz = 0 ;
@@ -4242,8 +4239,9 @@ int test_wc_PKCS7_BER(void)
42424239 wc_PKCS7_Free (pkcs7 );
42434240 pkcs7 = NULL ;
42444241
4245- #ifndef NO_DES3
4246- /* decode BER content */
4242+ #if !defined(NO_DES3 ) && !defined(NO_PKCS7_STREAM )
4243+ /* decode BER content - requires PKCS7 streaming to handle indefinite
4244+ * length encoding in the EnvelopedData structure */
42474245 ExpectTrue ((f = XFOPEN ("./certs/1024/client-cert.der" , "rb" )) != XBADFILE );
42484246 ExpectTrue ((derSz = (word32 )XFREAD (der , 1 , sizeof (der ), f )) > 0 );
42494247 if (f != XBADFILE ) {
@@ -4280,7 +4278,7 @@ int test_wc_PKCS7_BER(void)
42804278 sizeof (berContent ), decoded , sizeof (decoded )), WC_NO_ERR_TRACE (NOT_COMPILED_IN ));
42814279#endif
42824280 wc_PKCS7_Free (pkcs7 );
4283- #endif /* !NO_DES3 */
4281+ #endif /* !NO_DES3 && !NO_PKCS7_STREAM */
42844282#endif
42854283 return EXPECT_RESULT ();
42864284} /* END test_wc_PKCS7_BER() */
0 commit comments