Let test handshakes stop on certain errors
[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_EARLY_IGNORE_MISMATCH,
43     SSL_TEST_SERVERNAME_EARLY_REJECT_MISMATCH,
44     SSL_TEST_SERVERNAME_EARLY_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_METHOD_TLS = 0, /* Default */
56     SSL_TEST_METHOD_DTLS
57 } ssl_test_method_t;
58
59 typedef enum {
60     SSL_TEST_HANDSHAKE_SIMPLE = 0, /* Default */
61     SSL_TEST_HANDSHAKE_RESUME,
62     SSL_TEST_HANDSHAKE_RENEG_SERVER,
63     SSL_TEST_HANDSHAKE_RENEG_CLIENT,
64     SSL_TEST_HANDSHAKE_KEY_UPDATE_SERVER,
65     SSL_TEST_HANDSHAKE_KEY_UPDATE_CLIENT
66 } ssl_handshake_mode_t;
67
68 typedef enum {
69     SSL_TEST_CT_VALIDATION_NONE = 0, /* Default */
70     SSL_TEST_CT_VALIDATION_PERMISSIVE,
71     SSL_TEST_CT_VALIDATION_STRICT
72 } ssl_ct_validation_t;
73
74 typedef enum {
75     SSL_TEST_CERT_STATUS_NONE = 0, /* Default */
76     SSL_TEST_CERT_STATUS_GOOD_RESPONSE,
77     SSL_TEST_CERT_STATUS_BAD_RESPONSE
78 } ssl_cert_status_t;
79 /*
80  * Server/client settings that aren't supported by the SSL CONF library,
81  * such as callbacks.
82  */
83 typedef struct {
84     /* One of a number of predefined custom callbacks. */
85     ssl_verify_callback_t verify_callback;
86     /* One of a number of predefined server names use by the client */
87     ssl_servername_t servername;
88     /* Supported NPN and ALPN protocols. A comma-separated list. */
89     char *npn_protocols;
90     char *alpn_protocols;
91     ssl_ct_validation_t ct_validation;
92     /* Ciphersuites to set on a renegotiation */
93     char *reneg_ciphers;
94 } SSL_TEST_CLIENT_CONF;
95
96 typedef struct {
97     /* SNI callback (server-side). */
98     ssl_servername_callback_t servername_callback;
99     /* Supported NPN and ALPN protocols. A comma-separated list. */
100     char *npn_protocols;
101     char *alpn_protocols;
102     /* Whether to set a broken session ticket callback. */
103     int broken_session_ticket;
104     /* Should we send a CertStatus message? */
105     ssl_cert_status_t cert_status;
106 } SSL_TEST_SERVER_CONF;
107
108 typedef struct {
109     SSL_TEST_CLIENT_CONF client;
110     SSL_TEST_SERVER_CONF server;
111     SSL_TEST_SERVER_CONF server2;
112 } SSL_TEST_EXTRA_CONF;
113
114 typedef struct {
115     /*
116      * Global test configuration. Does not change between handshakes.
117      */
118     /* Whether the server/client CTX should use DTLS or TLS. */
119     ssl_test_method_t method;
120     /* Whether to test a resumed/renegotiated handshake. */
121     ssl_handshake_mode_t handshake_mode;
122     /*
123      * How much application data to exchange (default is 256 bytes).
124      * Both peers will send |app_data_size| bytes interleaved.
125      */
126     int app_data_size;
127     /* Maximum send fragment size. */
128     int max_fragment_size;
129     /* KeyUpdate type */
130     int key_update_type;
131
132     /*
133      * Extra server/client configurations. Per-handshake.
134      */
135     /* First handshake. */
136     SSL_TEST_EXTRA_CONF extra;
137     /* Resumed handshake. */
138     SSL_TEST_EXTRA_CONF resume_extra;
139
140     /*
141      * Test expectations. These apply to the LAST handshake.
142      */
143     /* Defaults to SUCCESS. */
144     ssl_test_result_t expected_result;
145     /* Alerts. 0 if no expectation. */
146     /* See ssl.h for alert codes. */
147     /* Alert sent by the client / received by the server. */
148     int expected_client_alert;
149     /* Alert sent by the server / received by the client. */
150     int expected_server_alert;
151     /* Negotiated protocol version. 0 if no expectation. */
152     /* See ssl.h for protocol versions. */
153     int expected_protocol;
154     /*
155      * The expected SNI context to use.
156      * We test server-side that the server switched to the expected context.
157      * Set by the callback upon success, so if the callback wasn't called or
158      * terminated with an alert, the servername will match with
159      * SSL_TEST_SERVERNAME_NONE.
160      * Note: in the event that the servername was accepted, the client should
161      * also receive an empty SNI extension back but we have no way of probing
162      * client-side via the API that this was the case.
163      */
164     ssl_servername_t expected_servername;
165     ssl_session_ticket_t session_ticket_expected;
166     /* The expected NPN/ALPN protocol to negotiate. */
167     char *expected_npn_protocol;
168     char *expected_alpn_protocol;
169     /* Whether the second handshake is resumed or a full handshake (boolean). */
170     int resumption_expected;
171     /* Expected temporary key type */
172     int expected_tmp_key_type;
173     /* Expected server certificate key type */
174     int expected_server_cert_type;
175     /* Expected server signing hash */
176     int expected_server_sign_hash;
177     /* Expected server signature type */
178     int expected_server_sign_type;
179     /* Expected client certificate key type */
180     int expected_client_cert_type;
181     /* Expected client signing hash */
182     int expected_client_sign_hash;
183     /* Expected client signature type */
184     int expected_client_sign_type;
185 } SSL_TEST_CTX;
186
187 const char *ssl_test_result_name(ssl_test_result_t result);
188 const char *ssl_alert_name(int alert);
189 const char *ssl_protocol_name(int protocol);
190 const char *ssl_verify_callback_name(ssl_verify_callback_t verify_callback);
191 const char *ssl_servername_name(ssl_servername_t server);
192 const char *ssl_servername_callback_name(ssl_servername_callback_t
193                                          servername_callback);
194 const char *ssl_session_ticket_name(ssl_session_ticket_t server);
195 const char *ssl_test_method_name(ssl_test_method_t method);
196 const char *ssl_handshake_mode_name(ssl_handshake_mode_t mode);
197 const char *ssl_ct_validation_name(ssl_ct_validation_t mode);
198 const char *ssl_certstatus_name(ssl_cert_status_t cert_status);
199
200 /*
201  * Load the test case context from |conf|.
202  * See test/README.ssltest.md for details on the conf file format.
203  */
204 SSL_TEST_CTX *SSL_TEST_CTX_create(const CONF *conf, const char *test_section);
205
206 SSL_TEST_CTX *SSL_TEST_CTX_new(void);
207
208 void SSL_TEST_CTX_free(SSL_TEST_CTX *ctx);
209
210 #endif  /* HEADER_SSL_TEST_CTX_H */