Debian Codegraph @

crt/s2n/tests/unit/s2n_optional_client_auth_test.c

raw symbols SCIP
1 /*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16 #include <fcntl.h>
17 #include <stdlib.h>
18
19 #include "api/s2n.h"
20 #include "crypto/s2n_fips.h"
21 #include "s2n_test.h"
22 #include "testlib/s2n_testlib.h"
23 #include "tls/s2n_cipher_suites.h"
24 #include "tls/s2n_security_policies.h"
25
26 int main(int argc, char **argv)
27 {
28 struct s2n_config *client_config = NULL;
29 struct s2n_config *server_config = NULL;
30 const struct s2n_security_policy *default_security_policy = NULL;
31 const struct s2n_cipher_preferences *default_cipher_preferences = NULL;
32 char *cert_chain_pem = NULL;
33 char *private_key_pem = NULL;
34 char *dhparams_pem = NULL;
35 struct s2n_cert_chain_and_key *chain_and_key = NULL;
36
37 BEGIN_TEST();
38
39 EXPECT_NOT_NULL(cert_chain_pem = malloc(S2N_MAX_TEST_PEM_SIZE));
40 EXPECT_NOT_NULL(private_key_pem = malloc(S2N_MAX_TEST_PEM_SIZE));
41 EXPECT_NOT_NULL(dhparams_pem = malloc(S2N_MAX_TEST_PEM_SIZE));
42
43 /* Setup baseline server config and certs. */
44 EXPECT_NOT_NULL(server_config = s2n_config_new());
45 EXPECT_SUCCESS(s2n_config_set_cipher_preferences(server_config, "20240501"));
46 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_CERT_CHAIN, cert_chain_pem, S2N_MAX_TEST_PEM_SIZE));
47 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_PRIVATE_KEY, private_key_pem, S2N_MAX_TEST_PEM_SIZE));
48 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_DHPARAMS, dhparams_pem, S2N_MAX_TEST_PEM_SIZE));
49
50 EXPECT_NOT_NULL(chain_and_key = s2n_cert_chain_and_key_new());
51 EXPECT_SUCCESS(s2n_cert_chain_and_key_load_pem(chain_and_key, cert_chain_pem, private_key_pem));
52 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, chain_and_key));
53
54 DEFER_CLEANUP(struct s2n_cert_chain_and_key *ecdsa_chain = NULL, s2n_cert_chain_and_key_ptr_free);
55 EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&ecdsa_chain,
56 S2N_DEFAULT_ECDSA_TEST_CERT_CHAIN, S2N_DEFAULT_ECDSA_TEST_PRIVATE_KEY));
57 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, ecdsa_chain));
58
59 EXPECT_SUCCESS(s2n_config_add_dhparams(server_config, dhparams_pem));
60 EXPECT_NOT_NULL(default_security_policy = server_config->security_policy);
61 EXPECT_NOT_NULL(default_cipher_preferences = default_security_policy->cipher_preferences);
62
63 /*
64 * Test optional client auth using **s2n_config_set_client_auth_type** with a valid client cert provided.
65 */
66
67 EXPECT_NOT_NULL(client_config = s2n_config_new());
68 EXPECT_SUCCESS(s2n_config_set_cipher_preferences(client_config, "20240501"));
69 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(client_config, chain_and_key));
70 EXPECT_SUCCESS(s2n_config_disable_x509_verification(client_config));
71 EXPECT_SUCCESS(s2n_config_set_client_auth_type(client_config, S2N_CERT_AUTH_OPTIONAL));
72
73 /* Server requires optional client auth and accepts the client cert. */
74 EXPECT_SUCCESS(s2n_config_set_client_auth_type(server_config, S2N_CERT_AUTH_OPTIONAL));
75 EXPECT_SUCCESS(s2n_config_disable_x509_verification(server_config));
76
77 /* Verify that a handshake succeeds for every cipher in the default list. */
78 for (int cipher_idx = 0; cipher_idx < default_security_policy->cipher_preferences->count; cipher_idx++) {
79 struct s2n_cipher_preferences server_cipher_preferences;
80 struct s2n_security_policy security_policy;
81 struct s2n_connection *client_conn = NULL;
82 struct s2n_connection *server_conn = NULL;
83
84 /* Craft a cipher preference with a cipher_idx cipher. */
85 EXPECT_MEMCPY_SUCCESS(&server_cipher_preferences, default_cipher_preferences, sizeof(server_cipher_preferences));
86 server_cipher_preferences.count = 1;
87 struct s2n_cipher_suite *cur_cipher = default_cipher_preferences->suites[cipher_idx];
88
89 if (!cur_cipher->available) {
90 /* Skip ciphers that aren't supported with the linked libcrypto. */
91 continue;
92 }
93
94 server_cipher_preferences.suites = &cur_cipher;
95
96 EXPECT_MEMCPY_SUCCESS(&security_policy, default_security_policy, sizeof(security_policy));
97 security_policy.cipher_preferences = &server_cipher_preferences;
98
99 client_config->security_policy = &security_policy;
100 server_config->security_policy = &security_policy;
101
102 /* Create nonblocking pipes. */
103 struct s2n_test_io_pair io_pair;
104 EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair));
105
106 EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
107 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
108
109 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
110 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
111
112 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
113
114 /* Verify the handshake was successful. */
115 EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
116
117 /* Verify that both connections negotiated mutual auth. */
118 EXPECT_TRUE(s2n_connection_client_cert_used(server_conn));
119 EXPECT_TRUE(s2n_connection_client_cert_used(client_conn));
120
121 EXPECT_SUCCESS(s2n_connection_free(client_conn));
122 EXPECT_SUCCESS(s2n_connection_free(server_conn));
123 EXPECT_SUCCESS(s2n_io_pair_close(&io_pair));
124 }
125
126 EXPECT_SUCCESS(s2n_config_free(client_config));
127
128 /*
129 * Test optional client auth using **s2n_config_set_client_auth_type** with S2N_CERT_AUTH_NONE for Server
130 */
131
132 EXPECT_NOT_NULL(client_config = s2n_config_new());
133 EXPECT_SUCCESS(s2n_config_set_cipher_preferences(client_config, "20240501"));
134 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(client_config, chain_and_key));
135 EXPECT_SUCCESS(s2n_config_disable_x509_verification(client_config));
136 EXPECT_SUCCESS(s2n_config_set_client_auth_type(client_config, S2N_CERT_AUTH_OPTIONAL));
137
138 /* Server does not request a Client Cert. */
139 EXPECT_SUCCESS(s2n_config_set_client_auth_type(server_config, S2N_CERT_AUTH_NONE));
140 EXPECT_SUCCESS(s2n_config_disable_x509_verification(server_config));
141
142 /* Verify that a handshake succeeds for every cipher in the default list. */
143 for (int cipher_idx = 0; cipher_idx < default_cipher_preferences->count; cipher_idx++) {
144 struct s2n_cipher_preferences server_cipher_preferences;
145 struct s2n_security_policy security_policy;
146 struct s2n_connection *client_conn = NULL;
147 struct s2n_connection *server_conn = NULL;
148
149 /* Craft a cipher preference with a cipher_idx cipher. */
150 EXPECT_MEMCPY_SUCCESS(&server_cipher_preferences, default_cipher_preferences, sizeof(server_cipher_preferences));
151 server_cipher_preferences.count = 1;
152 struct s2n_cipher_suite *cur_cipher = default_cipher_preferences->suites[cipher_idx];
153
154 if (!cur_cipher->available) {
155 /* Skip ciphers that aren't supported with the linked libcrypto. */
156 continue;
157 }
158
159 server_cipher_preferences.suites = &cur_cipher;
160
161 EXPECT_MEMCPY_SUCCESS(&security_policy, default_security_policy, sizeof(security_policy));
162 security_policy.cipher_preferences = &server_cipher_preferences;
163
164 client_config->security_policy = &security_policy;
165 server_config->security_policy = &security_policy;
166
167 /* Create nonblocking pipes. */
168 struct s2n_test_io_pair io_pair;
169 EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair));
170
171 EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
172 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
173
174 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
175 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
176
177 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
178
179 /* Verify the handshake was successful. */
180 EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
181
182 /* Verify that neither connections negotiated mutual auth. */
183 EXPECT_FALSE(s2n_connection_client_cert_used(server_conn));
184 EXPECT_FALSE(s2n_connection_client_cert_used(client_conn));
185
186 EXPECT_SUCCESS(s2n_connection_free(client_conn));
187 EXPECT_SUCCESS(s2n_connection_free(server_conn));
188 EXPECT_SUCCESS(s2n_io_pair_close(&io_pair));
189 }
190
191 EXPECT_SUCCESS(s2n_config_free(client_config));
192
193 /*
194 * Test optional client auth using **s2n_config_set_client_auth_type** with no client cert provided.
195 */
196
197 EXPECT_NOT_NULL(client_config = s2n_config_new());
198 EXPECT_SUCCESS(s2n_config_set_cipher_preferences(client_config, "20240501"));
199 EXPECT_SUCCESS(s2n_config_disable_x509_verification(client_config));
200 EXPECT_SUCCESS(s2n_config_set_client_auth_type(client_config, S2N_CERT_AUTH_OPTIONAL));
201
202 /* Server requires optional client auth and accepts the client cert. */
203 EXPECT_SUCCESS(s2n_config_set_client_auth_type(server_config, S2N_CERT_AUTH_OPTIONAL));
204 EXPECT_SUCCESS(s2n_config_disable_x509_verification(server_config));
205
206 /* Verify that a handshake succeeds for every cipher in the default list. */
207 for (int cipher_idx = 0; cipher_idx < default_cipher_preferences->count; cipher_idx++) {
208 struct s2n_cipher_preferences server_cipher_preferences;
209 struct s2n_security_policy security_policy;
210 struct s2n_connection *client_conn = NULL;
211 struct s2n_connection *server_conn = NULL;
212
213 /* Craft a cipher preference with a cipher_idx cipher. */
214 EXPECT_MEMCPY_SUCCESS(&server_cipher_preferences, default_cipher_preferences, sizeof(server_cipher_preferences));
215 server_cipher_preferences.count = 1;
216 struct s2n_cipher_suite *cur_cipher = default_cipher_preferences->suites[cipher_idx];
217
218 if (!cur_cipher->available) {
219 /* Skip ciphers that aren't supported with the linked libcrypto. */
220 continue;
221 }
222
223 server_cipher_preferences.suites = &cur_cipher;
224
225 EXPECT_MEMCPY_SUCCESS(&security_policy, default_security_policy, sizeof(security_policy));
226 security_policy.cipher_preferences = &server_cipher_preferences;
227
228 client_config->security_policy = &security_policy;
229 server_config->security_policy = &security_policy;
230
231 /* Create nonblocking pipes. */
232 struct s2n_test_io_pair io_pair;
233 EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair));
234
235 EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
236 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
237
238 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
239 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
240
241 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
242
243 /* Verify the handshake was successful. */
244 EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
245
246 /* Verify that neither connection negotiated mutual auth. */
247 EXPECT_FALSE(s2n_connection_client_cert_used(server_conn));
248 EXPECT_FALSE(s2n_connection_client_cert_used(client_conn));
249
250 EXPECT_SUCCESS(s2n_connection_free(client_conn));
251 EXPECT_SUCCESS(s2n_connection_free(server_conn));
252 EXPECT_SUCCESS(s2n_io_pair_close(&io_pair));
253 }
254
255 EXPECT_SUCCESS(s2n_config_free(client_config));
256
257 /*
258 * Test optional client auth using **s2n_connection_set_client_auth_type** with a valid client cert provided.
259 */
260
261 EXPECT_NOT_NULL(client_config = s2n_config_new());
262 EXPECT_SUCCESS(s2n_config_set_cipher_preferences(client_config, "20240501"));
263 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(client_config, chain_and_key));
264 EXPECT_SUCCESS(s2n_config_disable_x509_verification(client_config));
265 EXPECT_SUCCESS(s2n_config_set_client_auth_type(client_config, S2N_CERT_AUTH_REQUIRED));
266
267 /* Server requires no client auth but the connection will. */
268 EXPECT_SUCCESS(s2n_config_set_client_auth_type(server_config, S2N_CERT_AUTH_NONE));
269 EXPECT_SUCCESS(s2n_config_disable_x509_verification(server_config));
270
271 /* Verify that a handshake succeeds for every cipher in the default list. */
272 for (int cipher_idx = 0; cipher_idx < default_cipher_preferences->count; cipher_idx++) {
273 struct s2n_cipher_preferences server_cipher_preferences;
274 struct s2n_security_policy security_policy;
275 struct s2n_connection *client_conn = NULL;
276 struct s2n_connection *server_conn = NULL;
277
278 /* Craft a cipher preference with a cipher_idx cipher. */
279 EXPECT_MEMCPY_SUCCESS(&server_cipher_preferences, default_cipher_preferences, sizeof(server_cipher_preferences));
280 server_cipher_preferences.count = 1;
281 struct s2n_cipher_suite *cur_cipher = default_cipher_preferences->suites[cipher_idx];
282
283 if (!cur_cipher->available) {
284 /* Skip ciphers that aren't supported with the linked libcrypto. */
285 continue;
286 }
287
288 server_cipher_preferences.suites = &cur_cipher;
289
290 EXPECT_MEMCPY_SUCCESS(&security_policy, default_security_policy, sizeof(security_policy));
291 security_policy.cipher_preferences = &server_cipher_preferences;
292
293 client_config->security_policy = &security_policy;
294 server_config->security_policy = &security_policy;
295
296 /* Create nonblocking pipes. */
297 struct s2n_test_io_pair io_pair;
298 EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair));
299
300 EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
301 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
302
303 /* Override the config setting on the connection. */
304 EXPECT_SUCCESS(s2n_connection_set_client_auth_type(client_conn, S2N_CERT_AUTH_REQUIRED));
305
306 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
307 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
308
309 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
310
311 /* Override the config setting on the connection. */
312 EXPECT_SUCCESS(s2n_connection_set_client_auth_type(server_conn, S2N_CERT_AUTH_OPTIONAL));
313
314 /* Verify the handshake was successful. */
315 EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
316
317 /* Verify that both connections negotiated mutual auth. */
318 EXPECT_TRUE(s2n_connection_client_cert_used(server_conn));
319 EXPECT_TRUE(s2n_connection_client_cert_used(client_conn));
320
321 EXPECT_SUCCESS(s2n_connection_free(client_conn));
322 EXPECT_SUCCESS(s2n_connection_free(server_conn));
323 EXPECT_SUCCESS(s2n_io_pair_close(&io_pair));
324 }
325
326 EXPECT_SUCCESS(s2n_config_free(client_config));
327
328 /*
329 * Test optional client auth using **s2n_connection_set_client_auth_type** with no client cert provided.
330 */
331
332 EXPECT_NOT_NULL(client_config = s2n_config_new());
333 EXPECT_SUCCESS(s2n_config_set_cipher_preferences(client_config, "20240501"));
334 EXPECT_SUCCESS(s2n_config_disable_x509_verification(client_config));
335 EXPECT_SUCCESS(s2n_config_set_client_auth_type(client_config, S2N_CERT_AUTH_REQUIRED));
336
337 /* Server requires client auth but the connection will allow an empty client cert. */
338 EXPECT_SUCCESS(s2n_config_set_client_auth_type(server_config, S2N_CERT_AUTH_REQUIRED));
339 EXPECT_SUCCESS(s2n_config_disable_x509_verification(server_config));
340
341 /* Verify that a handshake succeeds for every cipher in the default list. */
342 for (int cipher_idx = 0; cipher_idx < default_cipher_preferences->count; cipher_idx++) {
343 struct s2n_cipher_preferences server_cipher_preferences;
344 struct s2n_security_policy security_policy;
345 struct s2n_connection *client_conn = NULL;
346 struct s2n_connection *server_conn = NULL;
347
348 /* Craft a cipher preference with a cipher_idx cipher. */
349 EXPECT_MEMCPY_SUCCESS(&server_cipher_preferences, default_cipher_preferences, sizeof(server_cipher_preferences));
350 server_cipher_preferences.count = 1;
351 struct s2n_cipher_suite *cur_cipher = default_cipher_preferences->suites[cipher_idx];
352
353 if (!cur_cipher->available) {
354 /* Skip ciphers that aren't supported with the linked libcrypto. */
355 continue;
356 }
357
358 server_cipher_preferences.suites = &cur_cipher;
359
360 EXPECT_MEMCPY_SUCCESS(&security_policy, default_security_policy, sizeof(security_policy));
361 security_policy.cipher_preferences = &server_cipher_preferences;
362
363 client_config->security_policy = &security_policy;
364 server_config->security_policy = &security_policy;
365
366 /* Create nonblocking pipes. */
367 struct s2n_test_io_pair io_pair;
368 EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair));
369
370 EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
371 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
372
373 /* Override the config setting on the connection. */
374 EXPECT_SUCCESS(s2n_connection_set_client_auth_type(client_conn, S2N_CERT_AUTH_OPTIONAL));
375
376 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
377 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
378
379 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
380
381 /* Override the config setting on the connection. */
382 EXPECT_SUCCESS(s2n_connection_set_client_auth_type(server_conn, S2N_CERT_AUTH_OPTIONAL));
383
384 /* Verify the handshake was successful. */
385 EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
386
387 /* Verify that neither connection negotiated mutual auth. */
388 EXPECT_FALSE(s2n_connection_client_cert_used(server_conn));
389 EXPECT_FALSE(s2n_connection_client_cert_used(client_conn));
390
391 EXPECT_SUCCESS(s2n_connection_free(client_conn));
392 EXPECT_SUCCESS(s2n_connection_free(server_conn));
393 EXPECT_SUCCESS(s2n_io_pair_close(&io_pair));
394 }
395
396 EXPECT_SUCCESS(s2n_config_free(client_config));
397
398 /*
399 * Test optional client auth using **s2n_config_set_client_auth_type** with an incorrect client
400 * cert provided fails negotiation, allowing the user to fatally kill the handshake if they want.
401 * https://tools.ietf.org/html/rfc5246#section-7.4.6
402 */
403
404 EXPECT_NOT_NULL(client_config = s2n_config_new());
405 EXPECT_SUCCESS(s2n_config_set_cipher_preferences(client_config, "20240501"));
406 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(client_config, chain_and_key));
407 EXPECT_SUCCESS(s2n_config_disable_x509_verification(client_config));
408 EXPECT_SUCCESS(s2n_config_set_client_auth_type(client_config, S2N_CERT_AUTH_OPTIONAL));
409
410 /* Server requires optional client auth but will reject the client cert. We need to reset the config, to turn validation back on*/
411 EXPECT_SUCCESS(s2n_config_free(server_config));
412 EXPECT_NOT_NULL(server_config = s2n_config_new());
413 EXPECT_SUCCESS(s2n_config_set_cipher_preferences(server_config, "20240501"));
414 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_DHPARAMS, dhparams_pem, S2N_MAX_TEST_PEM_SIZE));
415 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, chain_and_key));
416 EXPECT_SUCCESS(s2n_config_add_dhparams(server_config, dhparams_pem));
417 EXPECT_NOT_NULL(default_security_policy = server_config->security_policy);
418 EXPECT_SUCCESS(s2n_config_set_client_auth_type(server_config, S2N_CERT_AUTH_OPTIONAL));
419
420 /* Verify that a handshake fails for every cipher in the default list. */
421 for (int cipher_idx = 0; cipher_idx < default_cipher_preferences->count; cipher_idx++) {
422 struct s2n_cipher_preferences server_cipher_preferences;
423 struct s2n_security_policy security_policy;
424 struct s2n_connection *client_conn = NULL;
425 struct s2n_connection *server_conn = NULL;
426
427 /* Craft a cipher preference with a cipher_idx cipher. */
428 EXPECT_MEMCPY_SUCCESS(&server_cipher_preferences, default_cipher_preferences, sizeof(server_cipher_preferences));
429 server_cipher_preferences.count = 1;
430 struct s2n_cipher_suite *cur_cipher = default_cipher_preferences->suites[cipher_idx];
431
432 if (!cur_cipher->available) {
433 /* Skip ciphers that aren't supported with the linked libcrypto. */
434 continue;
435 }
436
437 server_cipher_preferences.suites = &cur_cipher;
438
439 EXPECT_MEMCPY_SUCCESS(&security_policy, default_security_policy, sizeof(security_policy));
440 security_policy.cipher_preferences = &server_cipher_preferences;
441
442 client_config->security_policy = &security_policy;
443 server_config->security_policy = &security_policy;
444
445 /* Create nonblocking pipes. */
446 struct s2n_test_io_pair io_pair;
447 EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair));
448
449 EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
450 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
451
452 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
453 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
454
455 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
456
457 /* Verify the handshake failed. Blinding is disabled for the failure case to speed up tests. */
458 EXPECT_SUCCESS(s2n_connection_set_blinding(server_conn, S2N_SELF_SERVICE_BLINDING));
459 EXPECT_FAILURE(s2n_negotiate_test_server_and_client(server_conn, client_conn));
460
461 /* Verify that neither connection negotiated mutual auth. */
462 EXPECT_FALSE(s2n_connection_client_cert_used(server_conn));
463 EXPECT_FALSE(s2n_connection_client_cert_used(client_conn));
464
465 EXPECT_SUCCESS(s2n_connection_free(client_conn));
466 EXPECT_SUCCESS(s2n_connection_free(server_conn));
467 EXPECT_SUCCESS(s2n_io_pair_close(&io_pair));
468 }
469
470 EXPECT_SUCCESS(s2n_config_free(client_config));
471
472 EXPECT_SUCCESS(s2n_config_free(server_config));
473 EXPECT_SUCCESS(s2n_cert_chain_and_key_free(chain_and_key));
474 free(cert_chain_pem);
475 free(private_key_pem);
476 free(dhparams_pem);
477 END_TEST();
478 }