Debian Codegraph @

crt/s2n/tests/unit/s2n_server_session_ticket_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 <stdint.h>
17
18 #include "s2n_test.h"
19 #include "stuffer/s2n_stuffer.h"
20 #include "tls/extensions/s2n_server_session_ticket.h"
21 #include "tls/s2n_config.h"
22 #include "tls/s2n_connection.h"
23 #include "tls/s2n_tls.h"
24 #include "tls/s2n_tls13.h"
25 #include "utils/s2n_safety.h"
26
27 static int s2n_test_enable_extension(struct s2n_connection *conn)
28 {
29 EXPECT_SUCCESS(s2n_config_set_session_tickets_onoff(conn->config, true));
30 conn->session_ticket_status = S2N_NEW_TICKET;
31 conn->actual_protocol_version = S2N_TLS12;
32 return S2N_SUCCESS;
33 }
34
35 int main(int argc, char **argv)
36 {
37 BEGIN_TEST();
38 EXPECT_SUCCESS(s2n_disable_tls13_in_test());
39
40 /* Test should_send */
41 {
42 struct s2n_config *config = NULL;
43 EXPECT_NOT_NULL(config = s2n_config_new());
44
45 struct s2n_connection *conn = NULL;
46 EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));
47 EXPECT_SUCCESS(s2n_connection_set_config(conn, config));
48
49 /* By default, do not send */
50 EXPECT_FALSE(s2n_server_session_ticket_extension.should_send(conn));
51
52 /* If all prerequisites met, send */
53 EXPECT_SUCCESS(s2n_test_enable_extension(conn));
54 EXPECT_TRUE(s2n_server_session_ticket_extension.should_send(conn));
55
56 /* If tickets not enabled, do not send */
57 EXPECT_SUCCESS(s2n_test_enable_extension(conn));
58 EXPECT_SUCCESS(s2n_config_set_session_tickets_onoff(config, false));
59 EXPECT_FALSE(s2n_server_session_ticket_extension.should_send(conn));
60
61 /* If ticket not new, do not send */
62 EXPECT_SUCCESS(s2n_test_enable_extension(conn));
63 conn->session_ticket_status = S2N_DECRYPT_TICKET;
64 EXPECT_FALSE(s2n_server_session_ticket_extension.should_send(conn));
65
66 /* If no ticket, do not send */
67 EXPECT_SUCCESS(s2n_test_enable_extension(conn));
68 conn->session_ticket_status = S2N_NO_TICKET;
69 EXPECT_FALSE(s2n_server_session_ticket_extension.should_send(conn));
70
71 /* If protocol version too high, do not send */
72 EXPECT_SUCCESS(s2n_test_enable_extension(conn));
73 conn->actual_protocol_version = S2N_TLS13;
74 EXPECT_FALSE(s2n_server_session_ticket_extension.should_send(conn));
75
76 EXPECT_SUCCESS(s2n_connection_free(conn));
77 EXPECT_SUCCESS(s2n_config_free(config));
78 };
79
80 /* Test server_session_ticket send and recv */
81 {
82 struct s2n_connection *conn = NULL;
83 EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));
84
85 EXPECT_SUCCESS(s2n_server_session_ticket_extension.send(conn, NULL));
86
87 EXPECT_EQUAL(conn->session_ticket_status, S2N_NO_TICKET);
88 EXPECT_SUCCESS(s2n_server_session_ticket_extension.recv(conn, NULL));
89 EXPECT_EQUAL(conn->session_ticket_status, S2N_NEW_TICKET);
90
91 EXPECT_SUCCESS(s2n_connection_free(conn));
92 };
93
94 END_TEST();
95 }