| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 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 |
|
| 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 |
|
| 47 |
S2N_FUZZ_ENSURE_MIN_LEN(len, 1); |
| 48 |
|
| 49 |
|
| 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 |
|
| 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 |
|
| 63 |
|
| 64 |
|
| 65 |
s2n_extensions_client_key_share_recv(server_conn, &fuzz_stuffer); |
| 66 |
|
| 67 |
|
| 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) |