@@ -26945,7 +26945,7 @@ static int test_wc_PKCS7_EncodeSignedData(void)
2694526945 int certSz;
2694626946 int keySz;
2694726947
26948- ExpectTrue((fp = XOPEN ("./certs/client-ecc-cert.der", "rb")) !=
26948+ ExpectTrue((fp = XFOPEN ("./certs/client-ecc-cert.der", "rb")) !=
2694926949 XBADFILE);
2695026950 ExpectIntGT(certSz = (int)XFREAD(cert, 1, ONEK_BUF, fp), 0);
2695126951 if (fp != XBADFILE) {
@@ -27099,6 +27099,7 @@ static int test_wc_PKCS7_EncodeSignedData(void)
2709927099
2710027100 wc_PKCS7_Free(pkcs7);
2710127101 DoExpectIntEQ(wc_FreeRng(&rng), 0);
27102+
2710227103#endif
2710327104 return EXPECT_RESULT();
2710427105} /* END test_wc_PKCS7_EncodeSignedData */
@@ -28008,6 +28009,79 @@ static int test_wc_PKCS7_VerifySignedData_RSA(void)
2800828009#endif /* !NO_PKCS7_STREAM */
2800928010
2801028011#endif /* !NO_RSA */
28012+ #if defined(ASN_BER_TO_DER) && !defined(NO_PKCS7_STREAM) && \
28013+ !defined(NO_FILESYSTEM)
28014+ {
28015+ XFILE signedBundle = XBADFILE;
28016+ int signedBundleSz = 0;
28017+ int chunkSz = 1;
28018+ int i, rc;
28019+ byte* buf = NULL;
28020+
28021+ ExpectTrue((signedBundle = XFOPEN("./certs/test-stream-sign.p7b",
28022+ "rb")) != XBADFILE);
28023+ ExpectTrue(XFSEEK(signedBundle, 0, XSEEK_END) == 0);
28024+ ExpectIntGT(signedBundleSz = (int)XFTELL(signedBundle), 0);
28025+ ExpectTrue(XFSEEK(signedBundle, 0, XSEEK_SET) == 0);
28026+ ExpectNotNull(buf = (byte*)XMALLOC(signedBundleSz, HEAP_HINT,
28027+ DYNAMIC_TYPE_FILE));
28028+ if (buf != NULL) {
28029+ ExpectIntEQ(XFREAD(buf, 1, signedBundleSz, signedBundle),
28030+ signedBundleSz);
28031+ }
28032+ if (signedBundle != XBADFILE) {
28033+ XFCLOSE(signedBundle);
28034+ signedBundle = XBADFILE;
28035+ }
28036+
28037+ ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
28038+ ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
28039+ for (i = 0; i < signedBundleSz;) {
28040+ int sz = (i + chunkSz > signedBundleSz)? signedBundleSz - i :
28041+ chunkSz;
28042+ rc = wc_PKCS7_VerifySignedData(pkcs7, buf + i, sz);
28043+ if (rc < 0 ) {
28044+ if (rc == WC_PKCS7_WANT_READ_E) {
28045+ i += sz;
28046+ continue;
28047+ }
28048+ break;
28049+ }
28050+ else {
28051+ break;
28052+ }
28053+ }
28054+ ExpectIntEQ(rc, PKCS7_SIGNEEDS_CHECK);
28055+ wc_PKCS7_Free(pkcs7);
28056+ pkcs7 = NULL;
28057+
28058+
28059+ /* now try with malformed bundle */
28060+ ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
28061+ ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
28062+ buf[signedBundleSz - 2] = buf[signedBundleSz - 2] + 1;
28063+ for (i = 0; i < signedBundleSz;) {
28064+ int sz = (i + chunkSz > signedBundleSz)? signedBundleSz - i :
28065+ chunkSz;
28066+ rc = wc_PKCS7_VerifySignedData(pkcs7, buf + i, sz);
28067+ if (rc < 0 ) {
28068+ if (rc == WC_PKCS7_WANT_READ_E) {
28069+ i += sz;
28070+ continue;
28071+ }
28072+ break;
28073+ }
28074+ else {
28075+ break;
28076+ }
28077+ }
28078+ ExpectIntEQ(rc, ASN_PARSE_E);
28079+ wc_PKCS7_Free(pkcs7);
28080+ pkcs7 = NULL;
28081+ if (buf != NULL)
28082+ XFREE(buf, HEAP_HINT, DYNAMIC_TYPE_FILE);
28083+ }
28084+ #endif /* BER and stream */
2801128085#endif
2801228086 return EXPECT_RESULT();
2801328087} /* END test_wc_PKCS7_VerifySignedData()_RSA */
0 commit comments