1 1.1 christos /* 2 1.1.1.2 christos * Copyright 2007-2024 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 static unsigned char rand_data[OSSL_CMP_TRANSACTIONID_LENGTH]; 15 1.1 christos 16 1.1 christos typedef struct test_fixture { 17 1.1 christos const char *test_case_name; 18 1.1 christos int expected; 19 1.1 christos OSSL_CMP_CTX *cmp_ctx; 20 1.1 christos OSSL_CMP_PKIHEADER *hdr; 21 1.1 christos 22 1.1 christos } CMP_HDR_TEST_FIXTURE; 23 1.1 christos 24 1.1 christos static void tear_down(CMP_HDR_TEST_FIXTURE *fixture) 25 1.1 christos { 26 1.1 christos OSSL_CMP_PKIHEADER_free(fixture->hdr); 27 1.1 christos OSSL_CMP_CTX_free(fixture->cmp_ctx); 28 1.1 christos OPENSSL_free(fixture); 29 1.1 christos } 30 1.1 christos 31 1.1 christos static CMP_HDR_TEST_FIXTURE *set_up(const char *const test_case_name) 32 1.1 christos { 33 1.1 christos CMP_HDR_TEST_FIXTURE *fixture; 34 1.1 christos 35 1.1 christos if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture)))) 36 1.1 christos return NULL; 37 1.1 christos fixture->test_case_name = test_case_name; 38 1.1 christos if (!TEST_ptr(fixture->cmp_ctx = OSSL_CMP_CTX_new(NULL, NULL))) 39 1.1 christos goto err; 40 1.1 christos if (!TEST_ptr(fixture->hdr = OSSL_CMP_PKIHEADER_new())) 41 1.1 christos goto err; 42 1.1 christos return fixture; 43 1.1 christos 44 1.1 christos err: 45 1.1 christos tear_down(fixture); 46 1.1 christos return NULL; 47 1.1 christos } 48 1.1 christos 49 1.1 christos static int execute_HDR_set_get_pvno_test(CMP_HDR_TEST_FIXTURE *fixture) 50 1.1 christos { 51 1.1 christos int pvno = 77; 52 1.1 christos 53 1.1 christos if (!TEST_int_eq(ossl_cmp_hdr_set_pvno(fixture->hdr, pvno), 1)) 54 1.1 christos return 0; 55 1.1 christos if (!TEST_int_eq(ossl_cmp_hdr_get_pvno(fixture->hdr), pvno)) 56 1.1 christos return 0; 57 1.1 christos return 1; 58 1.1 christos } 59 1.1 christos 60 1.1 christos static int test_HDR_set_get_pvno(void) 61 1.1 christos { 62 1.1 christos SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); 63 1.1 christos fixture->expected = 1; 64 1.1 christos EXECUTE_TEST(execute_HDR_set_get_pvno_test, tear_down); 65 1.1 christos return result; 66 1.1 christos } 67 1.1 christos 68 1.1 christos #define X509_NAME_ADD(n, rd, s) \ 69 1.1 christos X509_NAME_add_entry_by_txt((n), (rd), MBSTRING_ASC, (unsigned char *)(s), \ 70 1.1 christos -1, -1, 0) 71 1.1 christos 72 1.1 christos static int execute_HDR_get0_senderNonce_test(CMP_HDR_TEST_FIXTURE *fixture) 73 1.1 christos { 74 1.1.1.2 christos int res = 0; 75 1.1 christos X509_NAME *sender = X509_NAME_new(); 76 1.1 christos ASN1_OCTET_STRING *sn; 77 1.1 christos 78 1.1 christos if (!TEST_ptr(sender)) 79 1.1.1.2 christos goto err; 80 1.1 christos 81 1.1 christos X509_NAME_ADD(sender, "CN", "A common sender name"); 82 1.1 christos if (!TEST_int_eq(OSSL_CMP_CTX_set1_subjectName(fixture->cmp_ctx, sender), 83 1.1 christos 1)) 84 1.1.1.2 christos goto err; 85 1.1 christos if (!TEST_int_eq(ossl_cmp_hdr_init(fixture->cmp_ctx, fixture->hdr), 86 1.1 christos 1)) 87 1.1.1.2 christos goto err; 88 1.1 christos sn = ossl_cmp_hdr_get0_senderNonce(fixture->hdr); 89 1.1 christos if (!TEST_int_eq(ASN1_OCTET_STRING_cmp(fixture->cmp_ctx->senderNonce, sn), 90 1.1 christos 0)) 91 1.1.1.2 christos goto err; 92 1.1.1.2 christos 93 1.1.1.2 christos res = 1; 94 1.1.1.2 christos err: 95 1.1 christos X509_NAME_free(sender); 96 1.1.1.2 christos 97 1.1.1.2 christos return res; 98 1.1 christos } 99 1.1 christos 100 1.1 christos static int test_HDR_get0_senderNonce(void) 101 1.1 christos { 102 1.1 christos SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); 103 1.1 christos fixture->expected = 1; 104 1.1 christos EXECUTE_TEST(execute_HDR_get0_senderNonce_test, tear_down); 105 1.1 christos return result; 106 1.1 christos } 107 1.1 christos 108 1.1 christos static int execute_HDR_set1_sender_test(CMP_HDR_TEST_FIXTURE *fixture) 109 1.1 christos { 110 1.1.1.2 christos int res = 0; 111 1.1 christos X509_NAME *x509name = X509_NAME_new(); 112 1.1 christos 113 1.1 christos if (!TEST_ptr(x509name)) 114 1.1.1.2 christos goto err; 115 1.1 christos 116 1.1 christos X509_NAME_ADD(x509name, "CN", "A common sender name"); 117 1.1 christos if (!TEST_int_eq(ossl_cmp_hdr_set1_sender(fixture->hdr, x509name), 1)) 118 1.1.1.2 christos goto err; 119 1.1.1.2 christos 120 1.1 christos if (!TEST_int_eq(fixture->hdr->sender->type, GEN_DIRNAME)) 121 1.1.1.2 christos goto err; 122 1.1 christos 123 1.1 christos if (!TEST_int_eq(X509_NAME_cmp(fixture->hdr->sender->d.directoryName, 124 1.1 christos x509name), 0)) 125 1.1.1.2 christos goto err; 126 1.1 christos 127 1.1.1.2 christos res = 1; 128 1.1.1.2 christos err: 129 1.1 christos X509_NAME_free(x509name); 130 1.1.1.2 christos 131 1.1.1.2 christos return res; 132 1.1 christos } 133 1.1 christos 134 1.1 christos static int test_HDR_set1_sender(void) 135 1.1 christos { 136 1.1 christos SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); 137 1.1 christos fixture->expected = 1; 138 1.1 christos EXECUTE_TEST(execute_HDR_set1_sender_test, tear_down); 139 1.1 christos return result; 140 1.1 christos } 141 1.1 christos 142 1.1 christos static int execute_HDR_set1_recipient_test(CMP_HDR_TEST_FIXTURE *fixture) 143 1.1 christos { 144 1.1.1.2 christos int res = 0; 145 1.1 christos X509_NAME *x509name = X509_NAME_new(); 146 1.1 christos 147 1.1 christos if (!TEST_ptr(x509name)) 148 1.1.1.2 christos goto err; 149 1.1 christos 150 1.1 christos X509_NAME_ADD(x509name, "CN", "A common recipient name"); 151 1.1 christos if (!TEST_int_eq(ossl_cmp_hdr_set1_recipient(fixture->hdr, x509name), 1)) 152 1.1.1.2 christos goto err; 153 1.1 christos 154 1.1 christos if (!TEST_int_eq(fixture->hdr->recipient->type, GEN_DIRNAME)) 155 1.1.1.2 christos goto err; 156 1.1 christos 157 1.1 christos if (!TEST_int_eq(X509_NAME_cmp(fixture->hdr->recipient->d.directoryName, 158 1.1 christos x509name), 0)) 159 1.1.1.2 christos goto err; 160 1.1 christos 161 1.1.1.2 christos res = 1; 162 1.1.1.2 christos err: 163 1.1 christos X509_NAME_free(x509name); 164 1.1.1.2 christos 165 1.1.1.2 christos return res; 166 1.1 christos } 167 1.1 christos 168 1.1 christos static int test_HDR_set1_recipient(void) 169 1.1 christos { 170 1.1 christos SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); 171 1.1 christos fixture->expected = 1; 172 1.1 christos EXECUTE_TEST(execute_HDR_set1_recipient_test, tear_down); 173 1.1 christos return result; 174 1.1 christos } 175 1.1 christos 176 1.1 christos static int execute_HDR_update_messageTime_test(CMP_HDR_TEST_FIXTURE *fixture) 177 1.1 christos { 178 1.1 christos struct tm hdrtm, tmptm; 179 1.1 christos time_t hdrtime, before, after, now; 180 1.1 christos 181 1.1 christos now = time(NULL); 182 1.1 christos /* 183 1.1 christos * Trial and error reveals that passing the return value from gmtime 184 1.1 christos * directly to mktime in a mingw 32 bit build gives unexpected results. To 185 1.1 christos * work around this we take a copy of the return value first. 186 1.1 christos */ 187 1.1 christos tmptm = *gmtime(&now); 188 1.1 christos before = mktime(&tmptm); 189 1.1 christos 190 1.1 christos if (!TEST_true(ossl_cmp_hdr_update_messageTime(fixture->hdr))) 191 1.1 christos return 0; 192 1.1 christos if (!TEST_true(ASN1_TIME_to_tm(fixture->hdr->messageTime, &hdrtm))) 193 1.1 christos return 0; 194 1.1 christos 195 1.1 christos hdrtime = mktime(&hdrtm); 196 1.1 christos 197 1.1 christos if (!TEST_time_t_le(before, hdrtime)) 198 1.1 christos return 0; 199 1.1 christos now = time(NULL); 200 1.1 christos tmptm = *gmtime(&now); 201 1.1 christos after = mktime(&tmptm); 202 1.1 christos 203 1.1 christos return TEST_time_t_le(hdrtime, after); 204 1.1 christos } 205 1.1 christos 206 1.1 christos static int test_HDR_update_messageTime(void) 207 1.1 christos { 208 1.1 christos SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); 209 1.1 christos fixture->expected = 1; 210 1.1 christos EXECUTE_TEST(execute_HDR_update_messageTime_test, tear_down); 211 1.1 christos return result; 212 1.1 christos } 213 1.1 christos 214 1.1 christos static int execute_HDR_set1_senderKID_test(CMP_HDR_TEST_FIXTURE *fixture) 215 1.1 christos { 216 1.1 christos ASN1_OCTET_STRING *senderKID = ASN1_OCTET_STRING_new(); 217 1.1 christos int res = 0; 218 1.1 christos 219 1.1 christos if (!TEST_ptr(senderKID)) 220 1.1.1.2 christos goto err; 221 1.1 christos 222 1.1 christos if (!TEST_int_eq(ASN1_OCTET_STRING_set(senderKID, rand_data, 223 1.1 christos sizeof(rand_data)), 1)) 224 1.1 christos goto err; 225 1.1 christos if (!TEST_int_eq(ossl_cmp_hdr_set1_senderKID(fixture->hdr, senderKID), 1)) 226 1.1 christos goto err; 227 1.1 christos if (!TEST_int_eq(ASN1_OCTET_STRING_cmp(fixture->hdr->senderKID, 228 1.1 christos senderKID), 0)) 229 1.1 christos goto err; 230 1.1 christos res = 1; 231 1.1 christos err: 232 1.1 christos ASN1_OCTET_STRING_free(senderKID); 233 1.1 christos return res; 234 1.1 christos } 235 1.1 christos 236 1.1 christos static int test_HDR_set1_senderKID(void) 237 1.1 christos { 238 1.1 christos SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); 239 1.1 christos fixture->expected = 1; 240 1.1 christos EXECUTE_TEST(execute_HDR_set1_senderKID_test, tear_down); 241 1.1 christos return result; 242 1.1 christos } 243 1.1 christos 244 1.1 christos static int execute_HDR_push0_freeText_test(CMP_HDR_TEST_FIXTURE *fixture) 245 1.1 christos { 246 1.1 christos ASN1_UTF8STRING *text = ASN1_UTF8STRING_new(); 247 1.1 christos 248 1.1 christos if (!TEST_ptr(text)) 249 1.1 christos return 0; 250 1.1 christos 251 1.1 christos if (!ASN1_STRING_set(text, "A free text", -1)) 252 1.1 christos goto err; 253 1.1 christos 254 1.1 christos if (!TEST_int_eq(ossl_cmp_hdr_push0_freeText(fixture->hdr, text), 1)) 255 1.1 christos goto err; 256 1.1 christos 257 1.1 christos if (!TEST_true(text == sk_ASN1_UTF8STRING_value(fixture->hdr->freeText, 0))) 258 1.1 christos goto err; 259 1.1 christos 260 1.1 christos return 1; 261 1.1 christos 262 1.1 christos err: 263 1.1 christos ASN1_UTF8STRING_free(text); 264 1.1 christos return 0; 265 1.1 christos } 266 1.1 christos 267 1.1 christos static int test_HDR_push0_freeText(void) 268 1.1 christos { 269 1.1 christos SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); 270 1.1 christos fixture->expected = 1; 271 1.1 christos EXECUTE_TEST(execute_HDR_push0_freeText_test, tear_down); 272 1.1 christos return result; 273 1.1 christos } 274 1.1 christos 275 1.1 christos static int execute_HDR_push1_freeText_test(CMP_HDR_TEST_FIXTURE *fixture) 276 1.1 christos { 277 1.1 christos ASN1_UTF8STRING *text = ASN1_UTF8STRING_new(); 278 1.1 christos ASN1_UTF8STRING *pushed_text; 279 1.1 christos int res = 0; 280 1.1 christos 281 1.1 christos if (!TEST_ptr(text)) 282 1.1.1.2 christos goto err; 283 1.1 christos 284 1.1 christos if (!ASN1_STRING_set(text, "A free text", -1)) 285 1.1 christos goto err; 286 1.1 christos 287 1.1 christos if (!TEST_int_eq(ossl_cmp_hdr_push1_freeText(fixture->hdr, text), 1)) 288 1.1 christos goto err; 289 1.1 christos 290 1.1 christos pushed_text = sk_ASN1_UTF8STRING_value(fixture->hdr->freeText, 0); 291 1.1 christos if (!TEST_int_eq(ASN1_STRING_cmp(text, pushed_text), 0)) 292 1.1 christos goto err; 293 1.1 christos 294 1.1 christos res = 1; 295 1.1 christos err: 296 1.1 christos ASN1_UTF8STRING_free(text); 297 1.1.1.2 christos 298 1.1 christos return res; 299 1.1 christos } 300 1.1 christos 301 1.1 christos static int test_HDR_push1_freeText(void) 302 1.1 christos { 303 1.1 christos SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); 304 1.1 christos fixture->expected = 1; 305 1.1 christos EXECUTE_TEST(execute_HDR_push1_freeText_test, tear_down); 306 1.1 christos return result; 307 1.1 christos } 308 1.1 christos 309 1.1 christos static int 310 1.1 christos execute_HDR_generalInfo_push0_item_test(CMP_HDR_TEST_FIXTURE *fixture) 311 1.1 christos { 312 1.1 christos OSSL_CMP_ITAV *itav = OSSL_CMP_ITAV_new(); 313 1.1 christos 314 1.1 christos if (!TEST_ptr(itav)) 315 1.1 christos return 0; 316 1.1 christos 317 1.1 christos if (!TEST_int_eq(ossl_cmp_hdr_generalInfo_push0_item(fixture->hdr, itav), 318 1.1 christos 1)) 319 1.1 christos return 0; 320 1.1 christos 321 1.1 christos if (!TEST_true(itav == sk_OSSL_CMP_ITAV_value(fixture->hdr->generalInfo, 322 1.1 christos 0))) 323 1.1 christos return 0; 324 1.1 christos 325 1.1 christos return 1; 326 1.1 christos } 327 1.1 christos 328 1.1 christos static int test_HDR_generalInfo_push0_item(void) 329 1.1 christos { 330 1.1 christos SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); 331 1.1 christos fixture->expected = 1; 332 1.1 christos EXECUTE_TEST(execute_HDR_generalInfo_push0_item_test, tear_down); 333 1.1 christos return result; 334 1.1 christos } 335 1.1 christos 336 1.1 christos static int 337 1.1 christos execute_HDR_generalInfo_push1_items_test(CMP_HDR_TEST_FIXTURE *fixture) 338 1.1 christos { 339 1.1 christos const char oid[] = "1.2.3.4"; 340 1.1 christos char buf[20]; 341 1.1 christos OSSL_CMP_ITAV *itav, *pushed_itav; 342 1.1 christos STACK_OF(OSSL_CMP_ITAV) *itavs = NULL, *ginfo; 343 1.1 christos ASN1_INTEGER *asn1int = ASN1_INTEGER_new(); 344 1.1 christos ASN1_TYPE *val = ASN1_TYPE_new(); 345 1.1 christos ASN1_TYPE *pushed_val; 346 1.1 christos int res = 0; 347 1.1 christos 348 1.1 christos if (!TEST_ptr(asn1int)) 349 1.1 christos return 0; 350 1.1 christos 351 1.1 christos if (!TEST_ptr(val) 352 1.1 christos || !TEST_true(ASN1_INTEGER_set(asn1int, 88))) { 353 1.1 christos ASN1_INTEGER_free(asn1int); 354 1.1 christos return 0; 355 1.1 christos } 356 1.1 christos 357 1.1 christos ASN1_TYPE_set(val, V_ASN1_INTEGER, asn1int); 358 1.1 christos if (!TEST_ptr(itav = OSSL_CMP_ITAV_create(OBJ_txt2obj(oid, 1), val))) { 359 1.1 christos ASN1_TYPE_free(val); 360 1.1 christos return 0; 361 1.1 christos } 362 1.1 christos if (!TEST_true(OSSL_CMP_ITAV_push0_stack_item(&itavs, itav))) { 363 1.1 christos OSSL_CMP_ITAV_free(itav); 364 1.1 christos return 0; 365 1.1 christos } 366 1.1 christos 367 1.1 christos if (!TEST_int_eq(ossl_cmp_hdr_generalInfo_push1_items(fixture->hdr, itavs), 368 1.1 christos 1)) 369 1.1 christos goto err; 370 1.1 christos ginfo = fixture->hdr->generalInfo; 371 1.1 christos pushed_itav = sk_OSSL_CMP_ITAV_value(ginfo, 0); 372 1.1 christos OBJ_obj2txt(buf, sizeof(buf), OSSL_CMP_ITAV_get0_type(pushed_itav), 0); 373 1.1 christos if (!TEST_int_eq(memcmp(oid, buf, sizeof(oid)), 0)) 374 1.1 christos goto err; 375 1.1 christos 376 1.1 christos pushed_val = OSSL_CMP_ITAV_get0_value(sk_OSSL_CMP_ITAV_value(ginfo, 0)); 377 1.1 christos if (!TEST_int_eq(ASN1_TYPE_cmp(itav->infoValue.other, pushed_val), 0)) 378 1.1 christos goto err; 379 1.1 christos 380 1.1 christos res = 1; 381 1.1 christos 382 1.1 christos err: 383 1.1 christos sk_OSSL_CMP_ITAV_pop_free(itavs, OSSL_CMP_ITAV_free); 384 1.1 christos return res; 385 1.1 christos } 386 1.1 christos 387 1.1 christos static int test_HDR_generalInfo_push1_items(void) 388 1.1 christos { 389 1.1 christos SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); 390 1.1 christos fixture->expected = 1; 391 1.1 christos EXECUTE_TEST(execute_HDR_generalInfo_push1_items_test, tear_down); 392 1.1 christos return result; 393 1.1 christos } 394 1.1 christos 395 1.1 christos static int 396 1.1 christos execute_HDR_set_and_check_implicitConfirm_test(CMP_HDR_TEST_FIXTURE 397 1.1 christos * fixture) 398 1.1 christos { 399 1.1 christos return TEST_false(ossl_cmp_hdr_has_implicitConfirm(fixture->hdr)) 400 1.1 christos && TEST_true(ossl_cmp_hdr_set_implicitConfirm(fixture->hdr)) 401 1.1 christos && TEST_true(ossl_cmp_hdr_has_implicitConfirm(fixture->hdr)); 402 1.1 christos } 403 1.1 christos 404 1.1 christos static int test_HDR_set_and_check_implicit_confirm(void) 405 1.1 christos { 406 1.1 christos SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); 407 1.1 christos EXECUTE_TEST(execute_HDR_set_and_check_implicitConfirm_test, tear_down); 408 1.1 christos return result; 409 1.1 christos } 410 1.1 christos 411 1.1 christos 412 1.1 christos static int execute_HDR_init_test(CMP_HDR_TEST_FIXTURE *fixture) 413 1.1 christos { 414 1.1 christos ASN1_OCTET_STRING *header_nonce, *header_transactionID; 415 1.1 christos ASN1_OCTET_STRING *ctx_nonce; 416 1.1 christos 417 1.1 christos if (!TEST_int_eq(fixture->expected, 418 1.1 christos ossl_cmp_hdr_init(fixture->cmp_ctx, fixture->hdr))) 419 1.1 christos return 0; 420 1.1 christos if (fixture->expected == 0) 421 1.1 christos return 1; 422 1.1 christos 423 1.1 christos if (!TEST_int_eq(ossl_cmp_hdr_get_pvno(fixture->hdr), OSSL_CMP_PVNO)) 424 1.1 christos return 0; 425 1.1 christos 426 1.1 christos header_nonce = ossl_cmp_hdr_get0_senderNonce(fixture->hdr); 427 1.1 christos if (!TEST_int_eq(0, ASN1_OCTET_STRING_cmp(header_nonce, 428 1.1 christos fixture->cmp_ctx->senderNonce))) 429 1.1 christos return 0; 430 1.1 christos header_transactionID = OSSL_CMP_HDR_get0_transactionID(fixture->hdr); 431 1.1 christos if (!TEST_true(0 == ASN1_OCTET_STRING_cmp(header_transactionID, 432 1.1 christos fixture->cmp_ctx->transactionID))) 433 1.1 christos return 0; 434 1.1 christos 435 1.1 christos header_nonce = OSSL_CMP_HDR_get0_recipNonce(fixture->hdr); 436 1.1 christos ctx_nonce = fixture->cmp_ctx->recipNonce; 437 1.1 christos if (ctx_nonce != NULL 438 1.1 christos && (!TEST_ptr(header_nonce) 439 1.1 christos || !TEST_int_eq(0, ASN1_OCTET_STRING_cmp(header_nonce, 440 1.1 christos ctx_nonce)))) 441 1.1 christos return 0; 442 1.1 christos 443 1.1 christos return 1; 444 1.1 christos } 445 1.1 christos 446 1.1 christos static int test_HDR_init_with_ref(void) 447 1.1 christos { 448 1.1 christos unsigned char ref[CMP_TEST_REFVALUE_LENGTH]; 449 1.1 christos 450 1.1 christos SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); 451 1.1 christos 452 1.1 christos fixture->expected = 1; 453 1.1 christos if (!TEST_int_eq(1, RAND_bytes(ref, sizeof(ref))) 454 1.1 christos || !TEST_true(OSSL_CMP_CTX_set1_referenceValue(fixture->cmp_ctx, 455 1.1 christos ref, sizeof(ref)))) { 456 1.1 christos tear_down(fixture); 457 1.1 christos fixture = NULL; 458 1.1 christos } 459 1.1 christos EXECUTE_TEST(execute_HDR_init_test, tear_down); 460 1.1 christos return result; 461 1.1 christos } 462 1.1 christos 463 1.1 christos static int test_HDR_init_with_subject(void) 464 1.1 christos { 465 1.1 christos X509_NAME *subject = NULL; 466 1.1 christos 467 1.1 christos SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); 468 1.1 christos fixture->expected = 1; 469 1.1 christos if (!TEST_ptr(subject = X509_NAME_new()) 470 1.1 christos || !TEST_true(X509_NAME_ADD(subject, "CN", "Common Name")) 471 1.1 christos || !TEST_true(OSSL_CMP_CTX_set1_subjectName(fixture->cmp_ctx, 472 1.1 christos subject))) { 473 1.1 christos tear_down(fixture); 474 1.1 christos fixture = NULL; 475 1.1 christos } 476 1.1 christos X509_NAME_free(subject); 477 1.1 christos EXECUTE_TEST(execute_HDR_init_test, tear_down); 478 1.1 christos return result; 479 1.1 christos } 480 1.1 christos 481 1.1 christos 482 1.1 christos void cleanup_tests(void) 483 1.1 christos { 484 1.1 christos return; 485 1.1 christos } 486 1.1 christos 487 1.1 christos int setup_tests(void) 488 1.1 christos { 489 1.1 christos RAND_bytes(rand_data, OSSL_CMP_TRANSACTIONID_LENGTH); 490 1.1 christos /* Message header tests */ 491 1.1 christos ADD_TEST(test_HDR_set_get_pvno); 492 1.1 christos ADD_TEST(test_HDR_get0_senderNonce); 493 1.1 christos ADD_TEST(test_HDR_set1_sender); 494 1.1 christos ADD_TEST(test_HDR_set1_recipient); 495 1.1 christos ADD_TEST(test_HDR_update_messageTime); 496 1.1 christos ADD_TEST(test_HDR_set1_senderKID); 497 1.1 christos ADD_TEST(test_HDR_push0_freeText); 498 1.1 christos /* indirectly tests ossl_cmp_pkifreetext_push_str(): */ 499 1.1 christos ADD_TEST(test_HDR_push1_freeText); 500 1.1 christos ADD_TEST(test_HDR_generalInfo_push0_item); 501 1.1 christos ADD_TEST(test_HDR_generalInfo_push1_items); 502 1.1 christos ADD_TEST(test_HDR_set_and_check_implicit_confirm); 503 1.1 christos /* also tests public function OSSL_CMP_HDR_get0_transactionID(): */ 504 1.1 christos /* also tests public function OSSL_CMP_HDR_get0_recipNonce(): */ 505 1.1 christos /* also tests internal function ossl_cmp_hdr_get_pvno(): */ 506 1.1 christos ADD_TEST(test_HDR_init_with_ref); 507 1.1 christos ADD_TEST(test_HDR_init_with_subject); 508 1.1 christos return 1; 509 1.1 christos } 510