Debian Codegraph @

crt/s2n/tests/unit/s2n_ecc_point_format_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_ec_point_format.h"
18 #include "tls/s2n_cipher_suites.h"
19 #include "tls/s2n_resume.h"
20
21 int main(int argc, char **argv)
22 {
23 BEGIN_TEST();
24 EXPECT_SUCCESS(s2n_disable_tls13_in_test());
25
26 struct s2n_config *config = NULL;
27 EXPECT_NOT_NULL(config = s2n_config_new());
28
29 /* Test server should_send */
30 {
31 struct s2n_connection *conn = NULL;
32 EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));
33
34 /* Do not send for null connection */
35 EXPECT_FALSE(s2n_server_ec_point_format_extension.should_send(NULL));
36
37 /* Do not send for connection without chosen cipher */
38 conn->secure->cipher_suite = NULL;
39 EXPECT_FALSE(s2n_server_ec_point_format_extension.should_send(conn));
40
41 /* Do not send for connection without ec kex */
42 conn->secure->cipher_suite = &s2n_rsa_with_aes_128_cbc_sha;
43 EXPECT_FALSE(s2n_server_ec_point_format_extension.should_send(conn));
44 conn->secure->cipher_suite = &s2n_dhe_rsa_with_chacha20_poly1305_sha256;
45 EXPECT_FALSE(s2n_server_ec_point_format_extension.should_send(conn));
46
47 /* Do send for connection with ec kex */
48 conn->secure->cipher_suite = &s2n_ecdhe_ecdsa_with_aes_128_cbc_sha;
49 EXPECT_TRUE(s2n_server_ec_point_format_extension.should_send(conn));
50
51 EXPECT_SUCCESS(s2n_connection_free(conn));
52 };
53
54 /* Test send */
55 {
56 struct s2n_connection *conn = NULL;
57 EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
58 EXPECT_SUCCESS(s2n_connection_set_config(conn, config));
59
60 struct s2n_stuffer stuffer = { 0 };
61 EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));
62
63 EXPECT_SUCCESS(s2n_client_ec_point_format_extension.send(conn, &stuffer));
64
65 uint8_t length = 0;
66 EXPECT_SUCCESS(s2n_stuffer_read_uint8(&stuffer, &length));
67 EXPECT_EQUAL(length, s2n_stuffer_data_available(&stuffer));
68
69 uint8_t point_format = 0;
70 EXPECT_SUCCESS(s2n_stuffer_read_uint8(&stuffer, &point_format));
71 EXPECT_EQUAL(point_format, TLS_EC_POINT_FORMAT_UNCOMPRESSED);
72
73 EXPECT_EQUAL(s2n_stuffer_data_available(&stuffer), 0);
74
75 EXPECT_SUCCESS(s2n_stuffer_free(&stuffer));
76 EXPECT_SUCCESS(s2n_connection_free(conn));
77 };
78
79 /* Test recv */
80 {
81 struct s2n_connection *conn = NULL;
82 EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
83 EXPECT_SUCCESS(s2n_connection_set_config(conn, config));
84
85 struct s2n_stuffer stuffer = { 0 };
86 EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));
87
88 EXPECT_SUCCESS(s2n_client_ec_point_format_extension.send(conn, &stuffer));
89
90 EXPECT_FALSE(conn->ec_point_formats);
91 EXPECT_SUCCESS(s2n_client_ec_point_format_extension.recv(conn, &stuffer));
92 EXPECT_TRUE(conn->ec_point_formats);
93
94 EXPECT_SUCCESS(s2n_stuffer_free(&stuffer));
95 EXPECT_SUCCESS(s2n_connection_free(conn));
96 };
97
98 EXPECT_SUCCESS(s2n_config_free(config));
99
100 END_TEST();
101 }