| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include <stdint.h> |
| 21 |
|
| 22 |
#include <openssl/crypto.h> |
| 23 |
#include <openssl/err.h> |
| 24 |
|
| 25 |
#include "tls/extensions/s2n_client_supported_versions.h" |
| 26 |
|
| 27 |
#include "api/s2n.h" |
| 28 |
#include "stuffer/s2n_stuffer.h" |
| 29 |
#include "tls/s2n_connection.h" |
| 30 |
#include "tls/s2n_tls.h" |
| 31 |
#include "utils/s2n_safety.h" |
| 32 |
#include "s2n_test.h" |
| 33 |
#include "testlib/s2n_testlib.h" |
| 34 |
#include "tls/s2n_tls13.h" |
| 35 |
|
| 36 |
|
| 37 |
static const uint8_t TLS_VERSIONS[] = {S2N_TLS13}; |
| 38 |
|
| 39 |
int s2n_fuzz_init(int *argc, char **argv[]) |
| 40 |
{ |
| 41 |
POSIX_GUARD(s2n_enable_tls13_in_test()); |
| 42 |
return S2N_SUCCESS; |
| 43 |
} |
| 44 |
|
| 45 |
int s2n_fuzz_test(const uint8_t *buf, size_t len) |
| 46 |
{ |
| 47 |
|
| 48 |
S2N_FUZZ_ENSURE_MIN_LEN(len, 1); |
| 49 |
|
| 50 |
|
| 51 |
struct s2n_stuffer fuzz_stuffer = {0}; |
| 52 |
POSIX_GUARD(s2n_stuffer_alloc(&fuzz_stuffer, len)); |
| 53 |
POSIX_GUARD(s2n_stuffer_write_bytes(&fuzz_stuffer, buf, len)); |
| 54 |
|
| 55 |
struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER); |
| 56 |
POSIX_ENSURE_REF(server_conn); |
| 57 |
|
| 58 |
|
| 59 |
uint8_t randval = 0; |
| 60 |
POSIX_GUARD(s2n_stuffer_read_uint8(&fuzz_stuffer, &randval)); |
| 61 |
server_conn->server_protocol_version = TLS_VERSIONS[randval % s2n_array_len(TLS_VERSIONS)]; |
| 62 |
|
| 63 |
server_conn->config = s2n_config_new(); |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
s2n_extensions_client_supported_versions_recv(server_conn, &fuzz_stuffer); |
| 69 |
|
| 70 |
|
| 71 |
POSIX_GUARD(s2n_config_free(server_conn->config)); |
| 72 |
POSIX_GUARD(s2n_connection_free(server_conn)); |
| 73 |
POSIX_GUARD(s2n_stuffer_free(&fuzz_stuffer)); |
| 74 |
|
| 75 |
return S2N_SUCCESS; |
| 76 |
} |
| 77 |
|
| 78 |
S2N_FUZZ_TARGET(s2n_fuzz_init, s2n_fuzz_test, NULL) |
| 79 |
|