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