5f43f1e2ec6fe8ec2821b1282dc08a8a0e308511
[openssl.git] / test / cmp_vfy_test.c
1 /*
2  * Copyright 2007-2020 The OpenSSL Project Authors. All Rights Reserved.
3  * Copyright Nokia 2007-2019
4  * Copyright Siemens AG 2015-2019
5  *
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
10  */
11
12 #include "cmp_testlib.h"
13 #include "../crypto/crmf/crmf_local.h" /* for manipulating POPO signature */
14
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;
29
30 typedef struct test_fixture {
31     const char *test_case_name;
32     int expected;
33     OSSL_CMP_CTX *cmp_ctx;
34     OSSL_CMP_MSG *msg;
35     X509 *cert;
36     ossl_cmp_allow_unprotected_cb_t allow_unprotected_cb;
37     int additional_arg;
38 } CMP_VFY_TEST_FIXTURE;
39
40 static void tear_down(CMP_VFY_TEST_FIXTURE *fixture)
41 {
42     OSSL_CMP_MSG_free(fixture->msg);
43     OSSL_CMP_CTX_free(fixture->cmp_ctx);
44     OPENSSL_free(fixture);
45 }
46
47 static time_t test_time_valid = 0, test_time_after_expiration = 0;
48
49 static CMP_VFY_TEST_FIXTURE *set_up(const char *const test_case_name)
50 {
51     X509_STORE *ts = X509_STORE_new();
52     CMP_VFY_TEST_FIXTURE *fixture;
53
54     if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture))))
55         return NULL;
56     fixture->test_case_name = test_case_name;
57     if (ts == NULL
58             || !TEST_ptr(fixture->cmp_ctx = OSSL_CMP_CTX_new())
59             || !OSSL_CMP_CTX_set0_trustedStore(fixture->cmp_ctx, ts)
60             || !OSSL_CMP_CTX_set_log_cb(fixture->cmp_ctx, print_to_bio_out)) {
61         tear_down(fixture);
62         X509_STORE_free(ts);
63         return NULL;
64     }
65     X509_VERIFY_PARAM_set_time(X509_STORE_get0_param(ts), test_time_valid);
66     X509_STORE_set_verify_cb(ts, X509_STORE_CTX_print_verify_cb);
67     return fixture;
68 }
69
70 static X509 *srvcert = NULL;
71 static X509 *clcert = NULL;
72 /* chain */
73 static X509 *endentity1 = NULL, *endentity2 = NULL,
74     *intermediate = NULL, *root = NULL;
75 /* INSTA chain */
76 static X509 *insta_cert = NULL, *instaca_cert = NULL;
77
78 static unsigned char rand_data[OSSL_CMP_TRANSACTIONID_LENGTH];
79 static OSSL_CMP_MSG *ir_unprotected, *ir_rmprotection;
80
81 static int flip_bit(ASN1_BIT_STRING *bitstr)
82 {
83     int bit_num = 7;
84     int bit = ASN1_BIT_STRING_get_bit(bitstr, bit_num);
85
86     return ASN1_BIT_STRING_set_bit(bitstr, bit_num, !bit);
87 }
88
89 static int execute_verify_popo_test(CMP_VFY_TEST_FIXTURE *fixture)
90 {
91     if ((fixture->msg = load_pkimsg(ir_protected_f)) == NULL)
92         return 0;
93     if (fixture->expected == 0) {
94         const OSSL_CRMF_MSGS *reqs = fixture->msg->body->value.ir;
95         const OSSL_CRMF_MSG *req = sk_OSSL_CRMF_MSG_value(reqs, 0);
96         if (req == NULL || !flip_bit(req->popo->value.signature->signature))
97             return 0;
98     }
99     return TEST_int_eq(fixture->expected,
100                        ossl_cmp_verify_popo(fixture->msg,
101                                             fixture->additional_arg));
102 }
103
104 static int test_verify_popo(void)
105 {
106     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
107     fixture->expected = 1;
108     EXECUTE_TEST(execute_verify_popo_test, tear_down);
109     return result;
110 }
111
112 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
113 static int test_verify_popo_bad(void)
114 {
115     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
116     fixture->expected = 0;
117     EXECUTE_TEST(execute_verify_popo_test, tear_down);
118     return result;
119 }
120 #endif
121
122 static int execute_validate_msg_test(CMP_VFY_TEST_FIXTURE *fixture)
123 {
124     return TEST_int_eq(fixture->expected,
125                        OSSL_CMP_validate_msg(fixture->cmp_ctx, fixture->msg));
126 }
127
128 static int execute_validate_cert_path_test(CMP_VFY_TEST_FIXTURE *fixture)
129 {
130     X509_STORE *ts = OSSL_CMP_CTX_get0_trustedStore(fixture->cmp_ctx);
131     int res = TEST_int_eq(fixture->expected,
132                           OSSL_CMP_validate_cert_path(fixture->cmp_ctx,
133                                                       ts, fixture->cert));
134
135     OSSL_CMP_CTX_print_errors(fixture->cmp_ctx);
136     return res;
137 }
138
139 static int test_validate_msg_mac_alg_protection(void)
140 {
141     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
142     /* secret value belonging to cmp-test/CMP_IP_waitingStatus_PBM.der */
143     const unsigned char sec_1[] = {
144         '9', 'p', 'p', '8', '-', 'b', '3', '5', 'i', '-', 'X', 'd', '3',
145         'Q', '-', 'u', 'd', 'N', 'R'
146     };
147
148     fixture->expected = 1;
149     if (!TEST_true(OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx, sec_1,
150                                                  sizeof(sec_1)))
151             || !TEST_ptr(fixture->msg = load_pkimsg(ip_waiting_f))) {
152         tear_down(fixture);
153         fixture = NULL;
154     }
155     EXECUTE_TEST(execute_validate_msg_test, tear_down);
156     return result;
157 }
158
159 static int test_validate_msg_mac_alg_protection_bad(void)
160 {
161     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
162     const unsigned char sec_bad[] = {
163         '9', 'p', 'p', '8', '-', 'b', '3', '5', 'i', '-', 'X', 'd', '3',
164         'Q', '-', 'u', 'd', 'N', 'r'
165     };
166     fixture->expected = 0;
167
168     if (!TEST_true(OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx, sec_bad,
169                                                  sizeof(sec_bad)))
170             || !TEST_ptr(fixture->msg = load_pkimsg(ip_waiting_f))) {
171         tear_down(fixture);
172         fixture = NULL;
173     }
174     EXECUTE_TEST(execute_validate_msg_test, tear_down);
175     return result;
176 }
177
178 static int add_trusted(OSSL_CMP_CTX *ctx, X509 *cert)
179 {
180     return X509_STORE_add_cert(OSSL_CMP_CTX_get0_trustedStore(ctx), cert);
181 }
182
183 static int add_untrusted(OSSL_CMP_CTX *ctx, X509 *cert)
184 {
185     return ossl_cmp_sk_X509_add1_cert(OSSL_CMP_CTX_get0_untrusted_certs(ctx),
186                                       cert, 0, 0);
187 }
188
189 static int test_validate_msg_signature_partial_chain(int expired)
190 {
191     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
192     X509_STORE *ts = OSSL_CMP_CTX_get0_trustedStore(fixture->cmp_ctx);
193
194     fixture->expected = !expired;
195     if (ts == NULL
196             || !TEST_ptr(fixture->msg = load_pkimsg(ir_protected_f))
197             || !add_trusted(fixture->cmp_ctx, srvcert)) {
198         tear_down(fixture);
199         fixture = NULL;
200     } else {
201         X509_VERIFY_PARAM *vpm = X509_STORE_get0_param(ts);
202         X509_VERIFY_PARAM_set_flags(vpm, X509_V_FLAG_PARTIAL_CHAIN);
203         if (expired)
204             X509_VERIFY_PARAM_set_time(vpm, test_time_after_expiration);
205     }
206     EXECUTE_TEST(execute_validate_msg_test, tear_down);
207     return result;
208 }
209
210 static int test_validate_msg_signature_trusted_ok(void)
211 {
212     return test_validate_msg_signature_partial_chain(0);
213 }
214
215 static int test_validate_msg_signature_trusted_expired(void)
216 {
217     return test_validate_msg_signature_partial_chain(1);
218 }
219
220 static int test_validate_msg_signature_srvcert_wrong(void)
221 {
222     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
223     fixture->expected = 0;
224     if (!TEST_ptr(fixture->msg = load_pkimsg(ir_protected_f))
225         || !TEST_true(OSSL_CMP_CTX_set1_srvCert(fixture->cmp_ctx, clcert))) {
226         tear_down(fixture);
227         fixture = NULL;
228     }
229     EXECUTE_TEST(execute_validate_msg_test, tear_down);
230     return result;
231 }
232
233 static int test_validate_msg_signature_srvcert(int bad_sig)
234 {
235     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
236     fixture->expected = !bad_sig;
237     if (!TEST_ptr(fixture->msg = load_pkimsg(ir_protected_f))
238         || !TEST_true(OSSL_CMP_CTX_set1_srvCert(fixture->cmp_ctx, srvcert))
239         || (bad_sig && !flip_bit(fixture->msg->protection))) {
240         tear_down(fixture);
241         fixture = NULL;
242     }
243     EXECUTE_TEST(execute_validate_msg_test, tear_down);
244     return result;
245 }
246
247 static int test_validate_msg_signature_bad(void)
248 {
249     return test_validate_msg_signature_srvcert(1);
250 }
251
252 static int test_validate_msg_signature_sender_cert_srvcert(void)
253 {
254     return test_validate_msg_signature_srvcert(0);
255 }
256
257 static int test_validate_msg_signature_sender_cert_untrusted(void)
258 {
259     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
260     fixture->expected = 1;
261     if (!TEST_ptr(fixture->msg = load_pkimsg(ir_protected_0_extracerts))
262             || !add_trusted(fixture->cmp_ctx, instaca_cert)
263             || !add_untrusted(fixture->cmp_ctx, insta_cert)) {
264         tear_down(fixture);
265         fixture = NULL;
266     }
267     EXECUTE_TEST(execute_validate_msg_test, tear_down);
268     return result;
269 }
270
271 static int test_validate_msg_signature_sender_cert_trusted(void)
272 {
273     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
274     fixture->expected = 1;
275     if (!TEST_ptr(fixture->msg = load_pkimsg(ir_protected_0_extracerts))
276             || !add_trusted(fixture->cmp_ctx, instaca_cert)
277             || !add_trusted(fixture->cmp_ctx, insta_cert)) {
278         tear_down(fixture);
279         fixture = NULL;
280     }
281     EXECUTE_TEST(execute_validate_msg_test, tear_down);
282     return result;
283 }
284
285 static int test_validate_msg_signature_sender_cert_extracert(void)
286 {
287     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
288     fixture->expected = 1;
289     if (!TEST_ptr(fixture->msg = load_pkimsg(ir_protected_2_extracerts))
290             || !add_trusted(fixture->cmp_ctx, instaca_cert)) {
291         tear_down(fixture);
292         fixture = NULL;
293     }
294     EXECUTE_TEST(execute_validate_msg_test, tear_down);
295     return result;
296 }
297
298
299 static int test_validate_msg_signature_sender_cert_absent(void)
300 {
301     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
302     fixture->expected = 0;
303     if (!TEST_ptr(fixture->msg = load_pkimsg(ir_protected_0_extracerts))) {
304         tear_down(fixture);
305         fixture = NULL;
306     }
307     EXECUTE_TEST(execute_validate_msg_test, tear_down);
308     return result;
309 }
310
311
312 static int test_validate_with_sender(const X509_NAME *name, int expected)
313 {
314     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
315     fixture->expected = expected;
316     if (!TEST_ptr(fixture->msg = load_pkimsg(ir_protected_f))
317         || !TEST_true(OSSL_CMP_CTX_set1_expected_sender(fixture->cmp_ctx, name))
318         || !TEST_true(OSSL_CMP_CTX_set1_srvCert(fixture->cmp_ctx, srvcert))) {
319         tear_down(fixture);
320         fixture = NULL;
321     }
322     EXECUTE_TEST(execute_validate_msg_test, tear_down);
323     return result;
324 }
325
326 static int test_validate_msg_signature_expected_sender(void)
327 {
328     return test_validate_with_sender(X509_get_subject_name(srvcert), 1);
329 }
330
331 static int test_validate_msg_signature_unexpected_sender(void)
332 {
333     return test_validate_with_sender(X509_get_subject_name(root), 0);
334 }
335
336 static int test_validate_msg_unprotected_request(void)
337 {
338     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
339     fixture->expected = 0;
340     if (!TEST_ptr(fixture->msg = load_pkimsg(ir_unprotected_f))) {
341         tear_down(fixture);
342         fixture = NULL;
343     }
344     EXECUTE_TEST(execute_validate_msg_test, tear_down);
345     return result;
346 }
347
348 static void setup_path(CMP_VFY_TEST_FIXTURE **fixture, X509 *wrong, int expired)
349 {
350     (*fixture)->cert = endentity2;
351     (*fixture)->expected = wrong == NULL && !expired;
352     if (expired) {
353         X509_STORE *ts = OSSL_CMP_CTX_get0_trustedStore((*fixture)->cmp_ctx);
354         X509_VERIFY_PARAM *vpm = X509_STORE_get0_param(ts);
355         X509_VERIFY_PARAM_set_time(vpm, test_time_after_expiration);
356     }
357     if (!add_trusted((*fixture)->cmp_ctx, wrong == NULL ? root : wrong)
358             || !add_untrusted((*fixture)->cmp_ctx, endentity1)
359             || !add_untrusted((*fixture)->cmp_ctx, intermediate)) {
360         tear_down((*fixture));
361         (*fixture) = NULL;
362     }
363 }
364
365 static int test_validate_cert_path_ok(void)
366 {
367     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
368     setup_path(&fixture, NULL, 0);
369     EXECUTE_TEST(execute_validate_cert_path_test, tear_down);
370     return result;
371 }
372
373 static int test_validate_cert_path_wrong_anchor(void)
374 {
375     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
376     setup_path(&fixture, srvcert /* wrong/non-root cert */, 0);
377     EXECUTE_TEST(execute_validate_cert_path_test, tear_down);
378     return result;
379 }
380
381 static int test_validate_cert_path_expired(void)
382 {
383     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
384     setup_path(&fixture, NULL, 1);
385     EXECUTE_TEST(execute_validate_cert_path_test, tear_down);
386     return result;
387 }
388
389 static int execute_MSG_check_received_test(CMP_VFY_TEST_FIXTURE *fixture)
390 {
391     const OSSL_CMP_PKIHEADER *hdr = OSSL_CMP_MSG_get0_header(fixture->msg);
392     const ASN1_OCTET_STRING *tid = OSSL_CMP_HDR_get0_transactionID(hdr);
393
394     if (!TEST_int_eq(fixture->expected,
395                      ossl_cmp_msg_check_received(fixture->cmp_ctx,
396                                                  fixture->msg,
397                                                  fixture->allow_unprotected_cb,
398                                                  fixture->additional_arg)))
399         return 0;
400
401     if (fixture->expected < 0) /* error expected aready during above check */
402         return 1;
403     return
404         TEST_int_eq(0,
405                     ASN1_OCTET_STRING_cmp(ossl_cmp_hdr_get0_senderNonce(hdr),
406                                           fixture->cmp_ctx->recipNonce))
407         && TEST_int_eq(0,
408                        ASN1_OCTET_STRING_cmp(tid,
409                                              fixture->cmp_ctx->transactionID));
410 }
411
412 static int allow_unprotected(const OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *msg,
413                              int invalid_protection, int allow)
414 {
415     return allow;
416 }
417
418 static void setup_check_received(CMP_VFY_TEST_FIXTURE **fixture, int expected,
419                                  ossl_cmp_allow_unprotected_cb_t cb, int arg,
420                                  const unsigned char *trid_data,
421                                  const unsigned char *nonce_data)
422 {
423     OSSL_CMP_CTX *ctx = (*fixture)->cmp_ctx;
424     int nonce_len = OSSL_CMP_SENDERNONCE_LENGTH;
425
426     (*fixture)->expected = expected;
427     (*fixture)->allow_unprotected_cb = cb;
428     (*fixture)->additional_arg = arg;
429     (*fixture)->msg = OSSL_CMP_MSG_dup(ir_rmprotection);
430     if ((*fixture)->msg == NULL
431         || (nonce_data != NULL
432             && !ossl_cmp_asn1_octet_string_set1_bytes(&ctx->senderNonce,
433                                                       nonce_data, nonce_len))) {
434         tear_down((*fixture));
435         (*fixture) = NULL;
436     } else if (trid_data != NULL) {
437         ASN1_OCTET_STRING *trid = ASN1_OCTET_STRING_new();
438         if (trid == NULL
439             || !ASN1_OCTET_STRING_set(trid, trid_data,
440                                       OSSL_CMP_TRANSACTIONID_LENGTH)
441             || !OSSL_CMP_CTX_set1_transactionID(ctx, trid)) {
442             tear_down((*fixture));
443             (*fixture) = NULL;
444         }
445         ASN1_OCTET_STRING_free(trid);
446     }
447 }
448
449 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
450 static int test_MSG_check_received_no_protection_no_cb(void)
451 {
452     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
453     setup_check_received(&fixture, -1, NULL, 0, NULL, NULL);
454     EXECUTE_TEST(execute_MSG_check_received_test, tear_down);
455     return result;
456 }
457
458 static int test_MSG_check_received_no_protection_restrictive_cb(void)
459 {
460     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
461     setup_check_received(&fixture, -1, allow_unprotected, 0, NULL, NULL);
462     EXECUTE_TEST(execute_MSG_check_received_test, tear_down);
463     return result;
464 }
465 #endif
466
467 static int test_MSG_check_received_no_protection_permissive_cb(void)
468 {
469     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
470     setup_check_received(&fixture, OSSL_CMP_PKIBODY_IP, allow_unprotected, 1,
471                          NULL, NULL);
472     EXECUTE_TEST(execute_MSG_check_received_test, tear_down);
473     return result;
474 }
475
476 static int test_MSG_check_received_check_transaction_id(void)
477 {
478     /* Transaction id belonging to CMP_IR_rmprotection.der */
479     const unsigned char trans_id[OSSL_CMP_TRANSACTIONID_LENGTH] = {
480         0x39, 0xB6, 0x90, 0x28, 0xC4, 0xBC, 0x7A, 0xF6,
481         0xBE, 0xC6, 0x4A, 0x88, 0x97, 0xA6, 0x95, 0x0B
482     };
483
484     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
485     setup_check_received(&fixture, OSSL_CMP_PKIBODY_IP, allow_unprotected, 1,
486                          trans_id, NULL);
487     EXECUTE_TEST(execute_MSG_check_received_test, tear_down);
488     return result;
489 }
490
491 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
492 static int test_MSG_check_received_check_transaction_id_bad(void)
493 {
494     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
495     setup_check_received(&fixture, -1, allow_unprotected, 1, rand_data, NULL);
496     EXECUTE_TEST(execute_MSG_check_received_test, tear_down);
497     return result;
498 }
499 #endif
500
501 static int test_MSG_check_received_check_recipient_nonce(void)
502 {
503     /* Recipient nonce belonging to CMP_IP_ir_rmprotection.der */
504     const unsigned char rec_nonce[OSSL_CMP_SENDERNONCE_LENGTH] = {
505         0x48, 0xF1, 0x71, 0x1F, 0xE5, 0xAF, 0x1C, 0x8B,
506         0x21, 0x97, 0x5C, 0x84, 0x74, 0x49, 0xBA, 0x32
507     };
508
509     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
510     setup_check_received(&fixture, OSSL_CMP_PKIBODY_IP, allow_unprotected, 1,
511                          NULL, rec_nonce);
512     EXECUTE_TEST(execute_MSG_check_received_test, tear_down);
513     return result;
514 }
515
516 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
517 static int test_MSG_check_received_check_recipient_nonce_bad(void)
518 {
519     SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up);
520     setup_check_received(&fixture, -1, allow_unprotected, 1, NULL, rand_data);
521     EXECUTE_TEST(execute_MSG_check_received_test, tear_down);
522     return result;
523 }
524 #endif
525
526 void cleanup_tests(void)
527 {
528     X509_free(srvcert);
529     X509_free(clcert);
530     X509_free(endentity1);
531     X509_free(endentity2);
532     X509_free(intermediate);
533     X509_free(root);
534     X509_free(insta_cert);
535     X509_free(instaca_cert);
536     OSSL_CMP_MSG_free(ir_unprotected);
537     OSSL_CMP_MSG_free(ir_rmprotection);
538     return;
539 }
540
541 int setup_tests(void)
542 {
543     /* Set test time stamps */
544     struct tm ts = { 0 };
545
546     ts.tm_year = 2018 - 1900;      /* 2018 */
547     ts.tm_mon = 1;                 /* February */
548     ts.tm_mday = 18;               /* 18th */
549     test_time_valid = mktime(&ts); /* February 18th 2018 */
550     ts.tm_year += 10;              /* February 18th 2028 */
551     test_time_after_expiration = mktime(&ts);
552
553     if (!test_skip_common_options()) {
554         TEST_error("Error parsing test options\n");
555         return 0;
556     }
557
558     RAND_bytes(rand_data, OSSL_CMP_TRANSACTIONID_LENGTH);
559     if (!TEST_ptr(server_f = test_get_argument(0))
560             || !TEST_ptr(client_f = test_get_argument(1))
561             || !TEST_ptr(endentity1_f = test_get_argument(2))
562             || !TEST_ptr(endentity2_f = test_get_argument(3))
563             || !TEST_ptr(root_f = test_get_argument(4))
564             || !TEST_ptr(intermediate_f = test_get_argument(5))
565             || !TEST_ptr(ir_protected_f = test_get_argument(6))
566             || !TEST_ptr(ir_unprotected_f = test_get_argument(7))
567             || !TEST_ptr(ip_waiting_f = test_get_argument(8))
568             || !TEST_ptr(ir_rmprotection_f = test_get_argument(9))
569             || !TEST_ptr(instacert_f = test_get_argument(10))
570             || !TEST_ptr(instaca_f = test_get_argument(11))
571             || !TEST_ptr(ir_protected_0_extracerts = test_get_argument(12))
572             || !TEST_ptr(ir_protected_2_extracerts = test_get_argument(13))) {
573         TEST_error("usage: cmp_vfy_test server.crt client.crt "
574                    "EndEntity1.crt EndEntity2.crt "
575                    "Root_CA.crt Intermediate_CA.crt "
576                    "CMP_IR_protected.der CMP_IR_unprotected.der "
577                    "IP_waitingStatus_PBM.der IR_rmprotection.der "
578                    "insta.cert.pem insta_ca.cert.pem "
579                    "IR_protected_0_extraCerts.der "
580                    "IR_protected_2_extraCerts.der\n");
581         return 0;
582     }
583
584     /* Load certificates for cert chain */
585     if (!TEST_ptr(endentity1 = load_pem_cert(endentity1_f))
586             || !TEST_ptr(endentity2 = load_pem_cert(endentity2_f))
587             || !TEST_ptr(root = load_pem_cert(root_f))
588             || !TEST_ptr(intermediate = load_pem_cert(intermediate_f)))
589         goto err;
590
591     if (!TEST_ptr(insta_cert = load_pem_cert(instacert_f))
592             || !TEST_ptr(instaca_cert = load_pem_cert(instaca_f)))
593         goto err;
594
595     /* Load certificates for message validation */
596     if (!TEST_ptr(srvcert = load_pem_cert(server_f))
597             || !TEST_ptr(clcert = load_pem_cert(client_f)))
598         goto err;
599     if (!TEST_int_eq(1, RAND_bytes(rand_data, OSSL_CMP_TRANSACTIONID_LENGTH)))
600         goto err;
601     if (!TEST_ptr(ir_unprotected = load_pkimsg(ir_unprotected_f))
602             || !TEST_ptr(ir_rmprotection = load_pkimsg(ir_rmprotection_f)))
603         goto err;
604
605     /* Message validation tests */
606     ADD_TEST(test_verify_popo);
607 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
608     ADD_TEST(test_verify_popo_bad);
609 #endif
610     ADD_TEST(test_validate_msg_signature_trusted_ok);
611     ADD_TEST(test_validate_msg_signature_trusted_expired);
612     ADD_TEST(test_validate_msg_signature_srvcert_wrong);
613     ADD_TEST(test_validate_msg_signature_bad);
614     ADD_TEST(test_validate_msg_signature_sender_cert_srvcert);
615     ADD_TEST(test_validate_msg_signature_sender_cert_untrusted);
616     ADD_TEST(test_validate_msg_signature_sender_cert_trusted);
617     ADD_TEST(test_validate_msg_signature_sender_cert_extracert);
618     ADD_TEST(test_validate_msg_signature_sender_cert_absent);
619     ADD_TEST(test_validate_msg_signature_expected_sender);
620     ADD_TEST(test_validate_msg_signature_unexpected_sender);
621     ADD_TEST(test_validate_msg_unprotected_request);
622     ADD_TEST(test_validate_msg_mac_alg_protection);
623     ADD_TEST(test_validate_msg_mac_alg_protection_bad);
624
625     /* Cert path validation tests */
626     ADD_TEST(test_validate_cert_path_ok);
627     ADD_TEST(test_validate_cert_path_expired);
628     ADD_TEST(test_validate_cert_path_wrong_anchor);
629
630 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
631     ADD_TEST(test_MSG_check_received_no_protection_no_cb);
632     ADD_TEST(test_MSG_check_received_no_protection_restrictive_cb);
633 #endif
634     ADD_TEST(test_MSG_check_received_no_protection_permissive_cb);
635     ADD_TEST(test_MSG_check_received_check_transaction_id);
636 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
637     ADD_TEST(test_MSG_check_received_check_transaction_id_bad);
638 #endif
639     ADD_TEST(test_MSG_check_received_check_recipient_nonce);
640 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
641     ADD_TEST(test_MSG_check_received_check_recipient_nonce_bad);
642 #endif
643
644     return 1;
645
646  err:
647     cleanup_tests();
648     return 0;
649
650 }