Debian Codegraph @

crt/s2n/tests/unit/s2n_server_cert_status_request_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_cert_status_request.h"
18
19 int main(int argc, char **argv)
20 {
21 BEGIN_TEST();
22
23 /* Extension should not be sent by default */
24 {
25 DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), s2n_connection_ptr_free);
26 EXPECT_NOT_NULL(conn);
27
28 EXPECT_FALSE(s2n_server_cert_status_request_extension.should_send(conn));
29 }
30
31 /* Extension should be sent if OCSP stapling is supported and was requested */
32 {
33 DEFER_CLEANUP(struct s2n_config *config = s2n_config_new(), s2n_config_ptr_free);
34 EXPECT_NOT_NULL(config);
35
36 DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), s2n_connection_ptr_free);
37 EXPECT_NOT_NULL(conn);
38
39 if (s2n_x509_ocsp_stapling_supported()) {
40 EXPECT_SUCCESS(s2n_config_set_status_request_type(config, S2N_STATUS_REQUEST_OCSP));
41 EXPECT_SUCCESS(s2n_connection_set_config(conn, config));
42
43 EXPECT_TRUE(s2n_server_cert_status_request_extension.should_send(conn));
44 } else {
45 /* Requesting OCSP stapling should not be possible if not supported */
46 EXPECT_FAILURE_WITH_ERRNO(s2n_config_set_status_request_type(config, S2N_STATUS_REQUEST_OCSP),
47 S2N_ERR_OCSP_NOT_SUPPORTED);
48 EXPECT_SUCCESS(s2n_connection_set_config(conn, config));
49
50 EXPECT_FALSE(s2n_server_cert_status_request_extension.should_send(conn));
51 }
52 }
53
54 /* Extension should be empty */
55 {
56 DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), s2n_connection_ptr_free);
57 EXPECT_NOT_NULL(conn);
58
59 struct s2n_stuffer stuffer = { 0 };
60 EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));
61
62 EXPECT_SUCCESS(s2n_server_cert_status_request_extension.send(conn, &stuffer));
63
64 EXPECT_EQUAL(s2n_stuffer_data_available(&stuffer), 0);
65 }
66
67 END_TEST();
68 }