cmp_msg_test.c 18 KB

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