diff options
Diffstat (limited to 'src/regress/lib/libcrypto/ct/cttest.c')
| -rw-r--r-- | src/regress/lib/libcrypto/ct/cttest.c | 84 | 
1 files changed, 79 insertions, 5 deletions
diff --git a/src/regress/lib/libcrypto/ct/cttest.c b/src/regress/lib/libcrypto/ct/cttest.c index a14ae75d89..803b976ef6 100644 --- a/src/regress/lib/libcrypto/ct/cttest.c +++ b/src/regress/lib/libcrypto/ct/cttest.c  | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: cttest.c,v 1.2 2021/12/20 16:52:26 jsing Exp $ */ | 1 | /* $OpenBSD: cttest.c,v 1.3 2022/01/06 04:42:00 jsing Exp $ */ | 
| 2 | /* | 2 | /* | 
| 3 | * Copyright (c) 2021 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2021 Joel Sing <jsing@openbsd.org> | 
| 4 | * | 4 | * | 
| @@ -24,7 +24,9 @@ | |||
| 24 | 24 | ||
| 25 | #include "ct/ct.h" | 25 | #include "ct/ct.h" | 
| 26 | 26 | ||
| 27 | const char *test_cert_file; | 27 | char *test_ctlog_conf_file; | 
| 28 | char *test_cert_file; | ||
| 29 | char *test_issuer_file; | ||
| 28 | 30 | ||
| 29 | const int debug = 0; | 31 | const int debug = 0; | 
| 30 | 32 | ||
| @@ -391,21 +393,93 @@ ct_sct_base64_test(void) | |||
| 391 | return failed; | 393 | return failed; | 
| 392 | } | 394 | } | 
| 393 | 395 | ||
| 396 | static int | ||
| 397 | ct_sct_verify_test(void) | ||
| 398 | { | ||
| 399 | STACK_OF(SCT) *scts = NULL; | ||
| 400 | CT_POLICY_EVAL_CTX *ct_policy = NULL; | ||
| 401 | CTLOG_STORE *ctlog_store = NULL; | ||
| 402 | X509 *cert = NULL, *issuer = NULL; | ||
| 403 | const uint8_t *p; | ||
| 404 | SCT *sct; | ||
| 405 | int failed = 1; | ||
| 406 | |||
| 407 | cert_from_file(test_cert_file, &cert); | ||
| 408 | cert_from_file(test_issuer_file, &issuer); | ||
| 409 | |||
| 410 | if ((ctlog_store = CTLOG_STORE_new()) == NULL) | ||
| 411 | goto failure; | ||
| 412 | if (!CTLOG_STORE_load_file(ctlog_store, test_ctlog_conf_file)) | ||
| 413 | goto failure; | ||
| 414 | |||
| 415 | if ((ct_policy = CT_POLICY_EVAL_CTX_new()) == NULL) | ||
| 416 | goto failure; | ||
| 417 | |||
| 418 | CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(ct_policy, ctlog_store); | ||
| 419 | CT_POLICY_EVAL_CTX_set_time(ct_policy, 1641393117000); | ||
| 420 | |||
| 421 | if (!CT_POLICY_EVAL_CTX_set1_cert(ct_policy, cert)) | ||
| 422 | goto failure; | ||
| 423 | if (!CT_POLICY_EVAL_CTX_set1_issuer(ct_policy, issuer)) | ||
| 424 | goto failure; | ||
| 425 | |||
| 426 | p = scts_asn1; | ||
| 427 | if ((scts = d2i_SCT_LIST(NULL, &p, sizeof(scts_asn1))) == NULL) { | ||
| 428 | fprintf(stderr, "FAIL: failed to decode SCTS from ASN.1\n"); | ||
| 429 | ERR_print_errors_fp(stderr); | ||
| 430 | goto failure; | ||
| 431 | } | ||
| 432 | sct = sk_SCT_value(scts, 0); | ||
| 433 | |||
| 434 | if (!SCT_set_log_entry_type(sct, CT_LOG_ENTRY_TYPE_PRECERT)) | ||
| 435 | goto failure; | ||
| 436 | if (!SCT_validate(sct, ct_policy)) { | ||
| 437 | fprintf(stderr, "FAIL: SCT_validate failed\n"); | ||
| 438 | ERR_print_errors_fp(stderr); | ||
| 439 | goto failure; | ||
| 440 | } | ||
| 441 | |||
| 442 | failed = 0; | ||
| 443 | |||
| 444 | failure: | ||
| 445 | CT_POLICY_EVAL_CTX_free(ct_policy); | ||
| 446 | CTLOG_STORE_free(ctlog_store); | ||
| 447 | X509_free(cert); | ||
| 448 | X509_free(issuer); | ||
| 449 | |||
| 450 | return failed; | ||
| 451 | } | ||
| 452 | |||
| 394 | int | 453 | int | 
| 395 | main(int argc, char **argv) | 454 | main(int argc, char **argv) | 
| 396 | { | 455 | { | 
| 456 | const char *ctpath; | ||
| 397 | int failed = 0; | 457 | int failed = 0; | 
| 398 | 458 | ||
| 399 | if (argc != 2) { | 459 | if (argc != 2) { | 
| 400 | fprintf(stderr, "usage: %s certfile\n", argv[0]); | 460 | fprintf(stderr, "usage: %s ctpath\n", argv[0]); | 
| 401 | exit(1); | 461 | exit(1); | 
| 402 | } | 462 | } | 
| 403 | 463 | ctpath = argv[1]; | |
| 404 | test_cert_file = argv[1]; | 464 | |
| 465 | if (asprintf(&test_cert_file, "%s/%s", ctpath, | ||
| 466 | "libressl.org.crt") == -1) | ||
| 467 | errx(1, "asprintf test_cert_file"); | ||
| 468 | if (asprintf(&test_issuer_file, "%s/%s", ctpath, | ||
| 469 | "letsencrypt-r3.crt") == -1) | ||
| 470 | errx(1, "asprintf test_issuer_file"); | ||
| 471 | if (asprintf(&test_ctlog_conf_file, "%s/%s", ctpath, | ||
| 472 | "ctlog.conf") == -1) | ||
| 473 | errx(1, "asprintf test_ctlog_conf_file"); | ||
| 405 | 474 | ||
| 406 | failed |= ct_cert_test(); | 475 | failed |= ct_cert_test(); | 
| 407 | failed |= ct_sct_test(); | 476 | failed |= ct_sct_test(); | 
| 408 | failed |= ct_sct_base64_test(); | 477 | failed |= ct_sct_base64_test(); | 
| 478 | failed |= ct_sct_verify_test(); | ||
| 479 | |||
| 480 | free(test_cert_file); | ||
| 481 | free(test_issuer_file); | ||
| 482 | free(test_ctlog_conf_file); | ||
| 409 | 483 | ||
| 410 | return (failed); | 484 | return (failed); | 
| 411 | } | 485 | } | 
