1e1051a39Sopenharmony_ci/* 2e1051a39Sopenharmony_ci * Copyright 2007-2021 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci * Copyright Nokia 2007-2019 4e1051a39Sopenharmony_ci * Copyright Siemens AG 2015-2019 5e1051a39Sopenharmony_ci * 6e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 7e1051a39Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 8e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at 9e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html 10e1051a39Sopenharmony_ci */ 11e1051a39Sopenharmony_ci 12e1051a39Sopenharmony_ci#include "helpers/cmp_testlib.h" 13e1051a39Sopenharmony_ci 14e1051a39Sopenharmony_ci#include <openssl/x509_vfy.h> 15e1051a39Sopenharmony_ci 16e1051a39Sopenharmony_cistatic X509 *test_cert; 17e1051a39Sopenharmony_ci 18e1051a39Sopenharmony_ci/* Avoid using X509_new() via the generic macros below. */ 19e1051a39Sopenharmony_ci#define X509_new() X509_dup(test_cert) 20e1051a39Sopenharmony_ci 21e1051a39Sopenharmony_citypedef struct test_fixture { 22e1051a39Sopenharmony_ci const char *test_case_name; 23e1051a39Sopenharmony_ci OSSL_CMP_CTX *ctx; 24e1051a39Sopenharmony_ci} OSSL_CMP_CTX_TEST_FIXTURE; 25e1051a39Sopenharmony_ci 26e1051a39Sopenharmony_cistatic void tear_down(OSSL_CMP_CTX_TEST_FIXTURE *fixture) 27e1051a39Sopenharmony_ci{ 28e1051a39Sopenharmony_ci if (fixture != NULL) 29e1051a39Sopenharmony_ci OSSL_CMP_CTX_free(fixture->ctx); 30e1051a39Sopenharmony_ci OPENSSL_free(fixture); 31e1051a39Sopenharmony_ci} 32e1051a39Sopenharmony_ci 33e1051a39Sopenharmony_cistatic OSSL_CMP_CTX_TEST_FIXTURE *set_up(const char *const test_case_name) 34e1051a39Sopenharmony_ci{ 35e1051a39Sopenharmony_ci OSSL_CMP_CTX_TEST_FIXTURE *fixture; 36e1051a39Sopenharmony_ci 37e1051a39Sopenharmony_ci if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture)))) 38e1051a39Sopenharmony_ci return NULL; 39e1051a39Sopenharmony_ci if (!TEST_ptr(fixture->ctx = OSSL_CMP_CTX_new(NULL, NULL))) { 40e1051a39Sopenharmony_ci tear_down(fixture); 41e1051a39Sopenharmony_ci return NULL; 42e1051a39Sopenharmony_ci } 43e1051a39Sopenharmony_ci fixture->test_case_name = test_case_name; 44e1051a39Sopenharmony_ci return fixture; 45e1051a39Sopenharmony_ci} 46e1051a39Sopenharmony_ci 47e1051a39Sopenharmony_cistatic STACK_OF(X509) *sk_X509_new_1(void) 48e1051a39Sopenharmony_ci{ 49e1051a39Sopenharmony_ci STACK_OF(X509) *sk = sk_X509_new_null(); 50e1051a39Sopenharmony_ci X509 *x = X509_dup(test_cert); 51e1051a39Sopenharmony_ci 52e1051a39Sopenharmony_ci if (x == NULL || !sk_X509_push(sk, x)) { 53e1051a39Sopenharmony_ci sk_X509_free(sk); 54e1051a39Sopenharmony_ci X509_free(x); 55e1051a39Sopenharmony_ci sk = NULL; 56e1051a39Sopenharmony_ci } 57e1051a39Sopenharmony_ci return sk; 58e1051a39Sopenharmony_ci} 59e1051a39Sopenharmony_ci 60e1051a39Sopenharmony_cistatic void sk_X509_pop_X509_free(STACK_OF(X509) *sk) 61e1051a39Sopenharmony_ci{ 62e1051a39Sopenharmony_ci sk_X509_pop_free(sk, X509_free); 63e1051a39Sopenharmony_ci} 64e1051a39Sopenharmony_ci 65e1051a39Sopenharmony_cistatic int execute_CTX_reinit_test(OSSL_CMP_CTX_TEST_FIXTURE *fixture) 66e1051a39Sopenharmony_ci{ 67e1051a39Sopenharmony_ci OSSL_CMP_CTX *ctx = fixture->ctx; 68e1051a39Sopenharmony_ci ASN1_OCTET_STRING *bytes = NULL; 69e1051a39Sopenharmony_ci STACK_OF(X509) *certs = NULL; 70e1051a39Sopenharmony_ci int res = 0; 71e1051a39Sopenharmony_ci 72e1051a39Sopenharmony_ci /* set non-default values in all relevant fields */ 73e1051a39Sopenharmony_ci ctx->status = 1; 74e1051a39Sopenharmony_ci ctx->failInfoCode = 1; 75e1051a39Sopenharmony_ci if (!ossl_cmp_ctx_set0_statusString(ctx, sk_ASN1_UTF8STRING_new_null()) 76e1051a39Sopenharmony_ci || !ossl_cmp_ctx_set0_newCert(ctx, X509_dup(test_cert)) 77e1051a39Sopenharmony_ci || !TEST_ptr(certs = sk_X509_new_1()) 78e1051a39Sopenharmony_ci || !ossl_cmp_ctx_set1_newChain(ctx, certs) 79e1051a39Sopenharmony_ci || !ossl_cmp_ctx_set1_caPubs(ctx, certs) 80e1051a39Sopenharmony_ci || !ossl_cmp_ctx_set1_extraCertsIn(ctx, certs) 81e1051a39Sopenharmony_ci || !ossl_cmp_ctx_set0_validatedSrvCert(ctx, X509_dup(test_cert)) 82e1051a39Sopenharmony_ci || !TEST_ptr(bytes = ASN1_OCTET_STRING_new()) 83e1051a39Sopenharmony_ci || !OSSL_CMP_CTX_set1_transactionID(ctx, bytes) 84e1051a39Sopenharmony_ci || !OSSL_CMP_CTX_set1_senderNonce(ctx, bytes) 85e1051a39Sopenharmony_ci || !ossl_cmp_ctx_set1_recipNonce(ctx, bytes)) 86e1051a39Sopenharmony_ci goto err; 87e1051a39Sopenharmony_ci 88e1051a39Sopenharmony_ci if (!TEST_true(OSSL_CMP_CTX_reinit(ctx))) 89e1051a39Sopenharmony_ci goto err; 90e1051a39Sopenharmony_ci 91e1051a39Sopenharmony_ci /* check whether values have been reset to default in all relevant fields */ 92e1051a39Sopenharmony_ci if (!TEST_true(ctx->status == -1 93e1051a39Sopenharmony_ci && ctx->failInfoCode == -1 94e1051a39Sopenharmony_ci && ctx->statusString == NULL 95e1051a39Sopenharmony_ci && ctx->newCert == NULL 96e1051a39Sopenharmony_ci && ctx->newChain == NULL 97e1051a39Sopenharmony_ci && ctx->caPubs == NULL 98e1051a39Sopenharmony_ci && ctx->extraCertsIn == NULL 99e1051a39Sopenharmony_ci && ctx->validatedSrvCert == NULL 100e1051a39Sopenharmony_ci && ctx->transactionID == NULL 101e1051a39Sopenharmony_ci && ctx->senderNonce == NULL 102e1051a39Sopenharmony_ci && ctx->recipNonce == NULL)) 103e1051a39Sopenharmony_ci goto err; 104e1051a39Sopenharmony_ci 105e1051a39Sopenharmony_ci /* this does not check that all remaining fields are untouched */ 106e1051a39Sopenharmony_ci res = 1; 107e1051a39Sopenharmony_ci 108e1051a39Sopenharmony_ci err: 109e1051a39Sopenharmony_ci sk_X509_pop_X509_free(certs); 110e1051a39Sopenharmony_ci ASN1_OCTET_STRING_free(bytes); 111e1051a39Sopenharmony_ci return res; 112e1051a39Sopenharmony_ci} 113e1051a39Sopenharmony_ci 114e1051a39Sopenharmony_cistatic int test_CTX_reinit(void) 115e1051a39Sopenharmony_ci{ 116e1051a39Sopenharmony_ci SETUP_TEST_FIXTURE(OSSL_CMP_CTX_TEST_FIXTURE, set_up); 117e1051a39Sopenharmony_ci EXECUTE_TEST(execute_CTX_reinit_test, tear_down); 118e1051a39Sopenharmony_ci return result; 119e1051a39Sopenharmony_ci} 120e1051a39Sopenharmony_ci 121e1051a39Sopenharmony_ci#if !defined(OPENSSL_NO_ERR) && !defined(OPENSSL_NO_AUTOERRINIT) 122e1051a39Sopenharmony_ci 123e1051a39Sopenharmony_cistatic int msg_total_size = 0; 124e1051a39Sopenharmony_cistatic int msg_total_size_log_cb(const char *func, const char *file, int line, 125e1051a39Sopenharmony_ci OSSL_CMP_severity level, const char *msg) 126e1051a39Sopenharmony_ci{ 127e1051a39Sopenharmony_ci msg_total_size += strlen(msg); 128e1051a39Sopenharmony_ci TEST_note("total=%d len=%zu msg='%s'\n", msg_total_size, strlen(msg), msg); 129e1051a39Sopenharmony_ci return 1; 130e1051a39Sopenharmony_ci} 131e1051a39Sopenharmony_ci 132e1051a39Sopenharmony_ci# define STR64 "This is a 64 bytes looooooooooooooooooooooooooooooooong string.\n" 133e1051a39Sopenharmony_ci/* max string length ISO C90 compilers are required to support is 509. */ 134e1051a39Sopenharmony_ci# define STR509 STR64 STR64 STR64 STR64 STR64 STR64 STR64 \ 135e1051a39Sopenharmony_ci "This is a 61 bytes loooooooooooooooooooooooooooooong string.\n" 136e1051a39Sopenharmony_cistatic const char *const max_str_literal = STR509; 137e1051a39Sopenharmony_ci# define STR_SEP "<SEP>" 138e1051a39Sopenharmony_ci 139e1051a39Sopenharmony_cistatic int execute_CTX_print_errors_test(OSSL_CMP_CTX_TEST_FIXTURE *fixture) 140e1051a39Sopenharmony_ci{ 141e1051a39Sopenharmony_ci OSSL_CMP_CTX *ctx = fixture->ctx; 142e1051a39Sopenharmony_ci int base_err_msg_size, expected_size; 143e1051a39Sopenharmony_ci int res = 1; 144e1051a39Sopenharmony_ci 145e1051a39Sopenharmony_ci if (!TEST_true(OSSL_CMP_CTX_set_log_cb(ctx, NULL))) 146e1051a39Sopenharmony_ci res = 0; 147e1051a39Sopenharmony_ci if (!TEST_true(ctx->log_cb == NULL)) 148e1051a39Sopenharmony_ci res = 0; 149e1051a39Sopenharmony_ci 150e1051a39Sopenharmony_ci# ifndef OPENSSL_NO_STDIO 151e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_CMP, CMP_R_MULTIPLE_SAN_SOURCES); 152e1051a39Sopenharmony_ci OSSL_CMP_CTX_print_errors(ctx); /* should print above error to STDERR */ 153e1051a39Sopenharmony_ci# endif 154e1051a39Sopenharmony_ci 155e1051a39Sopenharmony_ci /* this should work regardless of OPENSSL_NO_STDIO and OPENSSL_NO_TRACE: */ 156e1051a39Sopenharmony_ci if (!TEST_true(OSSL_CMP_CTX_set_log_cb(ctx, msg_total_size_log_cb))) 157e1051a39Sopenharmony_ci res = 0; 158e1051a39Sopenharmony_ci if (!TEST_true(ctx->log_cb == msg_total_size_log_cb)) { 159e1051a39Sopenharmony_ci res = 0; 160e1051a39Sopenharmony_ci } else { 161e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_CMP, CMP_R_INVALID_ARGS); 162e1051a39Sopenharmony_ci base_err_msg_size = strlen("INVALID_ARGS"); 163e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT); 164e1051a39Sopenharmony_ci base_err_msg_size += strlen("NULL_ARGUMENT"); 165e1051a39Sopenharmony_ci expected_size = base_err_msg_size; 166e1051a39Sopenharmony_ci ossl_cmp_add_error_data("data1"); /* should prepend separator ":" */ 167e1051a39Sopenharmony_ci expected_size += strlen(":" "data1"); 168e1051a39Sopenharmony_ci ossl_cmp_add_error_data("data2"); /* should prepend separator " : " */ 169e1051a39Sopenharmony_ci expected_size += strlen(" : " "data2"); 170e1051a39Sopenharmony_ci ossl_cmp_add_error_line("new line"); /* should prepend separator "\n" */ 171e1051a39Sopenharmony_ci expected_size += strlen("\n" "new line"); 172e1051a39Sopenharmony_ci OSSL_CMP_CTX_print_errors(ctx); 173e1051a39Sopenharmony_ci if (!TEST_int_eq(msg_total_size, expected_size)) 174e1051a39Sopenharmony_ci res = 0; 175e1051a39Sopenharmony_ci 176e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_CMP, CMP_R_INVALID_ARGS); 177e1051a39Sopenharmony_ci base_err_msg_size = strlen("INVALID_ARGS") + strlen(":"); 178e1051a39Sopenharmony_ci expected_size = base_err_msg_size; 179e1051a39Sopenharmony_ci while (expected_size < 4096) { /* force split */ 180e1051a39Sopenharmony_ci ERR_add_error_txt(STR_SEP, max_str_literal); 181e1051a39Sopenharmony_ci expected_size += strlen(STR_SEP) + strlen(max_str_literal); 182e1051a39Sopenharmony_ci } 183e1051a39Sopenharmony_ci expected_size += base_err_msg_size - 2 * strlen(STR_SEP); 184e1051a39Sopenharmony_ci msg_total_size = 0; 185e1051a39Sopenharmony_ci OSSL_CMP_CTX_print_errors(ctx); 186e1051a39Sopenharmony_ci if (!TEST_int_eq(msg_total_size, expected_size)) 187e1051a39Sopenharmony_ci res = 0; 188e1051a39Sopenharmony_ci } 189e1051a39Sopenharmony_ci 190e1051a39Sopenharmony_ci return res; 191e1051a39Sopenharmony_ci} 192e1051a39Sopenharmony_ci 193e1051a39Sopenharmony_cistatic int test_CTX_print_errors(void) 194e1051a39Sopenharmony_ci{ 195e1051a39Sopenharmony_ci SETUP_TEST_FIXTURE(OSSL_CMP_CTX_TEST_FIXTURE, set_up); 196e1051a39Sopenharmony_ci EXECUTE_TEST(execute_CTX_print_errors_test, tear_down); 197e1051a39Sopenharmony_ci return result; 198e1051a39Sopenharmony_ci} 199e1051a39Sopenharmony_ci#endif 200e1051a39Sopenharmony_ci 201e1051a39Sopenharmony_cistatic 202e1051a39Sopenharmony_ciint execute_CTX_reqExtensions_have_SAN_test(OSSL_CMP_CTX_TEST_FIXTURE *fixture) 203e1051a39Sopenharmony_ci{ 204e1051a39Sopenharmony_ci OSSL_CMP_CTX *ctx = fixture->ctx; 205e1051a39Sopenharmony_ci const int len = 16; 206e1051a39Sopenharmony_ci unsigned char str[16 /* = len */]; 207e1051a39Sopenharmony_ci ASN1_OCTET_STRING *data = NULL; 208e1051a39Sopenharmony_ci X509_EXTENSION *ext = NULL; 209e1051a39Sopenharmony_ci X509_EXTENSIONS *exts = NULL; 210e1051a39Sopenharmony_ci int res = 0; 211e1051a39Sopenharmony_ci 212e1051a39Sopenharmony_ci if (!TEST_false(OSSL_CMP_CTX_reqExtensions_have_SAN(ctx))) 213e1051a39Sopenharmony_ci return 0; 214e1051a39Sopenharmony_ci 215e1051a39Sopenharmony_ci if (!TEST_int_eq(1, RAND_bytes(str, len)) 216e1051a39Sopenharmony_ci || !TEST_ptr(data = ASN1_OCTET_STRING_new()) 217e1051a39Sopenharmony_ci || !TEST_true(ASN1_OCTET_STRING_set(data, str, len))) 218e1051a39Sopenharmony_ci goto err; 219e1051a39Sopenharmony_ci ext = X509_EXTENSION_create_by_NID(NULL, NID_subject_alt_name, 0, data); 220e1051a39Sopenharmony_ci if (!TEST_ptr(ext) 221e1051a39Sopenharmony_ci || !TEST_ptr(exts = sk_X509_EXTENSION_new_null()) 222e1051a39Sopenharmony_ci || !TEST_true(sk_X509_EXTENSION_push(exts, ext)) 223e1051a39Sopenharmony_ci || !TEST_true(OSSL_CMP_CTX_set0_reqExtensions(ctx, exts))) { 224e1051a39Sopenharmony_ci X509_EXTENSION_free(ext); 225e1051a39Sopenharmony_ci sk_X509_EXTENSION_free(exts); 226e1051a39Sopenharmony_ci goto err; 227e1051a39Sopenharmony_ci } 228e1051a39Sopenharmony_ci if (TEST_int_eq(OSSL_CMP_CTX_reqExtensions_have_SAN(ctx), 1)) { 229e1051a39Sopenharmony_ci ext = sk_X509_EXTENSION_pop(exts); 230e1051a39Sopenharmony_ci res = TEST_false(OSSL_CMP_CTX_reqExtensions_have_SAN(ctx)); 231e1051a39Sopenharmony_ci X509_EXTENSION_free(ext); 232e1051a39Sopenharmony_ci } 233e1051a39Sopenharmony_ci err: 234e1051a39Sopenharmony_ci ASN1_OCTET_STRING_free(data); 235e1051a39Sopenharmony_ci return res; 236e1051a39Sopenharmony_ci} 237e1051a39Sopenharmony_ci 238e1051a39Sopenharmony_cistatic int test_CTX_reqExtensions_have_SAN(void) 239e1051a39Sopenharmony_ci{ 240e1051a39Sopenharmony_ci SETUP_TEST_FIXTURE(OSSL_CMP_CTX_TEST_FIXTURE, set_up); 241e1051a39Sopenharmony_ci EXECUTE_TEST(execute_CTX_reqExtensions_have_SAN_test, tear_down); 242e1051a39Sopenharmony_ci return result; 243e1051a39Sopenharmony_ci} 244e1051a39Sopenharmony_ci 245e1051a39Sopenharmony_cistatic int test_log_line; 246e1051a39Sopenharmony_cistatic int test_log_cb_res = 0; 247e1051a39Sopenharmony_cistatic int test_log_cb(const char *func, const char *file, int line, 248e1051a39Sopenharmony_ci OSSL_CMP_severity level, const char *msg) 249e1051a39Sopenharmony_ci{ 250e1051a39Sopenharmony_ci test_log_cb_res = 251e1051a39Sopenharmony_ci#ifndef PEDANTIC 252e1051a39Sopenharmony_ci (TEST_str_eq(func, "execute_cmp_ctx_log_cb_test") 253e1051a39Sopenharmony_ci || TEST_str_eq(func, "(unknown function)")) && 254e1051a39Sopenharmony_ci#endif 255e1051a39Sopenharmony_ci (TEST_str_eq(file, OPENSSL_FILE) 256e1051a39Sopenharmony_ci || TEST_str_eq(file, "(no file)")) 257e1051a39Sopenharmony_ci && (TEST_int_eq(line, test_log_line) || TEST_int_eq(line, 0)) 258e1051a39Sopenharmony_ci && (TEST_int_eq(level, OSSL_CMP_LOG_INFO) || TEST_int_eq(level, -1)) 259e1051a39Sopenharmony_ci && TEST_str_eq(msg, "ok"); 260e1051a39Sopenharmony_ci return 1; 261e1051a39Sopenharmony_ci} 262e1051a39Sopenharmony_ci 263e1051a39Sopenharmony_cistatic int execute_cmp_ctx_log_cb_test(OSSL_CMP_CTX_TEST_FIXTURE *fixture) 264e1051a39Sopenharmony_ci{ 265e1051a39Sopenharmony_ci int res = 1; 266e1051a39Sopenharmony_ci OSSL_CMP_CTX *ctx = fixture->ctx; 267e1051a39Sopenharmony_ci 268e1051a39Sopenharmony_ci OSSL_TRACE(ALL, "this general trace message is not shown by default\n"); 269e1051a39Sopenharmony_ci 270e1051a39Sopenharmony_ci OSSL_CMP_log_open(); 271e1051a39Sopenharmony_ci OSSL_CMP_log_open(); /* multiple calls should be harmless */ 272e1051a39Sopenharmony_ci 273e1051a39Sopenharmony_ci if (!TEST_true(OSSL_CMP_CTX_set_log_cb(ctx, NULL))) { 274e1051a39Sopenharmony_ci res = 0; 275e1051a39Sopenharmony_ci } else { 276e1051a39Sopenharmony_ci ossl_cmp_err(ctx, "this should be printed as CMP error message"); 277e1051a39Sopenharmony_ci ossl_cmp_warn(ctx, "this should be printed as CMP warning message"); 278e1051a39Sopenharmony_ci ossl_cmp_debug(ctx, "this should not be printed"); 279e1051a39Sopenharmony_ci TEST_true(OSSL_CMP_CTX_set_log_verbosity(ctx, OSSL_CMP_LOG_DEBUG)); 280e1051a39Sopenharmony_ci ossl_cmp_debug(ctx, "this should be printed as CMP debug message"); 281e1051a39Sopenharmony_ci TEST_true(OSSL_CMP_CTX_set_log_verbosity(ctx, OSSL_CMP_LOG_INFO)); 282e1051a39Sopenharmony_ci } 283e1051a39Sopenharmony_ci if (!TEST_true(OSSL_CMP_CTX_set_log_cb(ctx, test_log_cb))) { 284e1051a39Sopenharmony_ci res = 0; 285e1051a39Sopenharmony_ci } else { 286e1051a39Sopenharmony_ci test_log_line = OPENSSL_LINE + 1; 287e1051a39Sopenharmony_ci ossl_cmp_log2(INFO, ctx, "%s%c", "o", 'k'); 288e1051a39Sopenharmony_ci if (!TEST_int_eq(test_log_cb_res, 1)) 289e1051a39Sopenharmony_ci res = 0; 290e1051a39Sopenharmony_ci OSSL_CMP_CTX_set_log_verbosity(ctx, OSSL_CMP_LOG_ERR); 291e1051a39Sopenharmony_ci test_log_cb_res = -1; /* callback should not be called at all */ 292e1051a39Sopenharmony_ci test_log_line = OPENSSL_LINE + 1; 293e1051a39Sopenharmony_ci ossl_cmp_log2(INFO, ctx, "%s%c", "o", 'k'); 294e1051a39Sopenharmony_ci if (!TEST_int_eq(test_log_cb_res, -1)) 295e1051a39Sopenharmony_ci res = 0; 296e1051a39Sopenharmony_ci } 297e1051a39Sopenharmony_ci OSSL_CMP_log_close(); 298e1051a39Sopenharmony_ci OSSL_CMP_log_close(); /* multiple calls should be harmless */ 299e1051a39Sopenharmony_ci return res; 300e1051a39Sopenharmony_ci} 301e1051a39Sopenharmony_ci 302e1051a39Sopenharmony_cistatic int test_cmp_ctx_log_cb(void) 303e1051a39Sopenharmony_ci{ 304e1051a39Sopenharmony_ci SETUP_TEST_FIXTURE(OSSL_CMP_CTX_TEST_FIXTURE, set_up); 305e1051a39Sopenharmony_ci EXECUTE_TEST(execute_cmp_ctx_log_cb_test, tear_down); 306e1051a39Sopenharmony_ci return result; 307e1051a39Sopenharmony_ci} 308e1051a39Sopenharmony_ci 309e1051a39Sopenharmony_cistatic BIO *test_http_cb(BIO *bio, void *arg, int use_ssl, int detail) 310e1051a39Sopenharmony_ci{ 311e1051a39Sopenharmony_ci return NULL; 312e1051a39Sopenharmony_ci} 313e1051a39Sopenharmony_ci 314e1051a39Sopenharmony_cistatic OSSL_CMP_MSG *test_transfer_cb(OSSL_CMP_CTX *ctx, 315e1051a39Sopenharmony_ci const OSSL_CMP_MSG *req) 316e1051a39Sopenharmony_ci{ 317e1051a39Sopenharmony_ci return NULL; 318e1051a39Sopenharmony_ci} 319e1051a39Sopenharmony_ci 320e1051a39Sopenharmony_cistatic int test_certConf_cb(OSSL_CMP_CTX *ctx, X509 *cert, int fail_info, 321e1051a39Sopenharmony_ci const char **txt) 322e1051a39Sopenharmony_ci{ 323e1051a39Sopenharmony_ci return 0; 324e1051a39Sopenharmony_ci} 325e1051a39Sopenharmony_ci 326e1051a39Sopenharmony_citypedef OSSL_CMP_CTX CMP_CTX; /* prevents rewriting type name by below macro */ 327e1051a39Sopenharmony_ci#define OSSL_CMP_CTX 1 /* name prefix for exported setter functions */ 328e1051a39Sopenharmony_ci#define ossl_cmp_ctx 0 /* name prefix for internal setter functions */ 329e1051a39Sopenharmony_ci#define set 0 330e1051a39Sopenharmony_ci#define set0 0 331e1051a39Sopenharmony_ci#define set1 1 332e1051a39Sopenharmony_ci#define get 0 333e1051a39Sopenharmony_ci#define get0 0 334e1051a39Sopenharmony_ci#define get1 1 335e1051a39Sopenharmony_ci 336e1051a39Sopenharmony_ci#define DEFINE_SET_GET_BASE_TEST(PREFIX, SETN, GETN, DUP, FIELD, TYPE, ERR, \ 337e1051a39Sopenharmony_ci DEFAULT, NEW, FREE) \ 338e1051a39Sopenharmony_cistatic int \ 339e1051a39Sopenharmony_ciexecute_CTX_##SETN##_##GETN##_##FIELD(OSSL_CMP_CTX_TEST_FIXTURE *fixture) \ 340e1051a39Sopenharmony_ci{ \ 341e1051a39Sopenharmony_ci CMP_CTX *ctx = fixture->ctx; \ 342e1051a39Sopenharmony_ci int (*set_fn)(CMP_CTX *ctx, TYPE) = \ 343e1051a39Sopenharmony_ci (int (*)(CMP_CTX *ctx, TYPE))PREFIX##_##SETN##_##FIELD; \ 344e1051a39Sopenharmony_ci /* need type cast in above assignment as TYPE arg sometimes is const */ \ 345e1051a39Sopenharmony_ci TYPE (*get_fn)(const CMP_CTX *ctx) = OSSL_CMP_CTX_##GETN##_##FIELD; \ 346e1051a39Sopenharmony_ci TYPE val1_to_free = NEW; \ 347e1051a39Sopenharmony_ci TYPE val1 = val1_to_free; \ 348e1051a39Sopenharmony_ci TYPE val1_read = 0; /* 0 works for any type */ \ 349e1051a39Sopenharmony_ci TYPE val2_to_free = NEW; \ 350e1051a39Sopenharmony_ci TYPE val2 = val2_to_free; \ 351e1051a39Sopenharmony_ci TYPE val2_read = 0; \ 352e1051a39Sopenharmony_ci TYPE val3_read = 0; \ 353e1051a39Sopenharmony_ci int res = 1; \ 354e1051a39Sopenharmony_ci \ 355e1051a39Sopenharmony_ci if (!TEST_int_eq(ERR_peek_error(), 0)) \ 356e1051a39Sopenharmony_ci res = 0; \ 357e1051a39Sopenharmony_ci if (PREFIX == 1) { /* exported setter functions must test ctx == NULL */ \ 358e1051a39Sopenharmony_ci if ((*set_fn)(NULL, val1) || ERR_peek_error() == 0) { \ 359e1051a39Sopenharmony_ci TEST_error("setter did not return error on ctx == NULL"); \ 360e1051a39Sopenharmony_ci res = 0; \ 361e1051a39Sopenharmony_ci } \ 362e1051a39Sopenharmony_ci } \ 363e1051a39Sopenharmony_ci ERR_clear_error(); \ 364e1051a39Sopenharmony_ci \ 365e1051a39Sopenharmony_ci if ((*get_fn)(NULL) != ERR || ERR_peek_error() == 0) { \ 366e1051a39Sopenharmony_ci TEST_error("getter did not return error on ctx == NULL"); \ 367e1051a39Sopenharmony_ci res = 0; \ 368e1051a39Sopenharmony_ci } \ 369e1051a39Sopenharmony_ci ERR_clear_error(); \ 370e1051a39Sopenharmony_ci \ 371e1051a39Sopenharmony_ci val1_read = (*get_fn)(ctx); \ 372e1051a39Sopenharmony_ci if (!DEFAULT(val1_read)) { \ 373e1051a39Sopenharmony_ci TEST_error("did not get default value"); \ 374e1051a39Sopenharmony_ci res = 0; \ 375e1051a39Sopenharmony_ci } \ 376e1051a39Sopenharmony_ci if (!(*set_fn)(ctx, val1)) { \ 377e1051a39Sopenharmony_ci TEST_error("setting first value failed"); \ 378e1051a39Sopenharmony_ci res = 0; \ 379e1051a39Sopenharmony_ci } \ 380e1051a39Sopenharmony_ci if (SETN == 0) \ 381e1051a39Sopenharmony_ci val1_to_free = 0; /* 0 works for any type */ \ 382e1051a39Sopenharmony_ci \ 383e1051a39Sopenharmony_ci if (GETN == 1) \ 384e1051a39Sopenharmony_ci FREE(val1_read); \ 385e1051a39Sopenharmony_ci val1_read = (*get_fn)(ctx); \ 386e1051a39Sopenharmony_ci if (SETN == 0) { \ 387e1051a39Sopenharmony_ci if (val1_read != val1) { \ 388e1051a39Sopenharmony_ci TEST_error("set/get first value did not match"); \ 389e1051a39Sopenharmony_ci res = 0; \ 390e1051a39Sopenharmony_ci } \ 391e1051a39Sopenharmony_ci } else { \ 392e1051a39Sopenharmony_ci if (DUP && val1_read == val1) { \ 393e1051a39Sopenharmony_ci TEST_error("first set did not dup the value"); \ 394e1051a39Sopenharmony_ci res = 0; \ 395e1051a39Sopenharmony_ci } \ 396e1051a39Sopenharmony_ci if (DEFAULT(val1_read)) { \ 397e1051a39Sopenharmony_ci TEST_error("first set had no effect"); \ 398e1051a39Sopenharmony_ci res = 0; \ 399e1051a39Sopenharmony_ci } \ 400e1051a39Sopenharmony_ci } \ 401e1051a39Sopenharmony_ci \ 402e1051a39Sopenharmony_ci if (!(*set_fn)(ctx, val2)) { \ 403e1051a39Sopenharmony_ci TEST_error("setting second value failed"); \ 404e1051a39Sopenharmony_ci res = 0; \ 405e1051a39Sopenharmony_ci } \ 406e1051a39Sopenharmony_ci if (SETN == 0) \ 407e1051a39Sopenharmony_ci val2_to_free = 0; \ 408e1051a39Sopenharmony_ci \ 409e1051a39Sopenharmony_ci val2_read = (*get_fn)(ctx); \ 410e1051a39Sopenharmony_ci if (DEFAULT(val2_read)) { \ 411e1051a39Sopenharmony_ci TEST_error("second set reset the value"); \ 412e1051a39Sopenharmony_ci res = 0; \ 413e1051a39Sopenharmony_ci } \ 414e1051a39Sopenharmony_ci if (SETN == 0 && GETN == 0) { \ 415e1051a39Sopenharmony_ci if (val2_read != val2) { \ 416e1051a39Sopenharmony_ci TEST_error("set/get second value did not match"); \ 417e1051a39Sopenharmony_ci res = 0; \ 418e1051a39Sopenharmony_ci } \ 419e1051a39Sopenharmony_ci } else { \ 420e1051a39Sopenharmony_ci if (DUP && val2_read == val2) { \ 421e1051a39Sopenharmony_ci TEST_error("second set did not dup the value"); \ 422e1051a39Sopenharmony_ci res = 0; \ 423e1051a39Sopenharmony_ci } \ 424e1051a39Sopenharmony_ci if (val2 == val1) { \ 425e1051a39Sopenharmony_ci TEST_error("second value is same as first value"); \ 426e1051a39Sopenharmony_ci res = 0; \ 427e1051a39Sopenharmony_ci } \ 428e1051a39Sopenharmony_ci if (GETN == 1 && val2_read == val1_read) { \ 429e1051a39Sopenharmony_ci /* \ 430e1051a39Sopenharmony_ci * Note that if GETN == 0 then possibly val2_read == val1_read \ 431e1051a39Sopenharmony_ci * because set1 may allocate the new copy at the same location. \ 432e1051a39Sopenharmony_ci */ \ 433e1051a39Sopenharmony_ci TEST_error("second get returned same as first get"); \ 434e1051a39Sopenharmony_ci res = 0; \ 435e1051a39Sopenharmony_ci } \ 436e1051a39Sopenharmony_ci } \ 437e1051a39Sopenharmony_ci \ 438e1051a39Sopenharmony_ci val3_read = (*get_fn)(ctx); \ 439e1051a39Sopenharmony_ci if (DEFAULT(val3_read)) { \ 440e1051a39Sopenharmony_ci TEST_error("third set reset the value"); \ 441e1051a39Sopenharmony_ci res = 0; \ 442e1051a39Sopenharmony_ci } \ 443e1051a39Sopenharmony_ci if (GETN == 0) { \ 444e1051a39Sopenharmony_ci if (val3_read != val2_read) { \ 445e1051a39Sopenharmony_ci TEST_error("third get gave different value"); \ 446e1051a39Sopenharmony_ci res = 0; \ 447e1051a39Sopenharmony_ci } \ 448e1051a39Sopenharmony_ci } else { \ 449e1051a39Sopenharmony_ci if (DUP && val3_read == val2_read) { \ 450e1051a39Sopenharmony_ci TEST_error("third get did not create a new dup"); \ 451e1051a39Sopenharmony_ci res = 0; \ 452e1051a39Sopenharmony_ci } \ 453e1051a39Sopenharmony_ci } \ 454e1051a39Sopenharmony_ci /* this does not check that all remaining fields are untouched */ \ 455e1051a39Sopenharmony_ci \ 456e1051a39Sopenharmony_ci if (!TEST_int_eq(ERR_peek_error(), 0)) \ 457e1051a39Sopenharmony_ci res = 0; \ 458e1051a39Sopenharmony_ci \ 459e1051a39Sopenharmony_ci FREE(val1_to_free); \ 460e1051a39Sopenharmony_ci FREE(val2_to_free); \ 461e1051a39Sopenharmony_ci if (GETN == 1) { \ 462e1051a39Sopenharmony_ci FREE(val1_read); \ 463e1051a39Sopenharmony_ci FREE(val2_read); \ 464e1051a39Sopenharmony_ci FREE(val3_read); \ 465e1051a39Sopenharmony_ci } \ 466e1051a39Sopenharmony_ci return TEST_true(res); \ 467e1051a39Sopenharmony_ci} \ 468e1051a39Sopenharmony_ci\ 469e1051a39Sopenharmony_cistatic int test_CTX_##SETN##_##GETN##_##FIELD(void) \ 470e1051a39Sopenharmony_ci{ \ 471e1051a39Sopenharmony_ci SETUP_TEST_FIXTURE(OSSL_CMP_CTX_TEST_FIXTURE, set_up); \ 472e1051a39Sopenharmony_ci EXECUTE_TEST(execute_CTX_##SETN##_##GETN##_##FIELD, tear_down); \ 473e1051a39Sopenharmony_ci return result; \ 474e1051a39Sopenharmony_ci} 475e1051a39Sopenharmony_ci 476e1051a39Sopenharmony_cistatic char *char_new(void) 477e1051a39Sopenharmony_ci{ 478e1051a39Sopenharmony_ci return OPENSSL_strdup("test"); 479e1051a39Sopenharmony_ci} 480e1051a39Sopenharmony_ci 481e1051a39Sopenharmony_cistatic void char_free(char *val) 482e1051a39Sopenharmony_ci{ 483e1051a39Sopenharmony_ci OPENSSL_free(val); 484e1051a39Sopenharmony_ci} 485e1051a39Sopenharmony_ci 486e1051a39Sopenharmony_ci#define EMPTY_SK_X509(x) ((x) == NULL || sk_X509_num(x) == 0) 487e1051a39Sopenharmony_ci 488e1051a39Sopenharmony_cistatic X509_STORE *X509_STORE_new_1(void) 489e1051a39Sopenharmony_ci{ 490e1051a39Sopenharmony_ci X509_STORE *store = X509_STORE_new(); 491e1051a39Sopenharmony_ci 492e1051a39Sopenharmony_ci if (store != NULL) 493e1051a39Sopenharmony_ci X509_VERIFY_PARAM_set_flags(X509_STORE_get0_param(store), 1); 494e1051a39Sopenharmony_ci return store; 495e1051a39Sopenharmony_ci} 496e1051a39Sopenharmony_ci 497e1051a39Sopenharmony_ci#define DEFAULT_STORE(x) \ 498e1051a39Sopenharmony_ci ((x) == NULL || X509_VERIFY_PARAM_get_flags(X509_STORE_get0_param(x)) == 0) 499e1051a39Sopenharmony_ci 500e1051a39Sopenharmony_ci#define IS_NEG(x) ((x) < 0) 501e1051a39Sopenharmony_ci#define IS_0(x) ((x) == 0) /* for any type */ 502e1051a39Sopenharmony_ci#define DROP(x) (void)(x) /* dummy free() for non-pointer and function types */ 503e1051a39Sopenharmony_ci 504e1051a39Sopenharmony_ci#define RET_IF_NULL_ARG(ctx, ret) \ 505e1051a39Sopenharmony_ci if (ctx == NULL) { \ 506e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT); \ 507e1051a39Sopenharmony_ci return ret; \ 508e1051a39Sopenharmony_ci } 509e1051a39Sopenharmony_ci 510e1051a39Sopenharmony_ci#define DEFINE_SET_GET_TEST(OSSL_CMP, CTX, N, M, DUP, FIELD, TYPE) \ 511e1051a39Sopenharmony_ci DEFINE_SET_GET_BASE_TEST(OSSL_CMP##_##CTX, set##N, get##M, DUP, FIELD, \ 512e1051a39Sopenharmony_ci TYPE *, NULL, IS_0, TYPE##_new(), TYPE##_free) 513e1051a39Sopenharmony_ci 514e1051a39Sopenharmony_ci#define DEFINE_SET_GET_SK_TEST_DEFAULT(OSSL_CMP, CTX, N, M, FIELD, ELEM_TYPE, \ 515e1051a39Sopenharmony_ci DEFAULT, NEW, FREE) \ 516e1051a39Sopenharmony_ci DEFINE_SET_GET_BASE_TEST(OSSL_CMP##_##CTX, set##N, get##M, 1, FIELD, \ 517e1051a39Sopenharmony_ci STACK_OF(ELEM_TYPE)*, NULL, DEFAULT, NEW, FREE) 518e1051a39Sopenharmony_ci#define DEFINE_SET_GET_SK_TEST(OSSL_CMP, CTX, N, M, FIELD, T) \ 519e1051a39Sopenharmony_ci DEFINE_SET_GET_SK_TEST_DEFAULT(OSSL_CMP, CTX, N, M, FIELD, T, \ 520e1051a39Sopenharmony_ci IS_0, sk_##T##_new_null(), sk_##T##_free) 521e1051a39Sopenharmony_ci#define DEFINE_SET_GET_SK_X509_TEST(OSSL_CMP, CTX, N, M, FNAME) \ 522e1051a39Sopenharmony_ci DEFINE_SET_GET_SK_TEST_DEFAULT(OSSL_CMP, CTX, N, M, FNAME, X509, \ 523e1051a39Sopenharmony_ci EMPTY_SK_X509, \ 524e1051a39Sopenharmony_ci sk_X509_new_1(), sk_X509_pop_X509_free) 525e1051a39Sopenharmony_ci 526e1051a39Sopenharmony_ci#define DEFINE_SET_GET_TEST_DEFAULT(OSSL_CMP, CTX, N, M, DUP, FIELD, TYPE, \ 527e1051a39Sopenharmony_ci DEFAULT) \ 528e1051a39Sopenharmony_ci DEFINE_SET_GET_BASE_TEST(OSSL_CMP##_##CTX, set##N, get##M, DUP, FIELD, \ 529e1051a39Sopenharmony_ci TYPE *, NULL, DEFAULT, TYPE##_new(), TYPE##_free) 530e1051a39Sopenharmony_ci#define DEFINE_SET_TEST_DEFAULT(OSSL_CMP, CTX, N, DUP, FIELD, TYPE, DEFAULT) \ 531e1051a39Sopenharmony_ci static TYPE *OSSL_CMP_CTX_get0_##FIELD(const CMP_CTX *ctx) \ 532e1051a39Sopenharmony_ci { \ 533e1051a39Sopenharmony_ci RET_IF_NULL_ARG(ctx, NULL); \ 534e1051a39Sopenharmony_ci return (TYPE *)ctx->FIELD; \ 535e1051a39Sopenharmony_ci } \ 536e1051a39Sopenharmony_ci DEFINE_SET_GET_TEST_DEFAULT(OSSL_CMP, CTX, N, 0, DUP, FIELD, TYPE, DEFAULT) 537e1051a39Sopenharmony_ci#define DEFINE_SET_TEST(OSSL_CMP, CTX, N, DUP, FIELD, TYPE) \ 538e1051a39Sopenharmony_ci DEFINE_SET_TEST_DEFAULT(OSSL_CMP, CTX, N, DUP, FIELD, TYPE, IS_0) 539e1051a39Sopenharmony_ci 540e1051a39Sopenharmony_ci#define DEFINE_SET_SK_TEST(OSSL_CMP, CTX, N, FIELD, TYPE) \ 541e1051a39Sopenharmony_ci static STACK_OF(TYPE) *OSSL_CMP_CTX_get0_##FIELD(const CMP_CTX *ctx) \ 542e1051a39Sopenharmony_ci { \ 543e1051a39Sopenharmony_ci RET_IF_NULL_ARG(ctx, NULL); \ 544e1051a39Sopenharmony_ci return ctx->FIELD; \ 545e1051a39Sopenharmony_ci } \ 546e1051a39Sopenharmony_ci DEFINE_SET_GET_BASE_TEST(OSSL_CMP##_##CTX, set##N, get0, 1, FIELD, \ 547e1051a39Sopenharmony_ci STACK_OF(TYPE)*, NULL, IS_0, \ 548e1051a39Sopenharmony_ci sk_##TYPE##_new_null(), sk_##TYPE##_free) 549e1051a39Sopenharmony_ci 550e1051a39Sopenharmony_citypedef OSSL_HTTP_bio_cb_t OSSL_CMP_http_cb_t; 551e1051a39Sopenharmony_ci#define DEFINE_SET_CB_TEST(FIELD) \ 552e1051a39Sopenharmony_ci static OSSL_CMP_##FIELD##_t OSSL_CMP_CTX_get_##FIELD(const CMP_CTX *ctx) \ 553e1051a39Sopenharmony_ci { \ 554e1051a39Sopenharmony_ci RET_IF_NULL_ARG(ctx, NULL); \ 555e1051a39Sopenharmony_ci return ctx->FIELD; \ 556e1051a39Sopenharmony_ci } \ 557e1051a39Sopenharmony_ci DEFINE_SET_GET_BASE_TEST(OSSL_CMP_CTX, set, get, 0, FIELD, \ 558e1051a39Sopenharmony_ci OSSL_CMP_##FIELD##_t, NULL, IS_0, \ 559e1051a39Sopenharmony_ci test_##FIELD, DROP) 560e1051a39Sopenharmony_ci#define DEFINE_SET_GET_P_VOID_TEST(FIELD) \ 561e1051a39Sopenharmony_ci DEFINE_SET_GET_BASE_TEST(OSSL_CMP_CTX, set, get, 0, FIELD, void *, \ 562e1051a39Sopenharmony_ci NULL, IS_0, ((void *)1), DROP) 563e1051a39Sopenharmony_ci 564e1051a39Sopenharmony_ci#define DEFINE_SET_GET_INT_TEST_DEFAULT(OSSL_CMP, CTX, FIELD, DEFAULT) \ 565e1051a39Sopenharmony_ci DEFINE_SET_GET_BASE_TEST(OSSL_CMP##_##CTX, set, get, 0, FIELD, int, -1, \ 566e1051a39Sopenharmony_ci DEFAULT, 1, DROP) 567e1051a39Sopenharmony_ci#define DEFINE_SET_GET_INT_TEST(OSSL_CMP, CTX, FIELD) \ 568e1051a39Sopenharmony_ci DEFINE_SET_GET_INT_TEST_DEFAULT(OSSL_CMP, CTX, FIELD, IS_NEG) 569e1051a39Sopenharmony_ci#define DEFINE_SET_INT_TEST(FIELD) \ 570e1051a39Sopenharmony_ci static int OSSL_CMP_CTX_get_##FIELD(const CMP_CTX *ctx) \ 571e1051a39Sopenharmony_ci { \ 572e1051a39Sopenharmony_ci RET_IF_NULL_ARG(ctx, -1); \ 573e1051a39Sopenharmony_ci return ctx->FIELD; \ 574e1051a39Sopenharmony_ci } \ 575e1051a39Sopenharmony_ci DEFINE_SET_GET_INT_TEST_DEFAULT(OSSL_CMP, CTX, FIELD, IS_0) 576e1051a39Sopenharmony_ci 577e1051a39Sopenharmony_ci#define DEFINE_SET_GET_ARG_FN(SETN, GETN, FIELD, ARG, T) \ 578e1051a39Sopenharmony_ci static int OSSL_CMP_CTX_##SETN##_##FIELD##_##ARG(CMP_CTX *ctx, T val) \ 579e1051a39Sopenharmony_ci { \ 580e1051a39Sopenharmony_ci return OSSL_CMP_CTX_##SETN##_##FIELD(ctx, ARG, val); \ 581e1051a39Sopenharmony_ci } \ 582e1051a39Sopenharmony_ci \ 583e1051a39Sopenharmony_ci static T OSSL_CMP_CTX_##GETN##_##FIELD##_##ARG(const CMP_CTX *ctx) \ 584e1051a39Sopenharmony_ci { \ 585e1051a39Sopenharmony_ci return OSSL_CMP_CTX_##GETN##_##FIELD(ctx, ARG); \ 586e1051a39Sopenharmony_ci } 587e1051a39Sopenharmony_ci 588e1051a39Sopenharmony_ci#define DEFINE_SET_GET1_STR_FN(SETN, FIELD) \ 589e1051a39Sopenharmony_ci static int OSSL_CMP_CTX_##SETN##_##FIELD##_str(CMP_CTX *ctx, char *val)\ 590e1051a39Sopenharmony_ci { \ 591e1051a39Sopenharmony_ci return OSSL_CMP_CTX_##SETN##_##FIELD(ctx, (unsigned char *)val, \ 592e1051a39Sopenharmony_ci strlen(val)); \ 593e1051a39Sopenharmony_ci } \ 594e1051a39Sopenharmony_ci \ 595e1051a39Sopenharmony_ci static char *OSSL_CMP_CTX_get1_##FIELD##_str(const CMP_CTX *ctx) \ 596e1051a39Sopenharmony_ci { \ 597e1051a39Sopenharmony_ci const ASN1_OCTET_STRING *bytes = NULL; \ 598e1051a39Sopenharmony_ci \ 599e1051a39Sopenharmony_ci RET_IF_NULL_ARG(ctx, NULL); \ 600e1051a39Sopenharmony_ci bytes = ctx->FIELD; \ 601e1051a39Sopenharmony_ci return bytes == NULL ? NULL : \ 602e1051a39Sopenharmony_ci OPENSSL_strndup((char *)bytes->data, bytes->length); \ 603e1051a39Sopenharmony_ci } 604e1051a39Sopenharmony_ci 605e1051a39Sopenharmony_ci#define push 0 606e1051a39Sopenharmony_ci#define push0 0 607e1051a39Sopenharmony_ci#define push1 1 608e1051a39Sopenharmony_ci#define DEFINE_PUSH_BASE_TEST(PUSHN, DUP, FIELD, ELEM, TYPE, T, \ 609e1051a39Sopenharmony_ci DEFAULT, NEW, FREE) \ 610e1051a39Sopenharmony_cistatic TYPE sk_top_##FIELD(const CMP_CTX *ctx) \ 611e1051a39Sopenharmony_ci{ \ 612e1051a39Sopenharmony_ci return sk_##T##_value(ctx->FIELD, sk_##T##_num(ctx->FIELD) - 1); \ 613e1051a39Sopenharmony_ci} \ 614e1051a39Sopenharmony_ci\ 615e1051a39Sopenharmony_cistatic int execute_CTX_##PUSHN##_##ELEM(OSSL_CMP_CTX_TEST_FIXTURE *fixture) \ 616e1051a39Sopenharmony_ci{ \ 617e1051a39Sopenharmony_ci CMP_CTX *ctx = fixture->ctx; \ 618e1051a39Sopenharmony_ci int (*push_fn)(CMP_CTX *ctx, TYPE) = \ 619e1051a39Sopenharmony_ci (int (*)(CMP_CTX *ctx, TYPE))OSSL_CMP_CTX_##PUSHN##_##ELEM; \ 620e1051a39Sopenharmony_ci /* \ 621e1051a39Sopenharmony_ci * need type cast in above assignment because TYPE arg sometimes is const \ 622e1051a39Sopenharmony_ci */ \ 623e1051a39Sopenharmony_ci int n_elem = sk_##T##_num(ctx->FIELD); \ 624e1051a39Sopenharmony_ci STACK_OF(TYPE) field_read; \ 625e1051a39Sopenharmony_ci TYPE val1_to_free = NEW; \ 626e1051a39Sopenharmony_ci TYPE val1 = val1_to_free; \ 627e1051a39Sopenharmony_ci TYPE val1_read = 0; /* 0 works for any type */ \ 628e1051a39Sopenharmony_ci TYPE val2_to_free = NEW; \ 629e1051a39Sopenharmony_ci TYPE val2 = val2_to_free; \ 630e1051a39Sopenharmony_ci TYPE val2_read = 0; \ 631e1051a39Sopenharmony_ci int res = 1; \ 632e1051a39Sopenharmony_ci \ 633e1051a39Sopenharmony_ci if (!TEST_int_eq(ERR_peek_error(), 0)) \ 634e1051a39Sopenharmony_ci res = 0; \ 635e1051a39Sopenharmony_ci if ((*push_fn)(NULL, val1) || ERR_peek_error() == 0) { \ 636e1051a39Sopenharmony_ci TEST_error("pusher did not return error on ctx == NULL"); \ 637e1051a39Sopenharmony_ci res = 0; \ 638e1051a39Sopenharmony_ci } \ 639e1051a39Sopenharmony_ci ERR_clear_error(); \ 640e1051a39Sopenharmony_ci \ 641e1051a39Sopenharmony_ci if (n_elem < 0) /* can happen for NULL stack */ \ 642e1051a39Sopenharmony_ci n_elem = 0; \ 643e1051a39Sopenharmony_ci field_read = ctx->FIELD; \ 644e1051a39Sopenharmony_ci if (!DEFAULT(field_read)) { \ 645e1051a39Sopenharmony_ci TEST_error("did not get default value for stack field"); \ 646e1051a39Sopenharmony_ci res = 0; \ 647e1051a39Sopenharmony_ci } \ 648e1051a39Sopenharmony_ci if (!(*push_fn)(ctx, val1)) { \ 649e1051a39Sopenharmony_ci TEST_error("pushing first value failed"); \ 650e1051a39Sopenharmony_ci res = 0; \ 651e1051a39Sopenharmony_ci } \ 652e1051a39Sopenharmony_ci if (PUSHN == 0) \ 653e1051a39Sopenharmony_ci val1_to_free = 0; /* 0 works for any type */ \ 654e1051a39Sopenharmony_ci \ 655e1051a39Sopenharmony_ci if (sk_##T##_num(ctx->FIELD) != ++n_elem) { \ 656e1051a39Sopenharmony_ci TEST_error("pushing first value did not increment number"); \ 657e1051a39Sopenharmony_ci res = 0; \ 658e1051a39Sopenharmony_ci } \ 659e1051a39Sopenharmony_ci val1_read = sk_top_##FIELD(ctx); \ 660e1051a39Sopenharmony_ci if (PUSHN == 0) { \ 661e1051a39Sopenharmony_ci if (val1_read != val1) { \ 662e1051a39Sopenharmony_ci TEST_error("push/sk_top first value did not match"); \ 663e1051a39Sopenharmony_ci res = 0; \ 664e1051a39Sopenharmony_ci } \ 665e1051a39Sopenharmony_ci } else { \ 666e1051a39Sopenharmony_ci if (DUP && val1_read == val1) { \ 667e1051a39Sopenharmony_ci TEST_error("first push did not dup the value"); \ 668e1051a39Sopenharmony_ci res = 0; \ 669e1051a39Sopenharmony_ci } \ 670e1051a39Sopenharmony_ci } \ 671e1051a39Sopenharmony_ci \ 672e1051a39Sopenharmony_ci if (!(*push_fn)(ctx, val2)) { \ 673e1051a39Sopenharmony_ci TEST_error("pushting second value failed"); \ 674e1051a39Sopenharmony_ci res = 0; \ 675e1051a39Sopenharmony_ci } \ 676e1051a39Sopenharmony_ci if (PUSHN == 0) \ 677e1051a39Sopenharmony_ci val2_to_free = 0; \ 678e1051a39Sopenharmony_ci \ 679e1051a39Sopenharmony_ci if (sk_##T##_num(ctx->FIELD) != ++n_elem) { \ 680e1051a39Sopenharmony_ci TEST_error("pushing second value did not increment number"); \ 681e1051a39Sopenharmony_ci res = 0; \ 682e1051a39Sopenharmony_ci } \ 683e1051a39Sopenharmony_ci val2_read = sk_top_##FIELD(ctx); \ 684e1051a39Sopenharmony_ci if (PUSHN == 0) { \ 685e1051a39Sopenharmony_ci if (val2_read != val2) { \ 686e1051a39Sopenharmony_ci TEST_error("push/sk_top second value did not match"); \ 687e1051a39Sopenharmony_ci res = 0; \ 688e1051a39Sopenharmony_ci } \ 689e1051a39Sopenharmony_ci } else { \ 690e1051a39Sopenharmony_ci if (DUP && val2_read == val2) { \ 691e1051a39Sopenharmony_ci TEST_error("second push did not dup the value"); \ 692e1051a39Sopenharmony_ci res = 0; \ 693e1051a39Sopenharmony_ci } \ 694e1051a39Sopenharmony_ci if (val2 == val1) { \ 695e1051a39Sopenharmony_ci TEST_error("second value is same as first value"); \ 696e1051a39Sopenharmony_ci res = 0; \ 697e1051a39Sopenharmony_ci } \ 698e1051a39Sopenharmony_ci } \ 699e1051a39Sopenharmony_ci /* this does not check if all remaining fields and elems are untouched */ \ 700e1051a39Sopenharmony_ci \ 701e1051a39Sopenharmony_ci if (!TEST_int_eq(ERR_peek_error(), 0)) \ 702e1051a39Sopenharmony_ci res = 0; \ 703e1051a39Sopenharmony_ci \ 704e1051a39Sopenharmony_ci FREE(val1_to_free); \ 705e1051a39Sopenharmony_ci FREE(val2_to_free); \ 706e1051a39Sopenharmony_ci return TEST_true(res); \ 707e1051a39Sopenharmony_ci} \ 708e1051a39Sopenharmony_ci\ 709e1051a39Sopenharmony_cistatic int test_CTX_##PUSHN##_##ELEM(void) \ 710e1051a39Sopenharmony_ci{ \ 711e1051a39Sopenharmony_ci SETUP_TEST_FIXTURE(OSSL_CMP_CTX_TEST_FIXTURE, set_up); \ 712e1051a39Sopenharmony_ci EXECUTE_TEST(execute_CTX_##PUSHN##_##ELEM, tear_down); \ 713e1051a39Sopenharmony_ci return result; \ 714e1051a39Sopenharmony_ci} \ 715e1051a39Sopenharmony_ci 716e1051a39Sopenharmony_ci#define DEFINE_PUSH_TEST(N, DUP, FIELD, ELEM, TYPE) \ 717e1051a39Sopenharmony_ci DEFINE_PUSH_BASE_TEST(push##N, DUP, FIELD, ELEM, TYPE *, TYPE, \ 718e1051a39Sopenharmony_ci IS_0, TYPE##_new(), TYPE##_free) 719e1051a39Sopenharmony_ci 720e1051a39Sopenharmony_civoid cleanup_tests(void) 721e1051a39Sopenharmony_ci{ 722e1051a39Sopenharmony_ci return; 723e1051a39Sopenharmony_ci} 724e1051a39Sopenharmony_ci 725e1051a39Sopenharmony_ciDEFINE_SET_GET_ARG_FN(set, get, option, 35, int) /* OPT_IGNORE_KEYUSAGE */ 726e1051a39Sopenharmony_ciDEFINE_SET_GET_BASE_TEST(OSSL_CMP_CTX, set, get, 0, option_35, int, -1, IS_0, \ 727e1051a39Sopenharmony_ci 1 /* true */, DROP) 728e1051a39Sopenharmony_ci 729e1051a39Sopenharmony_ciDEFINE_SET_CB_TEST(log_cb) 730e1051a39Sopenharmony_ci 731e1051a39Sopenharmony_ciDEFINE_SET_TEST_DEFAULT(OSSL_CMP, CTX, 1, 1, serverPath, char, IS_0) 732e1051a39Sopenharmony_ciDEFINE_SET_TEST(OSSL_CMP, CTX, 1, 1, server, char) 733e1051a39Sopenharmony_ciDEFINE_SET_INT_TEST(serverPort) 734e1051a39Sopenharmony_ciDEFINE_SET_TEST(OSSL_CMP, CTX, 1, 1, proxy, char) 735e1051a39Sopenharmony_ciDEFINE_SET_TEST(OSSL_CMP, CTX, 1, 1, no_proxy, char) 736e1051a39Sopenharmony_ciDEFINE_SET_CB_TEST(http_cb) 737e1051a39Sopenharmony_ciDEFINE_SET_GET_P_VOID_TEST(http_cb_arg) 738e1051a39Sopenharmony_ciDEFINE_SET_CB_TEST(transfer_cb) 739e1051a39Sopenharmony_ciDEFINE_SET_GET_P_VOID_TEST(transfer_cb_arg) 740e1051a39Sopenharmony_ci 741e1051a39Sopenharmony_ciDEFINE_SET_TEST(OSSL_CMP, CTX, 1, 0, srvCert, X509) 742e1051a39Sopenharmony_ciDEFINE_SET_TEST(ossl_cmp, ctx, 0, 0, validatedSrvCert, X509) 743e1051a39Sopenharmony_ciDEFINE_SET_TEST(OSSL_CMP, CTX, 1, 1, expected_sender, X509_NAME) 744e1051a39Sopenharmony_ciDEFINE_SET_GET_BASE_TEST(OSSL_CMP_CTX, set0, get0, 0, trustedStore, 745e1051a39Sopenharmony_ci X509_STORE *, NULL, 746e1051a39Sopenharmony_ci DEFAULT_STORE, X509_STORE_new_1(), X509_STORE_free) 747e1051a39Sopenharmony_ciDEFINE_SET_GET_SK_X509_TEST(OSSL_CMP, CTX, 1, 0, untrusted) 748e1051a39Sopenharmony_ci 749e1051a39Sopenharmony_ciDEFINE_SET_TEST(OSSL_CMP, CTX, 1, 0, cert, X509) 750e1051a39Sopenharmony_ciDEFINE_SET_TEST(OSSL_CMP, CTX, 1, 0, pkey, EVP_PKEY) 751e1051a39Sopenharmony_ci 752e1051a39Sopenharmony_ciDEFINE_SET_TEST(OSSL_CMP, CTX, 1, 1, recipient, X509_NAME) 753e1051a39Sopenharmony_ciDEFINE_PUSH_TEST(0, 0, geninfo_ITAVs, geninfo_ITAV, OSSL_CMP_ITAV) 754e1051a39Sopenharmony_ciDEFINE_SET_SK_TEST(OSSL_CMP, CTX, 1, extraCertsOut, X509) 755e1051a39Sopenharmony_ciDEFINE_SET_GET_ARG_FN(set0, get0, newPkey, 1, EVP_PKEY *) /* priv == 1 */ 756e1051a39Sopenharmony_ciDEFINE_SET_GET_TEST(OSSL_CMP, CTX, 0, 0, 0, newPkey_1, EVP_PKEY) 757e1051a39Sopenharmony_ciDEFINE_SET_GET_ARG_FN(set0, get0, newPkey, 0, EVP_PKEY *) /* priv == 0 */ 758e1051a39Sopenharmony_ciDEFINE_SET_GET_TEST(OSSL_CMP, CTX, 0, 0, 0, newPkey_0, EVP_PKEY) 759e1051a39Sopenharmony_ciDEFINE_SET_GET1_STR_FN(set1, referenceValue) 760e1051a39Sopenharmony_ciDEFINE_SET_GET_TEST_DEFAULT(OSSL_CMP, CTX, 1, 1, 1, referenceValue_str, char, 761e1051a39Sopenharmony_ci IS_0) 762e1051a39Sopenharmony_ciDEFINE_SET_GET1_STR_FN(set1, secretValue) 763e1051a39Sopenharmony_ciDEFINE_SET_GET_TEST_DEFAULT(OSSL_CMP, CTX, 1, 1, 1, secretValue_str, char, IS_0) 764e1051a39Sopenharmony_ciDEFINE_SET_TEST(OSSL_CMP, CTX, 1, 1, issuer, X509_NAME) 765e1051a39Sopenharmony_ciDEFINE_SET_TEST(OSSL_CMP, CTX, 1, 1, subjectName, X509_NAME) 766e1051a39Sopenharmony_ci#ifdef ISSUE_9504_RESOLVED 767e1051a39Sopenharmony_ciDEFINE_PUSH_TEST(1, 1, subjectAltNames, subjectAltName, GENERAL_NAME) 768e1051a39Sopenharmony_ci#endif 769e1051a39Sopenharmony_ciDEFINE_SET_SK_TEST(OSSL_CMP, CTX, 0, reqExtensions, X509_EXTENSION) 770e1051a39Sopenharmony_ciDEFINE_PUSH_TEST(0, 0, policies, policy, POLICYINFO) 771e1051a39Sopenharmony_ciDEFINE_SET_TEST(OSSL_CMP, CTX, 1, 0, oldCert, X509) 772e1051a39Sopenharmony_ci#ifdef ISSUE_9504_RESOLVED 773e1051a39Sopenharmony_ciDEFINE_SET_TEST(OSSL_CMP, CTX, 1, 1, p10CSR, X509_REQ) 774e1051a39Sopenharmony_ci#endif 775e1051a39Sopenharmony_ciDEFINE_PUSH_TEST(0, 0, genm_ITAVs, genm_ITAV, OSSL_CMP_ITAV) 776e1051a39Sopenharmony_ciDEFINE_SET_CB_TEST(certConf_cb) 777e1051a39Sopenharmony_ciDEFINE_SET_GET_P_VOID_TEST(certConf_cb_arg) 778e1051a39Sopenharmony_ci 779e1051a39Sopenharmony_ciDEFINE_SET_GET_INT_TEST(ossl_cmp, ctx, status) 780e1051a39Sopenharmony_ciDEFINE_SET_GET_SK_TEST(ossl_cmp, ctx, 0, 0, statusString, ASN1_UTF8STRING) 781e1051a39Sopenharmony_ciDEFINE_SET_GET_INT_TEST(ossl_cmp, ctx, failInfoCode) 782e1051a39Sopenharmony_ciDEFINE_SET_GET_TEST(ossl_cmp, ctx, 0, 0, 0, newCert, X509) 783e1051a39Sopenharmony_ciDEFINE_SET_GET_SK_X509_TEST(ossl_cmp, ctx, 1, 1, newChain) 784e1051a39Sopenharmony_ciDEFINE_SET_GET_SK_X509_TEST(ossl_cmp, ctx, 1, 1, caPubs) 785e1051a39Sopenharmony_ciDEFINE_SET_GET_SK_X509_TEST(ossl_cmp, ctx, 1, 1, extraCertsIn) 786e1051a39Sopenharmony_ci 787e1051a39Sopenharmony_ciDEFINE_SET_TEST_DEFAULT(OSSL_CMP, CTX, 1, 1, transactionID, ASN1_OCTET_STRING, 788e1051a39Sopenharmony_ci IS_0) 789e1051a39Sopenharmony_ciDEFINE_SET_TEST(OSSL_CMP, CTX, 1, 1, senderNonce, ASN1_OCTET_STRING) 790e1051a39Sopenharmony_ciDEFINE_SET_TEST(ossl_cmp, ctx, 1, 1, recipNonce, ASN1_OCTET_STRING) 791e1051a39Sopenharmony_ci 792e1051a39Sopenharmony_ciint setup_tests(void) 793e1051a39Sopenharmony_ci{ 794e1051a39Sopenharmony_ci char *cert_file; 795e1051a39Sopenharmony_ci 796e1051a39Sopenharmony_ci if (!test_skip_common_options()) { 797e1051a39Sopenharmony_ci TEST_error("Error parsing test options\n"); 798e1051a39Sopenharmony_ci return 0; 799e1051a39Sopenharmony_ci } 800e1051a39Sopenharmony_ci 801e1051a39Sopenharmony_ci if (!TEST_ptr(cert_file = test_get_argument(0)) 802e1051a39Sopenharmony_ci || !TEST_ptr(test_cert = load_cert_pem(cert_file, NULL))) 803e1051a39Sopenharmony_ci return 0; 804e1051a39Sopenharmony_ci 805e1051a39Sopenharmony_ci /* OSSL_CMP_CTX_new() is tested by set_up() */ 806e1051a39Sopenharmony_ci /* OSSL_CMP_CTX_free() is tested by tear_down() */ 807e1051a39Sopenharmony_ci ADD_TEST(test_CTX_reinit); 808e1051a39Sopenharmony_ci 809e1051a39Sopenharmony_ci /* various CMP options: */ 810e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set_get_option_35); 811e1051a39Sopenharmony_ci /* CMP-specific callback for logging and outputting the error queue: */ 812e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set_get_log_cb); 813e1051a39Sopenharmony_ci /* 814e1051a39Sopenharmony_ci * also tests OSSL_CMP_log_open(), OSSL_CMP_CTX_set_log_verbosity(), 815e1051a39Sopenharmony_ci * ossl_cmp_err(), ossl_cmp_warn(), * ossl_cmp_debug(), 816e1051a39Sopenharmony_ci * ossl_cmp_log2(), ossl_cmp_log_parse_metadata(), and OSSL_CMP_log_close() 817e1051a39Sopenharmony_ci * with OSSL_CMP_severity OSSL_CMP_LOG_ERR/WARNING/DEBUG/INFO: 818e1051a39Sopenharmony_ci */ 819e1051a39Sopenharmony_ci ADD_TEST(test_cmp_ctx_log_cb); 820e1051a39Sopenharmony_ci#if !defined(OPENSSL_NO_ERR) && !defined(OPENSSL_NO_AUTOERRINIT) 821e1051a39Sopenharmony_ci /* 822e1051a39Sopenharmony_ci * also tests OSSL_CMP_CTX_set_log_cb(), OSSL_CMP_print_errors_cb(), 823e1051a39Sopenharmony_ci * and the macros ossl_cmp_add_error_data and ossl_cmp_add_error_line: 824e1051a39Sopenharmony_ci */ 825e1051a39Sopenharmony_ci ADD_TEST(test_CTX_print_errors); 826e1051a39Sopenharmony_ci#endif 827e1051a39Sopenharmony_ci /* message transfer: */ 828e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get0_serverPath); 829e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get0_server); 830e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set_get_serverPort); 831e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get0_proxy); 832e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get0_no_proxy); 833e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set_get_http_cb); 834e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set_get_http_cb_arg); 835e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set_get_transfer_cb); 836e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set_get_transfer_cb_arg); 837e1051a39Sopenharmony_ci /* server authentication: */ 838e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get0_srvCert); 839e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set0_get0_validatedSrvCert); 840e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get0_expected_sender); 841e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set0_get0_trustedStore); 842e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get0_untrusted); 843e1051a39Sopenharmony_ci /* client authentication: */ 844e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get0_cert); 845e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get0_pkey); 846e1051a39Sopenharmony_ci /* the following two also test ossl_cmp_asn1_octet_string_set1_bytes(): */ 847e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get1_referenceValue_str); 848e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get1_secretValue_str); 849e1051a39Sopenharmony_ci /* CMP message header and extra certificates: */ 850e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get0_recipient); 851e1051a39Sopenharmony_ci ADD_TEST(test_CTX_push0_geninfo_ITAV); 852e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get0_extraCertsOut); 853e1051a39Sopenharmony_ci /* certificate template: */ 854e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set0_get0_newPkey_1); 855e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set0_get0_newPkey_0); 856e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get0_issuer); 857e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get0_subjectName); 858e1051a39Sopenharmony_ci#ifdef ISSUE_9504_RESOLVED 859e1051a39Sopenharmony_ci /* 860e1051a39Sopenharmony_ci * test currently fails, see https://github.com/openssl/openssl/issues/9504 861e1051a39Sopenharmony_ci */ 862e1051a39Sopenharmony_ci ADD_TEST(test_CTX_push1_subjectAltName); 863e1051a39Sopenharmony_ci#endif 864e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set0_get0_reqExtensions); 865e1051a39Sopenharmony_ci ADD_TEST(test_CTX_reqExtensions_have_SAN); 866e1051a39Sopenharmony_ci ADD_TEST(test_CTX_push0_policy); 867e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get0_oldCert); 868e1051a39Sopenharmony_ci#ifdef ISSUE_9504_RESOLVED 869e1051a39Sopenharmony_ci /* 870e1051a39Sopenharmony_ci * test currently fails, see https://github.com/openssl/openssl/issues/9504 871e1051a39Sopenharmony_ci */ 872e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get0_p10CSR); 873e1051a39Sopenharmony_ci#endif 874e1051a39Sopenharmony_ci /* misc body contents: */ 875e1051a39Sopenharmony_ci ADD_TEST(test_CTX_push0_genm_ITAV); 876e1051a39Sopenharmony_ci /* certificate confirmation: */ 877e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set_get_certConf_cb); 878e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set_get_certConf_cb_arg); 879e1051a39Sopenharmony_ci /* result fetching: */ 880e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set_get_status); 881e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set0_get0_statusString); 882e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set_get_failInfoCode); 883e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set0_get0_newCert); 884e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get1_newChain); 885e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get1_caPubs); 886e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get1_extraCertsIn); 887e1051a39Sopenharmony_ci /* exported for testing and debugging purposes: */ 888e1051a39Sopenharmony_ci /* the following three also test ossl_cmp_asn1_octet_string_set1(): */ 889e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get0_transactionID); 890e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get0_senderNonce); 891e1051a39Sopenharmony_ci ADD_TEST(test_CTX_set1_get0_recipNonce); 892e1051a39Sopenharmony_ci return 1; 893e1051a39Sopenharmony_ci} 894