check return values for EVP_Digest*() APIs
[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 } ssl_test_result_t;
22
23 typedef enum {
24     SSL_TEST_VERIFY_NONE = 0, /* Default */
25     SSL_TEST_VERIFY_ACCEPT_ALL,
26     SSL_TEST_VERIFY_REJECT_ALL
27 } ssl_verify_callback_t;
28
29 typedef enum {
30     SSL_TEST_SERVERNAME_NONE = 0, /* Default */
31     SSL_TEST_SERVERNAME_SERVER1,
32     SSL_TEST_SERVERNAME_SERVER2,
33     SSL_TEST_SERVERNAME_INVALID
34 } ssl_servername_t;
35
36 typedef enum {
37     SSL_TEST_SERVERNAME_CB_NONE = 0,  /* Default */
38     SSL_TEST_SERVERNAME_IGNORE_MISMATCH,
39     SSL_TEST_SERVERNAME_REJECT_MISMATCH
40 } ssl_servername_callback_t;
41
42
43 typedef enum {
44     SSL_TEST_SESSION_TICKET_IGNORE = 0, /* Default */
45     SSL_TEST_SESSION_TICKET_YES,
46     SSL_TEST_SESSION_TICKET_NO,
47     SSL_TEST_SESSION_TICKET_BROKEN /* Special test */
48 } ssl_session_ticket_t;
49
50 typedef enum {
51     SSL_TEST_METHOD_TLS = 0, /* Default */
52     SSL_TEST_METHOD_DTLS
53 } ssl_test_method_t;
54
55 typedef struct ssl_test_ctx {
56     /* Test expectations. */
57     /* Defaults to SUCCESS. */
58     ssl_test_result_t expected_result;
59     /* Alerts. 0 if no expectation. */
60     /* See ssl.h for alert codes. */
61     /* Alert sent by the client / received by the server. */
62     int client_alert;
63     /* Alert sent by the server / received by the client. */
64     int server_alert;
65     /* Negotiated protocol version. 0 if no expectation. */
66     /* See ssl.h for protocol versions. */
67     int protocol;
68     /* One of a number of predefined custom callbacks. */
69     ssl_verify_callback_t client_verify_callback;
70     /* One of a number of predefined server names use by the client */
71     ssl_servername_t servername;
72     /*
73      * The expected SNI context to use.
74      * We test server-side that the server switched to the expected context.
75      * Set by the callback upon success, so if the callback wasn't called or
76      * terminated with an alert, the servername will match with
77      * SSL_TEST_SERVERNAME_NONE.
78      * Note: in the event that the servername was accepted, the client should
79      * also receive an empty SNI extension back but we have no way of probing
80      * client-side via the API that this was the case.
81      */
82     ssl_servername_t expected_servername;
83     ssl_servername_callback_t servername_callback;
84     ssl_session_ticket_t session_ticket_expected;
85     /* Whether the server/client CTX should use DTLS or TLS. */
86     ssl_test_method_t method;
87 } SSL_TEST_CTX;
88
89 const char *ssl_test_result_name(ssl_test_result_t result);
90 const char *ssl_alert_name(int alert);
91 const char *ssl_protocol_name(int protocol);
92 const char *ssl_verify_callback_name(ssl_verify_callback_t verify_callback);
93 const char *ssl_servername_name(ssl_servername_t server);
94 const char *ssl_servername_callback_name(ssl_servername_callback_t
95                                          servername_callback);
96 const char *ssl_session_ticket_name(ssl_session_ticket_t server);
97 const char *ssl_test_method_name(ssl_test_method_t method);
98
99 /*
100  * Load the test case context from |conf|.
101  * See test/README.ssl_test for details on the conf file format.
102  */
103 SSL_TEST_CTX *SSL_TEST_CTX_create(const CONF *conf, const char *test_section);
104
105 SSL_TEST_CTX *SSL_TEST_CTX_new(void);
106
107 void SSL_TEST_CTX_free(SSL_TEST_CTX *ctx);
108
109 #endif  /* HEADER_SSL_TEST_CTX_H */