| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "s2n_test.h" |
| 17 |
#include "testlib/s2n_testlib.h" |
| 18 |
#include "tls/extensions/s2n_early_data_indication.h" |
| 19 |
|
| 20 |
int main(int argc, char **argv) |
| 21 |
{ |
| 22 |
BEGIN_TEST(); |
| 23 |
|
| 24 |
|
| 25 |
{ |
| 26 |
|
| 27 |
EXPECT_FALSE(s2n_nst_early_data_indication_extension.should_send(NULL)); |
| 28 |
|
| 29 |
struct s2n_connection *conn = s2n_connection_new(S2N_SERVER); |
| 30 |
EXPECT_NOT_NULL(conn); |
| 31 |
|
| 32 |
|
| 33 |
EXPECT_FALSE(s2n_nst_early_data_indication_extension.should_send(conn)); |
| 34 |
|
| 35 |
|
| 36 |
EXPECT_SUCCESS(s2n_connection_set_server_max_early_data_size(conn, 0)); |
| 37 |
EXPECT_FALSE(s2n_nst_early_data_indication_extension.should_send(conn)); |
| 38 |
|
| 39 |
|
| 40 |
uint32_t server_max = 13; |
| 41 |
EXPECT_SUCCESS(s2n_connection_set_server_max_early_data_size(conn, server_max)); |
| 42 |
EXPECT_TRUE(s2n_nst_early_data_indication_extension.should_send(conn)); |
| 43 |
|
| 44 |
EXPECT_SUCCESS(s2n_connection_free(conn)); |
| 45 |
}; |
| 46 |
|
| 47 |
|
| 48 |
{ |
| 49 |
struct s2n_connection *conn = s2n_connection_new(S2N_SERVER); |
| 50 |
EXPECT_NOT_NULL(conn); |
| 51 |
conn->actual_protocol_version = S2N_TLS13; |
| 52 |
|
| 53 |
struct s2n_stuffer output = { 0 }; |
| 54 |
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&output, 0)); |
| 55 |
|
| 56 |
const uint32_t expected_max_early_data_size = 13; |
| 57 |
EXPECT_SUCCESS(s2n_connection_set_server_max_early_data_size(conn, expected_max_early_data_size)); |
| 58 |
|
| 59 |
|
| 60 |
EXPECT_FAILURE_WITH_ERRNO(s2n_nst_early_data_indication_extension.send(conn, NULL), S2N_ERR_NULL); |
| 61 |
EXPECT_FAILURE_WITH_ERRNO(s2n_nst_early_data_indication_extension.send(NULL, &output), S2N_ERR_NULL); |
| 62 |
|
| 63 |
uint32_t actual_max_early_data_size = 0; |
| 64 |
EXPECT_SUCCESS(s2n_nst_early_data_indication_extension.send(conn, &output)); |
| 65 |
EXPECT_SUCCESS(s2n_stuffer_read_uint32(&output, &actual_max_early_data_size)); |
| 66 |
EXPECT_EQUAL(expected_max_early_data_size, actual_max_early_data_size); |
| 67 |
|
| 68 |
EXPECT_SUCCESS(s2n_stuffer_free(&output)); |
| 69 |
EXPECT_SUCCESS(s2n_connection_free(conn)); |
| 70 |
}; |
| 71 |
|
| 72 |
|
| 73 |
{ |
| 74 |
struct s2n_connection *conn = s2n_connection_new(S2N_SERVER); |
| 75 |
EXPECT_NOT_NULL(conn); |
| 76 |
conn->actual_protocol_version = S2N_TLS13; |
| 77 |
|
| 78 |
struct s2n_stuffer input = { 0 }; |
| 79 |
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&input, 0)); |
| 80 |
|
| 81 |
|
| 82 |
EXPECT_FAILURE_WITH_ERRNO(s2n_nst_early_data_indication_extension.recv(conn, NULL), S2N_ERR_NULL); |
| 83 |
EXPECT_FAILURE_WITH_ERRNO(s2n_nst_early_data_indication_extension.recv(NULL, &input), S2N_ERR_NULL); |
| 84 |
|
| 85 |
const uint32_t expected_max_early_data_size = 13; |
| 86 |
EXPECT_SUCCESS(s2n_connection_set_server_max_early_data_size(conn, expected_max_early_data_size)); |
| 87 |
EXPECT_SUCCESS(s2n_nst_early_data_indication_extension.send(conn, &input)); |
| 88 |
|
| 89 |
EXPECT_SUCCESS(s2n_connection_set_server_max_early_data_size(conn, 0)); |
| 90 |
EXPECT_SUCCESS(s2n_nst_early_data_indication_extension.recv(conn, &input)); |
| 91 |
EXPECT_EQUAL(conn->server_max_early_data_size, expected_max_early_data_size); |
| 92 |
|
| 93 |
EXPECT_SUCCESS(s2n_stuffer_free(&input)); |
| 94 |
EXPECT_SUCCESS(s2n_connection_free(conn)); |
| 95 |
}; |
| 96 |
|
| 97 |
END_TEST(); |
| 98 |
} |