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