xref: /freebsd/crypto/openssl/test/cmp_protect_test.c (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1*e0c4386eSCy Schubert /*
2*e0c4386eSCy Schubert  * Copyright 2007-2023 The OpenSSL Project Authors. All Rights Reserved.
3*e0c4386eSCy Schubert  * Copyright Nokia 2007-2019
4*e0c4386eSCy Schubert  * Copyright Siemens AG 2015-2019
5*e0c4386eSCy Schubert  *
6*e0c4386eSCy Schubert  * Licensed under the Apache License 2.0 (the "License").  You may not use
7*e0c4386eSCy Schubert  * this file except in compliance with the License.  You can obtain a copy
8*e0c4386eSCy Schubert  * in the file LICENSE in the source distribution or at
9*e0c4386eSCy Schubert  * https://www.openssl.org/source/license.html
10*e0c4386eSCy Schubert  */
11*e0c4386eSCy Schubert 
12*e0c4386eSCy Schubert #include "helpers/cmp_testlib.h"
13*e0c4386eSCy Schubert 
14*e0c4386eSCy Schubert static const char *ir_protected_f;
15*e0c4386eSCy Schubert static const char *ir_unprotected_f;
16*e0c4386eSCy Schubert static const char *ip_PBM_f;
17*e0c4386eSCy Schubert 
18*e0c4386eSCy Schubert typedef struct test_fixture {
19*e0c4386eSCy Schubert     const char *test_case_name;
20*e0c4386eSCy Schubert     OSSL_CMP_CTX *cmp_ctx;
21*e0c4386eSCy Schubert     /* for protection tests */
22*e0c4386eSCy Schubert     OSSL_CMP_MSG *msg;
23*e0c4386eSCy Schubert     OSSL_CMP_PKISI *si; /* for error and response messages */
24*e0c4386eSCy Schubert     EVP_PKEY *pubkey;
25*e0c4386eSCy Schubert     unsigned char *mem;
26*e0c4386eSCy Schubert     int memlen;
27*e0c4386eSCy Schubert     X509 *cert;
28*e0c4386eSCy Schubert     STACK_OF(X509) *certs;
29*e0c4386eSCy Schubert     STACK_OF(X509) *chain;
30*e0c4386eSCy Schubert     int with_ss;
31*e0c4386eSCy Schubert     int callback_arg;
32*e0c4386eSCy Schubert     int expected;
33*e0c4386eSCy Schubert } CMP_PROTECT_TEST_FIXTURE;
34*e0c4386eSCy Schubert 
35*e0c4386eSCy Schubert static OSSL_LIB_CTX *libctx = NULL;
36*e0c4386eSCy Schubert static OSSL_PROVIDER *default_null_provider = NULL, *provider = NULL;
37*e0c4386eSCy Schubert 
tear_down(CMP_PROTECT_TEST_FIXTURE * fixture)38*e0c4386eSCy Schubert static void tear_down(CMP_PROTECT_TEST_FIXTURE *fixture)
39*e0c4386eSCy Schubert {
40*e0c4386eSCy Schubert     if (fixture != NULL) {
41*e0c4386eSCy Schubert         OSSL_CMP_CTX_free(fixture->cmp_ctx);
42*e0c4386eSCy Schubert         OSSL_CMP_MSG_free(fixture->msg);
43*e0c4386eSCy Schubert         OSSL_CMP_PKISI_free(fixture->si);
44*e0c4386eSCy Schubert 
45*e0c4386eSCy Schubert         OPENSSL_free(fixture->mem);
46*e0c4386eSCy Schubert         sk_X509_free(fixture->certs);
47*e0c4386eSCy Schubert         sk_X509_free(fixture->chain);
48*e0c4386eSCy Schubert 
49*e0c4386eSCy Schubert         OPENSSL_free(fixture);
50*e0c4386eSCy Schubert     }
51*e0c4386eSCy Schubert }
52*e0c4386eSCy Schubert 
set_up(const char * const test_case_name)53*e0c4386eSCy Schubert static CMP_PROTECT_TEST_FIXTURE *set_up(const char *const test_case_name)
54*e0c4386eSCy Schubert {
55*e0c4386eSCy Schubert     CMP_PROTECT_TEST_FIXTURE *fixture;
56*e0c4386eSCy Schubert 
57*e0c4386eSCy Schubert     if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture))))
58*e0c4386eSCy Schubert         return NULL;
59*e0c4386eSCy Schubert     fixture->test_case_name = test_case_name;
60*e0c4386eSCy Schubert     if (!TEST_ptr(fixture->cmp_ctx = OSSL_CMP_CTX_new(libctx, NULL))) {
61*e0c4386eSCy Schubert         tear_down(fixture);
62*e0c4386eSCy Schubert         return NULL;
63*e0c4386eSCy Schubert     }
64*e0c4386eSCy Schubert     return fixture;
65*e0c4386eSCy Schubert }
66*e0c4386eSCy Schubert 
67*e0c4386eSCy Schubert static EVP_PKEY *loadedprivkey = NULL;
68*e0c4386eSCy Schubert static EVP_PKEY *loadedpubkey = NULL;
69*e0c4386eSCy Schubert static EVP_PKEY *loadedkey = NULL;
70*e0c4386eSCy Schubert static X509 *cert = NULL;
71*e0c4386eSCy Schubert static unsigned char rand_data[OSSL_CMP_TRANSACTIONID_LENGTH];
72*e0c4386eSCy Schubert static OSSL_CMP_MSG *ir_unprotected, *ir_protected;
73*e0c4386eSCy Schubert static X509 *endentity1 = NULL, *endentity2 = NULL,
74*e0c4386eSCy Schubert     *root = NULL, *intermediate = NULL;
75*e0c4386eSCy Schubert 
execute_calc_protection_fails_test(CMP_PROTECT_TEST_FIXTURE * fixture)76*e0c4386eSCy Schubert static int execute_calc_protection_fails_test(CMP_PROTECT_TEST_FIXTURE *fixture)
77*e0c4386eSCy Schubert {
78*e0c4386eSCy Schubert     ASN1_BIT_STRING *protection =
79*e0c4386eSCy Schubert         ossl_cmp_calc_protection(fixture->cmp_ctx, fixture->msg);
80*e0c4386eSCy Schubert     int res = TEST_ptr_null(protection);
81*e0c4386eSCy Schubert 
82*e0c4386eSCy Schubert     ASN1_BIT_STRING_free(protection);
83*e0c4386eSCy Schubert     return res;
84*e0c4386eSCy Schubert }
85*e0c4386eSCy Schubert 
execute_calc_protection_pbmac_test(CMP_PROTECT_TEST_FIXTURE * fixture)86*e0c4386eSCy Schubert static int execute_calc_protection_pbmac_test(CMP_PROTECT_TEST_FIXTURE *fixture)
87*e0c4386eSCy Schubert {
88*e0c4386eSCy Schubert     ASN1_BIT_STRING *protection =
89*e0c4386eSCy Schubert         ossl_cmp_calc_protection(fixture->cmp_ctx, fixture->msg);
90*e0c4386eSCy Schubert     int res = TEST_ptr(protection)
91*e0c4386eSCy Schubert             && TEST_true(ASN1_STRING_cmp(protection,
92*e0c4386eSCy Schubert                                          fixture->msg->protection) == 0);
93*e0c4386eSCy Schubert 
94*e0c4386eSCy Schubert     ASN1_BIT_STRING_free(protection);
95*e0c4386eSCy Schubert     return res;
96*e0c4386eSCy Schubert }
97*e0c4386eSCy Schubert 
98*e0c4386eSCy Schubert /*
99*e0c4386eSCy Schubert  * This function works similarly to parts of CMP_verify_signature in cmp_vfy.c,
100*e0c4386eSCy Schubert  * but without the need for a OSSL_CMP_CTX or a X509 certificate
101*e0c4386eSCy Schubert  */
verify_signature(OSSL_CMP_MSG * msg,ASN1_BIT_STRING * protection,EVP_PKEY * pkey,EVP_MD * digest)102*e0c4386eSCy Schubert static int verify_signature(OSSL_CMP_MSG *msg,
103*e0c4386eSCy Schubert                             ASN1_BIT_STRING *protection,
104*e0c4386eSCy Schubert                             EVP_PKEY *pkey, EVP_MD *digest)
105*e0c4386eSCy Schubert {
106*e0c4386eSCy Schubert     OSSL_CMP_PROTECTEDPART prot_part;
107*e0c4386eSCy Schubert     unsigned char *prot_part_der = NULL;
108*e0c4386eSCy Schubert     int len;
109*e0c4386eSCy Schubert     EVP_MD_CTX *ctx = NULL;
110*e0c4386eSCy Schubert     int res;
111*e0c4386eSCy Schubert 
112*e0c4386eSCy Schubert     prot_part.header = OSSL_CMP_MSG_get0_header(msg);
113*e0c4386eSCy Schubert     prot_part.body = msg->body;
114*e0c4386eSCy Schubert     len = i2d_OSSL_CMP_PROTECTEDPART(&prot_part, &prot_part_der);
115*e0c4386eSCy Schubert     res =
116*e0c4386eSCy Schubert         TEST_int_ge(len, 0)
117*e0c4386eSCy Schubert         && TEST_ptr(ctx = EVP_MD_CTX_new())
118*e0c4386eSCy Schubert         && TEST_true(EVP_DigestVerifyInit(ctx, NULL, digest, NULL, pkey))
119*e0c4386eSCy Schubert         && TEST_int_eq(EVP_DigestVerify(ctx, protection->data,
120*e0c4386eSCy Schubert                                         protection->length,
121*e0c4386eSCy Schubert                                         prot_part_der, len), 1);
122*e0c4386eSCy Schubert     /* cleanup */
123*e0c4386eSCy Schubert     EVP_MD_CTX_free(ctx);
124*e0c4386eSCy Schubert     OPENSSL_free(prot_part_der);
125*e0c4386eSCy Schubert     return res;
126*e0c4386eSCy Schubert }
127*e0c4386eSCy Schubert 
128*e0c4386eSCy Schubert /* Calls OSSL_CMP_calc_protection and compares and verifies signature */
execute_calc_protection_signature_test(CMP_PROTECT_TEST_FIXTURE * fixture)129*e0c4386eSCy Schubert static int execute_calc_protection_signature_test(CMP_PROTECT_TEST_FIXTURE *
130*e0c4386eSCy Schubert                                                   fixture)
131*e0c4386eSCy Schubert {
132*e0c4386eSCy Schubert     ASN1_BIT_STRING *protection =
133*e0c4386eSCy Schubert         ossl_cmp_calc_protection(fixture->cmp_ctx, fixture->msg);
134*e0c4386eSCy Schubert     int ret = (TEST_ptr(protection)
135*e0c4386eSCy Schubert                    && TEST_true(ASN1_STRING_cmp(protection,
136*e0c4386eSCy Schubert                                                 fixture->msg->protection) == 0)
137*e0c4386eSCy Schubert                    && TEST_true(verify_signature(fixture->msg, protection,
138*e0c4386eSCy Schubert                                                  fixture->pubkey,
139*e0c4386eSCy Schubert                                                  fixture->cmp_ctx->digest)));
140*e0c4386eSCy Schubert 
141*e0c4386eSCy Schubert     ASN1_BIT_STRING_free(protection);
142*e0c4386eSCy Schubert     return ret;
143*e0c4386eSCy Schubert }
144*e0c4386eSCy Schubert 
test_cmp_calc_protection_no_key_no_secret(void)145*e0c4386eSCy Schubert static int test_cmp_calc_protection_no_key_no_secret(void)
146*e0c4386eSCy Schubert {
147*e0c4386eSCy Schubert     SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
148*e0c4386eSCy Schubert     if (!TEST_ptr(fixture->msg = load_pkimsg(ir_unprotected_f, libctx))
149*e0c4386eSCy Schubert             || !TEST_ptr(fixture->msg->header->protectionAlg =
150*e0c4386eSCy Schubert                          X509_ALGOR_new() /* no specific alg needed here */)) {
151*e0c4386eSCy Schubert         tear_down(fixture);
152*e0c4386eSCy Schubert         fixture = NULL;
153*e0c4386eSCy Schubert     }
154*e0c4386eSCy Schubert 
155*e0c4386eSCy Schubert     EXECUTE_TEST(execute_calc_protection_fails_test, tear_down);
156*e0c4386eSCy Schubert     return result;
157*e0c4386eSCy Schubert }
158*e0c4386eSCy Schubert 
test_cmp_calc_protection_pkey(void)159*e0c4386eSCy Schubert static int test_cmp_calc_protection_pkey(void)
160*e0c4386eSCy Schubert {
161*e0c4386eSCy Schubert     SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
162*e0c4386eSCy Schubert     fixture->pubkey = loadedpubkey;
163*e0c4386eSCy Schubert     if (!TEST_true(OSSL_CMP_CTX_set1_pkey(fixture->cmp_ctx, loadedprivkey))
164*e0c4386eSCy Schubert             || !TEST_ptr(fixture->msg = load_pkimsg(ir_protected_f, libctx))) {
165*e0c4386eSCy Schubert         tear_down(fixture);
166*e0c4386eSCy Schubert         fixture = NULL;
167*e0c4386eSCy Schubert     }
168*e0c4386eSCy Schubert     EXECUTE_TEST(execute_calc_protection_signature_test, tear_down);
169*e0c4386eSCy Schubert     return result;
170*e0c4386eSCy Schubert }
171*e0c4386eSCy Schubert 
test_cmp_calc_protection_pbmac(void)172*e0c4386eSCy Schubert static int test_cmp_calc_protection_pbmac(void)
173*e0c4386eSCy Schubert {
174*e0c4386eSCy Schubert     unsigned char sec_insta[] = { 'i', 'n', 's', 't', 'a' };
175*e0c4386eSCy Schubert 
176*e0c4386eSCy Schubert     SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
177*e0c4386eSCy Schubert     if (!TEST_true(OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx,
178*e0c4386eSCy Schubert                                                  sec_insta, sizeof(sec_insta)))
179*e0c4386eSCy Schubert             || !TEST_ptr(fixture->msg = load_pkimsg(ip_PBM_f, libctx))) {
180*e0c4386eSCy Schubert         tear_down(fixture);
181*e0c4386eSCy Schubert         fixture = NULL;
182*e0c4386eSCy Schubert     }
183*e0c4386eSCy Schubert     EXECUTE_TEST(execute_calc_protection_pbmac_test, tear_down);
184*e0c4386eSCy Schubert     return result;
185*e0c4386eSCy Schubert }
execute_MSG_protect_test(CMP_PROTECT_TEST_FIXTURE * fixture)186*e0c4386eSCy Schubert static int execute_MSG_protect_test(CMP_PROTECT_TEST_FIXTURE *fixture)
187*e0c4386eSCy Schubert {
188*e0c4386eSCy Schubert     return TEST_int_eq(fixture->expected,
189*e0c4386eSCy Schubert                        ossl_cmp_msg_protect(fixture->cmp_ctx, fixture->msg));
190*e0c4386eSCy Schubert }
191*e0c4386eSCy Schubert 
192*e0c4386eSCy Schubert #define SET_OPT_UNPROTECTED_SEND(ctx, val) \
193*e0c4386eSCy Schubert     OSSL_CMP_CTX_set_option((ctx), OSSL_CMP_OPT_UNPROTECTED_SEND, (val))
test_MSG_protect_unprotected_request(void)194*e0c4386eSCy Schubert static int test_MSG_protect_unprotected_request(void)
195*e0c4386eSCy Schubert {
196*e0c4386eSCy Schubert     SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
197*e0c4386eSCy Schubert 
198*e0c4386eSCy Schubert     fixture->expected = 1;
199*e0c4386eSCy Schubert     if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected))
200*e0c4386eSCy Schubert             || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 1))) {
201*e0c4386eSCy Schubert         tear_down(fixture);
202*e0c4386eSCy Schubert         fixture = NULL;
203*e0c4386eSCy Schubert     }
204*e0c4386eSCy Schubert     EXECUTE_TEST(execute_MSG_protect_test, tear_down);
205*e0c4386eSCy Schubert     return result;
206*e0c4386eSCy Schubert }
207*e0c4386eSCy Schubert 
test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key(void)208*e0c4386eSCy Schubert static int test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key(void)
209*e0c4386eSCy Schubert {
210*e0c4386eSCy Schubert     const size_t size = sizeof(rand_data) / 2;
211*e0c4386eSCy Schubert 
212*e0c4386eSCy Schubert     SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
213*e0c4386eSCy Schubert     fixture->expected = 1;
214*e0c4386eSCy Schubert 
215*e0c4386eSCy Schubert     if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected))
216*e0c4386eSCy Schubert             || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0))
217*e0c4386eSCy Schubert             /*
218*e0c4386eSCy Schubert              * Use half of the 16 bytes of random input
219*e0c4386eSCy Schubert              * for each reference and secret value
220*e0c4386eSCy Schubert              */
221*e0c4386eSCy Schubert             || !TEST_true(OSSL_CMP_CTX_set1_referenceValue(fixture->cmp_ctx,
222*e0c4386eSCy Schubert                                                            rand_data, size))
223*e0c4386eSCy Schubert             || !TEST_true(OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx,
224*e0c4386eSCy Schubert                                                         rand_data + size,
225*e0c4386eSCy Schubert                                                         size))) {
226*e0c4386eSCy Schubert         tear_down(fixture);
227*e0c4386eSCy Schubert         fixture = NULL;
228*e0c4386eSCy Schubert     }
229*e0c4386eSCy Schubert     EXECUTE_TEST(execute_MSG_protect_test, tear_down);
230*e0c4386eSCy Schubert     return result;
231*e0c4386eSCy Schubert }
232*e0c4386eSCy Schubert 
test_MSG_protect_with_certificate_and_key(void)233*e0c4386eSCy Schubert static int test_MSG_protect_with_certificate_and_key(void)
234*e0c4386eSCy Schubert {
235*e0c4386eSCy Schubert     SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
236*e0c4386eSCy Schubert     fixture->expected = 1;
237*e0c4386eSCy Schubert 
238*e0c4386eSCy Schubert     if (!TEST_ptr(fixture->msg =
239*e0c4386eSCy Schubert                   OSSL_CMP_MSG_dup(ir_unprotected))
240*e0c4386eSCy Schubert             || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0))
241*e0c4386eSCy Schubert             || !TEST_true(OSSL_CMP_CTX_set1_pkey(fixture->cmp_ctx, loadedkey))
242*e0c4386eSCy Schubert             || !TEST_true(OSSL_CMP_CTX_set1_cert(fixture->cmp_ctx, cert))) {
243*e0c4386eSCy Schubert         tear_down(fixture);
244*e0c4386eSCy Schubert         fixture = NULL;
245*e0c4386eSCy Schubert     }
246*e0c4386eSCy Schubert     EXECUTE_TEST(execute_MSG_protect_test, tear_down);
247*e0c4386eSCy Schubert     return result;
248*e0c4386eSCy Schubert }
249*e0c4386eSCy Schubert 
test_MSG_protect_certificate_based_without_cert(void)250*e0c4386eSCy Schubert static int test_MSG_protect_certificate_based_without_cert(void)
251*e0c4386eSCy Schubert {
252*e0c4386eSCy Schubert     OSSL_CMP_CTX *ctx;
253*e0c4386eSCy Schubert 
254*e0c4386eSCy Schubert     SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
255*e0c4386eSCy Schubert     ctx = fixture->cmp_ctx;
256*e0c4386eSCy Schubert     fixture->expected = 0;
257*e0c4386eSCy Schubert     if (!TEST_ptr(fixture->msg =
258*e0c4386eSCy Schubert                   OSSL_CMP_MSG_dup(ir_unprotected))
259*e0c4386eSCy Schubert             || !TEST_true(SET_OPT_UNPROTECTED_SEND(ctx, 0))
260*e0c4386eSCy Schubert             || !TEST_true(OSSL_CMP_CTX_set0_newPkey(ctx, 1, loadedkey))) {
261*e0c4386eSCy Schubert         tear_down(fixture);
262*e0c4386eSCy Schubert         fixture = NULL;
263*e0c4386eSCy Schubert     }
264*e0c4386eSCy Schubert     EVP_PKEY_up_ref(loadedkey);
265*e0c4386eSCy Schubert     EXECUTE_TEST(execute_MSG_protect_test, tear_down);
266*e0c4386eSCy Schubert     return result;
267*e0c4386eSCy Schubert }
268*e0c4386eSCy Schubert 
test_MSG_protect_no_key_no_secret(void)269*e0c4386eSCy Schubert static int test_MSG_protect_no_key_no_secret(void)
270*e0c4386eSCy Schubert {
271*e0c4386eSCy Schubert     SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
272*e0c4386eSCy Schubert     fixture->expected = 0;
273*e0c4386eSCy Schubert     if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected))
274*e0c4386eSCy Schubert             || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0))) {
275*e0c4386eSCy Schubert         tear_down(fixture);
276*e0c4386eSCy Schubert         fixture = NULL;
277*e0c4386eSCy Schubert     }
278*e0c4386eSCy Schubert     EXECUTE_TEST(execute_MSG_protect_test, tear_down);
279*e0c4386eSCy Schubert     return result;
280*e0c4386eSCy Schubert }
281*e0c4386eSCy Schubert 
test_MSG_protect_pbmac_no_sender(int with_ref)282*e0c4386eSCy Schubert static int test_MSG_protect_pbmac_no_sender(int with_ref)
283*e0c4386eSCy Schubert {
284*e0c4386eSCy Schubert     static unsigned char secret[] = { 47, 11, 8, 15 };
285*e0c4386eSCy Schubert     static unsigned char ref[] = { 0xca, 0xfe, 0xba, 0xbe };
286*e0c4386eSCy Schubert 
287*e0c4386eSCy Schubert     SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
288*e0c4386eSCy Schubert     fixture->expected = with_ref;
289*e0c4386eSCy Schubert     if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected))
290*e0c4386eSCy Schubert             || !SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0)
291*e0c4386eSCy Schubert             || !ossl_cmp_hdr_set1_sender(fixture->msg->header, NULL)
292*e0c4386eSCy Schubert             || !OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx,
293*e0c4386eSCy Schubert                                               secret, sizeof(secret))
294*e0c4386eSCy Schubert             || (!OSSL_CMP_CTX_set1_referenceValue(fixture->cmp_ctx,
295*e0c4386eSCy Schubert                                                   with_ref ? ref : NULL,
296*e0c4386eSCy Schubert                                                   sizeof(ref)))) {
297*e0c4386eSCy Schubert         tear_down(fixture);
298*e0c4386eSCy Schubert         fixture = NULL;
299*e0c4386eSCy Schubert     }
300*e0c4386eSCy Schubert     EXECUTE_TEST(execute_MSG_protect_test, tear_down);
301*e0c4386eSCy Schubert     return result;
302*e0c4386eSCy Schubert }
303*e0c4386eSCy Schubert 
test_MSG_protect_pbmac_no_sender_with_ref(void)304*e0c4386eSCy Schubert static int test_MSG_protect_pbmac_no_sender_with_ref(void)
305*e0c4386eSCy Schubert {
306*e0c4386eSCy Schubert     return test_MSG_protect_pbmac_no_sender(1);
307*e0c4386eSCy Schubert }
308*e0c4386eSCy Schubert 
test_MSG_protect_pbmac_no_sender_no_ref(void)309*e0c4386eSCy Schubert static int test_MSG_protect_pbmac_no_sender_no_ref(void)
310*e0c4386eSCy Schubert {
311*e0c4386eSCy Schubert     return test_MSG_protect_pbmac_no_sender(0);
312*e0c4386eSCy Schubert }
313*e0c4386eSCy Schubert 
execute_MSG_add_extraCerts_test(CMP_PROTECT_TEST_FIXTURE * fixture)314*e0c4386eSCy Schubert static int execute_MSG_add_extraCerts_test(CMP_PROTECT_TEST_FIXTURE *fixture)
315*e0c4386eSCy Schubert {
316*e0c4386eSCy Schubert     return TEST_true(ossl_cmp_msg_add_extraCerts(fixture->cmp_ctx,
317*e0c4386eSCy Schubert                                                  fixture->msg));
318*e0c4386eSCy Schubert }
319*e0c4386eSCy Schubert 
test_MSG_add_extraCerts(void)320*e0c4386eSCy Schubert static int test_MSG_add_extraCerts(void)
321*e0c4386eSCy Schubert {
322*e0c4386eSCy Schubert     SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
323*e0c4386eSCy Schubert     if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_protected))) {
324*e0c4386eSCy Schubert         tear_down(fixture);
325*e0c4386eSCy Schubert         fixture = NULL;
326*e0c4386eSCy Schubert     }
327*e0c4386eSCy Schubert     EXECUTE_TEST(execute_MSG_add_extraCerts_test, tear_down);
328*e0c4386eSCy Schubert     return result;
329*e0c4386eSCy Schubert }
330*e0c4386eSCy Schubert 
331*e0c4386eSCy Schubert #ifndef OPENSSL_NO_EC
332*e0c4386eSCy Schubert /* The cert chain tests use EC certs so we skip them in no-ec builds */
execute_cmp_build_cert_chain_test(CMP_PROTECT_TEST_FIXTURE * fixture)333*e0c4386eSCy Schubert static int execute_cmp_build_cert_chain_test(CMP_PROTECT_TEST_FIXTURE *fixture)
334*e0c4386eSCy Schubert {
335*e0c4386eSCy Schubert     int ret = 0;
336*e0c4386eSCy Schubert     OSSL_CMP_CTX *ctx = fixture->cmp_ctx;
337*e0c4386eSCy Schubert     X509_STORE *store;
338*e0c4386eSCy Schubert     STACK_OF(X509) *chain =
339*e0c4386eSCy Schubert         X509_build_chain(fixture->cert, fixture->certs, NULL,
340*e0c4386eSCy Schubert                          fixture->with_ss, ctx->libctx, ctx->propq);
341*e0c4386eSCy Schubert 
342*e0c4386eSCy Schubert     if (TEST_ptr(chain)) {
343*e0c4386eSCy Schubert         /* Check whether chain built is equal to the expected one */
344*e0c4386eSCy Schubert         ret = TEST_int_eq(0, STACK_OF_X509_cmp(chain, fixture->chain));
345*e0c4386eSCy Schubert         sk_X509_pop_free(chain, X509_free);
346*e0c4386eSCy Schubert     }
347*e0c4386eSCy Schubert     if (!ret)
348*e0c4386eSCy Schubert         return 0;
349*e0c4386eSCy Schubert 
350*e0c4386eSCy Schubert     if (TEST_ptr(store = X509_STORE_new())
351*e0c4386eSCy Schubert             && TEST_true(X509_STORE_add_cert(store, root))) {
352*e0c4386eSCy Schubert         X509_VERIFY_PARAM_set_flags(X509_STORE_get0_param(store),
353*e0c4386eSCy Schubert                                     X509_V_FLAG_NO_CHECK_TIME);
354*e0c4386eSCy Schubert         chain = X509_build_chain(fixture->cert, fixture->certs, store,
355*e0c4386eSCy Schubert                                  fixture->with_ss, ctx->libctx, ctx->propq);
356*e0c4386eSCy Schubert         ret = TEST_int_eq(fixture->expected, chain != NULL);
357*e0c4386eSCy Schubert         if (ret && chain != NULL) {
358*e0c4386eSCy Schubert             /* Check whether chain built is equal to the expected one */
359*e0c4386eSCy Schubert             ret = TEST_int_eq(0, STACK_OF_X509_cmp(chain, fixture->chain));
360*e0c4386eSCy Schubert             sk_X509_pop_free(chain, X509_free);
361*e0c4386eSCy Schubert         }
362*e0c4386eSCy Schubert     }
363*e0c4386eSCy Schubert     X509_STORE_free(store);
364*e0c4386eSCy Schubert     return ret;
365*e0c4386eSCy Schubert }
366*e0c4386eSCy Schubert 
test_cmp_build_cert_chain(void)367*e0c4386eSCy Schubert static int test_cmp_build_cert_chain(void)
368*e0c4386eSCy Schubert {
369*e0c4386eSCy Schubert     SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
370*e0c4386eSCy Schubert     fixture->expected = 1;
371*e0c4386eSCy Schubert     fixture->with_ss = 0;
372*e0c4386eSCy Schubert     fixture->cert = endentity2;
373*e0c4386eSCy Schubert     if (!TEST_ptr(fixture->certs = sk_X509_new_null())
374*e0c4386eSCy Schubert             || !TEST_ptr(fixture->chain = sk_X509_new_null())
375*e0c4386eSCy Schubert             || !TEST_true(sk_X509_push(fixture->certs, endentity1))
376*e0c4386eSCy Schubert             || !TEST_true(sk_X509_push(fixture->certs, root))
377*e0c4386eSCy Schubert             || !TEST_true(sk_X509_push(fixture->certs, intermediate))
378*e0c4386eSCy Schubert             || !TEST_true(sk_X509_push(fixture->chain, endentity2))
379*e0c4386eSCy Schubert             || !TEST_true(sk_X509_push(fixture->chain, intermediate))) {
380*e0c4386eSCy Schubert         tear_down(fixture);
381*e0c4386eSCy Schubert         fixture = NULL;
382*e0c4386eSCy Schubert     }
383*e0c4386eSCy Schubert     if (fixture != NULL) {
384*e0c4386eSCy Schubert         result = execute_cmp_build_cert_chain_test(fixture);
385*e0c4386eSCy Schubert         fixture->with_ss = 1;
386*e0c4386eSCy Schubert         if (result && TEST_true(sk_X509_push(fixture->chain, root)))
387*e0c4386eSCy Schubert             result = execute_cmp_build_cert_chain_test(fixture);
388*e0c4386eSCy Schubert     }
389*e0c4386eSCy Schubert     tear_down(fixture);
390*e0c4386eSCy Schubert     return result;
391*e0c4386eSCy Schubert }
392*e0c4386eSCy Schubert 
test_cmp_build_cert_chain_missing_intermediate(void)393*e0c4386eSCy Schubert static int test_cmp_build_cert_chain_missing_intermediate(void)
394*e0c4386eSCy Schubert {
395*e0c4386eSCy Schubert     SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
396*e0c4386eSCy Schubert     fixture->expected = 0;
397*e0c4386eSCy Schubert     fixture->with_ss = 0;
398*e0c4386eSCy Schubert     fixture->cert = endentity2;
399*e0c4386eSCy Schubert     if (!TEST_ptr(fixture->certs = sk_X509_new_null())
400*e0c4386eSCy Schubert             || !TEST_ptr(fixture->chain = sk_X509_new_null())
401*e0c4386eSCy Schubert             || !TEST_true(sk_X509_push(fixture->certs, endentity1))
402*e0c4386eSCy Schubert             || !TEST_true(sk_X509_push(fixture->certs, root))
403*e0c4386eSCy Schubert             || !TEST_true(sk_X509_push(fixture->chain, endentity2))) {
404*e0c4386eSCy Schubert         tear_down(fixture);
405*e0c4386eSCy Schubert         fixture = NULL;
406*e0c4386eSCy Schubert     }
407*e0c4386eSCy Schubert     EXECUTE_TEST(execute_cmp_build_cert_chain_test, tear_down);
408*e0c4386eSCy Schubert     return result;
409*e0c4386eSCy Schubert }
410*e0c4386eSCy Schubert 
test_cmp_build_cert_chain_no_root(void)411*e0c4386eSCy Schubert static int test_cmp_build_cert_chain_no_root(void)
412*e0c4386eSCy Schubert {
413*e0c4386eSCy Schubert     SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
414*e0c4386eSCy Schubert     fixture->expected = 1;
415*e0c4386eSCy Schubert     fixture->with_ss = 0;
416*e0c4386eSCy Schubert     fixture->cert = endentity2;
417*e0c4386eSCy Schubert     if (!TEST_ptr(fixture->certs = sk_X509_new_null())
418*e0c4386eSCy Schubert             || !TEST_ptr(fixture->chain = sk_X509_new_null())
419*e0c4386eSCy Schubert             || !TEST_true(sk_X509_push(fixture->certs, endentity1))
420*e0c4386eSCy Schubert             || !TEST_true(sk_X509_push(fixture->certs, intermediate))
421*e0c4386eSCy Schubert             || !TEST_true(sk_X509_push(fixture->chain, endentity2))
422*e0c4386eSCy Schubert             || !TEST_true(sk_X509_push(fixture->chain, intermediate))) {
423*e0c4386eSCy Schubert         tear_down(fixture);
424*e0c4386eSCy Schubert         fixture = NULL;
425*e0c4386eSCy Schubert     }
426*e0c4386eSCy Schubert     EXECUTE_TEST(execute_cmp_build_cert_chain_test, tear_down);
427*e0c4386eSCy Schubert     return result;
428*e0c4386eSCy Schubert }
429*e0c4386eSCy Schubert 
test_cmp_build_cert_chain_only_root(void)430*e0c4386eSCy Schubert static int test_cmp_build_cert_chain_only_root(void)
431*e0c4386eSCy Schubert {
432*e0c4386eSCy Schubert     SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
433*e0c4386eSCy Schubert     fixture->expected = 1;
434*e0c4386eSCy Schubert     fixture->with_ss = 0; /* still chain must include the only cert (root) */
435*e0c4386eSCy Schubert     fixture->cert = root;
436*e0c4386eSCy Schubert     if (!TEST_ptr(fixture->certs = sk_X509_new_null())
437*e0c4386eSCy Schubert             || !TEST_ptr(fixture->chain = sk_X509_new_null())
438*e0c4386eSCy Schubert             || !TEST_true(sk_X509_push(fixture->certs, root))
439*e0c4386eSCy Schubert             || !TEST_true(sk_X509_push(fixture->chain, root))) {
440*e0c4386eSCy Schubert         tear_down(fixture);
441*e0c4386eSCy Schubert         fixture = NULL;
442*e0c4386eSCy Schubert     }
443*e0c4386eSCy Schubert     EXECUTE_TEST(execute_cmp_build_cert_chain_test, tear_down);
444*e0c4386eSCy Schubert     return result;
445*e0c4386eSCy Schubert }
446*e0c4386eSCy Schubert 
test_cmp_build_cert_chain_no_certs(void)447*e0c4386eSCy Schubert static int test_cmp_build_cert_chain_no_certs(void)
448*e0c4386eSCy Schubert {
449*e0c4386eSCy Schubert     SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
450*e0c4386eSCy Schubert     fixture->expected = 0;
451*e0c4386eSCy Schubert     fixture->with_ss = 0;
452*e0c4386eSCy Schubert     fixture->cert = endentity2;
453*e0c4386eSCy Schubert     if (!TEST_ptr(fixture->certs = sk_X509_new_null())
454*e0c4386eSCy Schubert             || !TEST_ptr(fixture->chain = sk_X509_new_null())
455*e0c4386eSCy Schubert             || !TEST_true(sk_X509_push(fixture->chain, endentity2))) {
456*e0c4386eSCy Schubert         tear_down(fixture);
457*e0c4386eSCy Schubert         fixture = NULL;
458*e0c4386eSCy Schubert     }
459*e0c4386eSCy Schubert     EXECUTE_TEST(execute_cmp_build_cert_chain_test, tear_down);
460*e0c4386eSCy Schubert     return result;
461*e0c4386eSCy Schubert }
462*e0c4386eSCy Schubert #endif /* OPENSSL_NO_EC */
463*e0c4386eSCy Schubert 
execute_X509_STORE_test(CMP_PROTECT_TEST_FIXTURE * fixture)464*e0c4386eSCy Schubert static int execute_X509_STORE_test(CMP_PROTECT_TEST_FIXTURE *fixture)
465*e0c4386eSCy Schubert {
466*e0c4386eSCy Schubert     X509_STORE *store = X509_STORE_new();
467*e0c4386eSCy Schubert     STACK_OF(X509) *sk = NULL;
468*e0c4386eSCy Schubert     int res = 0;
469*e0c4386eSCy Schubert 
470*e0c4386eSCy Schubert     if (!TEST_true(ossl_cmp_X509_STORE_add1_certs(store,
471*e0c4386eSCy Schubert                                                   fixture->certs,
472*e0c4386eSCy Schubert                                                   fixture->callback_arg)))
473*e0c4386eSCy Schubert         goto err;
474*e0c4386eSCy Schubert     sk = X509_STORE_get1_all_certs(store);
475*e0c4386eSCy Schubert     if (!TEST_int_eq(0, STACK_OF_X509_cmp(sk, fixture->chain)))
476*e0c4386eSCy Schubert         goto err;
477*e0c4386eSCy Schubert     res = 1;
478*e0c4386eSCy Schubert  err:
479*e0c4386eSCy Schubert     X509_STORE_free(store);
480*e0c4386eSCy Schubert     sk_X509_pop_free(sk, X509_free);
481*e0c4386eSCy Schubert     return res;
482*e0c4386eSCy Schubert 
483*e0c4386eSCy Schubert }
484*e0c4386eSCy Schubert 
test_X509_STORE(void)485*e0c4386eSCy Schubert static int test_X509_STORE(void)
486*e0c4386eSCy Schubert {
487*e0c4386eSCy Schubert     SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
488*e0c4386eSCy Schubert     fixture->callback_arg = 0; /* self-issued allowed */
489*e0c4386eSCy Schubert     if (!TEST_ptr(fixture->certs = sk_X509_new_null())
490*e0c4386eSCy Schubert             || !sk_X509_push(fixture->certs, endentity1)
491*e0c4386eSCy Schubert             || !sk_X509_push(fixture->certs, endentity2)
492*e0c4386eSCy Schubert             || !sk_X509_push(fixture->certs, root)
493*e0c4386eSCy Schubert             || !sk_X509_push(fixture->certs, intermediate)
494*e0c4386eSCy Schubert             || !TEST_ptr(fixture->chain = sk_X509_dup(fixture->certs))) {
495*e0c4386eSCy Schubert         tear_down(fixture);
496*e0c4386eSCy Schubert         fixture = NULL;
497*e0c4386eSCy Schubert     }
498*e0c4386eSCy Schubert     EXECUTE_TEST(execute_X509_STORE_test, tear_down);
499*e0c4386eSCy Schubert     return result;
500*e0c4386eSCy Schubert }
501*e0c4386eSCy Schubert 
test_X509_STORE_only_self_issued(void)502*e0c4386eSCy Schubert static int test_X509_STORE_only_self_issued(void)
503*e0c4386eSCy Schubert {
504*e0c4386eSCy Schubert     SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up);
505*e0c4386eSCy Schubert     fixture->certs = sk_X509_new_null();
506*e0c4386eSCy Schubert     fixture->chain = sk_X509_new_null();
507*e0c4386eSCy Schubert     fixture->callback_arg = 1; /* only self-issued */
508*e0c4386eSCy Schubert     if (!TEST_true(sk_X509_push(fixture->certs, endentity1))
509*e0c4386eSCy Schubert             || !TEST_true(sk_X509_push(fixture->certs, endentity2))
510*e0c4386eSCy Schubert             || !TEST_true(sk_X509_push(fixture->certs, root))
511*e0c4386eSCy Schubert             || !TEST_true(sk_X509_push(fixture->certs, intermediate))
512*e0c4386eSCy Schubert             || !TEST_true(sk_X509_push(fixture->chain, root))) {
513*e0c4386eSCy Schubert         tear_down(fixture);
514*e0c4386eSCy Schubert         fixture = NULL;
515*e0c4386eSCy Schubert     }
516*e0c4386eSCy Schubert     EXECUTE_TEST(execute_X509_STORE_test, tear_down);
517*e0c4386eSCy Schubert     return result;
518*e0c4386eSCy Schubert }
519*e0c4386eSCy Schubert 
520*e0c4386eSCy Schubert 
cleanup_tests(void)521*e0c4386eSCy Schubert void cleanup_tests(void)
522*e0c4386eSCy Schubert {
523*e0c4386eSCy Schubert     EVP_PKEY_free(loadedprivkey);
524*e0c4386eSCy Schubert     EVP_PKEY_free(loadedpubkey);
525*e0c4386eSCy Schubert     EVP_PKEY_free(loadedkey);
526*e0c4386eSCy Schubert     X509_free(cert);
527*e0c4386eSCy Schubert     X509_free(endentity1);
528*e0c4386eSCy Schubert     X509_free(endentity2);
529*e0c4386eSCy Schubert     X509_free(root);
530*e0c4386eSCy Schubert     X509_free(intermediate);
531*e0c4386eSCy Schubert     OSSL_CMP_MSG_free(ir_protected);
532*e0c4386eSCy Schubert     OSSL_CMP_MSG_free(ir_unprotected);
533*e0c4386eSCy Schubert     OSSL_PROVIDER_unload(default_null_provider);
534*e0c4386eSCy Schubert     OSSL_PROVIDER_unload(provider);
535*e0c4386eSCy Schubert     OSSL_LIB_CTX_free(libctx);
536*e0c4386eSCy Schubert }
537*e0c4386eSCy Schubert 
538*e0c4386eSCy Schubert #define USAGE "server.pem IR_protected.der IR_unprotected.der IP_PBM.der " \
539*e0c4386eSCy Schubert     "server.crt server.pem EndEntity1.crt EndEntity2.crt Root_CA.crt " \
540*e0c4386eSCy Schubert     "Intermediate_CA.crt module_name [module_conf_file]\n"
OPT_TEST_DECLARE_USAGE(USAGE)541*e0c4386eSCy Schubert OPT_TEST_DECLARE_USAGE(USAGE)
542*e0c4386eSCy Schubert 
543*e0c4386eSCy Schubert int setup_tests(void)
544*e0c4386eSCy Schubert {
545*e0c4386eSCy Schubert     char *server_f;
546*e0c4386eSCy Schubert     char *server_key_f;
547*e0c4386eSCy Schubert     char *server_cert_f;
548*e0c4386eSCy Schubert     char *endentity1_f;
549*e0c4386eSCy Schubert     char *endentity2_f;
550*e0c4386eSCy Schubert     char *root_f;
551*e0c4386eSCy Schubert     char *intermediate_f;
552*e0c4386eSCy Schubert 
553*e0c4386eSCy Schubert     if (!test_skip_common_options()) {
554*e0c4386eSCy Schubert         TEST_error("Error parsing test options\n");
555*e0c4386eSCy Schubert         return 0;
556*e0c4386eSCy Schubert     }
557*e0c4386eSCy Schubert 
558*e0c4386eSCy Schubert     RAND_bytes(rand_data, OSSL_CMP_TRANSACTIONID_LENGTH);
559*e0c4386eSCy Schubert     if (!TEST_ptr(server_f = test_get_argument(0))
560*e0c4386eSCy Schubert             || !TEST_ptr(ir_protected_f = test_get_argument(1))
561*e0c4386eSCy Schubert             || !TEST_ptr(ir_unprotected_f = test_get_argument(2))
562*e0c4386eSCy Schubert             || !TEST_ptr(ip_PBM_f = test_get_argument(3))
563*e0c4386eSCy Schubert             || !TEST_ptr(server_cert_f = test_get_argument(4))
564*e0c4386eSCy Schubert             || !TEST_ptr(server_key_f = test_get_argument(5))
565*e0c4386eSCy Schubert             || !TEST_ptr(endentity1_f = test_get_argument(6))
566*e0c4386eSCy Schubert             || !TEST_ptr(endentity2_f = test_get_argument(7))
567*e0c4386eSCy Schubert             || !TEST_ptr(root_f = test_get_argument(8))
568*e0c4386eSCy Schubert             || !TEST_ptr(intermediate_f = test_get_argument(9))) {
569*e0c4386eSCy Schubert         TEST_error("usage: cmp_protect_test %s", USAGE);
570*e0c4386eSCy Schubert         return 0;
571*e0c4386eSCy Schubert     }
572*e0c4386eSCy Schubert 
573*e0c4386eSCy Schubert     if (!test_arg_libctx(&libctx, &default_null_provider, &provider, 10, USAGE))
574*e0c4386eSCy Schubert         return 0;
575*e0c4386eSCy Schubert 
576*e0c4386eSCy Schubert     if (!TEST_ptr(loadedkey = load_pkey_pem(server_key_f, libctx))
577*e0c4386eSCy Schubert             || !TEST_ptr(cert = load_cert_pem(server_cert_f, libctx)))
578*e0c4386eSCy Schubert         return 0;
579*e0c4386eSCy Schubert 
580*e0c4386eSCy Schubert     if (!TEST_ptr(loadedprivkey = load_pkey_pem(server_f, libctx)))
581*e0c4386eSCy Schubert         return 0;
582*e0c4386eSCy Schubert     if (TEST_true(EVP_PKEY_up_ref(loadedprivkey)))
583*e0c4386eSCy Schubert         loadedpubkey = loadedprivkey;
584*e0c4386eSCy Schubert     if (!TEST_ptr(ir_protected = load_pkimsg(ir_protected_f, libctx))
585*e0c4386eSCy Schubert             || !TEST_ptr(ir_unprotected = load_pkimsg(ir_unprotected_f, libctx)))
586*e0c4386eSCy Schubert         return 0;
587*e0c4386eSCy Schubert     if (!TEST_ptr(endentity1 = load_cert_pem(endentity1_f, libctx))
588*e0c4386eSCy Schubert             || !TEST_ptr(endentity2 = load_cert_pem(endentity2_f, libctx))
589*e0c4386eSCy Schubert             || !TEST_ptr(root = load_cert_pem(root_f, libctx))
590*e0c4386eSCy Schubert             || !TEST_ptr(intermediate = load_cert_pem(intermediate_f, libctx)))
591*e0c4386eSCy Schubert         return 0;
592*e0c4386eSCy Schubert     if (!TEST_int_eq(1, RAND_bytes(rand_data, OSSL_CMP_TRANSACTIONID_LENGTH)))
593*e0c4386eSCy Schubert         return 0;
594*e0c4386eSCy Schubert 
595*e0c4386eSCy Schubert     /* Message protection tests */
596*e0c4386eSCy Schubert     ADD_TEST(test_cmp_calc_protection_no_key_no_secret);
597*e0c4386eSCy Schubert     ADD_TEST(test_cmp_calc_protection_pkey);
598*e0c4386eSCy Schubert     ADD_TEST(test_cmp_calc_protection_pbmac);
599*e0c4386eSCy Schubert 
600*e0c4386eSCy Schubert     ADD_TEST(test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key);
601*e0c4386eSCy Schubert     ADD_TEST(test_MSG_protect_with_certificate_and_key);
602*e0c4386eSCy Schubert     ADD_TEST(test_MSG_protect_certificate_based_without_cert);
603*e0c4386eSCy Schubert     ADD_TEST(test_MSG_protect_unprotected_request);
604*e0c4386eSCy Schubert     ADD_TEST(test_MSG_protect_no_key_no_secret);
605*e0c4386eSCy Schubert     ADD_TEST(test_MSG_protect_pbmac_no_sender_with_ref);
606*e0c4386eSCy Schubert     ADD_TEST(test_MSG_protect_pbmac_no_sender_no_ref);
607*e0c4386eSCy Schubert     ADD_TEST(test_MSG_add_extraCerts);
608*e0c4386eSCy Schubert 
609*e0c4386eSCy Schubert #ifndef OPENSSL_NO_EC
610*e0c4386eSCy Schubert     ADD_TEST(test_cmp_build_cert_chain);
611*e0c4386eSCy Schubert     ADD_TEST(test_cmp_build_cert_chain_only_root);
612*e0c4386eSCy Schubert     ADD_TEST(test_cmp_build_cert_chain_no_root);
613*e0c4386eSCy Schubert     ADD_TEST(test_cmp_build_cert_chain_missing_intermediate);
614*e0c4386eSCy Schubert     ADD_TEST(test_cmp_build_cert_chain_no_certs);
615*e0c4386eSCy Schubert #endif
616*e0c4386eSCy Schubert 
617*e0c4386eSCy Schubert     ADD_TEST(test_X509_STORE);
618*e0c4386eSCy Schubert     ADD_TEST(test_X509_STORE_only_self_issued);
619*e0c4386eSCy Schubert 
620*e0c4386eSCy Schubert     return 1;
621*e0c4386eSCy Schubert }
622