From f13186827afc4d6e7d8d1192e733bcd6f0f814c4 Mon Sep 17 00:00:00 2001 From: Hideki Miyazaki Date: Mon, 8 Feb 2021 08:45:00 +0900 Subject: [PATCH] issue callback when exceeding depth limit rather than error out --- src/internal.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/internal.c b/src/internal.c index 5702513ce..c5dabefec 100644 --- a/src/internal.c +++ b/src/internal.c @@ -10834,12 +10834,7 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx, while (listSz) { word32 certSz; - #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) - if (args->totalCerts > ssl->verifyDepth) { - ssl->peerVerifyRet = X509_V_ERR_CERT_CHAIN_TOO_LONG; - ERROR_OUT(MAX_CHAIN_ERROR, exit_ppc); - } - #else + #if !defined(OPENSSL_EXTRA) && !defined(OPENSS_EXTRA_X509_SMALL) if (args->totalCerts >= ssl->verifyDepth || args->totalCerts >= MAX_CHAIN_DEPTH) { ERROR_OUT(MAX_CHAIN_ERROR, exit_ppc); @@ -11078,7 +11073,15 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx, (void)doCrlLookup; } #endif /* HAVE_OCSP || HAVE_CRL */ - +#ifdef OPENSSL_EXTRA + if (ret == 0 && + /* extend the limit "+1" until reaching + * an ultimately trusted issuer.*/ + args->count > (ssl->verifyDepth + 1)) { + ssl->peerVerifyRet = X509_V_ERR_CERT_CHAIN_TOO_LONG; + ret = MAX_CHAIN_ERROR; + } +#endif /* Do verify callback */ ret = DoVerifyCallback(ssl->ctx->cm, ssl, ret, args); if (ssl->options.verifyNone &&