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