Debian Codegraph @

crt/s2n/tests/unit/s2n_tls13_cert_request_extensions_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 <stdio.h>
17 #include <string.h>
18
19 #include "api/s2n.h"
20 #include "s2n_test.h"
21 #include "stuffer/s2n_stuffer.h"
22 #include "testlib/s2n_testlib.h"
23 #include "tls/extensions/s2n_server_signature_algorithms.h"
24 #include "tls/extensions/s2n_server_supported_versions.h"
25 #include "tls/s2n_tls.h"
26 #include "tls/s2n_tls13.h"
27 #include "utils/s2n_safety.h"
28
29 int main(int argc, char **argv)
30 {
31 BEGIN_TEST();
32 EXPECT_SUCCESS(s2n_enable_tls13_in_test());
33
34 /* Test correct required extension (sig_alg) sent and received */
35 {
36 struct s2n_connection *conn = NULL;
37 EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
38 conn->actual_protocol_version = S2N_TLS13;
39
40 EXPECT_EQUAL(conn->handshake_params.peer_sig_scheme_list.len, 0);
41 EXPECT_SUCCESS(s2n_tls13_cert_req_send(conn));
42 EXPECT_SUCCESS(s2n_tls13_cert_req_recv(conn));
43 EXPECT_NOT_EQUAL(conn->handshake_params.peer_sig_scheme_list.len, 0);
44
45 EXPECT_SUCCESS(s2n_connection_free(conn));
46 }
47
48 /* Test client fails to parse certificate request with no extensions */
49 {
50 struct s2n_connection *client_conn = NULL;
51 EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
52 client_conn->actual_protocol_version = S2N_TLS13;
53
54 /* Write 0 length request context https://tools.ietf.org/html/rfc8446#section-4.3.2 */
55 EXPECT_SUCCESS(s2n_stuffer_write_uint8(&client_conn->handshake.io, 0));
56 EXPECT_SUCCESS(s2n_extension_list_send(S2N_EXTENSION_LIST_EMPTY, client_conn, &client_conn->handshake.io));
57
58 EXPECT_FAILURE_WITH_ERRNO(s2n_tls13_cert_req_recv(client_conn), S2N_ERR_MISSING_EXTENSION);
59
60 EXPECT_SUCCESS(s2n_connection_free(client_conn));
61 };
62
63 EXPECT_SUCCESS(s2n_disable_tls13_in_test());
64 END_TEST();
65
66 return 0;
67 }