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 "s2n_test.h"
17 #include "testlib/s2n_testlib.h"
18 
19 #include "tls/extensions/s2n_extension_type.h"
20 #include "tls/extensions/s2n_extension_type_lists.h"
21 #include "utils/s2n_bitmap.h"
22 #include "tls/s2n_tls.h"
23 #include "tls/s2n_tls13.h"
24 
25 #define S2N_TEST_DATA_LEN 20
26 
27 #define EXPECT_BITFIELD_CLEAR(field) EXPECT_BYTEARRAY_EQUAL((field), &empty_bitfield, S2N_SUPPORTED_EXTENSIONS_BITFIELD_LEN)
28 
29 s2n_extension_type_id s2n_extension_iana_value_to_id(uint16_t iana_value);
30 
31 const s2n_extension_bitfield empty_bitfield = { 0 };
32 
test_send(struct s2n_connection * conn,struct s2n_stuffer * out)33 static int test_send(struct s2n_connection *conn, struct s2n_stuffer *out)
34 {
35     return s2n_stuffer_skip_write(out, S2N_TEST_DATA_LEN);
36 }
37 
test_send_too_much_data(struct s2n_connection * conn,struct s2n_stuffer * out)38 static int test_send_too_much_data(struct s2n_connection *conn, struct s2n_stuffer *out)
39 {
40     return s2n_stuffer_skip_write(out, UINT16_MAX + 1);
41 }
42 
test_recv(struct s2n_connection * conn,struct s2n_stuffer * in)43 static int test_recv(struct s2n_connection *conn, struct s2n_stuffer *in)
44 {
45     return S2N_SUCCESS;
46 }
47 
48 const s2n_extension_type test_extension_type = {
49         .iana_value = TLS_EXTENSION_SUPPORTED_VERSIONS,
50         .is_response = false,
51         .send = test_send,
52         .recv = test_recv,
53         .should_send = s2n_extension_always_send,
54         .if_missing = s2n_extension_noop_if_missing,
55 };
56 
main()57 int main()
58 {
59     BEGIN_TEST();
60     EXPECT_SUCCESS(s2n_disable_tls13());
61 
62     /* Test common implementations of methods */
63     {
64         /* Test common implementations for send */
65         EXPECT_FAILURE_WITH_ERRNO(s2n_extension_send_unimplemented(NULL, NULL), S2N_ERR_UNIMPLEMENTED);
66         EXPECT_SUCCESS(s2n_extension_send_noop(NULL, NULL));
67 
68         /* Test common implementations for recv */
69         EXPECT_FAILURE_WITH_ERRNO(s2n_extension_recv_unimplemented(NULL, NULL), S2N_ERR_UNIMPLEMENTED);
70         EXPECT_SUCCESS(s2n_extension_recv_noop(NULL, NULL));
71 
72         /* Test common implementations for should_send */
73         {
74             EXPECT_TRUE(s2n_extension_always_send(NULL));
75             EXPECT_FALSE(s2n_extension_never_send(NULL));
76 
77             struct s2n_connection conn = { 0 };
78             conn.actual_protocol_version = S2N_TLS12;
79             EXPECT_FALSE(s2n_extension_send_if_tls13_connection(&conn));
80             conn.actual_protocol_version = S2N_TLS13;
81             EXPECT_TRUE(s2n_extension_send_if_tls13_connection(&conn));
82         }
83 
84         /* Test common implementations for if_missing */
85         EXPECT_FAILURE_WITH_ERRNO(s2n_extension_error_if_missing(NULL), S2N_ERR_MISSING_EXTENSION);
86         EXPECT_SUCCESS(s2n_extension_noop_if_missing(NULL));
87     }
88 
89     /* Test s2n_extension_iana_value_to_id */
90     {
91         /* Extension appearing in the lookup table can be handled */
92         EXPECT_EQUAL(s2n_extension_iana_value_to_id(s2n_supported_extensions[5]), 5);
93 
94         /* Unknown extension in the lookup table can be handled
95          * 15 == heartbeat, which s2n will probably never support :) */
96         EXPECT_EQUAL(s2n_extension_iana_value_to_id(15), s2n_unsupported_extension);
97 
98         /* Extension with iana too large for the lookup table can be handled */
99         EXPECT_EQUAL(s2n_extension_iana_value_to_id(TLS_EXTENSION_RENEGOTIATION_INFO), 0);
100 
101         /* Unknown extension with iana too large for the lookup table can be handled
102          * 65280 == grease value (see https://tools.ietf.org/html/rfc8701) */
103         EXPECT_EQUAL(s2n_extension_iana_value_to_id(65280), s2n_unsupported_extension);
104 
105         /* Every supported extension can be handled */
106         for (int i = 0; i < S2N_SUPPORTED_EXTENSIONS_COUNT; i++) {
107             EXPECT_EQUAL(s2n_extension_iana_value_to_id(s2n_supported_extensions[i]), i);
108         }
109     }
110 
111     /* Test s2n_extension_supported_iana_value_to_id */
112     {
113         s2n_extension_type_id id = s2n_unsupported_extension;
114 
115         /* Supported extension id returned */
116         const uint16_t supported_extension_id = 5;
117         EXPECT_SUCCESS(s2n_extension_supported_iana_value_to_id(s2n_supported_extensions[supported_extension_id], &id));
118         EXPECT_EQUAL(id, supported_extension_id);
119 
120         /* Fail on unsupported iana value
121          * 15 == heartbeat, which s2n will probably never support :) */
122         EXPECT_FAILURE_WITH_ERRNO(s2n_extension_supported_iana_value_to_id(15, &id),
123                 S2N_ERR_UNRECOGNIZED_EXTENSION);
124     }
125 
126     /* Test bitfield behavior */
127     {
128         s2n_extension_bitfield test_bitfield = { 0 };
129         for (int i = 0; i < S2N_SUPPORTED_EXTENSIONS_COUNT; i++) {
130             uint16_t iana = s2n_supported_extensions[i];
131             s2n_extension_type_id id = s2n_extension_iana_value_to_id(iana);
132 
133             EXPECT_FALSE(S2N_CBIT_TEST(test_bitfield, id));
134             S2N_CBIT_SET(test_bitfield, id);
135             EXPECT_TRUE(S2N_CBIT_TEST(test_bitfield, id));
136             S2N_CBIT_CLR(test_bitfield, id);
137             EXPECT_FALSE(S2N_CBIT_TEST(test_bitfield, id));
138         }
139     }
140 
141     s2n_extension_type_id test_extension_id = s2n_extension_iana_value_to_id(test_extension_type.iana_value);
142     EXPECT_NOT_EQUAL(test_extension_id, s2n_unsupported_extension);
143 
144     /* Test s2n_extension_recv */
145     {
146         struct s2n_stuffer stuffer = { 0 };
147 
148         /* null check tests */
149         {
150             struct s2n_connection conn = { 0 };
151 
152             EXPECT_FAILURE(s2n_extension_recv(NULL, &conn, &stuffer));
153             EXPECT_FAILURE(s2n_extension_recv(&test_extension_type, NULL, &stuffer));
154 
155             s2n_extension_type extension_type_with_null_recv = test_extension_type;
156             extension_type_with_null_recv.recv = NULL;
157             EXPECT_FAILURE(s2n_extension_recv(&extension_type_with_null_recv, &conn, &stuffer));
158         }
159 
160         /* request extension */
161         {
162             struct s2n_connection conn = { 0 };
163             s2n_extension_type request_extension_type = test_extension_type;
164             request_extension_type.is_response = false;
165 
166             /* Succeeds and sets request flag */
167             EXPECT_SUCCESS(s2n_extension_recv(&request_extension_type, &conn, &stuffer));
168             EXPECT_TRUE(S2N_CBIT_TEST(conn.extension_requests_received, test_extension_id));
169         }
170 
171         /* response extension */
172         {
173             struct s2n_connection conn = { 0 };
174             s2n_extension_type response_extension_type = test_extension_type;
175             response_extension_type.is_response = true;
176 
177             /* Fails if request was not sent */
178             EXPECT_FAILURE_WITH_ERRNO(s2n_extension_recv(&response_extension_type, &conn, &stuffer), S2N_ERR_UNSUPPORTED_EXTENSION);
179             /* cppcheck-suppress sizeofDivisionMemfunc */
180             EXPECT_BITFIELD_CLEAR(conn.extension_requests_received);
181 
182             /* Succeeds (but does not set request flag) if request was sent */
183             S2N_CBIT_SET(conn.extension_requests_sent, test_extension_id);
184             EXPECT_SUCCESS(s2n_extension_recv(&response_extension_type, &conn, &stuffer));
185             /* cppcheck-suppress sizeofDivisionMemfunc */
186             EXPECT_BITFIELD_CLEAR(conn.extension_requests_received);
187         }
188 
189         /* "recv" errors */
190         {
191             struct s2n_connection conn = { 0 };
192             s2n_extension_type extension_type_with_failure = test_extension_type;
193             extension_type_with_failure.recv = s2n_extension_recv_unimplemented;
194 
195             EXPECT_FAILURE_WITH_ERRNO(s2n_extension_recv(&extension_type_with_failure, &conn, &stuffer), S2N_ERR_UNIMPLEMENTED);
196             /* cppcheck-suppress sizeofDivisionMemfunc */
197             EXPECT_BITFIELD_CLEAR(conn.extension_requests_received);
198         }
199     }
200 
201     /* Test s2n_extension_send */
202     {
203         /* null check tests */
204         {
205             struct s2n_connection conn = { 0 };
206             struct s2n_stuffer stuffer = { 0 };
207 
208             EXPECT_FAILURE(s2n_extension_send(NULL, &conn, &stuffer));
209             EXPECT_FAILURE(s2n_extension_send(&test_extension_type, NULL, &stuffer));
210 
211             s2n_extension_type extension_type_with_null_send = test_extension_type;
212             extension_type_with_null_send.send = NULL;
213             EXPECT_FAILURE(s2n_extension_send(&extension_type_with_null_send, &conn, &stuffer));
214 
215             s2n_extension_type extension_type_with_null_should_send = test_extension_type;
216             extension_type_with_null_should_send.should_send = NULL;
217             EXPECT_FAILURE(s2n_extension_send(&extension_type_with_null_should_send, &conn, &stuffer));
218         }
219 
220         /* request extension */
221         {
222             struct s2n_connection conn = { 0 };
223             struct s2n_stuffer stuffer = { 0 };
224             s2n_stuffer_alloc(&stuffer, S2N_TEST_DATA_LEN * 2);
225 
226             s2n_extension_type request_extension_type = test_extension_type;
227             request_extension_type.is_response = false;
228 
229             /* Succeeds and sets request flag */
230             EXPECT_SUCCESS(s2n_extension_send(&request_extension_type, &conn, &stuffer));
231             EXPECT_TRUE(S2N_CBIT_TEST(conn.extension_requests_sent, test_extension_id));
232 
233             /* writes iana_value */
234             uint16_t iana_value;
235             EXPECT_SUCCESS(s2n_stuffer_read_uint16(&stuffer, &iana_value));
236             EXPECT_EQUAL(iana_value, request_extension_type.iana_value);
237 
238             /* writes length */
239             uint16_t length;
240             EXPECT_SUCCESS(s2n_stuffer_read_uint16(&stuffer, &length));
241             EXPECT_EQUAL(length, s2n_stuffer_data_available(&stuffer));
242             EXPECT_EQUAL(length, S2N_TEST_DATA_LEN);
243 
244             s2n_stuffer_free(&stuffer);
245         }
246 
247         /* response extension */
248         {
249             struct s2n_connection conn = { 0 };
250             struct s2n_stuffer stuffer = { 0 };
251             s2n_stuffer_alloc(&stuffer, S2N_TEST_DATA_LEN * 2);
252 
253             s2n_extension_type response_extension_type = test_extension_type;
254             response_extension_type.is_response = true;
255 
256             /* Succeeds but no-op if request was not received */
257             EXPECT_SUCCESS(s2n_extension_send(&response_extension_type, &conn, &stuffer));
258             EXPECT_EQUAL(0, s2n_stuffer_data_available(&stuffer));
259             /* cppcheck-suppress sizeofDivisionMemfunc */
260             EXPECT_BITFIELD_CLEAR(conn.extension_requests_sent);
261 
262             /* Succeeds (but does not set request flag) if request was received */
263             S2N_CBIT_SET(conn.extension_requests_received, test_extension_id);
264             EXPECT_SUCCESS(s2n_extension_send(&response_extension_type, &conn, &stuffer));
265             /* cppcheck-suppress sizeofDivisionMemfunc */
266             EXPECT_BITFIELD_CLEAR(conn.extension_requests_sent);
267 
268             /* writes iana_value */
269             uint16_t iana_value;
270             EXPECT_SUCCESS(s2n_stuffer_read_uint16(&stuffer, &iana_value));
271             EXPECT_EQUAL(iana_value, response_extension_type.iana_value);
272 
273             /* writes length */
274             uint16_t length;
275             EXPECT_SUCCESS(s2n_stuffer_read_uint16(&stuffer, &length));
276             EXPECT_EQUAL(length, s2n_stuffer_data_available(&stuffer));
277             EXPECT_EQUAL(length, S2N_TEST_DATA_LEN);
278 
279             s2n_stuffer_free(&stuffer);
280         }
281 
282         /* "should_send" returns false */
283         {
284             struct s2n_connection conn = { 0 };
285             struct s2n_stuffer stuffer = { 0 };
286 
287             s2n_extension_type extension_type_with_never_send = test_extension_type;
288             extension_type_with_never_send.should_send = s2n_extension_never_send;
289 
290             EXPECT_SUCCESS(s2n_extension_send(&extension_type_with_never_send, &conn, &stuffer));
291             EXPECT_EQUAL(0, s2n_stuffer_data_available(&stuffer));
292             /* cppcheck-suppress sizeofDivisionMemfunc */
293             EXPECT_BITFIELD_CLEAR(conn.extension_requests_sent);
294         }
295 
296         /* "send" errors */
297         {
298             struct s2n_connection conn = { 0 };
299             struct s2n_stuffer stuffer = { 0 };
300             s2n_stuffer_alloc(&stuffer, S2N_TEST_DATA_LEN);
301 
302             s2n_extension_type extension_type_with_failure = test_extension_type;
303             extension_type_with_failure.send = s2n_extension_send_unimplemented;
304 
305             EXPECT_FAILURE_WITH_ERRNO(s2n_extension_send(&extension_type_with_failure, &conn, &stuffer), S2N_ERR_UNIMPLEMENTED);
306             /* cppcheck-suppress sizeofDivisionMemfunc */
307             EXPECT_BITFIELD_CLEAR(conn.extension_requests_sent);
308 
309             s2n_stuffer_free(&stuffer);
310         }
311 
312         /* "send" writes more data than will fit in the extension size */
313         {
314             struct s2n_connection conn = { 0 };
315             struct s2n_stuffer stuffer = { 0 };
316             s2n_stuffer_growable_alloc(&stuffer, 0);
317 
318             s2n_extension_type extension_type_with_too_much_data = test_extension_type;
319             extension_type_with_too_much_data.send = test_send_too_much_data;
320 
321             EXPECT_FAILURE_WITH_ERRNO(s2n_extension_send(&extension_type_with_too_much_data, &conn, &stuffer),
322                     S2N_ERR_SIZE_MISMATCH);
323 
324             s2n_stuffer_free(&stuffer);
325         }
326     }
327 
328     /* Test s2n_extension_is_missing */
329     {
330         /* null check tests */
331         {
332             struct s2n_connection conn = { 0 };
333 
334             EXPECT_FAILURE(s2n_extension_is_missing(NULL, &conn));
335             EXPECT_FAILURE(s2n_extension_is_missing(&test_extension_type, NULL));
336 
337             s2n_extension_type extension_type_with_null_if_missing = test_extension_type;
338             extension_type_with_null_if_missing.if_missing = NULL;
339             EXPECT_FAILURE(s2n_extension_is_missing(&extension_type_with_null_if_missing, &conn));
340         }
341 
342         /* Test no-op if_missing */
343         {
344             struct s2n_connection conn = { 0 };
345 
346             s2n_extension_type extension_type_with_noop_if_missing = test_extension_type;
347             extension_type_with_noop_if_missing.if_missing = s2n_extension_noop_if_missing;
348 
349             extension_type_with_noop_if_missing.is_response = false;
350             EXPECT_SUCCESS(s2n_extension_is_missing(&extension_type_with_noop_if_missing, &conn));
351 
352             extension_type_with_noop_if_missing.is_response = true;
353             EXPECT_SUCCESS(s2n_extension_is_missing(&extension_type_with_noop_if_missing, &conn));
354 
355             S2N_CBIT_SET(conn.extension_requests_sent, test_extension_id);
356             EXPECT_SUCCESS(s2n_extension_is_missing(&extension_type_with_noop_if_missing, &conn));
357         }
358 
359         /* Test error if_missing */
360         {
361             struct s2n_connection conn = { 0 };
362 
363             s2n_extension_type extension_type_with_error_if_missing = test_extension_type;
364             extension_type_with_error_if_missing.if_missing = s2n_extension_error_if_missing;
365 
366             /* Should fail for a request */
367             extension_type_with_error_if_missing.is_response = false;
368             EXPECT_FAILURE_WITH_ERRNO(s2n_extension_is_missing(&extension_type_with_error_if_missing, &conn),
369                     S2N_ERR_MISSING_EXTENSION);
370 
371             /* Should succeed for a response without a corresponding request.
372              * We don't expect to receive the response, so it isn't considered missing. */
373             extension_type_with_error_if_missing.is_response = true;
374             EXPECT_SUCCESS(s2n_extension_is_missing(&extension_type_with_error_if_missing, &conn));
375 
376             /* Should fail for a response with a corresponding request */
377             S2N_CBIT_SET(conn.extension_requests_sent, test_extension_id);
378             EXPECT_FAILURE_WITH_ERRNO(s2n_extension_is_missing(&extension_type_with_error_if_missing, &conn),
379                     S2N_ERR_MISSING_EXTENSION);
380         }
381     }
382 
383     /* Test minimum_version field */
384     {
385         EXPECT_SUCCESS(s2n_reset_tls13());
386 
387         s2n_extension_type test_extension_type_with_min = test_extension_type;
388         test_extension_type_with_min.minimum_version = S2N_TLS13;
389 
390         /* If any of these methods actually execute, they will fail */
391         test_extension_type_with_min.if_missing = s2n_extension_error_if_missing;
392         test_extension_type_with_min.send = s2n_extension_send_unimplemented;
393         test_extension_type_with_min.recv = s2n_extension_recv_unimplemented;
394 
395         struct s2n_connection conn = { 0 };
396 
397         /* Does not meet minimum.
398          * No methods execute, so no errors. */
399         {
400             conn.actual_protocol_version = S2N_TLS12;
401             EXPECT_SUCCESS(s2n_extension_recv(&test_extension_type_with_min, &conn, NULL));
402             EXPECT_SUCCESS(s2n_extension_send(&test_extension_type_with_min, &conn, NULL));
403             EXPECT_SUCCESS(s2n_extension_is_missing(&test_extension_type_with_min, &conn));
404         }
405 
406         /* Meets minimum.
407          * All methods execute, so all errors. */
408         {
409             conn.actual_protocol_version = S2N_TLS13;
410             EXPECT_FAILURE(s2n_extension_recv(&test_extension_type_with_min, &conn, NULL));
411             EXPECT_FAILURE(s2n_extension_send(&test_extension_type_with_min, &conn, NULL));
412             EXPECT_FAILURE(s2n_extension_is_missing(&test_extension_type_with_min, &conn));
413         }
414 
415         /* Ensure that no extension type sets nonzero minimum_version < S2N_TLS13.
416          * Currently, nonzero minimum_version < S2N_TLS13 will not necessarily work because earlier versions
417          * do not set their protocol version until after processing all extensions.
418          */
419         {
420             s2n_extension_type_list *list = NULL;
421             const s2n_extension_type *type = NULL;
422             for (s2n_extension_list_id list_i = 0; list_i < S2N_EXTENSION_LIST_IDS_COUNT; list_i++) {
423                 EXPECT_SUCCESS(s2n_extension_type_list_get(list_i, &list));
424                 EXPECT_NOT_NULL(list);
425                 for (size_t ext_i = 0; ext_i < list->count; ext_i++) {
426                     type = list->extension_types[ext_i];
427                     EXPECT_TRUE(type->minimum_version == 0 ||
428                             type->minimum_version >= S2N_TLS13);
429                 }
430             }
431         }
432 
433         /* Functional test: minimum-TLS1.3 extensions only used for TLS1.3 */
434         {
435             struct s2n_cert_chain_and_key *cert_chain = NULL;
436             EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&cert_chain,
437                     S2N_DEFAULT_ECDSA_TEST_CERT_CHAIN, S2N_DEFAULT_ECDSA_TEST_PRIVATE_KEY));
438 
439             struct s2n_config *test_all_config = s2n_config_new();
440             EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(test_all_config, cert_chain));
441             EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(test_all_config));
442             EXPECT_SUCCESS(s2n_config_set_cipher_preferences(test_all_config, "test_all"));
443 
444             uint16_t key_shares_id = s2n_extension_iana_value_to_id(TLS_EXTENSION_KEY_SHARE);
445 
446             /* Both TLS1.3 */
447             if (s2n_is_tls13_fully_supported()) {
448                 struct s2n_connection *client_conn = s2n_connection_new(S2N_CLIENT);
449                 EXPECT_NOT_NULL(client_conn);
450                 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, test_all_config));
451 
452                 struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER);
453                 EXPECT_NOT_NULL(server_conn);
454                 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, test_all_config));
455 
456                 struct s2n_test_io_pair io_pair = { 0 };
457                 EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair));
458                 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
459 
460                 /* All expected CLIENT_HELLO extensions sent and received */
461                 EXPECT_OK(s2n_negotiate_test_server_and_client_until_message(server_conn, client_conn, SERVER_HELLO));
462                 EXPECT_TRUE(S2N_CBIT_TEST(client_conn->extension_requests_sent, key_shares_id));
463                 EXPECT_TRUE(S2N_CBIT_TEST(server_conn->extension_requests_received, key_shares_id));
464 
465                 /* All expected SERVER_HELLO extensions sent and received */
466                 EXPECT_OK(s2n_negotiate_test_server_and_client_until_message(server_conn, client_conn, ENCRYPTED_EXTENSIONS));
467                 EXPECT_TRUE(S2N_CBIT_TEST(client_conn->extension_requests_received, key_shares_id));
468                 EXPECT_TRUE(S2N_CBIT_TEST(server_conn->extension_requests_sent, key_shares_id));
469 
470                 EXPECT_SUCCESS(s2n_connection_free(client_conn));
471                 EXPECT_SUCCESS(s2n_connection_free(server_conn));
472             }
473 
474             /* Client TLS1.2 */
475             {
476                 struct s2n_connection *client_conn = s2n_connection_new(S2N_CLIENT);
477                 EXPECT_NOT_NULL(client_conn);
478                 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, test_all_config));
479                 EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(client_conn, "test_all_tls12"));
480 
481                 struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER);
482                 EXPECT_NOT_NULL(server_conn);
483                 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, test_all_config));
484 
485                 struct s2n_test_io_pair io_pair = { 0 };
486                 EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair));
487                 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
488 
489                 /* No expected CLIENT_HELLO extensions sent and received */
490                 EXPECT_OK(s2n_negotiate_test_server_and_client_until_message(server_conn, client_conn, SERVER_HELLO));
491                 EXPECT_FALSE(S2N_CBIT_TEST(client_conn->extension_requests_sent, key_shares_id));
492                 EXPECT_FALSE(S2N_CBIT_TEST(server_conn->extension_requests_received, key_shares_id));
493 
494                 /* No expected SERVER_HELLO extensions sent and received */
495                 EXPECT_OK(s2n_negotiate_test_server_and_client_until_message(server_conn, client_conn, ENCRYPTED_EXTENSIONS));
496                 EXPECT_FALSE(S2N_CBIT_TEST(client_conn->extension_requests_received, key_shares_id));
497                 EXPECT_FALSE(S2N_CBIT_TEST(server_conn->extension_requests_sent, key_shares_id));
498 
499                 EXPECT_SUCCESS(s2n_connection_free(client_conn));
500                 EXPECT_SUCCESS(s2n_connection_free(server_conn));
501             }
502 
503             /* Client TLS 1.3 with Server TLS1.2 */
504             if (s2n_is_tls13_fully_supported()) {
505                 struct s2n_connection *client_conn = s2n_connection_new(S2N_CLIENT);
506                 EXPECT_NOT_NULL(client_conn);
507                 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, test_all_config));
508 
509                 struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER);
510                 EXPECT_NOT_NULL(server_conn);
511                 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, test_all_config));
512                 EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(server_conn, "test_all_tls12"));
513 
514                 struct s2n_test_io_pair io_pair = { 0 };
515                 EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair));
516                 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
517 
518                 /* Expected CLIENT_HELLO extensions sent, but not received */
519                 EXPECT_OK(s2n_negotiate_test_server_and_client_until_message(server_conn, client_conn, SERVER_HELLO));
520                 EXPECT_TRUE(S2N_CBIT_TEST(client_conn->extension_requests_sent, key_shares_id));
521                 EXPECT_FALSE(S2N_CBIT_TEST(server_conn->extension_requests_received, key_shares_id));
522 
523                 /* No expected SERVER_HELLO extensions sent and received */
524                 EXPECT_OK(s2n_negotiate_test_server_and_client_until_message(server_conn, client_conn, ENCRYPTED_EXTENSIONS));
525                 EXPECT_FALSE(S2N_CBIT_TEST(client_conn->extension_requests_received, key_shares_id));
526                 EXPECT_FALSE(S2N_CBIT_TEST(server_conn->extension_requests_sent, key_shares_id));
527 
528                 EXPECT_SUCCESS(s2n_connection_free(client_conn));
529                 EXPECT_SUCCESS(s2n_connection_free(server_conn));
530             }
531 
532             EXPECT_SUCCESS(s2n_config_free(test_all_config));
533             EXPECT_SUCCESS(s2n_cert_chain_and_key_free(cert_chain));
534         }
535     }
536 
537     END_TEST();
538 }
539