| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "api/s2n.h" |
| 17 |
#include "stuffer/s2n_stuffer.h" |
| 18 |
#include "tls/extensions/s2n_early_data_indication.h" |
| 19 |
#include "tls/s2n_connection.h" |
| 20 |
#include "tls/s2n_early_data.h" |
| 21 |
#include "utils/s2n_safety.h" |
| 22 |
|
| 23 |
static bool s2n_nst_early_data_indication_should_send(struct s2n_connection *conn) |
| 24 |
{ |
| 25 |
uint32_t server_max_early_data = 0; |
| 26 |
return s2n_result_is_ok(s2n_early_data_get_server_max_size(conn, &server_max_early_data)) |
| 27 |
&& server_max_early_data > 0; |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
static int s2n_nst_early_data_indication_send(struct s2n_connection *conn, struct s2n_stuffer *out) |
| 49 |
{ |
| 50 |
uint32_t server_max_early_data = 0; |
| 51 |
POSIX_GUARD_RESULT(s2n_early_data_get_server_max_size(conn, &server_max_early_data)); |
| 52 |
POSIX_GUARD(s2n_stuffer_write_uint32(out, server_max_early_data)); |
| 53 |
return S2N_SUCCESS; |
| 54 |
} |
| 55 |
|
| 56 |
static int s2n_nst_early_data_indiction_recv(struct s2n_connection *conn, struct s2n_stuffer *in) |
| 57 |
{ |
| 58 |
POSIX_ENSURE_REF(conn); |
| 59 |
uint32_t server_max_early_data = 0; |
| 60 |
POSIX_GUARD(s2n_stuffer_read_uint32(in, &server_max_early_data)); |
| 61 |
POSIX_GUARD(s2n_connection_set_server_max_early_data_size(conn, server_max_early_data)); |
| 62 |
return S2N_SUCCESS; |
| 63 |
} |
| 64 |
|
| 65 |
static int s2n_nst_early_data_indication_missing(struct s2n_connection *conn) |
| 66 |
{ |
| 67 |
POSIX_GUARD(s2n_connection_set_server_max_early_data_size(conn, 0)); |
| 68 |
return S2N_SUCCESS; |
| 69 |
} |
| 70 |
|
| 71 |
const s2n_extension_type s2n_nst_early_data_indication_extension = { |
| 72 |
.iana_value = TLS_EXTENSION_EARLY_DATA, |
| 73 |
.is_response = false, |
| 74 |
.send = s2n_nst_early_data_indication_send, |
| 75 |
.recv = s2n_nst_early_data_indiction_recv, |
| 76 |
.should_send = s2n_nst_early_data_indication_should_send, |
| 77 |
.if_missing = s2n_nst_early_data_indication_missing, |
| 78 |
}; |