blob: 3d8f72bbe58d1daaf9887979606f9a6ff68a2012 [file] [log] [blame]
Emilia Kasper453dfd82016-03-17 15:14:30 +01001/*
2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
Rich Salz440e5d82016-05-17 14:20:24 -04004 * Licensed under the OpenSSL license (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
Emilia Kasper453dfd82016-03-17 15:14:30 +01007 * https://www.openssl.org/source/license.html
Emilia Kasper453dfd82016-03-17 15:14:30 +01008 */
9
10#ifndef HEADER_SSL_TEST_CTX_H
11#define HEADER_SSL_TEST_CTX_H
12
13#include <openssl/conf.h>
14#include <openssl/ssl.h>
15
16typedef enum {
Emilia Kaspera263f322016-04-07 19:07:50 +020017 SSL_TEST_SUCCESS = 0, /* Default */
Emilia Kasper453dfd82016-03-17 15:14:30 +010018 SSL_TEST_SERVER_FAIL,
19 SSL_TEST_CLIENT_FAIL,
Emilia Kasper590ed3d2016-07-05 19:06:23 +020020 SSL_TEST_INTERNAL_ERROR,
21 /* Couldn't test resumption/renegotiation: original handshake failed. */
22 SSL_TEST_FIRST_HANDSHAKE_FAILED
Emilia Kasper453dfd82016-03-17 15:14:30 +010023} ssl_test_result_t;
24
Emilia Kaspera263f322016-04-07 19:07:50 +020025typedef enum {
26 SSL_TEST_VERIFY_NONE = 0, /* Default */
27 SSL_TEST_VERIFY_ACCEPT_ALL,
28 SSL_TEST_VERIFY_REJECT_ALL
29} ssl_verify_callback_t;
30
Todd Short5c753de2016-05-12 18:16:52 -040031typedef enum {
Emilia Kasper81fc33c2016-06-10 00:39:22 +020032 SSL_TEST_SERVERNAME_NONE = 0, /* Default */
33 SSL_TEST_SERVERNAME_SERVER1,
Emilia Kasperd2b23cd2016-06-20 17:20:25 +020034 SSL_TEST_SERVERNAME_SERVER2,
35 SSL_TEST_SERVERNAME_INVALID
Todd Short5c753de2016-05-12 18:16:52 -040036} ssl_servername_t;
37
38typedef enum {
Emilia Kasperd2b23cd2016-06-20 17:20:25 +020039 SSL_TEST_SERVERNAME_CB_NONE = 0, /* Default */
40 SSL_TEST_SERVERNAME_IGNORE_MISMATCH,
Benjamin Kaduk80de0c52017-01-31 16:06:30 -060041 SSL_TEST_SERVERNAME_REJECT_MISMATCH,
42 SSL_TEST_SERVERNAME_EARLY_IGNORE_MISMATCH,
43 SSL_TEST_SERVERNAME_EARLY_REJECT_MISMATCH,
44 SSL_TEST_SERVERNAME_EARLY_NO_V12
Emilia Kasperd2b23cd2016-06-20 17:20:25 +020045} ssl_servername_callback_t;
46
Emilia Kasperd2b23cd2016-06-20 17:20:25 +020047typedef enum {
Todd Short5c753de2016-05-12 18:16:52 -040048 SSL_TEST_SESSION_TICKET_IGNORE = 0, /* Default */
49 SSL_TEST_SESSION_TICKET_YES,
50 SSL_TEST_SESSION_TICKET_NO,
Rich Salzd3b64b82016-06-16 14:49:37 -040051 SSL_TEST_SESSION_TICKET_BROKEN /* Special test */
Emilia Kasper81fc33c2016-06-10 00:39:22 +020052} ssl_session_ticket_t;
Todd Short5c753de2016-05-12 18:16:52 -040053
Emilia Kasper74726752016-06-03 17:49:04 +020054typedef enum {
Matt Caswell439db0c2017-03-01 12:11:51 +000055 SSL_TEST_COMPRESSION_NO = 0, /* Default */
56 SSL_TEST_COMPRESSION_YES
57} ssl_compression_t;
58
59typedef enum {
Emilia Kasper74726752016-06-03 17:49:04 +020060 SSL_TEST_METHOD_TLS = 0, /* Default */
Rich Salzd3b64b82016-06-16 14:49:37 -040061 SSL_TEST_METHOD_DTLS
Emilia Kasper74726752016-06-03 17:49:04 +020062} ssl_test_method_t;
63
Emilia Kasper590ed3d2016-07-05 19:06:23 +020064typedef enum {
65 SSL_TEST_HANDSHAKE_SIMPLE = 0, /* Default */
66 SSL_TEST_HANDSHAKE_RESUME,
Matt Caswellfe7dd552016-09-27 11:50:43 +010067 SSL_TEST_HANDSHAKE_RENEG_SERVER,
Matt Caswell9b92f162017-02-15 09:25:52 +000068 SSL_TEST_HANDSHAKE_RENEG_CLIENT,
69 SSL_TEST_HANDSHAKE_KEY_UPDATE_SERVER,
70 SSL_TEST_HANDSHAKE_KEY_UPDATE_CLIENT
Emilia Kasper590ed3d2016-07-05 19:06:23 +020071} ssl_handshake_mode_t;
72
Emilia Kasperda085d22016-08-09 16:47:26 +020073typedef enum {
74 SSL_TEST_CT_VALIDATION_NONE = 0, /* Default */
75 SSL_TEST_CT_VALIDATION_PERMISSIVE,
76 SSL_TEST_CT_VALIDATION_STRICT
77} ssl_ct_validation_t;
Matt Caswell767ccc32016-08-30 14:20:18 +010078
79typedef enum {
80 SSL_TEST_CERT_STATUS_NONE = 0, /* Default */
81 SSL_TEST_CERT_STATUS_GOOD_RESPONSE,
82 SSL_TEST_CERT_STATUS_BAD_RESPONSE
83} ssl_cert_status_t;
Emilia Kasperea1ecd92017-03-14 13:48:54 +010084
Emilia Kasper9f48bba2016-07-21 16:29:48 +020085/*
86 * Server/client settings that aren't supported by the SSL CONF library,
87 * such as callbacks.
88 */
89typedef struct {
90 /* One of a number of predefined custom callbacks. */
91 ssl_verify_callback_t verify_callback;
92 /* One of a number of predefined server names use by the client */
93 ssl_servername_t servername;
94 /* Supported NPN and ALPN protocols. A comma-separated list. */
95 char *npn_protocols;
96 char *alpn_protocols;
Emilia Kasperda085d22016-08-09 16:47:26 +020097 ssl_ct_validation_t ct_validation;
Matt Caswellcc22cd52017-02-03 11:21:07 +000098 /* Ciphersuites to set on a renegotiation */
99 char *reneg_ciphers;
Emilia Kasperea1ecd92017-03-14 13:48:54 +0100100 char *srp_user;
101 char *srp_password;
Emilia Kasper9f48bba2016-07-21 16:29:48 +0200102} SSL_TEST_CLIENT_CONF;
103
104typedef struct {
105 /* SNI callback (server-side). */
106 ssl_servername_callback_t servername_callback;
107 /* Supported NPN and ALPN protocols. A comma-separated list. */
108 char *npn_protocols;
109 char *alpn_protocols;
110 /* Whether to set a broken session ticket callback. */
111 int broken_session_ticket;
Matt Caswell767ccc32016-08-30 14:20:18 +0100112 /* Should we send a CertStatus message? */
113 ssl_cert_status_t cert_status;
Emilia Kasperea1ecd92017-03-14 13:48:54 +0100114 /* An SRP user known to the server. */
115 char *srp_user;
116 char *srp_password;
Emilia Kasper9f48bba2016-07-21 16:29:48 +0200117} SSL_TEST_SERVER_CONF;
118
119typedef struct {
120 SSL_TEST_CLIENT_CONF client;
121 SSL_TEST_SERVER_CONF server;
122 SSL_TEST_SERVER_CONF server2;
123} SSL_TEST_EXTRA_CONF;
124
125typedef struct {
126 /*
127 * Global test configuration. Does not change between handshakes.
128 */
129 /* Whether the server/client CTX should use DTLS or TLS. */
130 ssl_test_method_t method;
131 /* Whether to test a resumed/renegotiated handshake. */
132 ssl_handshake_mode_t handshake_mode;
Emilia Kaspere0421bd2016-08-11 20:51:57 +0200133 /*
134 * How much application data to exchange (default is 256 bytes).
135 * Both peers will send |app_data_size| bytes interleaved.
136 */
137 int app_data_size;
Emilia Kasper6dc99742016-08-16 15:11:08 +0200138 /* Maximum send fragment size. */
139 int max_fragment_size;
Matt Caswell9b92f162017-02-15 09:25:52 +0000140 /* KeyUpdate type */
Matt Caswell4fbfe862017-02-16 17:04:40 +0000141 int key_update_type;
Emilia Kasper9f48bba2016-07-21 16:29:48 +0200142
143 /*
144 * Extra server/client configurations. Per-handshake.
145 */
146 /* First handshake. */
147 SSL_TEST_EXTRA_CONF extra;
148 /* Resumed handshake. */
149 SSL_TEST_EXTRA_CONF resume_extra;
150
151 /*
152 * Test expectations. These apply to the LAST handshake.
153 */
Emilia Kasper453dfd82016-03-17 15:14:30 +0100154 /* Defaults to SUCCESS. */
155 ssl_test_result_t expected_result;
156 /* Alerts. 0 if no expectation. */
157 /* See ssl.h for alert codes. */
158 /* Alert sent by the client / received by the server. */
Emilia Kasper9f48bba2016-07-21 16:29:48 +0200159 int expected_client_alert;
Emilia Kasper453dfd82016-03-17 15:14:30 +0100160 /* Alert sent by the server / received by the client. */
Emilia Kasper9f48bba2016-07-21 16:29:48 +0200161 int expected_server_alert;
Emilia Kasper453dfd82016-03-17 15:14:30 +0100162 /* Negotiated protocol version. 0 if no expectation. */
163 /* See ssl.h for protocol versions. */
Emilia Kasper9f48bba2016-07-21 16:29:48 +0200164 int expected_protocol;
Emilia Kasperd2b23cd2016-06-20 17:20:25 +0200165 /*
166 * The expected SNI context to use.
167 * We test server-side that the server switched to the expected context.
168 * Set by the callback upon success, so if the callback wasn't called or
169 * terminated with an alert, the servername will match with
170 * SSL_TEST_SERVERNAME_NONE.
171 * Note: in the event that the servername was accepted, the client should
172 * also receive an empty SNI extension back but we have no way of probing
173 * client-side via the API that this was the case.
174 */
175 ssl_servername_t expected_servername;
Emilia Kasper81fc33c2016-06-10 00:39:22 +0200176 ssl_session_ticket_t session_ticket_expected;
Matt Caswellb6611752017-03-02 13:41:10 +0000177 int compression_expected;
Emilia Kasper9f48bba2016-07-21 16:29:48 +0200178 /* The expected NPN/ALPN protocol to negotiate. */
Emilia Kasperce2cdac2016-07-04 20:16:14 +0200179 char *expected_npn_protocol;
Emilia Kasperce2cdac2016-07-04 20:16:14 +0200180 char *expected_alpn_protocol;
Emilia Kasper590ed3d2016-07-05 19:06:23 +0200181 /* Whether the second handshake is resumed or a full handshake (boolean). */
182 int resumption_expected;
Dr. Stephen Hensonb93ad052017-01-08 00:09:08 +0000183 /* Expected temporary key type */
184 int expected_tmp_key_type;
Dr. Stephen Henson7f5f35a2017-01-08 19:30:41 +0000185 /* Expected server certificate key type */
186 int expected_server_cert_type;
Dr. Stephen Hensonee5b6a42017-01-13 15:20:42 +0000187 /* Expected server signing hash */
188 int expected_server_sign_hash;
Dr. Stephen Henson54b7f2a2017-01-27 15:06:16 +0000189 /* Expected server signature type */
190 int expected_server_sign_type;
Dr. Stephen Henson7f5f35a2017-01-08 19:30:41 +0000191 /* Expected client certificate key type */
192 int expected_client_cert_type;
Dr. Stephen Hensonee5b6a42017-01-13 15:20:42 +0000193 /* Expected client signing hash */
194 int expected_client_sign_hash;
Dr. Stephen Henson54b7f2a2017-01-27 15:06:16 +0000195 /* Expected client signature type */
196 int expected_client_sign_type;
Emilia Kasper453dfd82016-03-17 15:14:30 +0100197} SSL_TEST_CTX;
198
Emilia Kaspera263f322016-04-07 19:07:50 +0200199const char *ssl_test_result_name(ssl_test_result_t result);
Emilia Kasper453dfd82016-03-17 15:14:30 +0100200const char *ssl_alert_name(int alert);
201const char *ssl_protocol_name(int protocol);
Emilia Kaspera263f322016-04-07 19:07:50 +0200202const char *ssl_verify_callback_name(ssl_verify_callback_t verify_callback);
Todd Short5c753de2016-05-12 18:16:52 -0400203const char *ssl_servername_name(ssl_servername_t server);
Emilia Kasperd2b23cd2016-06-20 17:20:25 +0200204const char *ssl_servername_callback_name(ssl_servername_callback_t
205 servername_callback);
Emilia Kasper81fc33c2016-06-10 00:39:22 +0200206const char *ssl_session_ticket_name(ssl_session_ticket_t server);
Emilia Kasper74726752016-06-03 17:49:04 +0200207const char *ssl_test_method_name(ssl_test_method_t method);
Emilia Kasper590ed3d2016-07-05 19:06:23 +0200208const char *ssl_handshake_mode_name(ssl_handshake_mode_t mode);
Emilia Kasperda085d22016-08-09 16:47:26 +0200209const char *ssl_ct_validation_name(ssl_ct_validation_t mode);
Matt Caswell767ccc32016-08-30 14:20:18 +0100210const char *ssl_certstatus_name(ssl_cert_status_t cert_status);
Emilia Kasper453dfd82016-03-17 15:14:30 +0100211
212/*
213 * Load the test case context from |conf|.
Emilia Kasper9f48bba2016-07-21 16:29:48 +0200214 * See test/README.ssltest.md for details on the conf file format.
Emilia Kasper453dfd82016-03-17 15:14:30 +0100215 */
216SSL_TEST_CTX *SSL_TEST_CTX_create(const CONF *conf, const char *test_section);
217
218SSL_TEST_CTX *SSL_TEST_CTX_new(void);
219
220void SSL_TEST_CTX_free(SSL_TEST_CTX *ctx);
221
222#endif /* HEADER_SSL_TEST_CTX_H */