Debian Codegraph @

crt/s2n/tests/unit/s2n_nst_early_data_indication_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 "s2n_test.h"
17 #include "testlib/s2n_testlib.h"
18 #include "tls/extensions/s2n_early_data_indication.h"
19
20 int main(int argc, char **argv)
21 {
22 BEGIN_TEST();
23
24 /* Test s2n_nst_early_data_indication_should_send */
25 {
26 /* Safety check */
27 EXPECT_FALSE(s2n_nst_early_data_indication_extension.should_send(NULL));
28
29 struct s2n_connection *conn = s2n_connection_new(S2N_SERVER);
30 EXPECT_NOT_NULL(conn);
31
32 /* Should not send if max_early_data_size not set */
33 EXPECT_FALSE(s2n_nst_early_data_indication_extension.should_send(conn));
34
35 /* Should not send if max_early_data_size set to 0 */
36 EXPECT_SUCCESS(s2n_connection_set_server_max_early_data_size(conn, 0));
37 EXPECT_FALSE(s2n_nst_early_data_indication_extension.should_send(conn));
38
39 /* Should send if max_early_data_size set to non-zero */
40 uint32_t server_max = 13;
41 EXPECT_SUCCESS(s2n_connection_set_server_max_early_data_size(conn, server_max));
42 EXPECT_TRUE(s2n_nst_early_data_indication_extension.should_send(conn));
43
44 EXPECT_SUCCESS(s2n_connection_free(conn));
45 };
46
47 /* Test s2n_nst_early_data_indiction_send */
48 {
49 struct s2n_connection *conn = s2n_connection_new(S2N_SERVER);
50 EXPECT_NOT_NULL(conn);
51 conn->actual_protocol_version = S2N_TLS13;
52
53 struct s2n_stuffer output = { 0 };
54 EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&output, 0));
55
56 const uint32_t expected_max_early_data_size = 13;
57 EXPECT_SUCCESS(s2n_connection_set_server_max_early_data_size(conn, expected_max_early_data_size));
58
59 /* Safety checks */
60 EXPECT_FAILURE_WITH_ERRNO(s2n_nst_early_data_indication_extension.send(conn, NULL), S2N_ERR_NULL);
61 EXPECT_FAILURE_WITH_ERRNO(s2n_nst_early_data_indication_extension.send(NULL, &output), S2N_ERR_NULL);
62
63 uint32_t actual_max_early_data_size = 0;
64 EXPECT_SUCCESS(s2n_nst_early_data_indication_extension.send(conn, &output));
65 EXPECT_SUCCESS(s2n_stuffer_read_uint32(&output, &actual_max_early_data_size));
66 EXPECT_EQUAL(expected_max_early_data_size, actual_max_early_data_size);
67
68 EXPECT_SUCCESS(s2n_stuffer_free(&output));
69 EXPECT_SUCCESS(s2n_connection_free(conn));
70 };
71
72 /* Test s2n_nst_early_data_indiction_recv */
73 {
74 struct s2n_connection *conn = s2n_connection_new(S2N_SERVER);
75 EXPECT_NOT_NULL(conn);
76 conn->actual_protocol_version = S2N_TLS13;
77
78 struct s2n_stuffer input = { 0 };
79 EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&input, 0));
80
81 /* Safety checks */
82 EXPECT_FAILURE_WITH_ERRNO(s2n_nst_early_data_indication_extension.recv(conn, NULL), S2N_ERR_NULL);
83 EXPECT_FAILURE_WITH_ERRNO(s2n_nst_early_data_indication_extension.recv(NULL, &input), S2N_ERR_NULL);
84
85 const uint32_t expected_max_early_data_size = 13;
86 EXPECT_SUCCESS(s2n_connection_set_server_max_early_data_size(conn, expected_max_early_data_size));
87 EXPECT_SUCCESS(s2n_nst_early_data_indication_extension.send(conn, &input));
88
89 EXPECT_SUCCESS(s2n_connection_set_server_max_early_data_size(conn, 0));
90 EXPECT_SUCCESS(s2n_nst_early_data_indication_extension.recv(conn, &input));
91 EXPECT_EQUAL(conn->server_max_early_data_size, expected_max_early_data_size);
92
93 EXPECT_SUCCESS(s2n_stuffer_free(&input));
94 EXPECT_SUCCESS(s2n_connection_free(conn));
95 };
96
97 END_TEST();
98 }