ssl_test.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /*
  2. * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <openssl/conf.h>
  12. #include <openssl/err.h>
  13. #include <openssl/ssl.h>
  14. #include <openssl/provider.h>
  15. #ifndef OPENSSL_NO_QUIC
  16. #include <openssl/quic.h>
  17. #endif
  18. #include "helpers/handshake.h"
  19. #include "helpers/ssl_test_ctx.h"
  20. #include "testutil.h"
  21. static CONF *conf = NULL;
  22. static OSSL_PROVIDER *defctxnull = NULL, *thisprov = NULL;
  23. static OSSL_LIB_CTX *libctx = NULL;
  24. /* Currently the section names are of the form test-<number>, e.g. test-15. */
  25. #define MAX_TESTCASE_NAME_LENGTH 100
  26. static const char *print_alert(int alert)
  27. {
  28. return alert ? SSL_alert_desc_string_long(alert) : "no alert";
  29. }
  30. static int check_result(HANDSHAKE_RESULT *result, SSL_TEST_CTX *test_ctx)
  31. {
  32. if (!TEST_int_eq(result->result, test_ctx->expected_result)) {
  33. TEST_info("ExpectedResult mismatch: expected %s, got %s.",
  34. ssl_test_result_name(test_ctx->expected_result),
  35. ssl_test_result_name(result->result));
  36. return 0;
  37. }
  38. return 1;
  39. }
  40. static int check_alerts(HANDSHAKE_RESULT *result, SSL_TEST_CTX *test_ctx)
  41. {
  42. if (!TEST_int_eq(result->client_alert_sent,
  43. result->client_alert_received)) {
  44. TEST_info("Client sent alert %s but server received %s.",
  45. print_alert(result->client_alert_sent),
  46. print_alert(result->client_alert_received));
  47. /*
  48. * We can't bail here because the peer doesn't always get far enough
  49. * to process a received alert. Specifically, in protocol version
  50. * negotiation tests, we have the following scenario.
  51. * Client supports TLS v1.2 only; Server supports TLS v1.1.
  52. * Client proposes TLS v1.2; server responds with 1.1;
  53. * Client now sends a protocol alert, using TLS v1.2 in the header.
  54. * The server, however, rejects the alert because of version mismatch
  55. * in the record layer; therefore, the server appears to never
  56. * receive the alert.
  57. */
  58. /* return 0; */
  59. }
  60. if (!TEST_int_eq(result->server_alert_sent,
  61. result->server_alert_received)) {
  62. TEST_info("Server sent alert %s but client received %s.",
  63. print_alert(result->server_alert_sent),
  64. print_alert(result->server_alert_received));
  65. /* return 0; */
  66. }
  67. /* Tolerate an alert if one wasn't explicitly specified in the test. */
  68. if (test_ctx->expected_client_alert
  69. /*
  70. * The info callback alert value is computed as
  71. * (s->s3->send_alert[0] << 8) | s->s3->send_alert[1]
  72. * where the low byte is the alert code and the high byte is other stuff.
  73. */
  74. && (result->client_alert_sent & 0xff) != test_ctx->expected_client_alert) {
  75. TEST_error("ClientAlert mismatch: expected %s, got %s.",
  76. print_alert(test_ctx->expected_client_alert),
  77. print_alert(result->client_alert_sent));
  78. return 0;
  79. }
  80. if (test_ctx->expected_server_alert
  81. && (result->server_alert_sent & 0xff) != test_ctx->expected_server_alert) {
  82. TEST_error("ServerAlert mismatch: expected %s, got %s.",
  83. print_alert(test_ctx->expected_server_alert),
  84. print_alert(result->server_alert_sent));
  85. return 0;
  86. }
  87. if (!TEST_int_le(result->client_num_fatal_alerts_sent, 1))
  88. return 0;
  89. if (!TEST_int_le(result->server_num_fatal_alerts_sent, 1))
  90. return 0;
  91. return 1;
  92. }
  93. static int check_protocol(HANDSHAKE_RESULT *result, SSL_TEST_CTX *test_ctx)
  94. {
  95. if (!TEST_int_eq(result->client_protocol, result->server_protocol)) {
  96. TEST_info("Client has protocol %s but server has %s.",
  97. ssl_protocol_name(result->client_protocol),
  98. ssl_protocol_name(result->server_protocol));
  99. return 0;
  100. }
  101. if (test_ctx->expected_protocol) {
  102. if (!TEST_int_eq(result->client_protocol,
  103. test_ctx->expected_protocol)) {
  104. TEST_info("Protocol mismatch: expected %s, got %s.\n",
  105. ssl_protocol_name(test_ctx->expected_protocol),
  106. ssl_protocol_name(result->client_protocol));
  107. return 0;
  108. }
  109. }
  110. return 1;
  111. }
  112. static int check_servername(HANDSHAKE_RESULT *result, SSL_TEST_CTX *test_ctx)
  113. {
  114. if (!TEST_int_eq(result->servername, test_ctx->expected_servername)) {
  115. TEST_info("Client ServerName mismatch, expected %s, got %s.",
  116. ssl_servername_name(test_ctx->expected_servername),
  117. ssl_servername_name(result->servername));
  118. return 0;
  119. }
  120. return 1;
  121. }
  122. static int check_session_ticket(HANDSHAKE_RESULT *result, SSL_TEST_CTX *test_ctx)
  123. {
  124. if (test_ctx->session_ticket_expected == SSL_TEST_SESSION_TICKET_IGNORE)
  125. return 1;
  126. if (!TEST_int_eq(result->session_ticket,
  127. test_ctx->session_ticket_expected)) {
  128. TEST_info("Client SessionTicketExpected mismatch, expected %s, got %s.",
  129. ssl_session_ticket_name(test_ctx->session_ticket_expected),
  130. ssl_session_ticket_name(result->session_ticket));
  131. return 0;
  132. }
  133. return 1;
  134. }
  135. static int check_session_id(HANDSHAKE_RESULT *result, SSL_TEST_CTX *test_ctx)
  136. {
  137. if (test_ctx->session_id_expected == SSL_TEST_SESSION_ID_IGNORE)
  138. return 1;
  139. if (!TEST_int_eq(result->session_id, test_ctx->session_id_expected)) {
  140. TEST_info("Client SessionIdExpected mismatch, expected %s, got %s\n.",
  141. ssl_session_id_name(test_ctx->session_id_expected),
  142. ssl_session_id_name(result->session_id));
  143. return 0;
  144. }
  145. return 1;
  146. }
  147. static int check_compression(HANDSHAKE_RESULT *result, SSL_TEST_CTX *test_ctx)
  148. {
  149. if (!TEST_int_eq(result->compression, test_ctx->compression_expected))
  150. return 0;
  151. return 1;
  152. }
  153. #ifndef OPENSSL_NO_NEXTPROTONEG
  154. static int check_npn(HANDSHAKE_RESULT *result, SSL_TEST_CTX *test_ctx)
  155. {
  156. int ret = 1;
  157. if (!TEST_str_eq(result->client_npn_negotiated,
  158. result->server_npn_negotiated))
  159. ret = 0;
  160. if (!TEST_str_eq(test_ctx->expected_npn_protocol,
  161. result->client_npn_negotiated))
  162. ret = 0;
  163. return ret;
  164. }
  165. #endif
  166. static int check_alpn(HANDSHAKE_RESULT *result, SSL_TEST_CTX *test_ctx)
  167. {
  168. int ret = 1;
  169. if (!TEST_str_eq(result->client_alpn_negotiated,
  170. result->server_alpn_negotiated))
  171. ret = 0;
  172. if (!TEST_str_eq(test_ctx->expected_alpn_protocol,
  173. result->client_alpn_negotiated))
  174. ret = 0;
  175. return ret;
  176. }
  177. static int check_session_ticket_app_data(HANDSHAKE_RESULT *result,
  178. SSL_TEST_CTX *test_ctx)
  179. {
  180. size_t result_len = 0;
  181. size_t expected_len = 0;
  182. /* consider empty and NULL strings to be the same */
  183. if (result->result_session_ticket_app_data != NULL)
  184. result_len = strlen(result->result_session_ticket_app_data);
  185. if (test_ctx->expected_session_ticket_app_data != NULL)
  186. expected_len = strlen(test_ctx->expected_session_ticket_app_data);
  187. if (result_len == 0 && expected_len == 0)
  188. return 1;
  189. if (!TEST_str_eq(result->result_session_ticket_app_data,
  190. test_ctx->expected_session_ticket_app_data))
  191. return 0;
  192. return 1;
  193. }
  194. static int check_resumption(HANDSHAKE_RESULT *result, SSL_TEST_CTX *test_ctx)
  195. {
  196. if (!TEST_int_eq(result->client_resumed, result->server_resumed))
  197. return 0;
  198. if (!TEST_int_eq(result->client_resumed, test_ctx->resumption_expected))
  199. return 0;
  200. return 1;
  201. }
  202. static int check_nid(const char *name, int expected_nid, int nid)
  203. {
  204. if (expected_nid == 0 || expected_nid == nid)
  205. return 1;
  206. TEST_error("%s type mismatch, %s vs %s\n",
  207. name, OBJ_nid2ln(expected_nid),
  208. nid == NID_undef ? "absent" : OBJ_nid2ln(nid));
  209. return 0;
  210. }
  211. static void print_ca_names(STACK_OF(X509_NAME) *names)
  212. {
  213. int i;
  214. if (names == NULL || sk_X509_NAME_num(names) == 0) {
  215. TEST_note(" <empty>");
  216. return;
  217. }
  218. for (i = 0; i < sk_X509_NAME_num(names); i++) {
  219. X509_NAME_print_ex(bio_err, sk_X509_NAME_value(names, i), 4,
  220. XN_FLAG_ONELINE);
  221. BIO_puts(bio_err, "\n");
  222. }
  223. }
  224. static int check_ca_names(const char *name,
  225. STACK_OF(X509_NAME) *expected_names,
  226. STACK_OF(X509_NAME) *names)
  227. {
  228. int i;
  229. if (expected_names == NULL)
  230. return 1;
  231. if (names == NULL || sk_X509_NAME_num(names) == 0) {
  232. if (TEST_int_eq(sk_X509_NAME_num(expected_names), 0))
  233. return 1;
  234. goto err;
  235. }
  236. if (sk_X509_NAME_num(names) != sk_X509_NAME_num(expected_names))
  237. goto err;
  238. for (i = 0; i < sk_X509_NAME_num(names); i++) {
  239. if (!TEST_int_eq(X509_NAME_cmp(sk_X509_NAME_value(names, i),
  240. sk_X509_NAME_value(expected_names, i)),
  241. 0)) {
  242. goto err;
  243. }
  244. }
  245. return 1;
  246. err:
  247. TEST_info("%s: list mismatch", name);
  248. TEST_note("Expected Names:");
  249. print_ca_names(expected_names);
  250. TEST_note("Received Names:");
  251. print_ca_names(names);
  252. return 0;
  253. }
  254. static int check_tmp_key(HANDSHAKE_RESULT *result, SSL_TEST_CTX *test_ctx)
  255. {
  256. return check_nid("Tmp key", test_ctx->expected_tmp_key_type,
  257. result->tmp_key_type);
  258. }
  259. static int check_server_cert_type(HANDSHAKE_RESULT *result,
  260. SSL_TEST_CTX *test_ctx)
  261. {
  262. return check_nid("Server certificate", test_ctx->expected_server_cert_type,
  263. result->server_cert_type);
  264. }
  265. static int check_server_sign_hash(HANDSHAKE_RESULT *result,
  266. SSL_TEST_CTX *test_ctx)
  267. {
  268. return check_nid("Server signing hash", test_ctx->expected_server_sign_hash,
  269. result->server_sign_hash);
  270. }
  271. static int check_server_sign_type(HANDSHAKE_RESULT *result,
  272. SSL_TEST_CTX *test_ctx)
  273. {
  274. return check_nid("Server signing", test_ctx->expected_server_sign_type,
  275. result->server_sign_type);
  276. }
  277. static int check_server_ca_names(HANDSHAKE_RESULT *result,
  278. SSL_TEST_CTX *test_ctx)
  279. {
  280. return check_ca_names("Server CA names",
  281. test_ctx->expected_server_ca_names,
  282. result->server_ca_names);
  283. }
  284. static int check_client_cert_type(HANDSHAKE_RESULT *result,
  285. SSL_TEST_CTX *test_ctx)
  286. {
  287. return check_nid("Client certificate", test_ctx->expected_client_cert_type,
  288. result->client_cert_type);
  289. }
  290. static int check_client_sign_hash(HANDSHAKE_RESULT *result,
  291. SSL_TEST_CTX *test_ctx)
  292. {
  293. return check_nid("Client signing hash", test_ctx->expected_client_sign_hash,
  294. result->client_sign_hash);
  295. }
  296. static int check_client_sign_type(HANDSHAKE_RESULT *result,
  297. SSL_TEST_CTX *test_ctx)
  298. {
  299. return check_nid("Client signing", test_ctx->expected_client_sign_type,
  300. result->client_sign_type);
  301. }
  302. static int check_client_ca_names(HANDSHAKE_RESULT *result,
  303. SSL_TEST_CTX *test_ctx)
  304. {
  305. return check_ca_names("Client CA names",
  306. test_ctx->expected_client_ca_names,
  307. result->client_ca_names);
  308. }
  309. static int check_cipher(HANDSHAKE_RESULT *result, SSL_TEST_CTX *test_ctx)
  310. {
  311. if (test_ctx->expected_cipher == NULL)
  312. return 1;
  313. if (!TEST_ptr(result->cipher))
  314. return 0;
  315. if (!TEST_str_eq(test_ctx->expected_cipher,
  316. result->cipher))
  317. return 0;
  318. return 1;
  319. }
  320. /*
  321. * This could be further simplified by constructing an expected
  322. * HANDSHAKE_RESULT, and implementing comparison methods for
  323. * its fields.
  324. */
  325. static int check_test(HANDSHAKE_RESULT *result, SSL_TEST_CTX *test_ctx)
  326. {
  327. int ret = 1;
  328. ret &= check_result(result, test_ctx);
  329. ret &= check_alerts(result, test_ctx);
  330. if (result->result == SSL_TEST_SUCCESS) {
  331. ret &= check_protocol(result, test_ctx);
  332. ret &= check_servername(result, test_ctx);
  333. ret &= check_session_ticket(result, test_ctx);
  334. ret &= check_compression(result, test_ctx);
  335. ret &= check_session_id(result, test_ctx);
  336. ret &= (result->session_ticket_do_not_call == 0);
  337. #ifndef OPENSSL_NO_NEXTPROTONEG
  338. ret &= check_npn(result, test_ctx);
  339. #endif
  340. ret &= check_cipher(result, test_ctx);
  341. ret &= check_alpn(result, test_ctx);
  342. ret &= check_session_ticket_app_data(result, test_ctx);
  343. ret &= check_resumption(result, test_ctx);
  344. ret &= check_tmp_key(result, test_ctx);
  345. ret &= check_server_cert_type(result, test_ctx);
  346. ret &= check_server_sign_hash(result, test_ctx);
  347. ret &= check_server_sign_type(result, test_ctx);
  348. ret &= check_server_ca_names(result, test_ctx);
  349. ret &= check_client_cert_type(result, test_ctx);
  350. ret &= check_client_sign_hash(result, test_ctx);
  351. ret &= check_client_sign_type(result, test_ctx);
  352. ret &= check_client_ca_names(result, test_ctx);
  353. }
  354. return ret;
  355. }
  356. static int test_handshake(int idx)
  357. {
  358. int ret = 0;
  359. SSL_CTX *server_ctx = NULL, *server2_ctx = NULL, *client_ctx = NULL,
  360. *resume_server_ctx = NULL, *resume_client_ctx = NULL;
  361. SSL_TEST_CTX *test_ctx = NULL;
  362. HANDSHAKE_RESULT *result = NULL;
  363. char test_app[MAX_TESTCASE_NAME_LENGTH];
  364. BIO_snprintf(test_app, sizeof(test_app), "test-%d", idx);
  365. test_ctx = SSL_TEST_CTX_create(conf, test_app, libctx);
  366. if (!TEST_ptr(test_ctx))
  367. goto err;
  368. #ifndef OPENSSL_NO_DTLS
  369. if (test_ctx->method == SSL_TEST_METHOD_DTLS) {
  370. server_ctx = SSL_CTX_new_ex(libctx, NULL, DTLS_server_method());
  371. if (!TEST_true(SSL_CTX_set_options(server_ctx,
  372. SSL_OP_ALLOW_CLIENT_RENEGOTIATION))
  373. || !TEST_true(SSL_CTX_set_max_proto_version(server_ctx, 0)))
  374. goto err;
  375. if (test_ctx->extra.server.servername_callback !=
  376. SSL_TEST_SERVERNAME_CB_NONE) {
  377. if (!TEST_ptr(server2_ctx =
  378. SSL_CTX_new_ex(libctx, NULL, DTLS_server_method()))
  379. || !TEST_true(SSL_CTX_set_options(server2_ctx,
  380. SSL_OP_ALLOW_CLIENT_RENEGOTIATION)))
  381. goto err;
  382. }
  383. client_ctx = SSL_CTX_new_ex(libctx, NULL, DTLS_client_method());
  384. if (!TEST_true(SSL_CTX_set_max_proto_version(client_ctx, 0)))
  385. goto err;
  386. if (test_ctx->handshake_mode == SSL_TEST_HANDSHAKE_RESUME) {
  387. resume_server_ctx = SSL_CTX_new_ex(libctx, NULL,
  388. DTLS_server_method());
  389. if (!TEST_true(SSL_CTX_set_max_proto_version(resume_server_ctx, 0))
  390. || !TEST_true(SSL_CTX_set_options(resume_server_ctx,
  391. SSL_OP_ALLOW_CLIENT_RENEGOTIATION)))
  392. goto err;
  393. resume_client_ctx = SSL_CTX_new_ex(libctx, NULL,
  394. DTLS_client_method());
  395. if (!TEST_true(SSL_CTX_set_max_proto_version(resume_client_ctx, 0)))
  396. goto err;
  397. if (!TEST_ptr(resume_server_ctx)
  398. || !TEST_ptr(resume_client_ctx))
  399. goto err;
  400. }
  401. }
  402. #endif
  403. if (test_ctx->method == SSL_TEST_METHOD_TLS) {
  404. #if !defined(OPENSSL_NO_TLS1_3) \
  405. && defined(OPENSSL_NO_EC) \
  406. && defined(OPENSSL_NO_DH)
  407. /* Without ec or dh there are no built-in groups for TLSv1.3 */
  408. int maxversion = TLS1_2_VERSION;
  409. #else
  410. int maxversion = 0;
  411. #endif
  412. server_ctx = SSL_CTX_new_ex(libctx, NULL, TLS_server_method());
  413. if (!TEST_true(SSL_CTX_set_max_proto_version(server_ctx, maxversion))
  414. || !TEST_true(SSL_CTX_set_options(server_ctx,
  415. SSL_OP_ALLOW_CLIENT_RENEGOTIATION)))
  416. goto err;
  417. /* SNI on resumption isn't supported/tested yet. */
  418. if (test_ctx->extra.server.servername_callback !=
  419. SSL_TEST_SERVERNAME_CB_NONE) {
  420. if (!TEST_ptr(server2_ctx =
  421. SSL_CTX_new_ex(libctx, NULL, TLS_server_method()))
  422. || !TEST_true(SSL_CTX_set_options(server2_ctx,
  423. SSL_OP_ALLOW_CLIENT_RENEGOTIATION)))
  424. goto err;
  425. if (!TEST_true(SSL_CTX_set_max_proto_version(server2_ctx,
  426. maxversion)))
  427. goto err;
  428. }
  429. client_ctx = SSL_CTX_new_ex(libctx, NULL, TLS_client_method());
  430. if (!TEST_true(SSL_CTX_set_max_proto_version(client_ctx, maxversion)))
  431. goto err;
  432. if (test_ctx->handshake_mode == SSL_TEST_HANDSHAKE_RESUME) {
  433. resume_server_ctx = SSL_CTX_new_ex(libctx, NULL,
  434. TLS_server_method());
  435. if (!TEST_true(SSL_CTX_set_max_proto_version(resume_server_ctx,
  436. maxversion))
  437. || !TEST_true(SSL_CTX_set_options(resume_server_ctx,
  438. SSL_OP_ALLOW_CLIENT_RENEGOTIATION)))
  439. goto err;
  440. resume_client_ctx = SSL_CTX_new_ex(libctx, NULL,
  441. TLS_client_method());
  442. if (!TEST_true(SSL_CTX_set_max_proto_version(resume_client_ctx,
  443. maxversion)))
  444. goto err;
  445. if (!TEST_ptr(resume_server_ctx)
  446. || !TEST_ptr(resume_client_ctx))
  447. goto err;
  448. }
  449. }
  450. #ifndef OPENSSL_NO_QUIC
  451. if (test_ctx->method == SSL_TEST_METHOD_QUIC) {
  452. server_ctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_server_method());
  453. if (test_ctx->extra.server.servername_callback !=
  454. SSL_TEST_SERVERNAME_CB_NONE) {
  455. if (!TEST_ptr(server2_ctx =
  456. SSL_CTX_new_ex(libctx, NULL,
  457. OSSL_QUIC_server_method())))
  458. goto err;
  459. }
  460. client_ctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
  461. if (test_ctx->handshake_mode == SSL_TEST_HANDSHAKE_RESUME) {
  462. resume_server_ctx = SSL_CTX_new_ex(libctx, NULL,
  463. OSSL_QUIC_server_method());
  464. resume_client_ctx = SSL_CTX_new_ex(libctx, NULL,
  465. OSSL_QUIC_client_method());
  466. if (!TEST_ptr(resume_server_ctx)
  467. || !TEST_ptr(resume_client_ctx))
  468. goto err;
  469. }
  470. }
  471. #endif
  472. #ifdef OPENSSL_NO_AUTOLOAD_CONFIG
  473. if (!TEST_true(OPENSSL_init_ssl(OPENSSL_INIT_LOAD_CONFIG, NULL)))
  474. goto err;
  475. #endif
  476. if (!TEST_ptr(server_ctx)
  477. || !TEST_ptr(client_ctx)
  478. || !TEST_int_gt(CONF_modules_load(conf, test_app, 0), 0))
  479. goto err;
  480. if (!SSL_CTX_config(server_ctx, "server")
  481. || !SSL_CTX_config(client_ctx, "client")) {
  482. goto err;
  483. }
  484. if (server2_ctx != NULL && !SSL_CTX_config(server2_ctx, "server2"))
  485. goto err;
  486. if (resume_server_ctx != NULL
  487. && !SSL_CTX_config(resume_server_ctx, "resume-server"))
  488. goto err;
  489. if (resume_client_ctx != NULL
  490. && !SSL_CTX_config(resume_client_ctx, "resume-client"))
  491. goto err;
  492. result = do_handshake(server_ctx, server2_ctx, client_ctx,
  493. resume_server_ctx, resume_client_ctx, test_ctx);
  494. if (result != NULL)
  495. ret = check_test(result, test_ctx);
  496. err:
  497. CONF_modules_unload(0);
  498. SSL_CTX_free(server_ctx);
  499. SSL_CTX_free(server2_ctx);
  500. SSL_CTX_free(client_ctx);
  501. SSL_CTX_free(resume_server_ctx);
  502. SSL_CTX_free(resume_client_ctx);
  503. SSL_TEST_CTX_free(test_ctx);
  504. HANDSHAKE_RESULT_free(result);
  505. return ret;
  506. }
  507. #define USAGE "conf_file module_name [module_conf_file]\n"
  508. OPT_TEST_DECLARE_USAGE(USAGE)
  509. int setup_tests(void)
  510. {
  511. long num_tests;
  512. if (!test_skip_common_options()) {
  513. TEST_error("Error parsing test options\n");
  514. return 0;
  515. }
  516. if (!TEST_ptr(conf = NCONF_new(NULL))
  517. /* argv[1] should point to the test conf file */
  518. || !TEST_int_gt(NCONF_load(conf, test_get_argument(0), NULL), 0)
  519. || !TEST_int_ne(NCONF_get_number_e(conf, NULL, "num_tests",
  520. &num_tests), 0)) {
  521. TEST_error("usage: ssl_test %s", USAGE);
  522. return 0;
  523. }
  524. if (!test_arg_libctx(&libctx, &defctxnull, &thisprov, 1, USAGE))
  525. return 0;
  526. ADD_ALL_TESTS(test_handshake, (int)num_tests);
  527. return 1;
  528. }
  529. void cleanup_tests(void)
  530. {
  531. NCONF_free(conf);
  532. OSSL_PROVIDER_unload(defctxnull);
  533. OSSL_PROVIDER_unload(thisprov);
  534. OSSL_LIB_CTX_free(libctx);
  535. }