2 * Copyright 2007-2022 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright Nokia 2007-2019
4 * Copyright Siemens AG 2015-2019
6 * Licensed under the Apache License 2.0 (the "License"). You may not use
7 * this file except in compliance with the License. You can obtain a copy
8 * in the file LICENSE in the source distribution or at
9 * https://www.openssl.org/source/license.html
12 #include "helpers/cmp_testlib.h"
13 #include "../crypto/crmf/crmf_local.h" /* for manipulating POPO signature */
15 static const char *server_f
;
16 static const char *client_f
;
17 static const char *endentity1_f
;
18 static const char *endentity2_f
;
19 static const char *root_f
;
20 static const char *intermediate_f
;
21 static const char *ir_protected_f
;
22 static const char *ir_unprotected_f
;
23 static const char *ir_rmprotection_f
;
24 static const char *ip_waiting_f
;
25 static const char *instacert_f
;
26 static const char *instaca_f
;
27 static const char *ir_protected_0_extracerts
;
28 static const char *ir_protected_2_extracerts
;
30 typedef struct test_fixture
{
31 const char *test_case_name
;
33 OSSL_CMP_CTX
*cmp_ctx
;
36 ossl_cmp_allow_unprotected_cb_t allow_unprotected_cb
;
38 } CMP_VFY_TEST_FIXTURE
;
40 static OSSL_LIB_CTX
*libctx
= NULL
;
41 static OSSL_PROVIDER
*default_null_provider
= NULL
, *provider
= NULL
;
43 static void tear_down(CMP_VFY_TEST_FIXTURE
*fixture
)
45 OSSL_CMP_MSG_free(fixture
->msg
);
46 OSSL_CMP_CTX_free(fixture
->cmp_ctx
);
47 OPENSSL_free(fixture
);
50 static time_t test_time_valid
= 0, test_time_after_expiration
= 0;
52 static CMP_VFY_TEST_FIXTURE
*set_up(const char *const test_case_name
)
55 CMP_VFY_TEST_FIXTURE
*fixture
;
57 if (!TEST_ptr(fixture
= OPENSSL_zalloc(sizeof(*fixture
))))
60 ts
= X509_STORE_new();
61 fixture
->test_case_name
= test_case_name
;
63 || !TEST_ptr(fixture
->cmp_ctx
= OSSL_CMP_CTX_new(libctx
, NULL
))
64 || !OSSL_CMP_CTX_set0_trusted(fixture
->cmp_ctx
, ts
)
65 || !OSSL_CMP_CTX_set_log_cb(fixture
->cmp_ctx
, print_to_bio_out
)) {
70 X509_VERIFY_PARAM_set_time(X509_STORE_get0_param(ts
), test_time_valid
);
71 X509_STORE_set_verify_cb(ts
, X509_STORE_CTX_print_verify_cb
);
75 static X509
*srvcert
= NULL
;
76 static X509
*clcert
= NULL
;
78 static X509
*endentity1
= NULL
, *endentity2
= NULL
,
79 *intermediate
= NULL
, *root
= NULL
;
81 static X509
*insta_cert
= NULL
, *instaca_cert
= NULL
;
83 static unsigned char rand_data
[OSSL_CMP_TRANSACTIONID_LENGTH
];
84 static OSSL_CMP_MSG
*ir_unprotected
, *ir_rmprotection
;
86 static int flip_bit(ASN1_BIT_STRING
*bitstr
)
89 int bit
= ASN1_BIT_STRING_get_bit(bitstr
, bit_num
);
91 return ASN1_BIT_STRING_set_bit(bitstr
, bit_num
, !bit
);
94 static int execute_verify_popo_test(CMP_VFY_TEST_FIXTURE
*fixture
)
96 if ((fixture
->msg
= load_pkimsg(ir_protected_f
, libctx
)) == NULL
)
98 if (fixture
->expected
== 0) {
99 const OSSL_CRMF_MSGS
*reqs
= fixture
->msg
->body
->value
.ir
;
100 const OSSL_CRMF_MSG
*req
= sk_OSSL_CRMF_MSG_value(reqs
, 0);
101 if (req
== NULL
|| !flip_bit(req
->popo
->value
.signature
->signature
))
104 return TEST_int_eq(fixture
->expected
,
105 ossl_cmp_verify_popo(fixture
->cmp_ctx
, fixture
->msg
,
106 fixture
->additional_arg
));
109 static int test_verify_popo(void)
111 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
112 fixture
->expected
= 1;
113 EXECUTE_TEST(execute_verify_popo_test
, tear_down
);
117 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
118 static int test_verify_popo_bad(void)
120 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
121 fixture
->expected
= 0;
122 EXECUTE_TEST(execute_verify_popo_test
, tear_down
);
127 /* indirectly checks also OSSL_CMP_validate_msg() */
128 static int execute_validate_msg_test(CMP_VFY_TEST_FIXTURE
*fixture
)
130 int res
= TEST_int_eq(fixture
->expected
,
131 ossl_cmp_msg_check_update(fixture
->cmp_ctx
,
132 fixture
->msg
, NULL
, 0));
133 X509
*validated
= OSSL_CMP_CTX_get0_validatedSrvCert(fixture
->cmp_ctx
);
135 return res
&& (!fixture
->expected
|| TEST_ptr_eq(validated
, fixture
->cert
));
138 static int execute_validate_cert_path_test(CMP_VFY_TEST_FIXTURE
*fixture
)
140 X509_STORE
*ts
= OSSL_CMP_CTX_get0_trusted(fixture
->cmp_ctx
);
141 int res
= TEST_int_eq(fixture
->expected
,
142 OSSL_CMP_validate_cert_path(fixture
->cmp_ctx
,
145 OSSL_CMP_CTX_print_errors(fixture
->cmp_ctx
);
149 static int test_validate_msg_mac_alg_protection(void)
151 /* secret value belonging to cmp-test/CMP_IP_waitingStatus_PBM.der */
152 const unsigned char sec_1
[] = {
153 '9', 'p', 'p', '8', '-', 'b', '3', '5', 'i', '-', 'X', 'd', '3',
154 'Q', '-', 'u', 'd', 'N', 'R'
157 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
158 fixture
->cert
= NULL
;
160 fixture
->expected
= 1;
161 if (!TEST_true(OSSL_CMP_CTX_set1_secretValue(fixture
->cmp_ctx
, sec_1
,
163 || !TEST_ptr(fixture
->msg
= load_pkimsg(ip_waiting_f
, libctx
))) {
167 EXECUTE_TEST(execute_validate_msg_test
, tear_down
);
171 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
172 static int test_validate_msg_mac_alg_protection_bad(void)
174 const unsigned char sec_bad
[] = {
175 '9', 'p', 'p', '8', '-', 'b', '3', '5', 'i', '-', 'X', 'd', '3',
176 'Q', '-', 'u', 'd', 'N', 'r'
179 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
180 fixture
->cert
= NULL
;
181 fixture
->expected
= 0;
183 if (!TEST_true(OSSL_CMP_CTX_set1_secretValue(fixture
->cmp_ctx
, sec_bad
,
185 || !TEST_ptr(fixture
->msg
= load_pkimsg(ip_waiting_f
, libctx
))) {
189 EXECUTE_TEST(execute_validate_msg_test
, tear_down
);
194 static int add_trusted(OSSL_CMP_CTX
*ctx
, X509
*cert
)
196 return X509_STORE_add_cert(OSSL_CMP_CTX_get0_trusted(ctx
), cert
);
199 static int add_untrusted(OSSL_CMP_CTX
*ctx
, X509
*cert
)
201 return X509_add_cert(OSSL_CMP_CTX_get0_untrusted(ctx
), cert
,
202 X509_ADD_FLAG_UP_REF
);
205 static int test_validate_msg_signature_partial_chain(int expired
)
209 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
210 fixture
->cert
= srvcert
;
212 ts
= OSSL_CMP_CTX_get0_trusted(fixture
->cmp_ctx
);
213 fixture
->expected
= !expired
;
215 || !TEST_ptr(fixture
->msg
= load_pkimsg(ir_protected_f
, libctx
))
216 || !add_trusted(fixture
->cmp_ctx
, srvcert
)) {
220 X509_VERIFY_PARAM
*vpm
= X509_STORE_get0_param(ts
);
221 X509_VERIFY_PARAM_set_flags(vpm
, X509_V_FLAG_PARTIAL_CHAIN
);
223 X509_VERIFY_PARAM_set_time(vpm
, test_time_after_expiration
);
225 EXECUTE_TEST(execute_validate_msg_test
, tear_down
);
229 static int test_validate_msg_signature_trusted_ok(void)
231 return test_validate_msg_signature_partial_chain(0);
234 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
235 static int test_validate_msg_signature_trusted_expired(void)
237 return test_validate_msg_signature_partial_chain(1);
241 static int test_validate_msg_signature_srvcert_wrong(void)
243 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
244 fixture
->expected
= 0;
245 if (!TEST_ptr(fixture
->msg
= load_pkimsg(ir_protected_f
, libctx
))
246 || !TEST_true(OSSL_CMP_CTX_set1_srvCert(fixture
->cmp_ctx
, clcert
))) {
250 EXECUTE_TEST(execute_validate_msg_test
, tear_down
);
254 static int test_validate_msg_signature_srvcert(int bad_sig
)
256 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
257 fixture
->cert
= srvcert
;
258 fixture
->expected
= !bad_sig
;
259 if (!TEST_ptr(fixture
->msg
= load_pkimsg(ir_protected_f
, libctx
))
260 || !TEST_true(OSSL_CMP_CTX_set1_srvCert(fixture
->cmp_ctx
, srvcert
))
261 || (bad_sig
&& !flip_bit(fixture
->msg
->protection
))) {
265 EXECUTE_TEST(execute_validate_msg_test
, tear_down
);
269 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
270 static int test_validate_msg_signature_bad(void)
272 return test_validate_msg_signature_srvcert(1);
276 static int test_validate_msg_signature_sender_cert_srvcert(void)
278 return test_validate_msg_signature_srvcert(0);
281 static int test_validate_msg_signature_sender_cert_untrusted(void)
283 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
284 fixture
->cert
= insta_cert
;
285 fixture
->expected
= 1;
286 if (!TEST_ptr(fixture
->msg
= load_pkimsg(ir_protected_0_extracerts
, libctx
))
287 || !add_trusted(fixture
->cmp_ctx
, instaca_cert
)
288 || !add_untrusted(fixture
->cmp_ctx
, insta_cert
)) {
292 EXECUTE_TEST(execute_validate_msg_test
, tear_down
);
296 static int test_validate_msg_signature_sender_cert_trusted(void)
298 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
299 fixture
->cert
= insta_cert
;
300 fixture
->expected
= 1;
301 if (!TEST_ptr(fixture
->msg
= load_pkimsg(ir_protected_0_extracerts
, libctx
))
302 || !add_trusted(fixture
->cmp_ctx
, instaca_cert
)
303 || !add_trusted(fixture
->cmp_ctx
, insta_cert
)) {
307 EXECUTE_TEST(execute_validate_msg_test
, tear_down
);
311 static int test_validate_msg_signature_sender_cert_extracert(void)
313 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
314 fixture
->expected
= 1;
315 if (!TEST_ptr(fixture
->msg
= load_pkimsg(ir_protected_2_extracerts
, libctx
))
316 || !add_trusted(fixture
->cmp_ctx
, instaca_cert
)) {
320 fixture
->cert
= sk_X509_value(fixture
->msg
->extraCerts
, 1); /* Insta CA */
321 EXECUTE_TEST(execute_validate_msg_test
, tear_down
);
326 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
327 static int test_validate_msg_signature_sender_cert_absent(void)
329 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
330 fixture
->expected
= 0;
331 if (!TEST_ptr(fixture
->msg
= load_pkimsg(ir_protected_0_extracerts
, libctx
))) {
335 EXECUTE_TEST(execute_validate_msg_test
, tear_down
);
340 static int test_validate_with_sender(const X509_NAME
*name
, int expected
)
342 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
343 fixture
->cert
= srvcert
;
344 fixture
->expected
= expected
;
345 if (!TEST_ptr(fixture
->msg
= load_pkimsg(ir_protected_f
, libctx
))
346 || !TEST_true(OSSL_CMP_CTX_set1_expected_sender(fixture
->cmp_ctx
, name
))
347 || !TEST_true(OSSL_CMP_CTX_set1_srvCert(fixture
->cmp_ctx
, srvcert
))) {
351 EXECUTE_TEST(execute_validate_msg_test
, tear_down
);
355 static int test_validate_msg_signature_expected_sender(void)
357 return test_validate_with_sender(X509_get_subject_name(srvcert
), 1);
360 static int test_validate_msg_signature_unexpected_sender(void)
362 return test_validate_with_sender(X509_get_subject_name(root
), 0);
365 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
366 static int test_validate_msg_unprotected_request(void)
368 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
369 fixture
->expected
= 0;
370 if (!TEST_ptr(fixture
->msg
= load_pkimsg(ir_unprotected_f
, libctx
))) {
374 EXECUTE_TEST(execute_validate_msg_test
, tear_down
);
379 static void setup_path(CMP_VFY_TEST_FIXTURE
**fixture
, X509
*wrong
, int expired
)
381 (*fixture
)->cert
= endentity2
;
382 (*fixture
)->expected
= wrong
== NULL
&& !expired
;
384 X509_STORE
*ts
= OSSL_CMP_CTX_get0_trusted((*fixture
)->cmp_ctx
);
385 X509_VERIFY_PARAM
*vpm
= X509_STORE_get0_param(ts
);
386 X509_VERIFY_PARAM_set_time(vpm
, test_time_after_expiration
);
388 if (!add_trusted((*fixture
)->cmp_ctx
, wrong
== NULL
? root
: wrong
)
389 || !add_untrusted((*fixture
)->cmp_ctx
, endentity1
)
390 || !add_untrusted((*fixture
)->cmp_ctx
, intermediate
)) {
391 tear_down((*fixture
));
396 static int test_validate_cert_path_ok(void)
398 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
399 setup_path(&fixture
, NULL
, 0);
400 EXECUTE_TEST(execute_validate_cert_path_test
, tear_down
);
404 static int test_validate_cert_path_wrong_anchor(void)
406 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
407 setup_path(&fixture
, srvcert
/* wrong/non-root cert */, 0);
408 EXECUTE_TEST(execute_validate_cert_path_test
, tear_down
);
412 static int test_validate_cert_path_expired(void)
414 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
415 setup_path(&fixture
, NULL
, 1);
416 EXECUTE_TEST(execute_validate_cert_path_test
, tear_down
);
420 static int execute_msg_check_test(CMP_VFY_TEST_FIXTURE
*fixture
)
422 const OSSL_CMP_PKIHEADER
*hdr
= OSSL_CMP_MSG_get0_header(fixture
->msg
);
423 const ASN1_OCTET_STRING
*tid
= OSSL_CMP_HDR_get0_transactionID(hdr
);
425 if (!TEST_int_eq(fixture
->expected
,
426 ossl_cmp_msg_check_update(fixture
->cmp_ctx
,
428 fixture
->allow_unprotected_cb
,
429 fixture
->additional_arg
)))
432 if (fixture
->expected
== 0) /* error expected already during above check */
436 ASN1_OCTET_STRING_cmp(ossl_cmp_hdr_get0_senderNonce(hdr
),
437 fixture
->cmp_ctx
->recipNonce
))
439 ASN1_OCTET_STRING_cmp(tid
,
440 fixture
->cmp_ctx
->transactionID
));
443 static int allow_unprotected(const OSSL_CMP_CTX
*ctx
, const OSSL_CMP_MSG
*msg
,
444 int invalid_protection
, int allow
)
449 static void setup_check_update(CMP_VFY_TEST_FIXTURE
**fixture
, int expected
,
450 ossl_cmp_allow_unprotected_cb_t cb
, int arg
,
451 const unsigned char *trid_data
,
452 const unsigned char *nonce_data
)
454 OSSL_CMP_CTX
*ctx
= (*fixture
)->cmp_ctx
;
455 int nonce_len
= OSSL_CMP_SENDERNONCE_LENGTH
;
457 (*fixture
)->expected
= expected
;
458 (*fixture
)->allow_unprotected_cb
= cb
;
459 (*fixture
)->additional_arg
= arg
;
460 (*fixture
)->msg
= OSSL_CMP_MSG_dup(ir_rmprotection
);
461 if ((*fixture
)->msg
== NULL
462 || (nonce_data
!= NULL
463 && !ossl_cmp_asn1_octet_string_set1_bytes(&ctx
->senderNonce
,
464 nonce_data
, nonce_len
))) {
465 tear_down((*fixture
));
467 } else if (trid_data
!= NULL
) {
468 ASN1_OCTET_STRING
*trid
= ASN1_OCTET_STRING_new();
470 || !ASN1_OCTET_STRING_set(trid
, trid_data
,
471 OSSL_CMP_TRANSACTIONID_LENGTH
)
472 || !OSSL_CMP_CTX_set1_transactionID(ctx
, trid
)) {
473 tear_down((*fixture
));
476 ASN1_OCTET_STRING_free(trid
);
480 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
481 static int test_msg_check_no_protection_no_cb(void)
483 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
484 setup_check_update(&fixture
, 0, NULL
, 0, NULL
, NULL
);
485 EXECUTE_TEST(execute_msg_check_test
, tear_down
);
489 static int test_msg_check_no_protection_restrictive_cb(void)
491 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
492 setup_check_update(&fixture
, 0, allow_unprotected
, 0, NULL
, NULL
);
493 EXECUTE_TEST(execute_msg_check_test
, tear_down
);
498 static int test_msg_check_no_protection_permissive_cb(void)
500 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
501 setup_check_update(&fixture
, 1, allow_unprotected
, 1, NULL
, NULL
);
502 EXECUTE_TEST(execute_msg_check_test
, tear_down
);
506 static int test_msg_check_transaction_id(void)
508 /* Transaction id belonging to CMP_IR_rmprotection.der */
509 const unsigned char trans_id
[OSSL_CMP_TRANSACTIONID_LENGTH
] = {
510 0x39, 0xB6, 0x90, 0x28, 0xC4, 0xBC, 0x7A, 0xF6,
511 0xBE, 0xC6, 0x4A, 0x88, 0x97, 0xA6, 0x95, 0x0B
514 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
515 setup_check_update(&fixture
, 1, allow_unprotected
, 1, trans_id
, NULL
);
516 EXECUTE_TEST(execute_msg_check_test
, tear_down
);
520 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
521 static int test_msg_check_transaction_id_bad(void)
523 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
524 setup_check_update(&fixture
, 0, allow_unprotected
, 1, rand_data
, NULL
);
525 EXECUTE_TEST(execute_msg_check_test
, tear_down
);
530 static int test_msg_check_recipient_nonce(void)
532 /* Recipient nonce belonging to CMP_IP_ir_rmprotection.der */
533 const unsigned char rec_nonce
[OSSL_CMP_SENDERNONCE_LENGTH
] = {
534 0x48, 0xF1, 0x71, 0x1F, 0xE5, 0xAF, 0x1C, 0x8B,
535 0x21, 0x97, 0x5C, 0x84, 0x74, 0x49, 0xBA, 0x32
538 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
539 setup_check_update(&fixture
, 1, allow_unprotected
, 1, NULL
, rec_nonce
);
540 EXECUTE_TEST(execute_msg_check_test
, tear_down
);
544 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
545 static int test_msg_check_recipient_nonce_bad(void)
547 SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE
, set_up
);
548 setup_check_update(&fixture
, 0, allow_unprotected
, 1, NULL
, rand_data
);
549 EXECUTE_TEST(execute_msg_check_test
, tear_down
);
554 void cleanup_tests(void)
558 X509_free(endentity1
);
559 X509_free(endentity2
);
560 X509_free(intermediate
);
562 X509_free(insta_cert
);
563 X509_free(instaca_cert
);
564 OSSL_CMP_MSG_free(ir_unprotected
);
565 OSSL_CMP_MSG_free(ir_rmprotection
);
566 OSSL_LIB_CTX_free(libctx
);
571 #define USAGE "server.crt client.crt " \
572 "EndEntity1.crt EndEntity2.crt " \
573 "Root_CA.crt Intermediate_CA.crt " \
574 "CMP_IR_protected.der CMP_IR_unprotected.der " \
575 "IP_waitingStatus_PBM.der IR_rmprotection.der " \
576 "insta.cert.pem insta_ca.cert.pem " \
577 "IR_protected_0_extraCerts.der " \
578 "IR_protected_2_extraCerts.der module_name [module_conf_file]\n"
579 OPT_TEST_DECLARE_USAGE(USAGE
)
581 int setup_tests(void)
583 /* Set test time stamps */
584 struct tm ts
= { 0 };
586 ts
.tm_year
= 2018 - 1900; /* 2018 */
587 ts
.tm_mon
= 1; /* February */
588 ts
.tm_mday
= 18; /* 18th */
589 test_time_valid
= mktime(&ts
); /* February 18th 2018 */
590 ts
.tm_year
+= 10; /* February 18th 2028 */
591 test_time_after_expiration
= mktime(&ts
);
593 if (!test_skip_common_options()) {
594 TEST_error("Error parsing test options\n");
598 RAND_bytes(rand_data
, OSSL_CMP_TRANSACTIONID_LENGTH
);
599 if (!TEST_ptr(server_f
= test_get_argument(0))
600 || !TEST_ptr(client_f
= test_get_argument(1))
601 || !TEST_ptr(endentity1_f
= test_get_argument(2))
602 || !TEST_ptr(endentity2_f
= test_get_argument(3))
603 || !TEST_ptr(root_f
= test_get_argument(4))
604 || !TEST_ptr(intermediate_f
= test_get_argument(5))
605 || !TEST_ptr(ir_protected_f
= test_get_argument(6))
606 || !TEST_ptr(ir_unprotected_f
= test_get_argument(7))
607 || !TEST_ptr(ip_waiting_f
= test_get_argument(8))
608 || !TEST_ptr(ir_rmprotection_f
= test_get_argument(9))
609 || !TEST_ptr(instacert_f
= test_get_argument(10))
610 || !TEST_ptr(instaca_f
= test_get_argument(11))
611 || !TEST_ptr(ir_protected_0_extracerts
= test_get_argument(12))
612 || !TEST_ptr(ir_protected_2_extracerts
= test_get_argument(13))) {
613 TEST_error("usage: cmp_vfy_test %s", USAGE
);
617 if (!test_arg_libctx(&libctx
, &default_null_provider
, &provider
, 14, USAGE
))
620 /* Load certificates for cert chain */
621 if (!TEST_ptr(endentity1
= load_cert_pem(endentity1_f
, libctx
))
622 || !TEST_ptr(endentity2
= load_cert_pem(endentity2_f
, libctx
))
623 || !TEST_ptr(root
= load_cert_pem(root_f
, NULL
))
624 || !TEST_ptr(intermediate
= load_cert_pem(intermediate_f
, libctx
)))
627 if (!TEST_ptr(insta_cert
= load_cert_pem(instacert_f
, libctx
))
628 || !TEST_ptr(instaca_cert
= load_cert_pem(instaca_f
, libctx
)))
631 /* Load certificates for message validation */
632 if (!TEST_ptr(srvcert
= load_cert_pem(server_f
, libctx
))
633 || !TEST_ptr(clcert
= load_cert_pem(client_f
, libctx
)))
635 if (!TEST_int_eq(1, RAND_bytes(rand_data
, OSSL_CMP_TRANSACTIONID_LENGTH
)))
637 if (!TEST_ptr(ir_unprotected
= load_pkimsg(ir_unprotected_f
, libctx
))
638 || !TEST_ptr(ir_rmprotection
= load_pkimsg(ir_rmprotection_f
, libctx
)))
641 /* Message validation tests */
642 ADD_TEST(test_verify_popo
);
643 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
644 ADD_TEST(test_verify_popo_bad
);
646 ADD_TEST(test_validate_msg_signature_trusted_ok
);
647 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
648 ADD_TEST(test_validate_msg_signature_trusted_expired
);
650 ADD_TEST(test_validate_msg_signature_srvcert_wrong
);
651 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
652 ADD_TEST(test_validate_msg_signature_bad
);
654 ADD_TEST(test_validate_msg_signature_sender_cert_srvcert
);
655 ADD_TEST(test_validate_msg_signature_sender_cert_untrusted
);
656 ADD_TEST(test_validate_msg_signature_sender_cert_trusted
);
657 ADD_TEST(test_validate_msg_signature_sender_cert_extracert
);
658 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
659 ADD_TEST(test_validate_msg_signature_sender_cert_absent
);
661 ADD_TEST(test_validate_msg_signature_expected_sender
);
662 ADD_TEST(test_validate_msg_signature_unexpected_sender
);
663 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
664 ADD_TEST(test_validate_msg_unprotected_request
);
666 ADD_TEST(test_validate_msg_mac_alg_protection
);
667 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
668 ADD_TEST(test_validate_msg_mac_alg_protection_bad
);
671 /* Cert path validation tests */
672 ADD_TEST(test_validate_cert_path_ok
);
673 ADD_TEST(test_validate_cert_path_expired
);
674 ADD_TEST(test_validate_cert_path_wrong_anchor
);
676 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
677 ADD_TEST(test_msg_check_no_protection_no_cb
);
678 ADD_TEST(test_msg_check_no_protection_restrictive_cb
);
680 ADD_TEST(test_msg_check_no_protection_permissive_cb
);
681 ADD_TEST(test_msg_check_transaction_id
);
682 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
683 ADD_TEST(test_msg_check_transaction_id_bad
);
685 ADD_TEST(test_msg_check_recipient_nonce
);
686 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
687 ADD_TEST(test_msg_check_recipient_nonce_bad
);