summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjsing <>2026-04-01 14:38:26 +0000
committerjsing <>2026-04-01 14:38:26 +0000
commit67ef63bdfc3a504381a2ca266dcaf63bae2c5bf5 (patch)
treeba628ea167739db71df8200e20d6387005e97ebc /src/lib
parent78103634af9a3c6964b84982770f7a76f56e8c2c (diff)
downloadopenbsd-67ef63bdfc3a504381a2ca266dcaf63bae2c5bf5.tar.gz
openbsd-67ef63bdfc3a504381a2ca266dcaf63bae2c5bf5.tar.bz2
openbsd-67ef63bdfc3a504381a2ca266dcaf63bae2c5bf5.zip
Restore the previous behaviour with maximum verification depth.
The maximum depth is not expected to include the leaf certificate - restore the decrement prior to checking, which means the previous behaviour is retained for the callback depth and the maximum depth. Reduce the maximum depth by one in order to avoid the overwrite that could previously occur. Thanks to anton@ for flagging the rust-openssl failure in regress. ok tb@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/x509/x509_verify.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/lib/libcrypto/x509/x509_verify.c b/src/lib/libcrypto/x509/x509_verify.c
index a530275ac9..fc3fbc14da 100644
--- a/src/lib/libcrypto/x509/x509_verify.c
+++ b/src/lib/libcrypto/x509/x509_verify.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_verify.c,v 1.74 2026/03/31 13:58:05 jsing Exp $ */ 1/* $OpenBSD: x509_verify.c,v 1.75 2026/04/01 14:38:26 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2020-2021 Bob Beck <beck@openbsd.org> 3 * Copyright (c) 2020-2021 Bob Beck <beck@openbsd.org>
4 * 4 *
@@ -666,13 +666,13 @@ x509_verify_build_chains(struct x509_verify_ctx *ctx, X509 *cert,
666 return; 666 return;
667 667
668 depth = sk_X509_num(current_chain->certs); 668 depth = sk_X509_num(current_chain->certs);
669 if (depth > 0)
670 depth--;
669 if (depth >= ctx->max_depth) { 671 if (depth >= ctx->max_depth) {
670 (void)x509_verify_cert_error(ctx, cert, depth, 672 (void)x509_verify_cert_error(ctx, cert, depth,
671 X509_V_ERR_CERT_CHAIN_TOO_LONG, 0); 673 X509_V_ERR_CERT_CHAIN_TOO_LONG, 0);
672 return; 674 return;
673 } 675 }
674 if (depth > 0)
675 depth--;
676 676
677 count = ctx->chains_count; 677 count = ctx->chains_count;
678 678
@@ -978,8 +978,8 @@ x509_verify_ctx_new_from_xsc(X509_STORE_CTX *xsc)
978 (ctx->intermediates = X509_chain_up_ref(xsc->untrusted)) == NULL) 978 (ctx->intermediates = X509_chain_up_ref(xsc->untrusted)) == NULL)
979 goto err; 979 goto err;
980 980
981 max_depth = X509_VERIFY_MAX_CHAIN_CERTS; 981 max_depth = X509_VERIFY_MAX_CHAIN_CERTS - 1;
982 if (xsc->param->depth > 0 && xsc->param->depth < X509_VERIFY_MAX_CHAIN_CERTS) 982 if (xsc->param->depth > 0 && xsc->param->depth < max_depth)
983 max_depth = xsc->param->depth; 983 max_depth = xsc->param->depth;
984 if (!x509_verify_ctx_set_max_depth(ctx, max_depth)) 984 if (!x509_verify_ctx_set_max_depth(ctx, max_depth))
985 goto err; 985 goto err;
@@ -1008,7 +1008,7 @@ x509_verify_ctx_new(STACK_OF(X509) *roots)
1008 goto err; 1008 goto err;
1009 } 1009 }
1010 1010
1011 ctx->max_depth = X509_VERIFY_MAX_CHAIN_CERTS; 1011 ctx->max_depth = X509_VERIFY_MAX_CHAIN_CERTS - 1;
1012 ctx->max_chains = X509_VERIFY_MAX_CHAINS; 1012 ctx->max_chains = X509_VERIFY_MAX_CHAINS;
1013 ctx->max_sigs = X509_VERIFY_MAX_SIGCHECKS; 1013 ctx->max_sigs = X509_VERIFY_MAX_SIGCHECKS;
1014 1014
@@ -1035,7 +1035,7 @@ x509_verify_ctx_free(struct x509_verify_ctx *ctx)
1035int 1035int
1036x509_verify_ctx_set_max_depth(struct x509_verify_ctx *ctx, size_t max) 1036x509_verify_ctx_set_max_depth(struct x509_verify_ctx *ctx, size_t max)
1037{ 1037{
1038 if (max < 1 || max > X509_VERIFY_MAX_CHAIN_CERTS) 1038 if (max < 1 || max >= X509_VERIFY_MAX_CHAIN_CERTS)
1039 return 0; 1039 return 0;
1040 ctx->max_depth = max; 1040 ctx->max_depth = max;
1041 return 1; 1041 return 1;