summaryrefslogtreecommitdiff
path: root/src/regress
diff options
context:
space:
mode:
authortb <>2026-05-04 13:49:07 +0000
committertb <>2026-05-04 13:49:07 +0000
commit3929ff270ef9b26fe9c48a308e3003faa4a61e1d (patch)
tree9a577f7adaeb0179bf440f33f33bb3c30f7621f6 /src/regress
parent934ab37db5ee3acfdf12b2d3882069127e140f0a (diff)
downloadopenbsd-3929ff270ef9b26fe9c48a308e3003faa4a61e1d.tar.gz
openbsd-3929ff270ef9b26fe9c48a308e3003faa4a61e1d.tar.bz2
openbsd-3929ff270ef9b26fe9c48a308e3003faa4a61e1d.zip
verify regress: allow setting verify depth and callback
This is pretty ugly and probably the the vct should be handed down to the verify_cert*() functions, but this works and doesn't make these tests any uglier than they already are. The callback regress was modified with a least effort approach.
Diffstat (limited to 'src/regress')
-rw-r--r--src/regress/lib/libcrypto/x509/callback.c15
-rw-r--r--src/regress/lib/libcrypto/x509/verify.c36
2 files changed, 38 insertions, 13 deletions
diff --git a/src/regress/lib/libcrypto/x509/callback.c b/src/regress/lib/libcrypto/x509/callback.c
index a3717bca24..24339e7613 100644
--- a/src/regress/lib/libcrypto/x509/callback.c
+++ b/src/regress/lib/libcrypto/x509/callback.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: callback.c,v 1.6 2026/03/31 13:39:48 jsing Exp $ */ 1/* $OpenBSD: callback.c,v 1.7 2026/05/04 13:49:07 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2020 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2020 Joel Sing <jsing@openbsd.org>
4 * Copyright (c) 2020-2021 Bob Beck <beck@openbsd.org> 4 * Copyright (c) 2020-2021 Bob Beck <beck@openbsd.org>
@@ -110,7 +110,7 @@ verify_cert_cb(int ok, X509_STORE_CTX *xsc)
110 110
111static void 111static void
112verify_cert(const char *roots_dir, const char *roots_file, 112verify_cert(const char *roots_dir, const char *roots_file,
113 const char *bundle_file, int *chains, int mode) 113 const char *bundle_file, int *chains, int set_depth, int mode)
114{ 114{
115 STACK_OF(X509) *roots = NULL, *bundle = NULL; 115 STACK_OF(X509) *roots = NULL, *bundle = NULL;
116 X509_STORE_CTX *xsc = NULL; 116 X509_STORE_CTX *xsc = NULL;
@@ -141,6 +141,10 @@ verify_cert(const char *roots_dir, const char *roots_file,
141 if (!X509_STORE_load_locations(store, NULL, roots_dir)) 141 if (!X509_STORE_load_locations(store, NULL, roots_dir))
142 errx(1, "failed to set by_dir directory of %s", roots_dir); 142 errx(1, "failed to set by_dir directory of %s", roots_dir);
143 } 143 }
144 if (set_depth > 0) {
145 X509_VERIFY_PARAM_set_depth(X509_STORE_CTX_get0_param(xsc),
146 set_depth);
147 }
144 if (mode == MODE_LEGACY_VFY) 148 if (mode == MODE_LEGACY_VFY)
145 X509_STORE_CTX_set_flags(xsc, X509_V_FLAG_LEGACY_VERIFY); 149 X509_STORE_CTX_set_flags(xsc, X509_V_FLAG_LEGACY_VERIFY);
146 else 150 else
@@ -174,6 +178,7 @@ verify_cert(const char *roots_dir, const char *roots_file,
174 178
175struct verify_cert_test { 179struct verify_cert_test {
176 const char *id; 180 const char *id;
181 int set_depth;
177 int want_chains; 182 int want_chains;
178 int failing; 183 int failing;
179}; 184};
@@ -378,7 +383,8 @@ verify_cert_test(const char *certs_path, int mode)
378 fprintf(output, "== Test %zu (%s)\n", i, vct->id); 383 fprintf(output, "== Test %zu (%s)\n", i, vct->id);
379 fprintf(output, "== Legacy:\n"); 384 fprintf(output, "== Legacy:\n");
380 mode = MODE_LEGACY_VFY; 385 mode = MODE_LEGACY_VFY;
381 verify_cert(roots_dir, roots_file, bundle_file, &chains, mode); 386 verify_cert(roots_dir, roots_file, bundle_file, &chains,
387 vct->set_depth, mode);
382 if ((mode == MODE_VERIFY && chains == vct->want_chains) || 388 if ((mode == MODE_VERIFY && chains == vct->want_chains) ||
383 (chains == 0 && vct->want_chains == 0) || 389 (chains == 0 && vct->want_chains == 0) ||
384 (chains == 1 && vct->want_chains > 0)) { 390 (chains == 1 && vct->want_chains > 0)) {
@@ -395,7 +401,8 @@ verify_cert_test(const char *certs_path, int mode)
395 fprintf(output, "\n"); 401 fprintf(output, "\n");
396 fprintf(output, "== Modern:\n"); 402 fprintf(output, "== Modern:\n");
397 mode = MODE_MODERN_VFY; 403 mode = MODE_MODERN_VFY;
398 verify_cert(roots_dir, roots_file, bundle_file, &chains, mode); 404 verify_cert(roots_dir, roots_file, bundle_file, &chains,
405 vct->set_depth, mode);
399 if ((mode == MODE_VERIFY && chains == vct->want_chains) || 406 if ((mode == MODE_VERIFY && chains == vct->want_chains) ||
400 (chains == 0 && vct->want_chains == 0) || 407 (chains == 0 && vct->want_chains == 0) ||
401 (chains == 1 && vct->want_chains > 0)) { 408 (chains == 1 && vct->want_chains > 0)) {
diff --git a/src/regress/lib/libcrypto/x509/verify.c b/src/regress/lib/libcrypto/x509/verify.c
index 77cdbfd915..c65c988948 100644
--- a/src/regress/lib/libcrypto/x509/verify.c
+++ b/src/regress/lib/libcrypto/x509/verify.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: verify.c,v 1.14 2026/04/01 14:39:11 jsing Exp $ */ 1/* $OpenBSD: verify.c,v 1.15 2026/05/04 13:49:07 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2020 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2020 Joel Sing <jsing@openbsd.org>
4 * Copyright (c) 2020-2021 Bob Beck <beck@openbsd.org> 4 * Copyright (c) 2020-2021 Bob Beck <beck@openbsd.org>
@@ -105,7 +105,7 @@ verify_cert_cb(int ok, X509_STORE_CTX *xsc)
105static void 105static void
106verify_cert(const char *roots_dir, const char *roots_file, 106verify_cert(const char *roots_dir, const char *roots_file,
107 const char *bundle_file, int *chains, int *error, int *error_depth, 107 const char *bundle_file, int *chains, int *error, int *error_depth,
108 int mode) 108 int set_depth, int (*verify_cb)(int, X509_STORE_CTX *), int mode)
109{ 109{
110 STACK_OF(X509) *roots = NULL, *bundle = NULL; 110 STACK_OF(X509) *roots = NULL, *bundle = NULL;
111 X509_STORE_CTX *xsc = NULL; 111 X509_STORE_CTX *xsc = NULL;
@@ -140,14 +140,21 @@ verify_cert(const char *roots_dir, const char *roots_file,
140 if (!X509_STORE_load_locations(store, NULL, roots_dir)) 140 if (!X509_STORE_load_locations(store, NULL, roots_dir))
141 errx(1, "failed to set by_dir directory of %s", roots_dir); 141 errx(1, "failed to set by_dir directory of %s", roots_dir);
142 } 142 }
143 if (set_depth > 0) {
144 X509_VERIFY_PARAM_set_depth(X509_STORE_CTX_get0_param(xsc),
145 set_depth);
146 }
143 if (mode == MODE_LEGACY_VFY) 147 if (mode == MODE_LEGACY_VFY)
144 X509_STORE_CTX_set_flags(xsc, X509_V_FLAG_LEGACY_VERIFY); 148 X509_STORE_CTX_set_flags(xsc, X509_V_FLAG_LEGACY_VERIFY);
145 else 149 else
146 X509_VERIFY_PARAM_clear_flags(X509_STORE_CTX_get0_param(xsc), 150 X509_VERIFY_PARAM_clear_flags(X509_STORE_CTX_get0_param(xsc),
147 X509_V_FLAG_LEGACY_VERIFY); 151 X509_V_FLAG_LEGACY_VERIFY);
148 152
149 if (verbose) 153 if (verbose && verify_cb == NULL)
150 X509_STORE_CTX_set_verify_cb(xsc, verify_cert_cb); 154 verify_cb = verify_cert_cb;
155 if (verify_cb != NULL)
156 X509_STORE_CTX_set_verify_cb(xsc, verify_cb);
157
151 if (!use_dir) 158 if (!use_dir)
152 X509_STORE_CTX_set0_trusted_stack(xsc, roots); 159 X509_STORE_CTX_set0_trusted_stack(xsc, roots);
153 160
@@ -176,7 +183,8 @@ verify_cert(const char *roots_dir, const char *roots_file,
176} 183}
177 184
178static void 185static void
179verify_cert_new(const char *roots_file, const char *bundle_file, int *chains) 186verify_cert_new(const char *roots_file, const char *bundle_file, int *chains,
187 int set_depth, int (*verify_cb)(int, X509_STORE_CTX *))
180{ 188{
181 STACK_OF(X509) *roots = NULL, *bundle = NULL; 189 STACK_OF(X509) *roots = NULL, *bundle = NULL;
182 X509_STORE_CTX *xsc = NULL; 190 X509_STORE_CTX *xsc = NULL;
@@ -199,13 +207,19 @@ verify_cert_new(const char *roots_file, const char *bundle_file, int *chains)
199 ERR_print_errors_fp(stderr); 207 ERR_print_errors_fp(stderr);
200 errx(1, "failed to init store context"); 208 errx(1, "failed to init store context");
201 } 209 }
202 if (verbose) 210 if (verbose && verify_cb == NULL)
203 X509_STORE_CTX_set_verify_cb(xsc, verify_cert_cb); 211 verify_cb = verify_cert_cb;
212 if (verify_cb != NULL)
213 X509_STORE_CTX_set_verify_cb(xsc, verify_cb);
204 214
205 if ((ctx = x509_verify_ctx_new(roots)) == NULL) 215 if ((ctx = x509_verify_ctx_new(roots)) == NULL)
206 errx(1, "failed to create ctx"); 216 errx(1, "failed to create ctx");
207 if (!x509_verify_ctx_set_intermediates(ctx, bundle)) 217 if (!x509_verify_ctx_set_intermediates(ctx, bundle))
208 errx(1, "failed to set intermediates"); 218 errx(1, "failed to set intermediates");
219 if (set_depth > 0) {
220 if (!x509_verify_ctx_set_max_depth(ctx, set_depth))
221 errx(1, "failed to set max depth");
222 }
209 223
210 if ((*chains = x509_verify(ctx, leaf, NULL)) == 0) { 224 if ((*chains = x509_verify(ctx, leaf, NULL)) == 0) {
211 fprintf(stderr, "failed to verify at %lu: %s\n", 225 fprintf(stderr, "failed to verify at %lu: %s\n",
@@ -238,8 +252,10 @@ verify_cert_new(const char *roots_file, const char *bundle_file, int *chains)
238 252
239struct verify_cert_test { 253struct verify_cert_test {
240 const char *id; 254 const char *id;
255 int (*verify_cb)(int, X509_STORE_CTX *);
241 int want_chains; 256 int want_chains;
242 int want_error; 257 int want_error;
258 int set_depth;
243 int want_error_depth; 259 int want_error_depth;
244 int want_legacy_error; 260 int want_legacy_error;
245 int want_legacy_error_depth; 261 int want_legacy_error_depth;
@@ -505,10 +521,12 @@ verify_cert_test(const char *certs_path, int mode)
505 521
506 fprintf(stderr, "== Test %zu (%s)\n", i, vct->id); 522 fprintf(stderr, "== Test %zu (%s)\n", i, vct->id);
507 if (mode == MODE_VERIFY) 523 if (mode == MODE_VERIFY)
508 verify_cert_new(roots_file, bundle_file, &chains); 524 verify_cert_new(roots_file, bundle_file, &chains,
525 vct->set_depth, vct->verify_cb);
509 else 526 else
510 verify_cert(roots_dir, roots_file, bundle_file, &chains, 527 verify_cert(roots_dir, roots_file, bundle_file, &chains,
511 &error, &error_depth, mode); 528 &error, &error_depth, vct->set_depth, vct->verify_cb,
529 mode);
512 530
513 if ((mode == MODE_VERIFY && chains == vct->want_chains) || 531 if ((mode == MODE_VERIFY && chains == vct->want_chains) ||
514 (chains == 0 && vct->want_chains == 0) || 532 (chains == 0 && vct->want_chains == 0) ||