]>
Commit | Line | Data |
---|---|---|
3dbc5156 DDO |
1 | /* |
2 | * Copyright 2007-2019 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 | ||
14 | static const char *server_cert_f; | |
15 | static const char *pkcs10_f; | |
16 | ||
17 | typedef struct test_fixture { | |
18 | const char *test_case_name; | |
19 | OSSL_CMP_CTX *cmp_ctx; | |
20 | /* for msg create tests */ | |
21 | int bodytype; | |
22 | int err_code; | |
23 | /* for certConf */ | |
24 | int fail_info; | |
25 | /* for protection tests */ | |
26 | OSSL_CMP_MSG *msg; | |
27 | int expected; | |
28 | /* for error and response messages */ | |
29 | OSSL_CMP_PKISI *si; | |
30 | } CMP_MSG_TEST_FIXTURE; | |
31 | ||
32 | static unsigned char ref[CMP_TEST_REFVALUE_LENGTH]; | |
33 | ||
34 | static void tear_down(CMP_MSG_TEST_FIXTURE *fixture) | |
35 | { | |
36 | OSSL_CMP_CTX_free(fixture->cmp_ctx); | |
37 | OSSL_CMP_MSG_free(fixture->msg); | |
38 | OSSL_CMP_PKISI_free(fixture->si); | |
39 | OPENSSL_free(fixture); | |
40 | } | |
41 | ||
42 | #define SET_OPT_UNPROTECTED_SEND(ctx, val) \ | |
43 | OSSL_CMP_CTX_set_option((ctx), OSSL_CMP_OPT_UNPROTECTED_SEND, (val)) | |
44 | static CMP_MSG_TEST_FIXTURE *set_up(const char *const test_case_name) | |
45 | { | |
46 | CMP_MSG_TEST_FIXTURE *fixture; | |
47 | ||
48 | if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture)))) | |
49 | return NULL; | |
50 | fixture->test_case_name = test_case_name; | |
51 | ||
52 | if (!TEST_ptr(fixture->cmp_ctx = OSSL_CMP_CTX_new()) | |
53 | || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 1)) | |
54 | || !TEST_true(OSSL_CMP_CTX_set1_referenceValue(fixture->cmp_ctx, | |
55 | ref, sizeof(ref)))) { | |
56 | tear_down(fixture); | |
57 | return NULL; | |
58 | } | |
59 | return fixture; | |
60 | } | |
61 | ||
62 | static EVP_PKEY *newkey = NULL; | |
63 | static X509 *cert = NULL; | |
64 | ||
65 | #define EXECUTE_MSG_CREATION_TEST(expr) \ | |
66 | do { \ | |
67 | OSSL_CMP_MSG *msg = NULL; \ | |
68 | int good = fixture->expected != 0 ? \ | |
69 | TEST_ptr(msg = (expr)) && TEST_true(valid_asn1_encoding(msg)) : \ | |
70 | TEST_ptr_null(msg = (expr)); \ | |
71 | \ | |
72 | OSSL_CMP_MSG_free(msg); \ | |
73 | return good; \ | |
74 | } while (0) | |
75 | ||
76 | /*- | |
77 | * The following tests call a cmp message creation function. | |
78 | * if fixture->expected != 0: | |
79 | * returns 1 if the message is created and syntactically correct. | |
80 | * if fixture->expected == 0 | |
81 | * returns 1 if message creation returns NULL | |
82 | */ | |
83 | static int execute_certreq_create_test(CMP_MSG_TEST_FIXTURE *fixture) | |
84 | { | |
85 | EXECUTE_MSG_CREATION_TEST(ossl_cmp_certReq_new(fixture->cmp_ctx, | |
86 | fixture->bodytype, | |
87 | fixture->err_code)); | |
88 | } | |
89 | ||
90 | static int execute_errormsg_create_test(CMP_MSG_TEST_FIXTURE *fixture) | |
91 | { | |
92 | EXECUTE_MSG_CREATION_TEST(ossl_cmp_error_new(fixture->cmp_ctx, fixture->si, | |
93 | fixture->err_code, | |
62dcd2aa | 94 | "details", 0)); |
3dbc5156 DDO |
95 | } |
96 | ||
97 | static int execute_rr_create_test(CMP_MSG_TEST_FIXTURE *fixture) | |
98 | { | |
99 | EXECUTE_MSG_CREATION_TEST(ossl_cmp_rr_new(fixture->cmp_ctx)); | |
100 | } | |
101 | ||
102 | static int execute_certconf_create_test(CMP_MSG_TEST_FIXTURE *fixture) | |
103 | { | |
104 | EXECUTE_MSG_CREATION_TEST(ossl_cmp_certConf_new | |
105 | (fixture->cmp_ctx, fixture->fail_info, NULL)); | |
106 | } | |
107 | ||
108 | static int execute_genm_create_test(CMP_MSG_TEST_FIXTURE *fixture) | |
109 | { | |
110 | EXECUTE_MSG_CREATION_TEST(ossl_cmp_genm_new(fixture->cmp_ctx)); | |
111 | } | |
112 | ||
113 | static int execute_pollreq_create_test(CMP_MSG_TEST_FIXTURE *fixture) | |
114 | { | |
115 | EXECUTE_MSG_CREATION_TEST(ossl_cmp_pollReq_new(fixture->cmp_ctx, 4711)); | |
116 | } | |
117 | ||
118 | static int execute_pkimessage_create_test(CMP_MSG_TEST_FIXTURE *fixture) | |
119 | { | |
120 | EXECUTE_MSG_CREATION_TEST(ossl_cmp_msg_create | |
121 | (fixture->cmp_ctx, fixture->bodytype)); | |
122 | } | |
123 | ||
235595c4 | 124 | static int set1_newPkey(OSSL_CMP_CTX *ctx, EVP_PKEY *pkey) |
3dbc5156 DDO |
125 | { |
126 | if (!EVP_PKEY_up_ref(pkey)) | |
127 | return 0; | |
128 | ||
129 | if (!OSSL_CMP_CTX_set0_newPkey(ctx, 1, pkey)) { | |
130 | EVP_PKEY_free(pkey); | |
131 | return 0; | |
132 | } | |
133 | return 1; | |
134 | } | |
135 | ||
136 | static int test_cmp_create_ir_protection_set(void) | |
137 | { | |
138 | SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); | |
139 | OSSL_CMP_CTX *ctx = fixture->cmp_ctx; | |
140 | unsigned char secret[16]; | |
141 | ||
142 | fixture->bodytype = OSSL_CMP_PKIBODY_IR; | |
bce58e7f | 143 | fixture->err_code = -1; |
3dbc5156 DDO |
144 | fixture->expected = 1; |
145 | if (!TEST_int_eq(1, RAND_bytes(secret, sizeof(secret))) | |
146 | || !TEST_true(SET_OPT_UNPROTECTED_SEND(ctx, 0)) | |
147 | || !TEST_true(set1_newPkey(ctx, newkey)) | |
148 | || !TEST_true(OSSL_CMP_CTX_set1_secretValue(ctx, secret, | |
149 | sizeof(secret)))) { | |
150 | tear_down(fixture); | |
151 | fixture = NULL; | |
152 | } | |
153 | EXECUTE_TEST(execute_certreq_create_test, tear_down); | |
154 | return result; | |
155 | } | |
156 | ||
157 | static int test_cmp_create_ir_protection_fails(void) | |
158 | { | |
159 | SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); | |
160 | fixture->bodytype = OSSL_CMP_PKIBODY_IR; | |
bce58e7f | 161 | fixture->err_code = -1; |
3dbc5156 DDO |
162 | fixture->expected = 0; |
163 | if (!TEST_true(OSSL_CMP_CTX_set1_pkey(fixture->cmp_ctx, newkey)) | |
164 | || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0)) | |
7e765f46 | 165 | /* newkey used by default for signing does not match cert: */ |
3dbc5156 DDO |
166 | || !TEST_true(OSSL_CMP_CTX_set1_clCert(fixture->cmp_ctx, cert))) { |
167 | tear_down(fixture); | |
168 | fixture = NULL; | |
169 | } | |
170 | EXECUTE_TEST(execute_certreq_create_test, tear_down); | |
171 | return result; | |
172 | } | |
173 | ||
174 | static int test_cmp_create_cr_without_key(void) | |
175 | { | |
176 | SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); | |
177 | fixture->bodytype = OSSL_CMP_PKIBODY_CR; | |
bce58e7f | 178 | fixture->err_code = -1; |
3dbc5156 DDO |
179 | fixture->expected = 0; |
180 | EXECUTE_TEST(execute_certreq_create_test, tear_down); | |
181 | return result; | |
182 | } | |
183 | ||
184 | static int test_cmp_create_cr(void) | |
185 | { | |
186 | SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); | |
187 | fixture->bodytype = OSSL_CMP_PKIBODY_CR; | |
bce58e7f | 188 | fixture->err_code = -1; |
3dbc5156 DDO |
189 | fixture->expected = 1; |
190 | if (!TEST_true(set1_newPkey(fixture->cmp_ctx, newkey))) { | |
191 | tear_down(fixture); | |
192 | fixture = NULL; | |
193 | } | |
194 | EXECUTE_TEST(execute_certreq_create_test, tear_down); | |
195 | return result; | |
196 | } | |
197 | ||
198 | static int test_cmp_create_certreq_with_invalid_bodytype(void) | |
199 | { | |
200 | SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); | |
201 | fixture->bodytype = OSSL_CMP_PKIBODY_RR; | |
bce58e7f | 202 | fixture->err_code = -1; |
3dbc5156 DDO |
203 | fixture->expected = 0; |
204 | if (!TEST_true(set1_newPkey(fixture->cmp_ctx, newkey))) { | |
205 | tear_down(fixture); | |
206 | fixture = NULL; | |
207 | } | |
208 | EXECUTE_TEST(execute_certreq_create_test, tear_down); | |
209 | return result; | |
210 | } | |
211 | ||
212 | static int test_cmp_create_p10cr(void) | |
213 | { | |
214 | SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); | |
215 | OSSL_CMP_CTX *ctx = fixture->cmp_ctx; | |
216 | X509_REQ *p10cr = NULL; | |
217 | ||
218 | fixture->bodytype = OSSL_CMP_PKIBODY_P10CR; | |
219 | fixture->err_code = CMP_R_ERROR_CREATING_P10CR; | |
220 | fixture->expected = 1; | |
221 | if (!TEST_ptr(p10cr = load_csr(pkcs10_f)) | |
222 | || !TEST_true(set1_newPkey(ctx, newkey)) | |
223 | || !TEST_true(OSSL_CMP_CTX_set1_p10CSR(ctx, p10cr))) { | |
224 | tear_down(fixture); | |
225 | fixture = NULL; | |
226 | } | |
227 | X509_REQ_free(p10cr); | |
228 | EXECUTE_TEST(execute_certreq_create_test, tear_down); | |
229 | return result; | |
230 | } | |
231 | ||
232 | static int test_cmp_create_p10cr_null(void) | |
233 | { | |
234 | SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); | |
235 | fixture->bodytype = OSSL_CMP_PKIBODY_P10CR; | |
236 | fixture->err_code = CMP_R_ERROR_CREATING_P10CR; | |
237 | fixture->expected = 0; | |
238 | if (!TEST_true(set1_newPkey(fixture->cmp_ctx, newkey))) { | |
239 | tear_down(fixture); | |
240 | fixture = NULL; | |
241 | } | |
242 | EXECUTE_TEST(execute_certreq_create_test, tear_down); | |
243 | return result; | |
244 | } | |
245 | ||
246 | static int test_cmp_create_kur(void) | |
247 | { | |
248 | SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); | |
249 | fixture->bodytype = OSSL_CMP_PKIBODY_KUR; | |
bce58e7f | 250 | fixture->err_code = -1; |
3dbc5156 DDO |
251 | fixture->expected = 1; |
252 | if (!TEST_true(set1_newPkey(fixture->cmp_ctx, newkey)) | |
253 | || !TEST_true(OSSL_CMP_CTX_set1_oldCert(fixture->cmp_ctx, cert))) { | |
254 | tear_down(fixture); | |
255 | fixture = NULL; | |
256 | } | |
257 | EXECUTE_TEST(execute_certreq_create_test, tear_down); | |
258 | return result; | |
259 | } | |
260 | ||
261 | static int test_cmp_create_kur_without_oldcert(void) | |
262 | { | |
263 | SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); | |
264 | fixture->bodytype = OSSL_CMP_PKIBODY_KUR; | |
bce58e7f | 265 | fixture->err_code = -1; |
3dbc5156 DDO |
266 | fixture->expected = 0; |
267 | if (!TEST_true(set1_newPkey(fixture->cmp_ctx, newkey))) { | |
268 | tear_down(fixture); | |
269 | fixture = NULL; | |
270 | } | |
271 | EXECUTE_TEST(execute_certreq_create_test, tear_down); | |
272 | return result; | |
273 | } | |
274 | ||
275 | static int test_cmp_create_certconf(void) | |
276 | { | |
277 | SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); | |
278 | fixture->fail_info = 0; | |
279 | fixture->expected = 1; | |
280 | if (!TEST_true(ossl_cmp_ctx_set0_newCert(fixture->cmp_ctx, | |
281 | X509_dup(cert)))) { | |
282 | tear_down(fixture); | |
283 | fixture = NULL; | |
284 | } | |
285 | EXECUTE_TEST(execute_certconf_create_test, tear_down); | |
286 | return result; | |
287 | } | |
288 | ||
289 | static int test_cmp_create_certconf_badAlg(void) | |
290 | { | |
291 | SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); | |
292 | fixture->fail_info = 1 << OSSL_CMP_PKIFAILUREINFO_badAlg; | |
293 | fixture->expected = 1; | |
294 | if (!TEST_true(ossl_cmp_ctx_set0_newCert(fixture->cmp_ctx, | |
295 | X509_dup(cert)))) { | |
296 | tear_down(fixture); | |
297 | fixture = NULL; | |
298 | } | |
299 | EXECUTE_TEST(execute_certconf_create_test, tear_down); | |
300 | return result; | |
301 | } | |
302 | ||
303 | static int test_cmp_create_certconf_fail_info_max(void) | |
304 | { | |
305 | SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); | |
306 | fixture->fail_info = 1 << OSSL_CMP_PKIFAILUREINFO_MAX; | |
307 | fixture->expected = 1; | |
308 | if (!TEST_true(ossl_cmp_ctx_set0_newCert(fixture->cmp_ctx, | |
309 | X509_dup(cert)))) { | |
310 | tear_down(fixture); | |
311 | fixture = NULL; | |
312 | } | |
313 | EXECUTE_TEST(execute_certconf_create_test, tear_down); | |
314 | return result; | |
315 | } | |
316 | ||
317 | static int test_cmp_create_error_msg(void) | |
318 | { | |
319 | SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); | |
62dcd2aa | 320 | fixture->si = OSSL_CMP_STATUSINFO_new(OSSL_CMP_PKISTATUS_rejection, |
3dbc5156 DDO |
321 | OSSL_CMP_PKIFAILUREINFO_systemFailure, |
322 | NULL); | |
323 | fixture->err_code = -1; | |
235595c4 | 324 | fixture->expected = 1; /* expected: message creation is successful */ |
3dbc5156 DDO |
325 | if (!TEST_true(set1_newPkey(fixture->cmp_ctx, newkey))) { |
326 | tear_down(fixture); | |
327 | fixture = NULL; | |
328 | } | |
329 | EXECUTE_TEST(execute_errormsg_create_test, tear_down); | |
330 | return result; | |
331 | } | |
332 | ||
333 | ||
334 | static int test_cmp_create_pollreq(void) | |
335 | { | |
336 | SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); | |
337 | fixture->expected = 1; | |
338 | EXECUTE_TEST(execute_pollreq_create_test, tear_down); | |
339 | return result; | |
340 | } | |
341 | ||
342 | static int test_cmp_create_rr(void) | |
343 | { | |
344 | SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); | |
345 | fixture->expected = 1; | |
346 | if (!TEST_true(OSSL_CMP_CTX_set1_oldCert(fixture->cmp_ctx, cert))) { | |
347 | tear_down(fixture); | |
348 | fixture = NULL; | |
349 | } | |
350 | EXECUTE_TEST(execute_rr_create_test, tear_down); | |
351 | return result; | |
352 | } | |
353 | ||
354 | static int test_cmp_create_genm(void) | |
355 | { | |
356 | OSSL_CMP_ITAV *iv = NULL; | |
357 | ||
358 | SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); | |
359 | fixture->expected = 1; | |
360 | iv = OSSL_CMP_ITAV_create(OBJ_nid2obj(NID_id_it_implicitConfirm), NULL); | |
7e765f46 | 361 | if (!TEST_ptr(iv) |
3dbc5156 DDO |
362 | || !TEST_true(OSSL_CMP_CTX_push0_genm_ITAV(fixture->cmp_ctx, iv))) { |
363 | OSSL_CMP_ITAV_free(iv); | |
364 | tear_down(fixture); | |
365 | fixture = NULL; | |
366 | } | |
367 | ||
368 | EXECUTE_TEST(execute_genm_create_test, tear_down); | |
369 | return result; | |
370 | } | |
371 | ||
372 | static int execute_certrep_create(CMP_MSG_TEST_FIXTURE *fixture) | |
373 | { | |
374 | OSSL_CMP_CERTREPMESSAGE *crepmsg = OSSL_CMP_CERTREPMESSAGE_new(); | |
375 | OSSL_CMP_CERTRESPONSE *read_cresp, *cresp = OSSL_CMP_CERTRESPONSE_new(); | |
376 | EVP_PKEY *privkey; | |
377 | X509 *certfromresp = NULL; | |
378 | int res = 0; | |
379 | ||
380 | if (crepmsg == NULL || cresp == NULL) | |
381 | goto err; | |
382 | if (!ASN1_INTEGER_set(cresp->certReqId, 99)) | |
383 | goto err; | |
384 | if ((cresp->certifiedKeyPair = OSSL_CMP_CERTIFIEDKEYPAIR_new()) == NULL) | |
385 | goto err; | |
386 | cresp->certifiedKeyPair->certOrEncCert->type = | |
387 | OSSL_CMP_CERTORENCCERT_CERTIFICATE; | |
388 | if ((cresp->certifiedKeyPair->certOrEncCert->value.certificate = | |
389 | X509_dup(cert)) == NULL | |
390 | || !sk_OSSL_CMP_CERTRESPONSE_push(crepmsg->response, cresp)) | |
391 | goto err; | |
392 | cresp = NULL; | |
393 | read_cresp = ossl_cmp_certrepmessage_get0_certresponse(crepmsg, 99); | |
394 | if (!TEST_ptr(read_cresp)) | |
395 | goto err; | |
396 | if (!TEST_ptr_null(ossl_cmp_certrepmessage_get0_certresponse(crepmsg, 88))) | |
397 | goto err; | |
398 | privkey = OSSL_CMP_CTX_get0_newPkey(fixture->cmp_ctx, 1); /* may be NULL */ | |
399 | certfromresp = ossl_cmp_certresponse_get1_certificate(privkey, read_cresp); | |
400 | if (certfromresp == NULL || !TEST_int_eq(X509_cmp(cert, certfromresp), 0)) | |
401 | goto err; | |
402 | ||
403 | res = 1; | |
404 | err: | |
405 | X509_free(certfromresp); | |
406 | OSSL_CMP_CERTRESPONSE_free(cresp); | |
407 | OSSL_CMP_CERTREPMESSAGE_free(crepmsg); | |
408 | return res; | |
409 | } | |
410 | ||
411 | static int test_cmp_create_certrep(void) | |
412 | { | |
413 | SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); | |
414 | EXECUTE_TEST(execute_certrep_create, tear_down); | |
415 | return result; | |
416 | } | |
417 | ||
418 | ||
419 | static int execute_rp_create(CMP_MSG_TEST_FIXTURE *fixture) | |
420 | { | |
62dcd2aa | 421 | OSSL_CMP_PKISI *si = OSSL_CMP_STATUSINFO_new(33, 44, "a text"); |
3dbc5156 DDO |
422 | X509_NAME *issuer = X509_NAME_new(); |
423 | ASN1_INTEGER *serial = ASN1_INTEGER_new(); | |
424 | OSSL_CRMF_CERTID *cid = NULL; | |
425 | OSSL_CMP_MSG *rpmsg = NULL; | |
426 | int res = 0; | |
427 | ||
428 | if (si == NULL || issuer == NULL || serial == NULL) | |
429 | goto err; | |
430 | ||
431 | if (!X509_NAME_add_entry_by_txt(issuer, "CN", MBSTRING_ASC, | |
235595c4 | 432 | (unsigned char *)"The Issuer", -1, -1, 0) |
3dbc5156 DDO |
433 | || !ASN1_INTEGER_set(serial, 99) |
434 | || (cid = OSSL_CRMF_CERTID_gen(issuer, serial)) == NULL | |
435 | || (rpmsg = ossl_cmp_rp_new(fixture->cmp_ctx, si, cid, 1)) == NULL) | |
436 | goto err; | |
437 | ||
438 | if (!TEST_ptr(ossl_cmp_revrepcontent_get_CertId(rpmsg->body->value.rp, 0))) | |
439 | goto err; | |
440 | ||
62dcd2aa | 441 | if (!TEST_ptr(ossl_cmp_revrepcontent_get_pkisi(rpmsg->body->value.rp, 0))) |
3dbc5156 DDO |
442 | goto err; |
443 | ||
444 | res = 1; | |
445 | err: | |
446 | ASN1_INTEGER_free(serial); | |
447 | X509_NAME_free(issuer); | |
448 | OSSL_CRMF_CERTID_free(cid); | |
449 | OSSL_CMP_PKISI_free(si); | |
450 | OSSL_CMP_MSG_free(rpmsg); | |
451 | return res; | |
452 | } | |
453 | ||
454 | static int test_cmp_create_rp(void) | |
455 | { | |
456 | SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); | |
457 | EXECUTE_TEST(execute_rp_create, tear_down); | |
458 | return result; | |
459 | } | |
460 | ||
461 | static int execute_pollrep_create(CMP_MSG_TEST_FIXTURE *fixture) | |
462 | { | |
463 | OSSL_CMP_MSG *pollrep; | |
464 | int res = 0; | |
465 | ||
466 | pollrep = ossl_cmp_pollRep_new(fixture->cmp_ctx, 77, 2000); | |
467 | if (!TEST_ptr(pollrep)) | |
468 | return 0; | |
235595c4 DDO |
469 | if (!TEST_ptr(ossl_cmp_pollrepcontent_get0_pollrep(pollrep->body-> |
470 | value.pollRep, 77))) | |
3dbc5156 | 471 | goto err; |
235595c4 DDO |
472 | if (!TEST_ptr_null(ossl_cmp_pollrepcontent_get0_pollrep(pollrep->body-> |
473 | value.pollRep, 88))) | |
3dbc5156 DDO |
474 | goto err; |
475 | ||
476 | res = 1; | |
477 | err: | |
478 | OSSL_CMP_MSG_free(pollrep); | |
479 | return res; | |
480 | } | |
481 | ||
482 | static int test_cmp_create_pollrep(void) | |
483 | { | |
484 | SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); | |
485 | EXECUTE_TEST(execute_pollrep_create, tear_down); | |
486 | return result; | |
487 | } | |
488 | ||
489 | static int test_cmp_pkimessage_create(int bodytype) | |
490 | { | |
491 | X509_REQ *p10cr = NULL; | |
492 | ||
493 | SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); | |
494 | ||
495 | switch (fixture->bodytype = bodytype) { | |
496 | case OSSL_CMP_PKIBODY_P10CR: | |
497 | fixture->expected = 1; | |
498 | if (!TEST_true(OSSL_CMP_CTX_set1_p10CSR(fixture->cmp_ctx, | |
499 | p10cr = load_csr(pkcs10_f)))) { | |
500 | tear_down(fixture); | |
501 | fixture = NULL; | |
502 | } | |
503 | X509_REQ_free(p10cr); | |
504 | break; | |
505 | case OSSL_CMP_PKIBODY_IR: | |
506 | case OSSL_CMP_PKIBODY_IP: | |
507 | case OSSL_CMP_PKIBODY_CR: | |
508 | case OSSL_CMP_PKIBODY_CP: | |
509 | case OSSL_CMP_PKIBODY_KUR: | |
510 | case OSSL_CMP_PKIBODY_KUP: | |
511 | case OSSL_CMP_PKIBODY_RR: | |
512 | case OSSL_CMP_PKIBODY_RP: | |
513 | case OSSL_CMP_PKIBODY_PKICONF: | |
514 | case OSSL_CMP_PKIBODY_GENM: | |
515 | case OSSL_CMP_PKIBODY_GENP: | |
516 | case OSSL_CMP_PKIBODY_ERROR: | |
517 | case OSSL_CMP_PKIBODY_CERTCONF: | |
518 | case OSSL_CMP_PKIBODY_POLLREQ: | |
519 | case OSSL_CMP_PKIBODY_POLLREP: | |
520 | fixture->expected = 1; | |
521 | break; | |
522 | default: | |
523 | fixture->expected = 0; | |
524 | break; | |
525 | } | |
526 | ||
527 | EXECUTE_TEST(execute_pkimessage_create_test, tear_down); | |
528 | return result; | |
529 | } | |
530 | ||
531 | void cleanup_tests(void) | |
532 | { | |
533 | EVP_PKEY_free(newkey); | |
534 | X509_free(cert); | |
535 | } | |
536 | ||
537 | int setup_tests(void) | |
538 | { | |
8d242823 MC |
539 | if (!test_skip_common_options()) { |
540 | TEST_error("Error parsing test options\n"); | |
541 | return 0; | |
542 | } | |
543 | ||
3dbc5156 DDO |
544 | if (!TEST_ptr(server_cert_f = test_get_argument(0)) |
545 | || !TEST_ptr(pkcs10_f = test_get_argument(1))) { | |
546 | TEST_error("usage: cmp_msg_test server.crt pkcs10.der\n"); | |
547 | return 0; | |
548 | } | |
549 | ||
550 | if (!TEST_ptr(newkey = gen_rsa()) | |
551 | || !TEST_ptr(cert = load_pem_cert(server_cert_f)) | |
552 | || !TEST_int_eq(1, RAND_bytes(ref, sizeof(ref)))) { | |
553 | cleanup_tests(); | |
554 | return 0; | |
555 | } | |
556 | ||
557 | /* Message creation tests */ | |
558 | ADD_TEST(test_cmp_create_certreq_with_invalid_bodytype); | |
559 | ADD_TEST(test_cmp_create_ir_protection_fails); | |
560 | ADD_TEST(test_cmp_create_ir_protection_set); | |
561 | ADD_TEST(test_cmp_create_error_msg); | |
562 | ADD_TEST(test_cmp_create_certconf); | |
563 | ADD_TEST(test_cmp_create_certconf_badAlg); | |
564 | ADD_TEST(test_cmp_create_certconf_fail_info_max); | |
565 | ADD_TEST(test_cmp_create_kur); | |
566 | ADD_TEST(test_cmp_create_kur_without_oldcert); | |
567 | ADD_TEST(test_cmp_create_cr); | |
568 | ADD_TEST(test_cmp_create_cr_without_key); | |
569 | ADD_TEST(test_cmp_create_p10cr); | |
570 | ADD_TEST(test_cmp_create_p10cr_null); | |
571 | ADD_TEST(test_cmp_create_pollreq); | |
572 | ADD_TEST(test_cmp_create_rr); | |
573 | ADD_TEST(test_cmp_create_rp); | |
574 | ADD_TEST(test_cmp_create_genm); | |
575 | ADD_TEST(test_cmp_create_certrep); | |
576 | ADD_TEST(test_cmp_create_pollrep); | |
577 | ADD_ALL_TESTS_NOSUBTEST(test_cmp_pkimessage_create, | |
578 | OSSL_CMP_PKIBODY_POLLREP + 1); | |
579 | return 1; | |
580 | } |