Skip to content

Commit 96138e7

Browse files
ColtonWilleydouzzer
authored andcommitted
Restore proper error code handling for self signed CA in non-trusted intermediates
1 parent 4c63668 commit 96138e7

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/x509_str.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ int wolfSSL_X509_verify_cert(WOLFSSL_X509_STORE_CTX* ctx)
305305
int depth = 0;
306306
WOLFSSL_X509 *issuer = NULL;
307307
WOLFSSL_X509 *orig = NULL;
308+
WOLFSSL_X509 *tmp = NULL;
308309
WOLF_STACK_OF(WOLFSSL_X509)* certs = NULL;
309310
WOLFSSL_ENTER("wolfSSL_X509_verify_cert");
310311

@@ -355,6 +356,25 @@ int wolfSSL_X509_verify_cert(WOLFSSL_X509_STORE_CTX* ctx)
355356
/* Try to find an untrusted issuer first */
356357
ret = X509StoreGetIssuerEx(&issuer, certs,
357358
ctx->current_cert);
359+
if (issuer != NULL &&
360+
wolfSSL_X509_NAME_cmp(&issuer->issuer, &issuer->subject) == 0) {
361+
ret = WOLFSSL_FAILURE;
362+
/* Self signed allowed if in set trusted stack, otherwise
363+
* ignore it and fall back to see if its in CM */
364+
if ((certs == ctx->setTrustedSk) &&
365+
(wolfSSL_sk_X509_num(certs) > numInterAdd)) {
366+
for (i = wolfSSL_sk_X509_num(certs) - 1;
367+
i > (numInterAdd > 0 ? numInterAdd - 1 : 0);
368+
i++) {
369+
tmp = wolfSSL_sk_X509_value(certs, i);
370+
if (wolfSSL_X509_NAME_cmp(
371+
&issuer->subject, &tmp->subject) == 0) {
372+
ret = WOLFSSL_SUCCESS;
373+
break;
374+
}
375+
}
376+
}
377+
}
358378
if (ret == WOLFSSL_SUCCESS) {
359379
if (ctx->current_cert == issuer) {
360380
wolfSSL_sk_X509_push(ctx->chain, ctx->current_cert);

tests/api.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60421,10 +60421,14 @@ static int test_X509_STORE_untrusted(void)
6042160421
/* Succeeds because path to loaded CA is available. */
6042260422
ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted2, 1, 0, 1),
6042360423
TEST_SUCCESS);
60424-
/* Root CA in untrusted chain is OK */
60424+
/* Root CA in untrusted chain is OK so long as CA has been loaded
60425+
* properly */
6042560426
ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted3, 1, 0, 1),
6042660427
TEST_SUCCESS);
60427-
ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted3, 1, 0, 0),
60428+
/* Still needs properly loaded CA, while including it in untrusted
60429+
* list is not an error, it also doesnt count for verify */
60430+
ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted3, 0,
60431+
X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, 0),
6042860432
TEST_SUCCESS);
6042960433
/* Succeeds because path to loaded CA is available. */
6043060434
ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted4, 1, 0, 1),

0 commit comments

Comments
 (0)