Debian Codegraph @

crt/s2n/tests/unit/s2n_pq_mlkem_policies_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 "crypto/s2n_mldsa.h"
17 #include "crypto/s2n_pq.h"
18 #include "s2n_test.h"
19 #include "testlib/s2n_testlib.h"
20 #include "tls/s2n_kem.h"
21 #include "tls/s2n_security_policies.h"
22 #include "tls/s2n_tls.h"
23
24 static S2N_RESULT s2n_policy_has_cipher(const struct s2n_security_policy *security_policy, const struct s2n_cipher_suite *needle, bool *val)
25 {
26 RESULT_ENSURE_REF(security_policy);
27 RESULT_ENSURE_REF(security_policy->cipher_preferences);
28 RESULT_ENSURE_REF(security_policy->cipher_preferences->suites);
29
30 for (size_t i = 0; i < security_policy->cipher_preferences->count; i++) {
31 const struct s2n_cipher_suite *hay = security_policy->cipher_preferences->suites[i];
32 if (hay == needle) {
33 *val = true;
34 return S2N_RESULT_OK;
35 }
36 }
37
38 *val = false;
39 return S2N_RESULT_OK;
40 }
41
42 static S2N_RESULT s2n_policy_has_kem(const struct s2n_security_policy *security_policy, const struct s2n_kem **kem_list, size_t kem_list_count, bool *val)
43 {
44 RESULT_ENSURE_REF(security_policy);
45 RESULT_ENSURE_REF(security_policy->kem_preferences);
46
47 if (security_policy->kem_preferences->tls13_kem_groups == NULL || security_policy->kem_preferences->tls13_kem_group_count == 0) {
48 *val = false;
49 return S2N_RESULT_OK;
50 }
51
52 for (size_t i = 0; i < security_policy->kem_preferences->tls13_kem_group_count; i++) {
53 const struct s2n_kem_group *supported_kem_group = security_policy->kem_preferences->tls13_kem_groups[i];
54 RESULT_ENSURE_REF(supported_kem_group);
55 for (int j = 0; j < kem_list_count; j++) {
56 const struct s2n_kem *banned_kem = kem_list[j];
57 RESULT_ENSURE_REF(banned_kem);
58 if (supported_kem_group->kem == banned_kem) {
59 *val = true;
60 return S2N_RESULT_OK;
61 }
62 }
63 }
64
65 *val = false;
66 return S2N_RESULT_OK;
67 }
68
69 static S2N_RESULT s2n_policy_in_list(const char *policy_name, const char **exception_list, size_t list_count, bool *val)
70 {
71 RESULT_ENSURE_REF(policy_name);
72
73 for (size_t i = 0; i < list_count; i++) {
74 const char *exception = exception_list[i];
75 RESULT_ENSURE_REF(exception);
76
77 if (strlen(policy_name) != strlen(exception)) {
78 continue;
79 }
80
81 if (memcmp(policy_name, exception, strlen(policy_name)) == 0) {
82 *val = true;
83 return S2N_RESULT_OK;
84 }
85 }
86
87 *val = false;
88 return S2N_RESULT_OK;
89 }
90
91 /* List of all ML-KEM Parameter sizes */
92 const struct s2n_kem *mlkem_list[] = {
93 &s2n_mlkem_768,
94 &s2n_mlkem_1024
95 };
96
97 /* Ciphers that should not be present in TLS Policies that have ML-KEM */
98 const struct s2n_cipher_suite *legacy_cipher_suites[] = {
99 &s2n_rsa_with_3des_ede_cbc_sha,
100 &s2n_dhe_rsa_with_3des_ede_cbc_sha,
101 &s2n_ecdhe_rsa_with_3des_ede_cbc_sha,
102 &s2n_ecdhe_rsa_with_rc4_128_sha,
103 &s2n_rsa_with_rc4_128_sha,
104 &s2n_rsa_with_rc4_128_md5,
105 &s2n_null_cipher_suite,
106 };
107
108 /* List of s2n TLS Security Policies that are allowed to have legacy TLS Ciphers and support ML-KEM */
109 const char *cipher_exceptions[] = {
110 "CloudFront-Upstream-2025-PQ",
111 "CloudFront-Upstream-TLS-1-0-2025-PQ",
112 "CloudFront-Upstream-TLS-1-1-2025-PQ",
113 "CloudFront-Upstream-TLS-1-2-2025-PQ",
114 "CloudFront-Upstream-TLS-1-3-2025-PQ",
115 "CloudFront-SSL-v-3",
116 "CloudFront-TLS-1-0-2014",
117 "CloudFront-TLS-1-0-2014-PQ-Beta",
118 "CloudFront-TLS-1-0-2014-sha256",
119 "CloudFront-TLS-1-0-2016",
120 "test_all",
121 "20260520",
122 "20260520_gcm",
123 };
124
125 /* List of s2n TLS Security Policies that are allowed to have a minimum TLS Version below TLS 1.2 and support ML-KEM */
126 const char *tls_version_exceptions[] = {
127 "AWS-CRT-SDK-TLSv1.0-2025-PQ",
128 "CloudFront-Upstream-2025-PQ",
129 "CloudFront-Upstream-TLS-1-0-2025-PQ",
130 "CloudFront-Upstream-TLS-1-1-2025-PQ",
131 "CloudFront-SSL-v-3",
132 "CloudFront-TLS-1-0-2014",
133 "CloudFront-TLS-1-0-2014-PQ-Beta",
134 "CloudFront-TLS-1-0-2014-sha256",
135 "CloudFront-TLS-1-0-2016",
136 "CloudFront-TLS-1-1-2016",
137 "test_all",
138 "20260520",
139 "20260520_gcm",
140 };
141
142 const size_t mlkem_list_size = s2n_array_len(mlkem_list);
143 const size_t cipher_exceptions_size = s2n_array_len(cipher_exceptions);
144 const size_t tls_version_exceptions_size = s2n_array_len(tls_version_exceptions);
145
146 int main(int argc, char **argv)
147 {
148 BEGIN_TEST();
149
150 /* Enforce minimum requirements on all security policies that support ML-KEM */
151 for (size_t policy_index = 0; security_policy_selection[policy_index].version != NULL; policy_index++) {
152 const struct s2n_security_policy_selection selection = security_policy_selection[policy_index];
153 const char *policy_name = selection.version;
154 const struct s2n_security_policy *security_policy = selection.security_policy;
155 POSIX_ENSURE_REF(security_policy);
156
157 bool has_mlkem = false;
158 EXPECT_OK(s2n_policy_has_kem(security_policy, mlkem_list, mlkem_list_size, &has_mlkem));
159
160 if (!has_mlkem) {
161 continue;
162 }
163
164 /* ML-KEM requires TLS 1.3 in order to be negotiated. Ensure that Policies with ML-KEM also support TLS 1.3 */
165 bool has_tls_13_cipher = false;
166 for (size_t i = 0; i < security_policy->cipher_preferences->count; i++) {
167 if (security_policy->cipher_preferences->suites[i]->minimum_required_tls_version == S2N_TLS13) {
168 has_tls_13_cipher = true;
169 break;
170 }
171 }
172 EXPECT_TRUE(has_tls_13_cipher);
173
174 /* Ensure all security policies that have ML-KEM support do not use previous draft wire-format
175 * for Hybrid KeyShares with length prefixing. */
176 const struct s2n_kem_preferences *kem_preferences = security_policy->kem_preferences;
177 POSIX_ENSURE_REF(kem_preferences);
178 EXPECT_FALSE(s2n_tls13_client_must_use_hybrid_kem_length_prefix(kem_preferences));
179
180 /* All security policies that have ML-KEM should have TLS 1.2 as their minimum supported TLS Version */
181 if (security_policy->minimum_protocol_version < S2N_TLS12) {
182 bool has_exception = false;
183 EXPECT_OK(s2n_policy_in_list(policy_name, tls_version_exceptions, tls_version_exceptions_size, &has_exception));
184
185 if (!has_exception) {
186 fprintf(stdout, "Security Policy: %s has ML-KEM and uses a legacy TLS Version: %d\n",
187 policy_name, security_policy->minimum_protocol_version);
188 FAIL_MSG("ML-KEM policies should not contain legacy TLS Versions.");
189 }
190 }
191
192 /* Policies that have ML-KEM should not have 3DES or RC4 */
193 for (int j = 0; j < s2n_array_len(legacy_cipher_suites); j++) {
194 bool has_cipher = false;
195 EXPECT_OK(s2n_policy_has_cipher(security_policy, legacy_cipher_suites[j], &has_cipher));
196
197 if (has_cipher) {
198 bool has_exception = false;
199 EXPECT_OK(s2n_policy_in_list(policy_name, cipher_exceptions, cipher_exceptions_size, &has_exception));
200
201 if (!has_exception) {
202 fprintf(stdout, "Security Policy: %s has ML-KEM and legacy cipher: %s\n",
203 policy_name, legacy_cipher_suites[j]->name);
204 FAIL_MSG("ML-KEM policies should not contain legacy ciphers.");
205 }
206 }
207 }
208 }
209
210 /* Test configuring a PQ only policy on different libcryptos. */
211 const char *pq_only_policies[] = { "test_pq_only", "cnsa_2" };
212 for (int i = 0; i < s2n_array_len(pq_only_policies); i++) {
213 DEFER_CLEANUP(struct s2n_config *config = s2n_config_new(), s2n_config_ptr_free);
214 EXPECT_NOT_NULL(config);
215 const char *policy = pq_only_policies[i];
216
217 if (!s2n_is_tls13_fully_supported()) {
218 EXPECT_FAILURE_WITH_ERRNO(s2n_config_set_cipher_preferences(config, policy), S2N_ERR_PROTOCOL_VERSION_UNSUPPORTED);
219 } else if (!s2n_libcrypto_supports_mlkem()) {
220 EXPECT_FAILURE_WITH_ERRNO(s2n_config_set_cipher_preferences(config, policy), S2N_ERR_INVALID_SECURITY_POLICY);
221 } else {
222 EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, policy));
223 }
224 }
225
226 /* Self-talk tests for PQ only policies on supported libcryptos. */
227 if (s2n_is_tls13_fully_supported() && s2n_libcrypto_supports_mlkem()) {
228 DEFER_CLEANUP(struct s2n_cert_chain_and_key *chain_and_key = NULL, s2n_cert_chain_and_key_ptr_free);
229 EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&chain_and_key,
230 S2N_DEFAULT_TEST_CERT_CHAIN, S2N_DEFAULT_TEST_PRIVATE_KEY));
231
232 /* Test a PQ-only policy is able to negotiate. */
233 {
234 DEFER_CLEANUP(struct s2n_config *config = s2n_config_new(), s2n_config_ptr_free);
235 EXPECT_NOT_NULL(config);
236 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, chain_and_key));
237 EXPECT_SUCCESS(s2n_config_set_verification_ca_location(config, S2N_DEFAULT_TEST_CERT_CHAIN, NULL));
238 EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "test_pq_only"));
239
240 DEFER_CLEANUP(struct s2n_connection *client_conn = s2n_connection_new(S2N_CLIENT), s2n_connection_ptr_free);
241 EXPECT_NOT_NULL(client_conn);
242 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, config));
243 EXPECT_SUCCESS(s2n_set_server_name(client_conn, "localhost"));
244
245 DEFER_CLEANUP(struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER), s2n_connection_ptr_free);
246 EXPECT_NOT_NULL(server_conn);
247 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, config));
248
249 DEFER_CLEANUP(struct s2n_test_io_pair io_pair = { 0 }, s2n_io_pair_close);
250 EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair));
251 EXPECT_SUCCESS(s2n_connection_set_io_pair(client_conn, &io_pair));
252 EXPECT_SUCCESS(s2n_connection_set_io_pair(server_conn, &io_pair));
253
254 EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
255 /* Assert classical ECC is not negotiated & kem group is negotiated. */
256 EXPECT_NULL(server_conn->kex_params.server_ecc_evp_params.negotiated_curve);
257 EXPECT_NOT_NULL(server_conn->kex_params.server_kem_group_params.kem_group);
258 }
259
260 /* Expect failure when a non-PQ client attempts to negotiate with a PQ-only server. */
261 {
262 DEFER_CLEANUP(struct s2n_config *config = s2n_config_new(), s2n_config_ptr_free);
263 EXPECT_NOT_NULL(config);
264 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, chain_and_key));
265 EXPECT_SUCCESS(s2n_config_set_verification_ca_location(config, S2N_DEFAULT_TEST_CERT_CHAIN, NULL));
266
267 DEFER_CLEANUP(struct s2n_connection *client_conn = s2n_connection_new(S2N_CLIENT), s2n_connection_ptr_free);
268 EXPECT_NOT_NULL(client_conn);
269 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, config));
270 EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(client_conn, "20240503"));
271 EXPECT_SUCCESS(s2n_set_server_name(client_conn, "localhost"));
272
273 DEFER_CLEANUP(struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER), s2n_connection_ptr_free);
274 EXPECT_NOT_NULL(server_conn);
275 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, config));
276 EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(server_conn, "test_pq_only"));
277 EXPECT_SUCCESS(s2n_connection_set_blinding(server_conn, S2N_SELF_SERVICE_BLINDING));
278
279 DEFER_CLEANUP(struct s2n_test_io_pair io_pair = { 0 }, s2n_io_pair_close);
280 EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair));
281 EXPECT_SUCCESS(s2n_connection_set_io_pair(client_conn, &io_pair));
282 EXPECT_SUCCESS(s2n_connection_set_io_pair(server_conn, &io_pair));
283
284 EXPECT_FAILURE_WITH_ERRNO(s2n_negotiate_test_server_and_client(server_conn, client_conn),
285 S2N_ERR_INVALID_SUPPORTED_GROUP_STATE);
286 /* Assert server negotiated_curve and kem_group are both NULL. */
287 EXPECT_NULL(server_conn->kex_params.server_ecc_evp_params.negotiated_curve);
288 EXPECT_NULL(server_conn->kex_params.server_kem_group_params.kem_group);
289 }
290 }
291
292 /* Self-talk tests for `cnsa_2` and `cnsa_1_2_interop` policies on supported libcryptos. */
293 if (s2n_is_tls13_fully_supported() && s2n_libcrypto_supports_mlkem() && s2n_mldsa_is_supported()) {
294 DEFER_CLEANUP(struct s2n_cert_chain_and_key *ecdsa_sha384_chain_and_key = NULL, s2n_cert_chain_and_key_ptr_free);
295 EXPECT_SUCCESS(s2n_test_cert_permutation_load_server_chain(&ecdsa_sha384_chain_and_key, "ec", "ecdsa", "p384", "sha384"));
296 const char *ecdsa_sha384_cert = "../pems/permutations/ec_ecdsa_p384_sha384/server-chain.pem";
297
298 DEFER_CLEANUP(struct s2n_cert_chain_and_key *mldsa44_chain_and_key = NULL, s2n_cert_chain_and_key_ptr_free);
299 EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&mldsa44_chain_and_key, S2N_MLDSA44_CERT, S2N_MLDSA44_KEY));
300
301 DEFER_CLEANUP(struct s2n_cert_chain_and_key *mldsa87_chain_and_key = NULL, s2n_cert_chain_and_key_ptr_free);
302 EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&mldsa87_chain_and_key, S2N_MLDSA87_CERT, S2N_MLDSA87_KEY));
303
304 DEFER_CLEANUP(struct s2n_config *cnsa2_config = s2n_config_new(), s2n_config_ptr_free);
305 EXPECT_NOT_NULL(cnsa2_config);
306 /* `cnsa_2` policy only accepts ML-DSA-87 for signing. */
307 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(cnsa2_config, mldsa44_chain_and_key));
308 EXPECT_FAILURE_WITH_ERRNO(s2n_config_set_cipher_preferences(cnsa2_config, "cnsa_2"), S2N_ERR_SECURITY_POLICY_INCOMPATIBLE_CERT);
309
310 /* clang-format off */
311 struct {
312 const char *client_policy;
313 const char *server_policy;
314 const char *server_name;
315 s2n_error expected_error;
316 bool hrr_expected;
317 const char *expected_group;
318 const char *expected_sig_scheme;
319 } test_cases[] = {
320 {
321 .client_policy = "cnsa_2",
322 .server_policy = "cnsa_2",
323 .server_name = "LAMPS WG",
324 .expected_error = S2N_ERR_OK,
325 .hrr_expected = false,
326 .expected_group = "MLKEM1024",
327 .expected_sig_scheme = "mldsa87",
328 },
329 /* `test_all` supports both pure MLKEM1024 (not the most preferred) and ML-DSA-87. */
330 {
331 .client_policy = "test_all",
332 .server_policy = "cnsa_2",
333 .server_name = "LAMPS WG",
334 .expected_error = S2N_ERR_OK,
335 .hrr_expected = true,
336 .expected_group = "MLKEM1024",
337 .expected_sig_scheme = "mldsa87",
338 },
339 /* `20250721` does not support pure MLKEM1024. */
340 {
341 .client_policy = "20250721",
342 .server_policy = "cnsa_2",
343 .server_name = "LAMPS WG",
344 .expected_error = S2N_ERR_INVALID_SUPPORTED_GROUP_STATE,
345 },
346 /* `test_pq_only` does not support ML-DSA-87. */
347 {
348 .client_policy = "test_pq_only",
349 .server_policy = "cnsa_2",
350 .server_name = "LAMPS WG",
351 .expected_error = S2N_ERR_INVALID_SIGNATURE_SCHEME,
352 },
353 /* Client side `cnsa_2` failure case: server sends an ML-DSA-44 cert. */
354 {
355 .client_policy = "cnsa_2",
356 .server_policy = "test_all",
357 .server_name = "LAMPS WG",
358 .expected_error = S2N_ERR_SECURITY_POLICY_INCOMPATIBLE_CERT,
359 },
360 /* `cnsa_1_2_interop` is compatible with the CNSA 2.0 policy. */
361 {
362 .client_policy = "cnsa_2",
363 .server_policy = "cnsa_1_2_interop",
364 .server_name = "LAMPS WG",
365 .expected_error = S2N_ERR_OK,
366 .hrr_expected = false,
367 .expected_group = "MLKEM1024",
368 .expected_sig_scheme = "mldsa87",
369 },
370 /* `cnsa_1_2_interop` is compatible with the CNSA 1.0 policy. */
371 {
372 .client_policy = "rfc9151",
373 .server_policy = "cnsa_1_2_interop",
374 .server_name = "localhost",
375 .expected_error = S2N_ERR_OK,
376 .hrr_expected = false,
377 .expected_group = "secp384r1",
378 .expected_sig_scheme = "ecdsa_secp384r1_sha384",
379 },
380 /* `cnsa_1_2_interop` prefers pure MLKEM1024 over secp384r1 curve. */
381 {
382 .client_policy = "cnsa_1_2_interop",
383 .server_policy = "cnsa_1_2_interop",
384 .server_name = "LAMPS WG",
385 .expected_error = S2N_ERR_OK,
386 .hrr_expected = false,
387 .expected_group = "MLKEM1024",
388 .expected_sig_scheme = "mldsa87",
389 },
390 /* `20250721` does not support pure MLKEM1024 and prefers secp256r1 over secp384r1. */
391 {
392 .client_policy = "20250721",
393 .server_policy = "cnsa_1_2_interop",
394 .server_name = "LAMPS WG",
395 .expected_error = S2N_ERR_OK,
396 .hrr_expected = true,
397 .expected_group = "secp384r1",
398 .expected_sig_scheme = "mldsa87",
399 },
400 /* Default CRT policy does not support ML-DSA-87 and prefers hybrid MLKEM over pure MLKEM1024. */
401 {
402 .client_policy = "AWS-CRT-SDK-TLSv1.0-2025-PQ",
403 .server_policy = "cnsa_1_2_interop",
404 .server_name = "localhost",
405 .expected_error = S2N_ERR_OK,
406 .hrr_expected = true,
407 .expected_group = "MLKEM1024",
408 .expected_sig_scheme = "ecdsa_secp384r1_sha384",
409 },
410 };
411 /* clang-format on */
412
413 for (int i = 0; i < s2n_array_len(test_cases); i++) {
414 DEFER_CLEANUP(struct s2n_config *server_config = s2n_config_new(), s2n_config_ptr_free);
415 EXPECT_NOT_NULL(server_config);
416 DEFER_CLEANUP(struct s2n_config *client_config = s2n_config_new(), s2n_config_ptr_free);
417 EXPECT_NOT_NULL(client_config);
418
419 if (strcmp(test_cases[i].server_policy, "test_all") == 0) {
420 /* Client side `cnsa_2` failure case: server sends an ML-DSA-44 cert. */
421 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, mldsa44_chain_and_key));
422 EXPECT_SUCCESS(s2n_config_set_verification_ca_location(client_config, S2N_MLDSA44_CERT, NULL));
423 } else if (strcmp(test_cases[i].server_name, "LAMPS WG") == 0) {
424 /* "LAMPS WG" is the server name used by the RFC ML-DSA test certificate. */
425 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, mldsa87_chain_and_key));
426 EXPECT_SUCCESS(s2n_config_set_verification_ca_location(client_config, S2N_MLDSA87_CERT, NULL));
427 } else {
428 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, ecdsa_sha384_chain_and_key));
429 EXPECT_SUCCESS(s2n_config_set_verification_ca_location(client_config, ecdsa_sha384_cert, NULL));
430 }
431
432 DEFER_CLEANUP(struct s2n_connection *client_conn = s2n_connection_new(S2N_CLIENT), s2n_connection_ptr_free);
433 EXPECT_NOT_NULL(client_conn);
434 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
435 EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(client_conn, test_cases[i].client_policy));
436 EXPECT_SUCCESS(s2n_set_server_name(client_conn, test_cases[i].server_name));
437 EXPECT_SUCCESS(s2n_connection_set_blinding(client_conn, S2N_SELF_SERVICE_BLINDING));
438
439 DEFER_CLEANUP(struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER), s2n_connection_ptr_free);
440 EXPECT_NOT_NULL(server_conn);
441 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
442 EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(server_conn, test_cases[i].server_policy));
443 EXPECT_SUCCESS(s2n_connection_set_blinding(server_conn, S2N_SELF_SERVICE_BLINDING));
444
445 DEFER_CLEANUP(struct s2n_test_io_pair io_pair = { 0 }, s2n_io_pair_close);
446 EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair));
447 EXPECT_SUCCESS(s2n_connection_set_io_pair(client_conn, &io_pair));
448 EXPECT_SUCCESS(s2n_connection_set_io_pair(server_conn, &io_pair));
449
450 if (test_cases[i].expected_error == S2N_ERR_OK) {
451 EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
452 } else {
453 EXPECT_FAILURE_WITH_ERRNO(s2n_negotiate_test_server_and_client(server_conn, client_conn), test_cases[i].expected_error);
454 continue;
455 }
456 EXPECT_EQUAL(test_cases[i].hrr_expected, s2n_is_hello_retry_handshake(server_conn));
457
458 const char *selected_group;
459 EXPECT_SUCCESS(s2n_connection_get_key_exchange_group(server_conn, &selected_group));
460 EXPECT_EQUAL(strcmp(test_cases[i].expected_group, selected_group), 0);
461
462 const char *selected_sig_scheme;
463 EXPECT_SUCCESS(s2n_connection_get_signature_scheme(server_conn, &selected_sig_scheme));
464 EXPECT_EQUAL(strcmp(test_cases[i].expected_sig_scheme, selected_sig_scheme), 0);
465 }
466 }
467
468 END_TEST();
469 }