summaryrefslogtreecommitdiff
path: root/src/regress/lib
diff options
context:
space:
mode:
authortb <>2020-12-01 07:48:35 +0000
committertb <>2020-12-01 07:48:35 +0000
commitfe9a195ac00f9935f811b02fa498dcfde9616ecf (patch)
treeefa79c474dfb8c9002ae3409085600652bac921c /src/regress/lib
parent7e83d137a386213a28873ba8555b80f3902047ea (diff)
downloadopenbsd-fe9a195ac00f9935f811b02fa498dcfde9616ecf.tar.gz
openbsd-fe9a195ac00f9935f811b02fa498dcfde9616ecf.tar.bz2
openbsd-fe9a195ac00f9935f811b02fa498dcfde9616ecf.zip
Add an ssl_methods() unit test that currently only covers the
behavior of SSL_is_server(). This would have caught the regression introduced in the method unification.
Diffstat (limited to 'src/regress/lib')
-rw-r--r--src/regress/lib/libssl/unit/ssl_methods.c192
1 files changed, 192 insertions, 0 deletions
diff --git a/src/regress/lib/libssl/unit/ssl_methods.c b/src/regress/lib/libssl/unit/ssl_methods.c
new file mode 100644
index 0000000000..688bea45bf
--- /dev/null
+++ b/src/regress/lib/libssl/unit/ssl_methods.c
@@ -0,0 +1,192 @@
1/* $OpenBSD: ssl_methods.c,v 1.1 2020/12/01 07:48:35 tb Exp $ */
2/*
3 * Copyright (c) 2020 Theo Buehler <tb@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <stdio.h>
19
20#include <openssl/ssl.h>
21
22struct ssl_method_test_data {
23 const SSL_METHOD *(*method)(void);
24 const char *name;
25 int server;
26};
27
28struct ssl_method_test_data ssl_method_tests[] = {
29 {
30 .method = SSLv23_method,
31 .name = "SSLv23_method",
32 .server = 1,
33 },
34 {
35 .method = SSLv23_server_method,
36 .name = "SSLv23_server_method",
37 .server = 1,
38 },
39 {
40 .method = SSLv23_client_method,
41 .name = "SSLv23_client_method",
42 .server = 0,
43 },
44
45 {
46 .method = TLSv1_method,
47 .name = "TLSv1_method",
48 .server = 1,
49 },
50 {
51 .method = TLSv1_server_method,
52 .name = "TLSv1_server_method",
53 .server = 1,
54 },
55 {
56 .method = TLSv1_client_method,
57 .name = "TLSv1_client_method",
58 .server = 0,
59 },
60
61 {
62 .method = TLSv1_1_method,
63 .name = "TLSv1_1_method",
64 .server = 1,
65 },
66 {
67 .method = TLSv1_1_server_method,
68 .name = "TLSv1_1_server_method",
69 .server = 1,
70 },
71 {
72 .method = TLSv1_1_client_method,
73 .name = "TLSv1_1_client_method",
74 .server = 0,
75 },
76
77 {
78 .method = TLSv1_2_method,
79 .name = "TLSv1_2_method",
80 .server = 1,
81 },
82 {
83 .method = TLSv1_2_server_method,
84 .name = "TLSv1_2_server_method",
85 .server = 1,
86 },
87 {
88 .method = TLSv1_2_client_method,
89 .name = "TLSv1_2_client_method",
90 .server = 0,
91 },
92
93 {
94 .method = TLS_method,
95 .name = "TLS_method",
96 .server = 1,
97 },
98 {
99 .method = TLS_server_method,
100 .name = "TLS_server_method",
101 .server = 1,
102 },
103 {
104 .method = TLS_client_method,
105 .name = "TLS_client_method",
106 .server = 0,
107 },
108
109 {
110 .method = DTLSv1_method,
111 .name = "DTLSv1_method",
112 .server = 1,
113 },
114 {
115 .method = DTLSv1_server_method,
116 .name = "DTLSv1_server_method",
117 .server = 1,
118 },
119 {
120 .method = DTLSv1_client_method,
121 .name = "DTLSv1_client_method",
122 .server = 0,
123 },
124
125 {
126 .method = DTLS_method,
127 .name = "DTLS_method",
128 .server = 1,
129 },
130 {
131 .method = DTLS_server_method,
132 .name = "DTLS_server_method",
133 .server = 1,
134 },
135 {
136 .method = DTLS_client_method,
137 .name = "DTLS_client_method",
138 .server = 0,
139 },
140};
141
142#define N_METHOD_TESTS (sizeof(ssl_method_tests) / sizeof(ssl_method_tests[0]))
143
144int test_client_or_server_method(struct ssl_method_test_data *);
145
146int
147test_client_or_server_method(struct ssl_method_test_data *testcase)
148{
149 SSL_CTX *ssl_ctx;
150 SSL *ssl = NULL;
151 int failed = 1;
152
153 if ((ssl_ctx = SSL_CTX_new(testcase->method())) == NULL) {
154 fprintf(stderr, "SSL_CTX_new returned NULL\n");
155 goto err;
156 }
157
158 if ((ssl = SSL_new(ssl_ctx)) == NULL) {
159 fprintf(stderr, "SSL_CTX_new returned NULL\n");
160 goto err;
161 }
162
163 if (SSL_is_server(ssl) != testcase->server) {
164 fprintf(stderr, "%s: SSL_is_server: want %d, got %d\n",
165 testcase->name, testcase->server, SSL_is_server(ssl));
166 goto err;
167 }
168
169 failed = 0;
170
171 err:
172 SSL_free(ssl);
173 SSL_CTX_free(ssl_ctx);
174
175 return failed;
176}
177
178int
179main(int argc, char **argv)
180{
181 size_t i;
182 int failed = 0;
183
184 for (i = 0; i < N_METHOD_TESTS; i++) {
185 failed |= test_client_or_server_method(&ssl_method_tests[i]);
186 }
187
188 if (failed == 0)
189 printf("PASS %s\n", __FILE__);
190
191 return failed;
192}