@@ -22145,19 +22145,24 @@ static int test_ParseSerial0FixtureMatrix(void)
2214522145 defined(WOLFSSL_PEM_TO_DER) && !defined(WOLFSSL_NO_PEM) && \
2214622146 !defined(WOLFSSL_NO_ASN_STRICT) && !defined(WOLFSSL_PYTHON) && \
2214722147 !defined(WOLFSSL_ASN_ALLOW_0_SERIAL)
22148+ /* Each case asserts a policy outcome (accept vs reject), not a specific
22149+ * error code. wc_ParseCert can fail via several distinct codes
22150+ * (ASN_PARSE_E, ASN_UNKNOWN_OID_E, etc.) depending on which
22151+ * OID-recognition features are compiled into the build; matching any
22152+ * specific code is brittle across configs. */
2214822153 struct {
2214922154 const char* path;
22150- int expectedCertType ; /* expected wc_ParseCert(..., CERT_TYPE) */
22151- int expectedCaType; /* expected wc_ParseCert(..., CA_TYPE) */
22155+ int certTypeShouldPass ; /* 1: expect ret == 0; 0: expect ret != 0 */
22156+ int caTypeShouldPass;
2215222157 } cases[] = {
22153- { "./certs/test-serial0/root_serial0.pem",
22154- WC_NO_ERR_TRACE(ASN_PARSE_E), 0 },
22155- { "./certs/test-serial0/intermediate_serial0 .pem",
22156- WC_NO_ERR_TRACE(ASN_PARSE_E), WC_NO_ERR_TRACE(ASN_PARSE_E) },
22157- { "./certs/test-serial0/selfsigned_nonca_serial0.pem",
22158- WC_NO_ERR_TRACE(ASN_PARSE_E), WC_NO_ERR_TRACE(ASN_PARSE_E) },
22159- { "./certs/test-serial0/ee_serial0 .pem",
22160- WC_NO_ERR_TRACE(ASN_PARSE_E), WC_NO_ERR_TRACE(ASN_PARSE_E) },
22158+ /* Root CA serial 0 is rejected as CERT_TYPE, accepted as trust
22159+ * anchor (CA_TYPE) per the exemption in ParseCertRelative. */
22160+ { "./certs/test-serial0/root_serial0 .pem", 0, 1 } ,
22161+ /* Intermediate CA: CA:TRUE but issuer != subject, so the trust
22162+ * anchor exemption (cert->selfSigned) does not apply. */
22163+ { "./certs/test-serial0/intermediate_serial0.pem", 0, 0 },
22164+ { "./certs/test-serial0/selfsigned_nonca_serial0 .pem", 0, 0 } ,
22165+ { "./certs/test-serial0/ee_serial0.pem", 0, 0 },
2216122166 };
2216222167 size_t i;
2216322168
@@ -22167,6 +22172,7 @@ static int test_ParseSerial0FixtureMatrix(void)
2216722172 byte* derBuf = NULL;
2216822173 int derSz = 0;
2216922174 DecodedCert dc;
22175+ int ret;
2217022176
2217122177 ExpectIntEQ(load_file(cases[i].path, &pemBuf, &pemSz), 0);
2217222178 ExpectNotNull(derBuf = (byte*)XMALLOC(pemSz, NULL,
@@ -22175,13 +22181,19 @@ static int test_ParseSerial0FixtureMatrix(void)
2217522181 (int)pemSz, CERT_TYPE), 0);
2217622182
2217722183 wc_InitDecodedCert(&dc, derBuf, (word32)derSz, NULL);
22178- ExpectIntEQ(wc_ParseCert(&dc, CERT_TYPE, NO_VERIFY, NULL),
22179- cases[i].expectedCertType);
22184+ ret = wc_ParseCert(&dc, CERT_TYPE, NO_VERIFY, NULL);
22185+ if (cases[i].certTypeShouldPass)
22186+ ExpectIntEQ(ret, 0);
22187+ else
22188+ ExpectIntNE(ret, 0);
2218022189 wc_FreeDecodedCert(&dc);
2218122190
2218222191 wc_InitDecodedCert(&dc, derBuf, (word32)derSz, NULL);
22183- ExpectIntEQ(wc_ParseCert(&dc, CA_TYPE, NO_VERIFY, NULL),
22184- cases[i].expectedCaType);
22192+ ret = wc_ParseCert(&dc, CA_TYPE, NO_VERIFY, NULL);
22193+ if (cases[i].caTypeShouldPass)
22194+ ExpectIntEQ(ret, 0);
22195+ else
22196+ ExpectIntNE(ret, 0);
2218522197 wc_FreeDecodedCert(&dc);
2218622198
2218722199 XFREE(derBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
0 commit comments