Fix migration guide mappings for i2o/o2i_ECPublicKey
[openssl.git] / test / ssl_test_ctx.h
1 /*
2  * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (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 OSSL_TEST_SSL_TEST_CTX_H
11 #define OSSL_TEST_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_TEST_HANDSHAKE_POST_HANDSHAKE_AUTH
78 } ssl_handshake_mode_t;
79
80 typedef enum {
81     SSL_TEST_CT_VALIDATION_NONE = 0, /* Default */
82     SSL_TEST_CT_VALIDATION_PERMISSIVE,
83     SSL_TEST_CT_VALIDATION_STRICT
84 } ssl_ct_validation_t;
85
86 typedef enum {
87     SSL_TEST_CERT_STATUS_NONE = 0, /* Default */
88     SSL_TEST_CERT_STATUS_GOOD_RESPONSE,
89     SSL_TEST_CERT_STATUS_BAD_RESPONSE
90 } ssl_cert_status_t;
91
92 /*
93  * Server/client settings that aren't supported by the SSL CONF library,
94  * such as callbacks.
95  */
96 typedef struct {
97     /* One of a number of predefined custom callbacks. */
98     ssl_verify_callback_t verify_callback;
99     /* One of a number of predefined server names use by the client */
100     ssl_servername_t servername;
101     /* Maximum Fragment Length extension mode */
102     int max_fragment_len_mode;
103     /* Supported NPN and ALPN protocols. A comma-separated list. */
104     char *npn_protocols;
105     char *alpn_protocols;
106     ssl_ct_validation_t ct_validation;
107     /* Ciphersuites to set on a renegotiation */
108     char *reneg_ciphers;
109     char *srp_user;
110     char *srp_password;
111     /* PHA enabled */
112     int enable_pha;
113     /* Do not send extms on renegotiation */
114     int no_extms_on_reneg;
115 } SSL_TEST_CLIENT_CONF;
116
117 typedef struct {
118     /* SNI callback (server-side). */
119     ssl_servername_callback_t servername_callback;
120     /* Supported NPN and ALPN protocols. A comma-separated list. */
121     char *npn_protocols;
122     char *alpn_protocols;
123     /* Whether to set a broken session ticket callback. */
124     int broken_session_ticket;
125     /* Should we send a CertStatus message? */
126     ssl_cert_status_t cert_status;
127     /* An SRP user known to the server. */
128     char *srp_user;
129     char *srp_password;
130     /* Forced PHA */
131     int force_pha;
132     char *session_ticket_app_data;
133 } SSL_TEST_SERVER_CONF;
134
135 typedef struct {
136     SSL_TEST_CLIENT_CONF client;
137     SSL_TEST_SERVER_CONF server;
138     SSL_TEST_SERVER_CONF server2;
139 } SSL_TEST_EXTRA_CONF;
140
141 typedef struct {
142     /*
143      * Global test configuration. Does not change between handshakes.
144      */
145     /* Whether the server/client CTX should use DTLS or TLS. */
146     ssl_test_method_t method;
147     /* Whether to test a resumed/renegotiated handshake. */
148     ssl_handshake_mode_t handshake_mode;
149     /*
150      * How much application data to exchange (default is 256 bytes).
151      * Both peers will send |app_data_size| bytes interleaved.
152      */
153     int app_data_size;
154     /* Maximum send fragment size. */
155     int max_fragment_size;
156     /* KeyUpdate type */
157     int key_update_type;
158
159     /*
160      * Extra server/client configurations. Per-handshake.
161      */
162     /* First handshake. */
163     SSL_TEST_EXTRA_CONF extra;
164     /* Resumed handshake. */
165     SSL_TEST_EXTRA_CONF resume_extra;
166
167     /*
168      * Test expectations. These apply to the LAST handshake.
169      */
170     /* Defaults to SUCCESS. */
171     ssl_test_result_t expected_result;
172     /* Alerts. 0 if no expectation. */
173     /* See ssl.h for alert codes. */
174     /* Alert sent by the client / received by the server. */
175     int expected_client_alert;
176     /* Alert sent by the server / received by the client. */
177     int expected_server_alert;
178     /* Negotiated protocol version. 0 if no expectation. */
179     /* See ssl.h for protocol versions. */
180     int expected_protocol;
181     /*
182      * The expected SNI context to use.
183      * We test server-side that the server switched to the expected context.
184      * Set by the callback upon success, so if the callback wasn't called or
185      * terminated with an alert, the servername will match with
186      * SSL_TEST_SERVERNAME_NONE.
187      * Note: in the event that the servername was accepted, the client should
188      * also receive an empty SNI extension back but we have no way of probing
189      * client-side via the API that this was the case.
190      */
191     ssl_servername_t expected_servername;
192     ssl_session_ticket_t session_ticket_expected;
193     int compression_expected;
194     /* The expected NPN/ALPN protocol to negotiate. */
195     char *expected_npn_protocol;
196     char *expected_alpn_protocol;
197     /* Whether the second handshake is resumed or a full handshake (boolean). */
198     int resumption_expected;
199     /* Expected temporary key type */
200     int expected_tmp_key_type;
201     /* Expected server certificate key type */
202     int expected_server_cert_type;
203     /* Expected server signing hash */
204     int expected_server_sign_hash;
205     /* Expected server signature type */
206     int expected_server_sign_type;
207     /* Expected server CA names */
208     STACK_OF(X509_NAME) *expected_server_ca_names;
209     /* Expected client certificate key type */
210     int expected_client_cert_type;
211     /* Expected client signing hash */
212     int expected_client_sign_hash;
213     /* Expected client signature type */
214     int expected_client_sign_type;
215     /* Expected CA names for client auth */
216     STACK_OF(X509_NAME) *expected_client_ca_names;
217     /* Whether to use SCTP for the transport */
218     int use_sctp;
219     /* Enable SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG on client side */
220     int enable_client_sctp_label_bug;
221     /* Enable SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG on server side */
222     int enable_server_sctp_label_bug;
223     /* Whether to expect a session id from the server */
224     ssl_session_id_t session_id_expected;
225     char *expected_cipher;
226     /* Expected Session Ticket Application Data */
227     char *expected_session_ticket_app_data;
228
229     OPENSSL_CTX *libctx;
230 } SSL_TEST_CTX;
231
232 const char *ssl_test_result_name(ssl_test_result_t result);
233 const char *ssl_alert_name(int alert);
234 const char *ssl_protocol_name(int protocol);
235 const char *ssl_verify_callback_name(ssl_verify_callback_t verify_callback);
236 const char *ssl_servername_name(ssl_servername_t server);
237 const char *ssl_servername_callback_name(ssl_servername_callback_t
238                                          servername_callback);
239 const char *ssl_session_ticket_name(ssl_session_ticket_t server);
240 const char *ssl_session_id_name(ssl_session_id_t server);
241 const char *ssl_test_method_name(ssl_test_method_t method);
242 const char *ssl_handshake_mode_name(ssl_handshake_mode_t mode);
243 const char *ssl_ct_validation_name(ssl_ct_validation_t mode);
244 const char *ssl_certstatus_name(ssl_cert_status_t cert_status);
245 const char *ssl_max_fragment_len_name(int MFL_mode);
246
247 /*
248  * Load the test case context from |conf|.
249  * See test/README.ssltest.md for details on the conf file format.
250  */
251 SSL_TEST_CTX *SSL_TEST_CTX_create(const CONF *conf, const char *test_section,
252                                   OPENSSL_CTX *libctx);
253
254 SSL_TEST_CTX *SSL_TEST_CTX_new(OPENSSL_CTX *libctx);
255
256 void SSL_TEST_CTX_free(SSL_TEST_CTX *ctx);
257
258 #endif  /* OSSL_TEST_SSL_TEST_CTX_H */