|
34 | 34 | #ifdef OPENSSL_EXTRA |
35 | 35 | static int X509StoreGetIssuerEx(WOLFSSL_X509 **issuer, |
36 | 36 | WOLFSSL_STACK *certs, WOLFSSL_X509 *x); |
37 | | -static int X509StorePopCert(WOLFSSL_STACK *certs_stack, WOLFSSL_STACK *dest_stack, |
| 37 | +static int X509StorePopCert(WOLFSSL_STACK *certs_stack, |
| 38 | + WOLFSSL_STACK *dest_stack, |
38 | 39 | WOLFSSL_X509 *cert); |
39 | 40 | static int X509StoreAddCa(WOLFSSL_X509_STORE* store, |
40 | 41 | WOLFSSL_X509* x509, int type); |
@@ -566,14 +567,17 @@ int wolfSSL_X509_verify_cert(WOLFSSL_X509_STORE_CTX* ctx) |
566 | 567 | continue; |
567 | 568 |
|
568 | 569 | retry: |
569 | | - /* Current certificate failed, but it is possible there is an alternative |
570 | | - * cert with the same subject key which will work. Retry until all |
571 | | - * possible candidate certs are exhausted. */ |
572 | | - WOLFSSL_MSG("X509_verify_cert current cert failed, retrying with other certs."); |
573 | | - ret = X509StoreRemoveCa(ctx->store, ctx->current_cert, WOLFSSL_TEMP_CA); |
| 570 | + /* Current certificate failed, but it is possible there is an |
| 571 | + * alternative cert with the same subject key which will work. |
| 572 | + * Retry until all possible candidate certs are exhausted. */ |
| 573 | + WOLFSSL_MSG("X509_verify_cert current cert failed," |
| 574 | + "retrying with other certs."); |
| 575 | + ret = X509StoreRemoveCa(ctx->store, ctx->current_cert, |
| 576 | + WOLFSSL_TEMP_CA); |
574 | 577 | X509StorePopCert(certs, failedCerts, ctx->current_cert); |
575 | 578 | ctx->current_cert = wolfSSL_sk_X509_pop(ctx->chain); |
576 | | - depth++; |
| 579 | + if (depth < origDepth) |
| 580 | + depth++; |
577 | 581 | } |
578 | 582 |
|
579 | 583 | exit: |
@@ -1094,15 +1098,18 @@ static int X509StoreGetIssuerEx(WOLFSSL_X509 **issuer, |
1094 | 1098 | return WOLFSSL_FAILURE; |
1095 | 1099 | } |
1096 | 1100 |
|
1097 | | -static int X509StorePopCert(WOLFSSL_STACK *certs_stack, WOLFSSL_STACK *dest_stack, WOLFSSL_X509 *cert) { |
| 1101 | +static int X509StorePopCert(WOLFSSL_STACK *certs_stack, |
| 1102 | + WOLFSSL_STACK *dest_stack, |
| 1103 | + WOLFSSL_X509 *cert) { |
1098 | 1104 | int i; |
1099 | 1105 |
|
1100 | 1106 | if (certs_stack == NULL || dest_stack == NULL || cert == NULL) |
1101 | 1107 | return WOLFSSL_FATAL_ERROR; |
1102 | 1108 |
|
1103 | 1109 | for (i = 0; i < wolfSSL_sk_X509_num(certs_stack); i++) { |
1104 | 1110 | if (wolfSSL_sk_X509_value(certs_stack, i) == cert) { |
1105 | | - wolfSSL_sk_X509_push(dest_stack, (WOLFSSL_X509*)wolfSSL_sk_pop_node(certs_stack, i)); |
| 1111 | + wolfSSL_sk_X509_push(dest_stack, |
| 1112 | + (WOLFSSL_X509*)wolfSSL_sk_pop_node(certs_stack, i)); |
1106 | 1113 | return WOLFSSL_SUCCESS; |
1107 | 1114 | } |
1108 | 1115 | } |
@@ -1456,7 +1463,8 @@ static int X509StoreRemoveCa(WOLFSSL_X509_STORE* store, |
1456 | 1463 | return result; |
1457 | 1464 | } |
1458 | 1465 | XMEMSET(dCert, 0, sizeof(DecodedCert)); |
1459 | | - wc_InitDecodedCert(dCert, x509->derCert->buffer, x509->derCert->length, NULL); |
| 1466 | + wc_InitDecodedCert(dCert, x509->derCert->buffer, |
| 1467 | + x509->derCert->length, NULL); |
1460 | 1468 | result = wc_ParseCert(dCert, CA_TYPE, NO_VERIFY, store->cm); |
1461 | 1469 | if (result) |
1462 | 1470 | return WOLFSSL_FATAL_ERROR; |
|
0 commit comments