diff options
author | tb <> | 2020-12-01 08:05:06 +0000 |
---|---|---|
committer | tb <> | 2020-12-01 08:05:06 +0000 |
commit | cc0ddc52eadc398d5fe5711a7b86aefbf1c7f00b (patch) | |
tree | 8967d5d6afd598d6a0073540ae44ccb644e0b0da /src/regress/lib | |
parent | 59204468e7721056eb440bc812dd2e63e2cb0ea1 (diff) | |
download | openbsd-cc0ddc52eadc398d5fe5711a7b86aefbf1c7f00b.tar.gz openbsd-cc0ddc52eadc398d5fe5711a7b86aefbf1c7f00b.tar.bz2 openbsd-cc0ddc52eadc398d5fe5711a7b86aefbf1c7f00b.zip |
Extend the methods test to cover dtls methods as well
Diffstat (limited to 'src/regress/lib')
-rw-r--r-- | src/regress/lib/libssl/unit/ssl_methods.c | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/src/regress/lib/libssl/unit/ssl_methods.c b/src/regress/lib/libssl/unit/ssl_methods.c index 688bea45bf..163d22c55f 100644 --- a/src/regress/lib/libssl/unit/ssl_methods.c +++ b/src/regress/lib/libssl/unit/ssl_methods.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_methods.c,v 1.1 2020/12/01 07:48:35 tb Exp $ */ | 1 | /* $OpenBSD: ssl_methods.c,v 1.2 2020/12/01 08:05:06 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2020 Theo Buehler <tb@openbsd.org> | 3 | * Copyright (c) 2020 Theo Buehler <tb@openbsd.org> |
4 | * | 4 | * |
@@ -23,6 +23,7 @@ struct ssl_method_test_data { | |||
23 | const SSL_METHOD *(*method)(void); | 23 | const SSL_METHOD *(*method)(void); |
24 | const char *name; | 24 | const char *name; |
25 | int server; | 25 | int server; |
26 | int dtls; | ||
26 | }; | 27 | }; |
27 | 28 | ||
28 | struct ssl_method_test_data ssl_method_tests[] = { | 29 | struct ssl_method_test_data ssl_method_tests[] = { |
@@ -30,118 +31,140 @@ struct ssl_method_test_data ssl_method_tests[] = { | |||
30 | .method = SSLv23_method, | 31 | .method = SSLv23_method, |
31 | .name = "SSLv23_method", | 32 | .name = "SSLv23_method", |
32 | .server = 1, | 33 | .server = 1, |
34 | .dtls = 0, | ||
33 | }, | 35 | }, |
34 | { | 36 | { |
35 | .method = SSLv23_server_method, | 37 | .method = SSLv23_server_method, |
36 | .name = "SSLv23_server_method", | 38 | .name = "SSLv23_server_method", |
37 | .server = 1, | 39 | .server = 1, |
40 | .dtls = 0, | ||
38 | }, | 41 | }, |
39 | { | 42 | { |
40 | .method = SSLv23_client_method, | 43 | .method = SSLv23_client_method, |
41 | .name = "SSLv23_client_method", | 44 | .name = "SSLv23_client_method", |
42 | .server = 0, | 45 | .server = 0, |
46 | .dtls = 0, | ||
43 | }, | 47 | }, |
44 | 48 | ||
45 | { | 49 | { |
46 | .method = TLSv1_method, | 50 | .method = TLSv1_method, |
47 | .name = "TLSv1_method", | 51 | .name = "TLSv1_method", |
48 | .server = 1, | 52 | .server = 1, |
53 | .dtls = 0, | ||
49 | }, | 54 | }, |
50 | { | 55 | { |
51 | .method = TLSv1_server_method, | 56 | .method = TLSv1_server_method, |
52 | .name = "TLSv1_server_method", | 57 | .name = "TLSv1_server_method", |
53 | .server = 1, | 58 | .server = 1, |
59 | .dtls = 0, | ||
54 | }, | 60 | }, |
55 | { | 61 | { |
56 | .method = TLSv1_client_method, | 62 | .method = TLSv1_client_method, |
57 | .name = "TLSv1_client_method", | 63 | .name = "TLSv1_client_method", |
58 | .server = 0, | 64 | .server = 0, |
65 | .dtls = 0, | ||
59 | }, | 66 | }, |
60 | 67 | ||
61 | { | 68 | { |
62 | .method = TLSv1_1_method, | 69 | .method = TLSv1_1_method, |
63 | .name = "TLSv1_1_method", | 70 | .name = "TLSv1_1_method", |
64 | .server = 1, | 71 | .server = 1, |
72 | .dtls = 0, | ||
65 | }, | 73 | }, |
66 | { | 74 | { |
67 | .method = TLSv1_1_server_method, | 75 | .method = TLSv1_1_server_method, |
68 | .name = "TLSv1_1_server_method", | 76 | .name = "TLSv1_1_server_method", |
69 | .server = 1, | 77 | .server = 1, |
78 | .dtls = 0, | ||
70 | }, | 79 | }, |
71 | { | 80 | { |
72 | .method = TLSv1_1_client_method, | 81 | .method = TLSv1_1_client_method, |
73 | .name = "TLSv1_1_client_method", | 82 | .name = "TLSv1_1_client_method", |
74 | .server = 0, | 83 | .server = 0, |
84 | .dtls = 0, | ||
75 | }, | 85 | }, |
76 | 86 | ||
77 | { | 87 | { |
78 | .method = TLSv1_2_method, | 88 | .method = TLSv1_2_method, |
79 | .name = "TLSv1_2_method", | 89 | .name = "TLSv1_2_method", |
80 | .server = 1, | 90 | .server = 1, |
91 | .dtls = 0, | ||
81 | }, | 92 | }, |
82 | { | 93 | { |
83 | .method = TLSv1_2_server_method, | 94 | .method = TLSv1_2_server_method, |
84 | .name = "TLSv1_2_server_method", | 95 | .name = "TLSv1_2_server_method", |
85 | .server = 1, | 96 | .server = 1, |
97 | .dtls = 0, | ||
86 | }, | 98 | }, |
87 | { | 99 | { |
88 | .method = TLSv1_2_client_method, | 100 | .method = TLSv1_2_client_method, |
89 | .name = "TLSv1_2_client_method", | 101 | .name = "TLSv1_2_client_method", |
90 | .server = 0, | 102 | .server = 0, |
103 | .dtls = 0, | ||
91 | }, | 104 | }, |
92 | 105 | ||
93 | { | 106 | { |
94 | .method = TLS_method, | 107 | .method = TLS_method, |
95 | .name = "TLS_method", | 108 | .name = "TLS_method", |
96 | .server = 1, | 109 | .server = 1, |
110 | .dtls = 0, | ||
97 | }, | 111 | }, |
98 | { | 112 | { |
99 | .method = TLS_server_method, | 113 | .method = TLS_server_method, |
100 | .name = "TLS_server_method", | 114 | .name = "TLS_server_method", |
101 | .server = 1, | 115 | .server = 1, |
116 | .dtls = 0, | ||
102 | }, | 117 | }, |
103 | { | 118 | { |
104 | .method = TLS_client_method, | 119 | .method = TLS_client_method, |
105 | .name = "TLS_client_method", | 120 | .name = "TLS_client_method", |
106 | .server = 0, | 121 | .server = 0, |
122 | .dtls = 0, | ||
107 | }, | 123 | }, |
108 | 124 | ||
109 | { | 125 | { |
110 | .method = DTLSv1_method, | 126 | .method = DTLSv1_method, |
111 | .name = "DTLSv1_method", | 127 | .name = "DTLSv1_method", |
112 | .server = 1, | 128 | .server = 1, |
129 | .dtls = 1, | ||
113 | }, | 130 | }, |
114 | { | 131 | { |
115 | .method = DTLSv1_server_method, | 132 | .method = DTLSv1_server_method, |
116 | .name = "DTLSv1_server_method", | 133 | .name = "DTLSv1_server_method", |
117 | .server = 1, | 134 | .server = 1, |
135 | .dtls = 1, | ||
118 | }, | 136 | }, |
119 | { | 137 | { |
120 | .method = DTLSv1_client_method, | 138 | .method = DTLSv1_client_method, |
121 | .name = "DTLSv1_client_method", | 139 | .name = "DTLSv1_client_method", |
122 | .server = 0, | 140 | .server = 0, |
141 | .dtls = 1, | ||
123 | }, | 142 | }, |
124 | 143 | ||
125 | { | 144 | { |
126 | .method = DTLS_method, | 145 | .method = DTLS_method, |
127 | .name = "DTLS_method", | 146 | .name = "DTLS_method", |
128 | .server = 1, | 147 | .server = 1, |
148 | .dtls = 1, | ||
129 | }, | 149 | }, |
130 | { | 150 | { |
131 | .method = DTLS_server_method, | 151 | .method = DTLS_server_method, |
132 | .name = "DTLS_server_method", | 152 | .name = "DTLS_server_method", |
133 | .server = 1, | 153 | .server = 1, |
154 | .dtls = 1, | ||
134 | }, | 155 | }, |
135 | { | 156 | { |
136 | .method = DTLS_client_method, | 157 | .method = DTLS_client_method, |
137 | .name = "DTLS_client_method", | 158 | .name = "DTLS_client_method", |
138 | .server = 0, | 159 | .server = 0, |
160 | .dtls = 1, | ||
139 | }, | 161 | }, |
140 | }; | 162 | }; |
141 | 163 | ||
142 | #define N_METHOD_TESTS (sizeof(ssl_method_tests) / sizeof(ssl_method_tests[0])) | 164 | #define N_METHOD_TESTS (sizeof(ssl_method_tests) / sizeof(ssl_method_tests[0])) |
143 | 165 | ||
144 | int test_client_or_server_method(struct ssl_method_test_data *); | 166 | int test_client_or_server_method(struct ssl_method_test_data *); |
167 | int test_dtls_method(struct ssl_method_test_data *); | ||
145 | 168 | ||
146 | int | 169 | int |
147 | test_client_or_server_method(struct ssl_method_test_data *testcase) | 170 | test_client_or_server_method(struct ssl_method_test_data *testcase) |
@@ -176,6 +199,38 @@ test_client_or_server_method(struct ssl_method_test_data *testcase) | |||
176 | } | 199 | } |
177 | 200 | ||
178 | int | 201 | int |
202 | test_dtls_method(struct ssl_method_test_data *testcase) | ||
203 | { | ||
204 | SSL_CTX *ssl_ctx; | ||
205 | SSL *ssl = NULL; | ||
206 | int failed = 1; | ||
207 | |||
208 | if ((ssl_ctx = SSL_CTX_new(testcase->method())) == NULL) { | ||
209 | fprintf(stderr, "SSL_CTX_new returned NULL\n"); | ||
210 | goto err; | ||
211 | } | ||
212 | |||
213 | if ((ssl = SSL_new(ssl_ctx)) == NULL) { | ||
214 | fprintf(stderr, "SSL_CTX_new returned NULL\n"); | ||
215 | goto err; | ||
216 | } | ||
217 | |||
218 | if (SSL_is_dtls(ssl) != testcase->dtls) { | ||
219 | fprintf(stderr, "%s: SSL_is_dtls: want %d, got %d\n", | ||
220 | testcase->name, testcase->dtls, SSL_is_dtls(ssl)); | ||
221 | goto err; | ||
222 | } | ||
223 | |||
224 | failed = 0; | ||
225 | |||
226 | err: | ||
227 | SSL_free(ssl); | ||
228 | SSL_CTX_free(ssl_ctx); | ||
229 | |||
230 | return failed; | ||
231 | } | ||
232 | |||
233 | int | ||
179 | main(int argc, char **argv) | 234 | main(int argc, char **argv) |
180 | { | 235 | { |
181 | size_t i; | 236 | size_t i; |
@@ -183,6 +238,7 @@ main(int argc, char **argv) | |||
183 | 238 | ||
184 | for (i = 0; i < N_METHOD_TESTS; i++) { | 239 | for (i = 0; i < N_METHOD_TESTS; i++) { |
185 | failed |= test_client_or_server_method(&ssl_method_tests[i]); | 240 | failed |= test_client_or_server_method(&ssl_method_tests[i]); |
241 | failed |= test_dtls_method(&ssl_method_tests[i]); | ||
186 | } | 242 | } |
187 | 243 | ||
188 | if (failed == 0) | 244 | if (failed == 0) |