Lines Matching defs:fixture

38 static void tear_down(CMP_PROTECT_TEST_FIXTURE *fixture)
40 OSSL_CMP_CTX_free(fixture->cmp_ctx);
41 OSSL_CMP_MSG_free(fixture->msg);
42 OSSL_CMP_PKISI_free(fixture->si);
44 OPENSSL_free(fixture->mem);
45 sk_X509_free(fixture->certs);
46 sk_X509_free(fixture->chain);
48 OPENSSL_free(fixture);
53 CMP_PROTECT_TEST_FIXTURE *fixture;
55 if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture))))
57 fixture->test_case_name = test_case_name;
58 if (!TEST_ptr(fixture->cmp_ctx = OSSL_CMP_CTX_new(libctx, NULL))) {
59 tear_down(fixture);
62 return fixture;
74 static int execute_calc_protection_fails_test(CMP_PROTECT_TEST_FIXTURE *fixture)
77 ossl_cmp_calc_protection(fixture->cmp_ctx, fixture->msg);
84 static int execute_calc_protection_pbmac_test(CMP_PROTECT_TEST_FIXTURE *fixture)
87 ossl_cmp_calc_protection(fixture->cmp_ctx, fixture->msg);
90 fixture->msg->protection) == 0);
128 fixture)
131 ossl_cmp_calc_protection(fixture->cmp_ctx, fixture->msg);
134 fixture->msg->protection) == 0)
135 && TEST_true(verify_signature(fixture->msg, protection,
136 fixture->pubkey,
137 fixture->cmp_ctx->digest)));
146 if (!TEST_ptr(fixture->msg = load_pkimsg(ir_unprotected_f, libctx))
147 || !TEST_ptr(fixture->msg->header->protectionAlg =
149 tear_down(fixture);
150 fixture = NULL;
160 fixture->pubkey = loadedpubkey;
161 if (!TEST_true(OSSL_CMP_CTX_set1_pkey(fixture->cmp_ctx, loadedprivkey))
162 || !TEST_ptr(fixture->msg = load_pkimsg(ir_protected_f, libctx))) {
163 tear_down(fixture);
164 fixture = NULL;
175 if (!TEST_true(OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx,
177 || !TEST_ptr(fixture->msg = load_pkimsg(ip_PBM_f, libctx))) {
178 tear_down(fixture);
179 fixture = NULL;
184 static int execute_MSG_protect_test(CMP_PROTECT_TEST_FIXTURE *fixture)
186 return TEST_int_eq(fixture->expected,
187 ossl_cmp_msg_protect(fixture->cmp_ctx, fixture->msg));
196 fixture->expected = 1;
197 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected))
198 || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 1))) {
199 tear_down(fixture);
200 fixture = NULL;
211 fixture->expected = 1;
213 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected))
214 || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0))
219 || !TEST_true(OSSL_CMP_CTX_set1_referenceValue(fixture->cmp_ctx,
221 || !TEST_true(OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx,
224 tear_down(fixture);
225 fixture = NULL;
234 fixture->expected = 1;
236 if (!TEST_ptr(fixture->msg =
238 || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0))
239 || !TEST_true(OSSL_CMP_CTX_set1_pkey(fixture->cmp_ctx, loadedkey))
240 || !TEST_true(OSSL_CMP_CTX_set1_cert(fixture->cmp_ctx, cert))) {
241 tear_down(fixture);
242 fixture = NULL;
253 ctx = fixture->cmp_ctx;
254 fixture->expected = 0;
255 if (!TEST_ptr(fixture->msg =
259 tear_down(fixture);
260 fixture = NULL;
270 fixture->expected = 0;
271 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected))
272 || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0))) {
273 tear_down(fixture);
274 fixture = NULL;
286 fixture->expected = with_ref;
287 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected))
288 || !SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0)
289 || !ossl_cmp_hdr_set1_sender(fixture->msg->header, NULL)
290 || !OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx,
292 || (!OSSL_CMP_CTX_set1_referenceValue(fixture->cmp_ctx,
295 tear_down(fixture);
296 fixture = NULL;
312 static int execute_MSG_add_extraCerts_test(CMP_PROTECT_TEST_FIXTURE *fixture)
314 return TEST_true(ossl_cmp_msg_add_extraCerts(fixture->cmp_ctx,
315 fixture->msg));
321 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_protected))) {
322 tear_down(fixture);
323 fixture = NULL;
331 static int execute_cmp_build_cert_chain_test(CMP_PROTECT_TEST_FIXTURE *fixture)
334 OSSL_CMP_CTX *ctx = fixture->cmp_ctx;
337 X509_build_chain(fixture->cert, fixture->certs, NULL,
338 fixture->with_ss, ctx->libctx, ctx->propq);
342 ret = TEST_int_eq(0, STACK_OF_X509_cmp(chain, fixture->chain));
352 chain = X509_build_chain(fixture->cert, fixture->certs, store,
353 fixture->with_ss, ctx->libctx, ctx->propq);
354 ret = TEST_int_eq(fixture->expected, chain != NULL);
357 ret = TEST_int_eq(0, STACK_OF_X509_cmp(chain, fixture->chain));
368 fixture->expected = 1;
369 fixture->with_ss = 0;
370 fixture->cert = endentity2;
371 if (!TEST_ptr(fixture->certs = sk_X509_new_null())
372 || !TEST_ptr(fixture->chain = sk_X509_new_null())
373 || !TEST_true(sk_X509_push(fixture->certs, endentity1))
374 || !TEST_true(sk_X509_push(fixture->certs, root))
375 || !TEST_true(sk_X509_push(fixture->certs, intermediate))
376 || !TEST_true(sk_X509_push(fixture->chain, endentity2))
377 || !TEST_true(sk_X509_push(fixture->chain, intermediate))) {
378 tear_down(fixture);
379 fixture = NULL;
381 if (fixture != NULL) {
382 result = execute_cmp_build_cert_chain_test(fixture);
383 fixture->with_ss = 1;
384 if (result && TEST_true(sk_X509_push(fixture->chain, root)))
385 result = execute_cmp_build_cert_chain_test(fixture);
387 tear_down(fixture);
394 fixture->expected = 0;
395 fixture->with_ss = 0;
396 fixture->cert = endentity2;
397 if (!TEST_ptr(fixture->certs = sk_X509_new_null())
398 || !TEST_ptr(fixture->chain = sk_X509_new_null())
399 || !TEST_true(sk_X509_push(fixture->certs, endentity1))
400 || !TEST_true(sk_X509_push(fixture->certs, root))
401 || !TEST_true(sk_X509_push(fixture->chain, endentity2))) {
402 tear_down(fixture);
403 fixture = NULL;
412 fixture->expected = 1;
413 fixture->with_ss = 0;
414 fixture->cert = endentity2;
415 if (!TEST_ptr(fixture->certs = sk_X509_new_null())
416 || !TEST_ptr(fixture->chain = sk_X509_new_null())
417 || !TEST_true(sk_X509_push(fixture->certs, endentity1))
418 || !TEST_true(sk_X509_push(fixture->certs, intermediate))
419 || !TEST_true(sk_X509_push(fixture->chain, endentity2))
420 || !TEST_true(sk_X509_push(fixture->chain, intermediate))) {
421 tear_down(fixture);
422 fixture = NULL;
431 fixture->expected = 1;
432 fixture->with_ss = 0; /* still chain must include the only cert (root) */
433 fixture->cert = root;
434 if (!TEST_ptr(fixture->certs = sk_X509_new_null())
435 || !TEST_ptr(fixture->chain = sk_X509_new_null())
436 || !TEST_true(sk_X509_push(fixture->certs, root))
437 || !TEST_true(sk_X509_push(fixture->chain, root))) {
438 tear_down(fixture);
439 fixture = NULL;
448 fixture->expected = 0;
449 fixture->with_ss = 0;
450 fixture->cert = endentity2;
451 if (!TEST_ptr(fixture->certs = sk_X509_new_null())
452 || !TEST_ptr(fixture->chain = sk_X509_new_null())
453 || !TEST_true(sk_X509_push(fixture->chain, endentity2))) {
454 tear_down(fixture);
455 fixture = NULL;
462 static int execute_X509_STORE_test(CMP_PROTECT_TEST_FIXTURE *fixture)
469 fixture->certs,
470 fixture->callback_arg)))
473 if (!TEST_int_eq(0, STACK_OF_X509_cmp(sk, fixture->chain)))
486 fixture->callback_arg = 0; /* self-issued allowed */
487 if (!TEST_ptr(fixture->certs = sk_X509_new_null())
488 || !sk_X509_push(fixture->certs, endentity1)
489 || !sk_X509_push(fixture->certs, endentity2)
490 || !sk_X509_push(fixture->certs, root)
491 || !sk_X509_push(fixture->certs, intermediate)
492 || !TEST_ptr(fixture->chain = sk_X509_dup(fixture->certs))) {
493 tear_down(fixture);
494 fixture = NULL;
503 fixture->certs = sk_X509_new_null();
504 fixture->chain = sk_X509_new_null();
505 fixture->callback_arg = 1; /* only self-issued */
506 if (!TEST_true(sk_X509_push(fixture->certs, endentity1))
507 || !TEST_true(sk_X509_push(fixture->certs, endentity2))
508 || !TEST_true(sk_X509_push(fixture->certs, root))
509 || !TEST_true(sk_X509_push(fixture->certs, intermediate))
510 || !TEST_true(sk_X509_push(fixture->chain, root))) {
511 tear_down(fixture);
512 fixture = NULL;