Debian Codegraph @

crt/s2n/tests/unit/s2n_cert_status_response_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 "testlib/s2n_testlib.h"
18 #include "tls/extensions/s2n_cert_status_response.h"
19
20 const uint8_t ocsp_data[] = "OCSP DATA";
21
22 int s2n_test_enable_sending_extension(struct s2n_connection *conn, struct s2n_cert_chain_and_key *chain_and_key)
23 {
24 conn->mode = S2N_SERVER;
25 conn->status_type = S2N_STATUS_REQUEST_OCSP;
26 conn->handshake_params.our_chain_and_key = chain_and_key;
27 EXPECT_SUCCESS(s2n_cert_chain_and_key_set_ocsp_data(chain_and_key, ocsp_data, s2n_array_len(ocsp_data)));
28 return S2N_SUCCESS;
29 }
30
31 int main(int argc, char **argv)
32 {
33 BEGIN_TEST();
34 EXPECT_SUCCESS(s2n_disable_tls13_in_test());
35
36 DEFER_CLEANUP(struct s2n_cert_chain_and_key *chain_and_key = NULL, s2n_cert_chain_and_key_ptr_free);
37 EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&chain_and_key,
38 S2N_DEFAULT_TEST_CERT_CHAIN, S2N_DEFAULT_TEST_PRIVATE_KEY));
39
40 /* 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_CLIENT));
47 EXPECT_SUCCESS(s2n_connection_set_config(conn, config));
48
49 /* Don't send by default */
50 EXPECT_FALSE(s2n_cert_status_response_extension.should_send(conn));
51
52 /* Send if all prerequisites met */
53 EXPECT_SUCCESS(s2n_test_enable_sending_extension(conn, chain_and_key));
54 EXPECT_TRUE(s2n_cert_status_response_extension.should_send(conn));
55
56 /* Don't send if client */
57 EXPECT_SUCCESS(s2n_test_enable_sending_extension(conn, chain_and_key));
58 conn->mode = S2N_CLIENT;
59 EXPECT_FALSE(s2n_cert_status_response_extension.should_send(conn));
60
61 /* Don't send if no status request configured */
62 EXPECT_SUCCESS(s2n_test_enable_sending_extension(conn, chain_and_key));
63 conn->status_type = S2N_STATUS_REQUEST_NONE;
64 EXPECT_FALSE(s2n_cert_status_response_extension.should_send(conn));
65
66 /* Don't send if no certificate set */
67 EXPECT_SUCCESS(s2n_test_enable_sending_extension(conn, chain_and_key));
68 conn->handshake_params.our_chain_and_key = NULL;
69 EXPECT_FALSE(s2n_cert_status_response_extension.should_send(conn));
70
71 /* Don't send if no ocsp data */
72 EXPECT_SUCCESS(s2n_test_enable_sending_extension(conn, chain_and_key));
73 EXPECT_SUCCESS(s2n_free(&conn->handshake_params.our_chain_and_key->ocsp_status));
74 EXPECT_FALSE(s2n_cert_status_response_extension.should_send(conn));
75
76 EXPECT_SUCCESS(s2n_connection_free(conn));
77 EXPECT_SUCCESS(s2n_config_free(config));
78 };
79
80 /* Set oscp data */
81 EXPECT_SUCCESS(s2n_cert_chain_and_key_set_ocsp_data(chain_and_key, ocsp_data, s2n_array_len(ocsp_data)));
82
83 /* Test send and recv */
84 {
85 struct s2n_connection *conn = NULL;
86 EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));
87
88 EXPECT_SUCCESS(s2n_cert_status_response_extension.send(conn, NULL));
89
90 EXPECT_EQUAL(conn->status_type, S2N_STATUS_REQUEST_NONE);
91 EXPECT_SUCCESS(s2n_cert_status_response_extension.recv(conn, NULL));
92 EXPECT_EQUAL(conn->status_type, S2N_STATUS_REQUEST_OCSP);
93
94 EXPECT_SUCCESS(s2n_connection_free(conn));
95 };
96
97 END_TEST();
98 }