Debian Codegraph @

crt/s2n/tests/unit/s2n_server_server_name_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_server_server_name.h"
18 #include "tls/s2n_connection.h"
19 #include "tls/s2n_handshake.h"
20
21 #define S2N_TEST_RESUMPTION_HANDSHAKE (NEGOTIATED)
22 #define S2N_TEST_NOT_RESUMPTION_HANDSHAKE (NEGOTIATED | FULL_HANDSHAKE)
23
24 int main(int argc, char **argv)
25 {
26 BEGIN_TEST();
27 EXPECT_SUCCESS(s2n_disable_tls13_in_test());
28
29 /* should_send */
30 {
31 struct s2n_connection *conn = NULL;
32 EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
33
34 /* By default, do not send */
35 EXPECT_FALSE(s2n_server_server_name_extension.should_send(conn));
36
37 /* server_name not used and resumption handshake -> do not send */
38 conn->server_name_used = false;
39 conn->handshake.handshake_type = S2N_TEST_RESUMPTION_HANDSHAKE;
40 EXPECT_FALSE(s2n_server_server_name_extension.should_send(conn));
41
42 /* server_name used and resumption handshake -> do not send */
43 conn->server_name_used = true;
44 conn->handshake.handshake_type = S2N_TEST_RESUMPTION_HANDSHAKE;
45 EXPECT_FALSE(s2n_server_server_name_extension.should_send(conn));
46
47 /* server_name not used and not resumption handshake -> do not send */
48 conn->server_name_used = false;
49 conn->handshake.handshake_type = S2N_TEST_NOT_RESUMPTION_HANDSHAKE;
50 EXPECT_FALSE(s2n_server_server_name_extension.should_send(conn));
51
52 /* server_name used and not resumption handshake -> send */
53 conn->server_name_used = true;
54 conn->handshake.handshake_type = S2N_TEST_NOT_RESUMPTION_HANDSHAKE;
55 EXPECT_TRUE(s2n_server_server_name_extension.should_send(conn));
56
57 EXPECT_SUCCESS(s2n_connection_free(conn));
58 };
59
60 /* send */
61 {
62 /* Send writes nothing and always succeeds. */
63 EXPECT_SUCCESS(s2n_server_server_name_extension.send(NULL, NULL));
64 };
65
66 /* recv */
67 {
68 struct s2n_connection *conn = NULL;
69 EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
70
71 /* Recv reads nothing and always succeeds */
72 EXPECT_FALSE(conn->server_name_used);
73 EXPECT_SUCCESS(s2n_server_server_name_extension.recv(conn, NULL));
74 EXPECT_TRUE(conn->server_name_used);
75
76 EXPECT_SUCCESS(s2n_connection_free(conn));
77 };
78
79 END_TEST();
80 }