| 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 "api/s2n.h" |
| 25 |
#include "stuffer/s2n_stuffer.h" |
| 26 |
#include "tls/s2n_connection.h" |
| 27 |
#include "tls/s2n_tls.h" |
| 28 |
#include "utils/s2n_safety.h" |
| 29 |
#include "s2n_test.h" |
| 30 |
#include "testlib/s2n_testlib.h" |
| 31 |
|
| 32 |
static char *cert_chain, *private_key; |
| 33 |
struct s2n_cert_chain_and_key *default_cert; |
| 34 |
struct s2n_config *client_config; |
| 35 |
|
| 36 |
int s2n_fuzz_init(int *argc, char **argv[]) |
| 37 |
{ |
| 38 |
|
| 39 |
cert_chain = malloc(S2N_MAX_TEST_PEM_SIZE); |
| 40 |
POSIX_ENSURE_REF(cert_chain); |
| 41 |
private_key = malloc(S2N_MAX_TEST_PEM_SIZE); |
| 42 |
POSIX_ENSURE_REF(private_key); |
| 43 |
default_cert = s2n_cert_chain_and_key_new(); |
| 44 |
POSIX_ENSURE_REF(default_cert); |
| 45 |
client_config = s2n_config_new(); |
| 46 |
POSIX_ENSURE_REF(client_config); |
| 47 |
POSIX_GUARD(s2n_read_test_pem(S2N_DEFAULT_TEST_CERT_CHAIN, cert_chain, S2N_MAX_TEST_PEM_SIZE)); |
| 48 |
POSIX_GUARD(s2n_read_test_pem(S2N_DEFAULT_TEST_PRIVATE_KEY, private_key, S2N_MAX_TEST_PEM_SIZE)); |
| 49 |
POSIX_GUARD(s2n_cert_chain_and_key_load_pem(default_cert, cert_chain, private_key)); |
| 50 |
POSIX_GUARD(s2n_config_add_cert_chain_and_key_to_store(client_config, default_cert)); |
| 51 |
return S2N_SUCCESS; |
| 52 |
} |
| 53 |
|
| 54 |
int s2n_fuzz_test(const uint8_t *buf, size_t len) |
| 55 |
{ |
| 56 |
|
| 57 |
struct s2n_connection *client_conn = s2n_connection_new(S2N_SERVER); |
| 58 |
POSIX_ENSURE_REF(client_conn); |
| 59 |
POSIX_GUARD(s2n_connection_set_config(client_conn, client_config)); |
| 60 |
POSIX_GUARD(s2n_stuffer_write_bytes(&client_conn->handshake.io, buf, len)); |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
s2n_tls13_cert_req_recv(client_conn); |
| 66 |
|
| 67 |
|
| 68 |
POSIX_GUARD(s2n_connection_free(client_conn)); |
| 69 |
|
| 70 |
return S2N_SUCCESS; |
| 71 |
} |
| 72 |
|
| 73 |
static void s2n_fuzz_cleanup() |
| 74 |
{ |
| 75 |
s2n_config_free(client_config); |
| 76 |
free(cert_chain); |
| 77 |
free(private_key); |
| 78 |
s2n_cert_chain_and_key_free(default_cert); |
| 79 |
} |
| 80 |
|
| 81 |
S2N_FUZZ_TARGET(s2n_fuzz_init, s2n_fuzz_test, s2n_fuzz_cleanup) |