Debian Codegraph @

crt/s2n/tests/unit/s2n_client_sct_list_extension_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 "tls/extensions/s2n_client_sct_list.h"
18
19 int main(int argc, char **argv)
20 {
21 BEGIN_TEST();
22 EXPECT_SUCCESS(s2n_disable_tls13_in_test());
23
24 /* Test should_send */
25 {
26 struct s2n_config *config = NULL;
27 EXPECT_NOT_NULL(config = s2n_config_new());
28
29 struct s2n_connection *conn = NULL;
30 EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
31 EXPECT_SUCCESS(s2n_connection_set_config(conn, config));
32
33 /* Default configs use S2N_CT_SUPPORT_NONE */
34 EXPECT_FALSE(s2n_client_sct_list_extension.should_send(conn));
35
36 /* Use cipher preferences that do include PQ */
37 EXPECT_SUCCESS(s2n_config_set_ct_support_level(config, S2N_CT_SUPPORT_REQUEST));
38 EXPECT_TRUE(s2n_client_sct_list_extension.should_send(conn));
39
40 EXPECT_SUCCESS(s2n_connection_free(conn));
41 EXPECT_SUCCESS(s2n_config_free(config));
42 };
43
44 /* Test send */
45 {
46 struct s2n_config *config = NULL;
47 EXPECT_NOT_NULL(config = s2n_config_new());
48
49 struct s2n_connection *conn = NULL;
50 EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
51 EXPECT_SUCCESS(s2n_connection_set_config(conn, config));
52
53 struct s2n_stuffer stuffer = { 0 };
54 EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));
55
56 EXPECT_SUCCESS(s2n_client_sct_list_extension.send(conn, &stuffer));
57 EXPECT_EQUAL(s2n_stuffer_data_available(&stuffer), 0);
58
59 EXPECT_SUCCESS(s2n_stuffer_free(&stuffer));
60 EXPECT_SUCCESS(s2n_connection_free(conn));
61 EXPECT_SUCCESS(s2n_config_free(config));
62 };
63
64 /* Test receive */
65 {
66 struct s2n_config *config = NULL;
67 EXPECT_NOT_NULL(config = s2n_config_new());
68
69 struct s2n_connection *conn = NULL;
70 EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
71 EXPECT_SUCCESS(s2n_connection_set_config(conn, config));
72
73 struct s2n_stuffer stuffer = { 0 };
74 EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));
75
76 EXPECT_SUCCESS(s2n_client_sct_list_extension.send(conn, &stuffer));
77
78 EXPECT_NOT_EQUAL(conn->ct_level_requested, S2N_CT_SUPPORT_REQUEST);
79 EXPECT_SUCCESS(s2n_client_sct_list_extension.recv(conn, &stuffer));
80 EXPECT_EQUAL(conn->ct_level_requested, S2N_CT_SUPPORT_REQUEST);
81
82 EXPECT_SUCCESS(s2n_stuffer_free(&stuffer));
83 EXPECT_SUCCESS(s2n_connection_free(conn));
84 EXPECT_SUCCESS(s2n_config_free(config));
85 };
86
87 END_TEST();
88 }