Debian Codegraph @

crt/s2n/tests/fuzz/s2n_extensions_client_key_share_recv_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 /* Target Functions: s2n_extensions_client_key_share_recv s2n_ecc_evp_read_params_point
17 s2n_ecc_evp_parse_params_point s2n_ecc_evp_params_free */
18
19 #include <stdint.h>
20
21 #include <openssl/crypto.h>
22 #include <openssl/err.h>
23
24 #include "tls/extensions/s2n_client_key_share.h"
25
26 #include "api/s2n.h"
27 #include "stuffer/s2n_stuffer.h"
28 #include "tls/s2n_connection.h"
29 #include "tls/s2n_tls.h"
30 #include "utils/s2n_safety.h"
31 #include "s2n_test.h"
32 #include "testlib/s2n_testlib.h"
33 #include "tls/s2n_tls13.h"
34
35 /* This test is for TLS versions 1.3 and up only */
36 static const uint8_t TLS_VERSIONS[] = {S2N_TLS13};
37
38 int s2n_fuzz_init(int *argc, char **argv[])
39 {
40 POSIX_GUARD(s2n_enable_tls13_in_test());
41 return S2N_SUCCESS;
42 }
43
44 int s2n_fuzz_test(const uint8_t *buf, size_t len)
45 {
46 /* We need at least one byte of input to set parameters */
47 S2N_FUZZ_ENSURE_MIN_LEN(len, 1);
48
49 /* Setup */
50 struct s2n_stuffer fuzz_stuffer = {0};
51 POSIX_GUARD(s2n_stuffer_alloc(&fuzz_stuffer, len));
52 POSIX_GUARD(s2n_stuffer_write_bytes(&fuzz_stuffer, buf, len));
53
54 struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER);
55 POSIX_ENSURE_REF(server_conn);
56
57 /* Pull a byte off the libfuzzer input and use it to set parameters */
58 uint8_t randval = 0;
59 POSIX_GUARD(s2n_stuffer_read_uint8(&fuzz_stuffer, &randval));
60 server_conn->actual_protocol_version = TLS_VERSIONS[randval % s2n_array_len(TLS_VERSIONS)];
61
62 /* Run Test
63 * Do not use GUARD macro here since the connection memory hasn't been freed.
64 */
65 s2n_extensions_client_key_share_recv(server_conn, &fuzz_stuffer);
66
67 /* Cleanup */
68 POSIX_GUARD(s2n_connection_free(server_conn));
69 POSIX_GUARD(s2n_stuffer_free(&fuzz_stuffer));
70
71 return S2N_SUCCESS;
72 }
73
74 S2N_FUZZ_TARGET(s2n_fuzz_init, s2n_fuzz_test, NULL)