[packettest] Fix misplaced parentheses
[openssl.git] / test / ssl_test_ctx.h
1 /*
2  * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * 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
7  * https://www.openssl.org/source/license.html
8  */
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
16 typedef enum {
17     SSL_TEST_SUCCESS = 0,  /* Default */
18     SSL_TEST_SERVER_FAIL,
19     SSL_TEST_CLIENT_FAIL,
20     SSL_TEST_INTERNAL_ERROR,
21     /* Couldn't test resumption/renegotiation: original handshake failed. */
22     SSL_TEST_FIRST_HANDSHAKE_FAILED
23 } ssl_test_result_t;
24
25 typedef 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
31 typedef enum {
32     SSL_TEST_SERVERNAME_NONE = 0, /* Default */
33     SSL_TEST_SERVERNAME_SERVER1,
34     SSL_TEST_SERVERNAME_SERVER2,
35     SSL_TEST_SERVERNAME_INVALID
36 } ssl_servername_t;
37
38 typedef enum {
39     SSL_TEST_SERVERNAME_CB_NONE = 0,  /* Default */
40     SSL_TEST_SERVERNAME_IGNORE_MISMATCH,
41     SSL_TEST_SERVERNAME_REJECT_MISMATCH,
42     SSL_TEST_SERVERNAME_CLIENT_HELLO_IGNORE_MISMATCH,
43     SSL_TEST_SERVERNAME_CLIENT_HELLO_REJECT_MISMATCH,
44     SSL_TEST_SERVERNAME_CLIENT_HELLO_NO_V12
45 } ssl_servername_callback_t;
46
47 typedef enum {
48     SSL_TEST_SESSION_TICKET_IGNORE = 0, /* Default */
49     SSL_TEST_SESSION_TICKET_YES,
50     SSL_TEST_SESSION_TICKET_NO,
51     SSL_TEST_SESSION_TICKET_BROKEN /* Special test */
52 } ssl_session_ticket_t;
53
54 typedef enum {
55     SSL_TEST_COMPRESSION_NO = 0, /* Default */
56     SSL_TEST_COMPRESSION_YES
57 } ssl_compression_t;
58
59 typedef enum {
60     SSL_TEST_SESSION_ID_IGNORE = 0, /* Default */
61     SSL_TEST_SESSION_ID_YES,
62     SSL_TEST_SESSION_ID_NO
63 } ssl_session_id_t;
64
65 typedef enum {
66     SSL_TEST_METHOD_TLS = 0, /* Default */
67     SSL_TEST_METHOD_DTLS
68 } ssl_test_method_t;
69
70 typedef enum {
71     SSL_TEST_HANDSHAKE_SIMPLE = 0, /* Default */
72     SSL_TEST_HANDSHAKE_RESUME,
73     SSL_TEST_HANDSHAKE_RENEG_SERVER,
74     SSL_TEST_HANDSHAKE_RENEG_CLIENT,
75     SSL_TEST_HANDSHAKE_KEY_UPDATE_SERVER,
76     SSL_TEST_HANDSHAKE_KEY_UPDATE_CLIENT
77 } ssl_handshake_mode_t;
78
79 typedef enum {
80     SSL_TEST_CT_VALIDATION_NONE = 0, /* Default */
81     SSL_TEST_CT_VALIDATION_PERMISSIVE,
82     SSL_TEST_CT_VALIDATION_STRICT
83 } ssl_ct_validation_t;
84
85 typedef enum {
86     SSL_TEST_CERT_STATUS_NONE = 0, /* Default */
87     SSL_TEST_CERT_STATUS_GOOD_RESPONSE,
88     SSL_TEST_CERT_STATUS_BAD_RESPONSE
89 } ssl_cert_status_t;
90
91 /*
92  * Server/client settings that aren't supported by the SSL CONF library,
93  * such as callbacks.
94  */
95 typedef struct {
96     /* One of a number of predefined custom callbacks. */
97     ssl_verify_callback_t verify_callback;
98     /* One of a number of predefined server names use by the client */
99     ssl_servername_t servername;
100     /* Supported NPN and ALPN protocols. A comma-separated list. */
101     char *npn_protocols;
102     char *alpn_protocols;
103     ssl_ct_validation_t ct_validation;
104     /* Ciphersuites to set on a renegotiation */
105     char *reneg_ciphers;
106     char *srp_user;
107     char *srp_password;
108 } SSL_TEST_CLIENT_CONF;
109
110 typedef struct {
111     /* SNI callback (server-side). */
112     ssl_servername_callback_t servername_callback;
113     /* Supported NPN and ALPN protocols. A comma-separated list. */
114     char *npn_protocols;
115     char *alpn_protocols;
116     /* Whether to set a broken session ticket callback. */
117     int broken_session_ticket;
118     /* Should we send a CertStatus message? */
119     ssl_cert_status_t cert_status;
120     /* An SRP user known to the server. */
121     char *srp_user;
122     char *srp_password;
123 } SSL_TEST_SERVER_CONF;
124
125 typedef struct {
126     SSL_TEST_CLIENT_CONF client;
127     SSL_TEST_SERVER_CONF server;
128     SSL_TEST_SERVER_CONF server2;
129 } SSL_TEST_EXTRA_CONF;
130
131 typedef struct {
132     /*
133      * Global test configuration. Does not change between handshakes.
134      */
135     /* Whether the server/client CTX should use DTLS or TLS. */
136     ssl_test_method_t method;
137     /* Whether to test a resumed/renegotiated handshake. */
138     ssl_handshake_mode_t handshake_mode;
139     /*
140      * How much application data to exchange (default is 256 bytes).
141      * Both peers will send |app_data_size| bytes interleaved.
142      */
143     int app_data_size;
144     /* Maximum send fragment size. */
145     int max_fragment_size;
146     /* KeyUpdate type */
147     int key_update_type;
148
149     /*
150      * Extra server/client configurations. Per-handshake.
151      */
152     /* First handshake. */
153     SSL_TEST_EXTRA_CONF extra;
154     /* Resumed handshake. */
155     SSL_TEST_EXTRA_CONF resume_extra;
156
157     /*
158      * Test expectations. These apply to the LAST handshake.
159      */
160     /* Defaults to SUCCESS. */
161     ssl_test_result_t expected_result;
162     /* Alerts. 0 if no expectation. */
163     /* See ssl.h for alert codes. */
164     /* Alert sent by the client / received by the server. */
165     int expected_client_alert;
166     /* Alert sent by the server / received by the client. */
167     int expected_server_alert;
168     /* Negotiated protocol version. 0 if no expectation. */
169     /* See ssl.h for protocol versions. */
170     int expected_protocol;
171     /*
172      * The expected SNI context to use.
173      * We test server-side that the server switched to the expected context.
174      * Set by the callback upon success, so if the callback wasn't called or
175      * terminated with an alert, the servername will match with
176      * SSL_TEST_SERVERNAME_NONE.
177      * Note: in the event that the servername was accepted, the client should
178      * also receive an empty SNI extension back but we have no way of probing
179      * client-side via the API that this was the case.
180      */
181     ssl_servername_t expected_servername;
182     ssl_session_ticket_t session_ticket_expected;
183     int compression_expected;
184     /* The expected NPN/ALPN protocol to negotiate. */
185     char *expected_npn_protocol;
186     char *expected_alpn_protocol;
187     /* Whether the second handshake is resumed or a full handshake (boolean). */
188     int resumption_expected;
189     /* Expected temporary key type */
190     int expected_tmp_key_type;
191     /* Expected server certificate key type */
192     int expected_server_cert_type;
193     /* Expected server signing hash */
194     int expected_server_sign_hash;
195     /* Expected server signature type */
196     int expected_server_sign_type;
197     /* Expected server CA names */
198     STACK_OF(X509_NAME) *expected_server_ca_names;
199     /* Expected client certificate key type */
200     int expected_client_cert_type;
201     /* Expected client signing hash */
202     int expected_client_sign_hash;
203     /* Expected client signature type */
204     int expected_client_sign_type;
205     /* Expected CA names for client auth */
206     STACK_OF(X509_NAME) *expected_client_ca_names;
207     /* Whether to use SCTP for the transport */
208     int use_sctp;
209     /* Whether to expect a session id from the server */
210     ssl_session_id_t session_id_expected;
211 } SSL_TEST_CTX;
212
213 const char *ssl_test_result_name(ssl_test_result_t result);
214 const char *ssl_alert_name(int alert);
215 const char *ssl_protocol_name(int protocol);
216 const char *ssl_verify_callback_name(ssl_verify_callback_t verify_callback);
217 const char *ssl_servername_name(ssl_servername_t server);
218 const char *ssl_servername_callback_name(ssl_servername_callback_t
219                                          servername_callback);
220 const char *ssl_session_ticket_name(ssl_session_ticket_t server);
221 const char *ssl_session_id_name(ssl_session_id_t server);
222 const char *ssl_test_method_name(ssl_test_method_t method);
223 const char *ssl_handshake_mode_name(ssl_handshake_mode_t mode);
224 const char *ssl_ct_validation_name(ssl_ct_validation_t mode);
225 const char *ssl_certstatus_name(ssl_cert_status_t cert_status);
226
227 /*
228  * Load the test case context from |conf|.
229  * See test/README.ssltest.md for details on the conf file format.
230  */
231 SSL_TEST_CTX *SSL_TEST_CTX_create(const CONF *conf, const char *test_section);
232
233 SSL_TEST_CTX *SSL_TEST_CTX_new(void);
234
235 void SSL_TEST_CTX_free(SSL_TEST_CTX *ctx);
236
237 #endif  /* HEADER_SSL_TEST_CTX_H */