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