Fix tests for no-nextprotoneg
[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     /* Not yet implemented */
60     SSL_TEST_HANDSHAKE_RENEGOTIATE
61 } ssl_handshake_mode_t;
62
63 typedef struct ssl_test_ctx {
64     /* Test expectations. */
65     /* Defaults to SUCCESS. */
66     ssl_test_result_t expected_result;
67     /* Alerts. 0 if no expectation. */
68     /* See ssl.h for alert codes. */
69     /* Alert sent by the client / received by the server. */
70     int client_alert;
71     /* Alert sent by the server / received by the client. */
72     int server_alert;
73     /* Negotiated protocol version. 0 if no expectation. */
74     /* See ssl.h for protocol versions. */
75     int protocol;
76     /* One of a number of predefined custom callbacks. */
77     ssl_verify_callback_t client_verify_callback;
78     /* One of a number of predefined server names use by the client */
79     ssl_servername_t servername;
80     /*
81      * The expected SNI context to use.
82      * We test server-side that the server switched to the expected context.
83      * Set by the callback upon success, so if the callback wasn't called or
84      * terminated with an alert, the servername will match with
85      * SSL_TEST_SERVERNAME_NONE.
86      * Note: in the event that the servername was accepted, the client should
87      * also receive an empty SNI extension back but we have no way of probing
88      * client-side via the API that this was the case.
89      */
90     ssl_servername_t expected_servername;
91     ssl_servername_callback_t servername_callback;
92     ssl_session_ticket_t session_ticket_expected;
93     /* Whether the server/client CTX should use DTLS or TLS. */
94     ssl_test_method_t method;
95
96     /*
97      * NPN and ALPN protocols supported by the client, server, and second
98      * (SNI) server. A comma-separated list.
99      */
100     char *client_npn_protocols;
101     char *server_npn_protocols;
102     char *server2_npn_protocols;
103     char *expected_npn_protocol;
104     char *client_alpn_protocols;
105     char *server_alpn_protocols;
106     char *server2_alpn_protocols;
107     char *expected_alpn_protocol;
108
109     /* Whether to test a resumed/renegotiated handshake. */
110     ssl_handshake_mode_t handshake_mode;
111     /* Whether the second handshake is resumed or a full handshake (boolean). */
112     int resumption_expected;
113 } SSL_TEST_CTX;
114
115 const char *ssl_test_result_name(ssl_test_result_t result);
116 const char *ssl_alert_name(int alert);
117 const char *ssl_protocol_name(int protocol);
118 const char *ssl_verify_callback_name(ssl_verify_callback_t verify_callback);
119 const char *ssl_servername_name(ssl_servername_t server);
120 const char *ssl_servername_callback_name(ssl_servername_callback_t
121                                          servername_callback);
122 const char *ssl_session_ticket_name(ssl_session_ticket_t server);
123 const char *ssl_test_method_name(ssl_test_method_t method);
124 const char *ssl_handshake_mode_name(ssl_handshake_mode_t mode);
125
126 /*
127  * Load the test case context from |conf|.
128  * See test/README.ssl_test for details on the conf file format.
129  */
130 SSL_TEST_CTX *SSL_TEST_CTX_create(const CONF *conf, const char *test_section);
131
132 SSL_TEST_CTX *SSL_TEST_CTX_new(void);
133
134 void SSL_TEST_CTX_free(SSL_TEST_CTX *ctx);
135
136 #endif  /* HEADER_SSL_TEST_CTX_H */