Skip to content

Commit 47abfb5

Browse files
committed
x509_str: verify leaf signature even when verify_cb overrides INVALID_CA
When verify_cb returned WOLFSSL_SUCCESS to suppress X509_V_ERR_INVALID_CA for a non-CA issuer, control skipped X509StoreVerifyCert and the leaf signature was never checked. Drop the else so signature verification runs on every issuer.
1 parent 5eb0263 commit 47abfb5

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

src/x509_str.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,10 @@ int wolfSSL_X509_verify_cert(WOLFSSL_X509_STORE_CTX* ctx)
705705

706706
/* We found our issuer in the non-trusted cert list, add it
707707
* to the CM and verify the current cert against it */
708-
/* RFC 5280 4.2.1.9: reject non-CA issuer. */
708+
/* RFC 5280 4.2.1.9: reject non-CA issuer. verify_cb may
709+
* suppress the INVALID_CA error to keep building the chain,
710+
* but the leaf signature must still be verified against the
711+
* issuer below — never skip X509StoreVerifyCert. */
709712
if (!issuer->isCa) {
710713
SetupStoreCtxError_ex(ctx, X509_V_ERR_INVALID_CA,
711714
(ctx->chain) ? (int)(ctx->chain->num + 1) : 1);
@@ -724,26 +727,23 @@ int wolfSSL_X509_verify_cert(WOLFSSL_X509_STORE_CTX* ctx)
724727
goto exit;
725728
}
726729
}
727-
else {
728-
ret = X509StoreAddCa(ctx->store, issuer,
729-
WOLFSSL_TEMP_CA);
730-
if (ret != WOLFSSL_SUCCESS) {
731-
X509VerifyCertSetupRetry(ctx, certs, failedCerts,
732-
&depth, origDepth);
733-
continue;
734-
}
735-
added = 1;
736-
ret = X509StoreVerifyCert(ctx);
737-
if (ret != WOLFSSL_SUCCESS) {
738-
if ((origDepth - depth) <= 1)
739-
added = 0;
740-
X509VerifyCertSetupRetry(ctx, certs, failedCerts,
741-
&depth, origDepth);
742-
continue;
743-
}
744-
/* Add it to the current chain and look at the issuer cert next */
745-
wolfSSL_sk_X509_push(ctx->chain, ctx->current_cert);
730+
ret = X509StoreAddCa(ctx->store, issuer, WOLFSSL_TEMP_CA);
731+
if (ret != WOLFSSL_SUCCESS) {
732+
X509VerifyCertSetupRetry(ctx, certs, failedCerts,
733+
&depth, origDepth);
734+
continue;
746735
}
736+
added = 1;
737+
ret = X509StoreVerifyCert(ctx);
738+
if (ret != WOLFSSL_SUCCESS) {
739+
if ((origDepth - depth) <= 1)
740+
added = 0;
741+
X509VerifyCertSetupRetry(ctx, certs, failedCerts,
742+
&depth, origDepth);
743+
continue;
744+
}
745+
/* Add it to the current chain and look at the issuer cert next */
746+
wolfSSL_sk_X509_push(ctx->chain, ctx->current_cert);
747747
ctx->current_cert = issuer;
748748
}
749749
else if (ret == WC_NO_ERR_TRACE(WOLFSSL_FAILURE)) {

0 commit comments

Comments
 (0)