diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libcrypto/x509/callback.c | 24 | ||||
| -rw-r--r-- | src/regress/lib/libcrypto/x509/verify.c | 85 |
2 files changed, 105 insertions, 4 deletions
diff --git a/src/regress/lib/libcrypto/x509/callback.c b/src/regress/lib/libcrypto/x509/callback.c index 24339e7613..a021115531 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.7 2026/05/04 13:49:07 tb Exp $ */ | 1 | /* $OpenBSD: callback.c,v 1.8 2026/05/04 13:52:39 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> |
| @@ -177,6 +177,7 @@ verify_cert(const char *roots_dir, const char *roots_file, | |||
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | struct verify_cert_test { | 179 | struct verify_cert_test { |
| 180 | const char *desc; | ||
| 180 | const char *id; | 181 | const char *id; |
| 181 | int set_depth; | 182 | int set_depth; |
| 182 | int want_chains; | 183 | int want_chains; |
| @@ -193,6 +194,24 @@ struct verify_cert_test verify_cert_tests[] = { | |||
| 193 | .want_chains = 1, | 194 | .want_chains = 1, |
| 194 | }, | 195 | }, |
| 195 | { | 196 | { |
| 197 | .desc = "2a with depth 2", | ||
| 198 | .id = "2a", | ||
| 199 | .set_depth = 2, | ||
| 200 | .want_chains = 1, | ||
| 201 | }, | ||
| 202 | { | ||
| 203 | .desc = "2a with depth 1", | ||
| 204 | .id = "2a", | ||
| 205 | .set_depth = 1, | ||
| 206 | .want_chains = 0, | ||
| 207 | }, | ||
| 208 | { | ||
| 209 | .desc = "2a with depth 1", | ||
| 210 | .id = "2a", | ||
| 211 | .set_depth = 1, | ||
| 212 | .want_chains = 0, | ||
| 213 | }, | ||
| 214 | { | ||
| 196 | .id = "2b", | 215 | .id = "2b", |
| 197 | .want_chains = 0, | 216 | .want_chains = 0, |
| 198 | }, | 217 | }, |
| @@ -380,7 +399,8 @@ verify_cert_test(const char *certs_path, int mode) | |||
| 380 | if (asprintf(&roots_dir, "./%s/roots", vct->id) == -1) | 399 | if (asprintf(&roots_dir, "./%s/roots", vct->id) == -1) |
| 381 | errx(1, "asprintf"); | 400 | errx(1, "asprintf"); |
| 382 | 401 | ||
| 383 | fprintf(output, "== Test %zu (%s)\n", i, vct->id); | 402 | fprintf(output, "== Test %zu (%s)\n", i, |
| 403 | vct->desc != NULL ? vct->desc : vct->id); | ||
| 384 | fprintf(output, "== Legacy:\n"); | 404 | fprintf(output, "== Legacy:\n"); |
| 385 | mode = MODE_LEGACY_VFY; | 405 | mode = MODE_LEGACY_VFY; |
| 386 | verify_cert(roots_dir, roots_file, bundle_file, &chains, | 406 | verify_cert(roots_dir, roots_file, bundle_file, &chains, |
diff --git a/src/regress/lib/libcrypto/x509/verify.c b/src/regress/lib/libcrypto/x509/verify.c index c65c988948..8696209922 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.15 2026/05/04 13:49:07 tb Exp $ */ | 1 | /* $OpenBSD: verify.c,v 1.16 2026/05/04 13:52:39 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> |
| @@ -102,6 +102,41 @@ verify_cert_cb(int ok, X509_STORE_CTX *xsc) | |||
| 102 | return ok; | 102 | return ok; |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | static int | ||
| 106 | verify_cert_depth_cb(int ok, X509_STORE_CTX *xsc) | ||
| 107 | { | ||
| 108 | int verify_err; | ||
| 109 | |||
| 110 | ok = verify_cert_cb(ok, xsc); | ||
| 111 | |||
| 112 | verify_err = X509_STORE_CTX_get_error(xsc); | ||
| 113 | if (verify_err == X509_V_ERR_CERT_CHAIN_TOO_LONG) { | ||
| 114 | fprintf(stderr, "overriding verify error at depth %d: %s\n", | ||
| 115 | X509_STORE_CTX_get_error_depth(xsc), | ||
| 116 | X509_verify_cert_error_string(verify_err)); | ||
| 117 | ok = 1; | ||
| 118 | } | ||
| 119 | |||
| 120 | return ok; | ||
| 121 | } | ||
| 122 | |||
| 123 | static int | ||
| 124 | verify_cert_yolo_cb(int ok, X509_STORE_CTX *xsc) | ||
| 125 | { | ||
| 126 | int verify_err; | ||
| 127 | |||
| 128 | verify_cert_cb(ok, xsc); | ||
| 129 | |||
| 130 | verify_err = X509_STORE_CTX_get_error(xsc); | ||
| 131 | if (verify_err != X509_V_OK) { | ||
| 132 | fprintf(stderr, "overriding verify error at depth %d: %s\n", | ||
| 133 | X509_STORE_CTX_get_error_depth(xsc), | ||
| 134 | X509_verify_cert_error_string(verify_err)); | ||
| 135 | } | ||
| 136 | |||
| 137 | return 1; | ||
| 138 | } | ||
| 139 | |||
| 105 | static void | 140 | static void |
| 106 | verify_cert(const char *roots_dir, const char *roots_file, | 141 | verify_cert(const char *roots_dir, const char *roots_file, |
| 107 | const char *bundle_file, int *chains, int *error, int *error_depth, | 142 | const char *bundle_file, int *chains, int *error, int *error_depth, |
| @@ -251,6 +286,7 @@ verify_cert_new(const char *roots_file, const char *bundle_file, int *chains, | |||
| 251 | } | 286 | } |
| 252 | 287 | ||
| 253 | struct verify_cert_test { | 288 | struct verify_cert_test { |
| 289 | const char *desc; | ||
| 254 | const char *id; | 290 | const char *id; |
| 255 | int (*verify_cb)(int, X509_STORE_CTX *); | 291 | int (*verify_cb)(int, X509_STORE_CTX *); |
| 256 | int want_chains; | 292 | int want_chains; |
| @@ -272,6 +308,32 @@ struct verify_cert_test verify_cert_tests[] = { | |||
| 272 | .want_chains = 1, | 308 | .want_chains = 1, |
| 273 | }, | 309 | }, |
| 274 | { | 310 | { |
| 311 | .desc = "2a with depth 2", | ||
| 312 | .id = "2a", | ||
| 313 | .set_depth = 2, | ||
| 314 | .want_chains = 1, | ||
| 315 | }, | ||
| 316 | { | ||
| 317 | .desc = "2a with depth 1", | ||
| 318 | .id = "2a", | ||
| 319 | .set_depth = 1, | ||
| 320 | .want_chains = 0, | ||
| 321 | .want_error = X509_V_ERR_CERT_CHAIN_TOO_LONG, | ||
| 322 | .want_error_depth = 1, | ||
| 323 | .want_legacy_error = X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, | ||
| 324 | .want_legacy_error_depth = 1, | ||
| 325 | }, | ||
| 326 | { | ||
| 327 | .desc = "2a with depth 1 and depth callback", | ||
| 328 | .id = "2a", | ||
| 329 | .verify_cb = verify_cert_depth_cb, | ||
| 330 | .set_depth = 1, | ||
| 331 | .want_chains = 1, | ||
| 332 | .want_legacy_error = X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, | ||
| 333 | .want_legacy_error_depth = 1, | ||
| 334 | .failing = 1, | ||
| 335 | }, | ||
| 336 | { | ||
| 275 | .id = "2b", | 337 | .id = "2b", |
| 276 | .want_chains = 0, | 338 | .want_chains = 0, |
| 277 | .want_error = X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, | 339 | .want_error = X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, |
| @@ -482,6 +544,13 @@ struct verify_cert_test verify_cert_tests[] = { | |||
| 482 | .want_error_depth = 0, | 544 | .want_error_depth = 0, |
| 483 | }, | 545 | }, |
| 484 | { | 546 | { |
| 547 | .desc = "14a with yolo callback", | ||
| 548 | .id = "14a", | ||
| 549 | .verify_cb = verify_cert_yolo_cb, | ||
| 550 | .want_chains = 1, | ||
| 551 | .want_error_depth = 0, | ||
| 552 | }, | ||
| 553 | { | ||
| 485 | .id = "14b", | 554 | .id = "14b", |
| 486 | .want_chains = 0, | 555 | .want_chains = 0, |
| 487 | .want_error = X509_V_ERR_CERT_CHAIN_TOO_LONG, | 556 | .want_error = X509_V_ERR_CERT_CHAIN_TOO_LONG, |
| @@ -490,6 +559,17 @@ struct verify_cert_test verify_cert_tests[] = { | |||
| 490 | .want_legacy_error_depth = 0, | 559 | .want_legacy_error_depth = 0, |
| 491 | .failing = 1, | 560 | .failing = 1, |
| 492 | }, | 561 | }, |
| 562 | { | ||
| 563 | .desc = "14b with yolo callback", | ||
| 564 | .id = "14b", | ||
| 565 | .verify_cb = verify_cert_yolo_cb, | ||
| 566 | .want_chains = 0, | ||
| 567 | .want_error = X509_V_ERR_CERT_CHAIN_TOO_LONG, | ||
| 568 | .want_error_depth = 32, | ||
| 569 | .want_legacy_error = 0, | ||
| 570 | .want_legacy_error_depth = 0, | ||
| 571 | .failing = 1, | ||
| 572 | }, | ||
| 493 | }; | 573 | }; |
| 494 | 574 | ||
| 495 | #define N_VERIFY_CERT_TESTS \ | 575 | #define N_VERIFY_CERT_TESTS \ |
| @@ -519,7 +599,8 @@ verify_cert_test(const char *certs_path, int mode) | |||
| 519 | error = 0; | 599 | error = 0; |
| 520 | error_depth = 0; | 600 | error_depth = 0; |
| 521 | 601 | ||
| 522 | fprintf(stderr, "== Test %zu (%s)\n", i, vct->id); | 602 | fprintf(stderr, "== Test %zu (%s)\n", i, |
| 603 | vct->desc != NULL ? vct->desc : vct->id); | ||
| 523 | if (mode == MODE_VERIFY) | 604 | if (mode == MODE_VERIFY) |
| 524 | verify_cert_new(roots_file, bundle_file, &chains, | 605 | verify_cert_new(roots_file, bundle_file, &chains, |
| 525 | vct->set_depth, vct->verify_cb); | 606 | vct->set_depth, vct->verify_cb); |
