2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
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
10 #ifndef HEADER_SSL_TEST_CTX_H
11 #define HEADER_SSL_TEST_CTX_H
13 #include <openssl/conf.h>
14 #include <openssl/ssl.h>
17 SSL_TEST_SUCCESS = 0, /* Default */
20 SSL_TEST_INTERNAL_ERROR,
21 /* Couldn't test resumption/renegotiation: original handshake failed. */
22 SSL_TEST_FIRST_HANDSHAKE_FAILED
26 SSL_TEST_VERIFY_NONE = 0, /* Default */
27 SSL_TEST_VERIFY_ACCEPT_ALL,
28 SSL_TEST_VERIFY_REJECT_ALL
29 } ssl_verify_callback_t;
32 SSL_TEST_SERVERNAME_NONE = 0, /* Default */
33 SSL_TEST_SERVERNAME_SERVER1,
34 SSL_TEST_SERVERNAME_SERVER2,
35 SSL_TEST_SERVERNAME_INVALID
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;
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;
52 SSL_TEST_METHOD_TLS = 0, /* Default */
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;
64 * Server/client settings that aren't supported by the SSL CONF library,
68 /* One of a number of predefined custom callbacks. */
69 ssl_verify_callback_t verify_callback;
70 /* One of a number of predefined server names use by the client */
71 ssl_servername_t servername;
72 /* Supported NPN and ALPN protocols. A comma-separated list. */
75 } SSL_TEST_CLIENT_CONF;
78 /* SNI callback (server-side). */
79 ssl_servername_callback_t servername_callback;
80 /* Supported NPN and ALPN protocols. A comma-separated list. */
83 /* Whether to set a broken session ticket callback. */
84 int broken_session_ticket;
85 } SSL_TEST_SERVER_CONF;
88 SSL_TEST_CLIENT_CONF client;
89 SSL_TEST_SERVER_CONF server;
90 SSL_TEST_SERVER_CONF server2;
91 } SSL_TEST_EXTRA_CONF;
95 * Global test configuration. Does not change between handshakes.
97 /* Whether the server/client CTX should use DTLS or TLS. */
98 ssl_test_method_t method;
99 /* Whether to test a resumed/renegotiated handshake. */
100 ssl_handshake_mode_t handshake_mode;
103 * Extra server/client configurations. Per-handshake.
105 /* First handshake. */
106 SSL_TEST_EXTRA_CONF extra;
107 /* Resumed handshake. */
108 SSL_TEST_EXTRA_CONF resume_extra;
111 * Test expectations. These apply to the LAST handshake.
113 /* Defaults to SUCCESS. */
114 ssl_test_result_t expected_result;
115 /* Alerts. 0 if no expectation. */
116 /* See ssl.h for alert codes. */
117 /* Alert sent by the client / received by the server. */
118 int expected_client_alert;
119 /* Alert sent by the server / received by the client. */
120 int expected_server_alert;
121 /* Negotiated protocol version. 0 if no expectation. */
122 /* See ssl.h for protocol versions. */
123 int expected_protocol;
125 * The expected SNI context to use.
126 * We test server-side that the server switched to the expected context.
127 * Set by the callback upon success, so if the callback wasn't called or
128 * terminated with an alert, the servername will match with
129 * SSL_TEST_SERVERNAME_NONE.
130 * Note: in the event that the servername was accepted, the client should
131 * also receive an empty SNI extension back but we have no way of probing
132 * client-side via the API that this was the case.
134 ssl_servername_t expected_servername;
135 ssl_session_ticket_t session_ticket_expected;
136 /* The expected NPN/ALPN protocol to negotiate. */
137 char *expected_npn_protocol;
138 char *expected_alpn_protocol;
139 /* Whether the second handshake is resumed or a full handshake (boolean). */
140 int resumption_expected;
143 const char *ssl_test_result_name(ssl_test_result_t result);
144 const char *ssl_alert_name(int alert);
145 const char *ssl_protocol_name(int protocol);
146 const char *ssl_verify_callback_name(ssl_verify_callback_t verify_callback);
147 const char *ssl_servername_name(ssl_servername_t server);
148 const char *ssl_servername_callback_name(ssl_servername_callback_t
149 servername_callback);
150 const char *ssl_session_ticket_name(ssl_session_ticket_t server);
151 const char *ssl_test_method_name(ssl_test_method_t method);
152 const char *ssl_handshake_mode_name(ssl_handshake_mode_t mode);
155 * Load the test case context from |conf|.
156 * See test/README.ssltest.md for details on the conf file format.
158 SSL_TEST_CTX *SSL_TEST_CTX_create(const CONF *conf, const char *test_section);
160 SSL_TEST_CTX *SSL_TEST_CTX_new(void);
162 void SSL_TEST_CTX_free(SSL_TEST_CTX *ctx);
164 #endif /* HEADER_SSL_TEST_CTX_H */