@@ -23794,19 +23794,24 @@ static int test_ParseSerial0FixtureMatrix(void)
2379423794 defined(WOLFSSL_PEM_TO_DER) && !defined(WOLFSSL_NO_PEM) && \
2379523795 !defined(WOLFSSL_NO_ASN_STRICT) && !defined(WOLFSSL_PYTHON) && \
2379623796 !defined(WOLFSSL_ASN_ALLOW_0_SERIAL)
23797+ /* Each case asserts a policy outcome (accept vs reject), not a specific
23798+ * error code. wc_ParseCert can fail via several distinct codes
23799+ * (ASN_PARSE_E, ASN_UNKNOWN_OID_E, etc.) depending on which
23800+ * OID-recognition features are compiled into the build; matching any
23801+ * specific code is brittle across configs. */
2379723802 struct {
2379823803 const char* path;
23799- int expectedCertType ; /* expected wc_ParseCert(..., CERT_TYPE) */
23800- int expectedCaType; /* expected wc_ParseCert(..., CA_TYPE) */
23804+ int certTypeShouldPass ; /* 1: expect ret == 0; 0: expect ret != 0 */
23805+ int caTypeShouldPass;
2380123806 } cases[] = {
23802- { "./certs/test-serial0/root_serial0.pem",
23803- WC_NO_ERR_TRACE(ASN_PARSE_E), 0 },
23804- { "./certs/test-serial0/intermediate_serial0 .pem",
23805- WC_NO_ERR_TRACE(ASN_PARSE_E), WC_NO_ERR_TRACE(ASN_PARSE_E) },
23806- { "./certs/test-serial0/selfsigned_nonca_serial0.pem",
23807- WC_NO_ERR_TRACE(ASN_PARSE_E), WC_NO_ERR_TRACE(ASN_PARSE_E) },
23808- { "./certs/test-serial0/ee_serial0 .pem",
23809- WC_NO_ERR_TRACE(ASN_PARSE_E), WC_NO_ERR_TRACE(ASN_PARSE_E) },
23807+ /* Root CA serial 0 is rejected as CERT_TYPE, accepted as trust
23808+ * anchor (CA_TYPE) per the exemption in ParseCertRelative. */
23809+ { "./certs/test-serial0/root_serial0 .pem", 0, 1 } ,
23810+ /* Intermediate CA: CA:TRUE but issuer != subject, so the trust
23811+ * anchor exemption (cert->selfSigned) does not apply. */
23812+ { "./certs/test-serial0/intermediate_serial0.pem", 0, 0 },
23813+ { "./certs/test-serial0/selfsigned_nonca_serial0 .pem", 0, 0 } ,
23814+ { "./certs/test-serial0/ee_serial0.pem", 0, 0 },
2381023815 };
2381123816 size_t i;
2381223817
@@ -23816,6 +23821,7 @@ static int test_ParseSerial0FixtureMatrix(void)
2381623821 byte* derBuf = NULL;
2381723822 int derSz = 0;
2381823823 DecodedCert dc;
23824+ int ret;
2381923825
2382023826 ExpectIntEQ(load_file(cases[i].path, &pemBuf, &pemSz), 0);
2382123827 ExpectNotNull(derBuf = (byte*)XMALLOC(pemSz, NULL,
@@ -23824,13 +23830,19 @@ static int test_ParseSerial0FixtureMatrix(void)
2382423830 (int)pemSz, CERT_TYPE), 0);
2382523831
2382623832 wc_InitDecodedCert(&dc, derBuf, (word32)derSz, NULL);
23827- ExpectIntEQ(wc_ParseCert(&dc, CERT_TYPE, NO_VERIFY, NULL),
23828- cases[i].expectedCertType);
23833+ ret = wc_ParseCert(&dc, CERT_TYPE, NO_VERIFY, NULL);
23834+ if (cases[i].certTypeShouldPass)
23835+ ExpectIntEQ(ret, 0);
23836+ else
23837+ ExpectIntNE(ret, 0);
2382923838 wc_FreeDecodedCert(&dc);
2383023839
2383123840 wc_InitDecodedCert(&dc, derBuf, (word32)derSz, NULL);
23832- ExpectIntEQ(wc_ParseCert(&dc, CA_TYPE, NO_VERIFY, NULL),
23833- cases[i].expectedCaType);
23841+ ret = wc_ParseCert(&dc, CA_TYPE, NO_VERIFY, NULL);
23842+ if (cases[i].caTypeShouldPass)
23843+ ExpectIntEQ(ret, 0);
23844+ else
23845+ ExpectIntNE(ret, 0);
2383423846 wc_FreeDecodedCert(&dc);
2383523847
2383623848 XFREE(derBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
0 commit comments