| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "tls/extensions/s2n_client_max_frag_len.h" |
| 17 |
|
| 18 |
#include <stdint.h> |
| 19 |
|
| 20 |
#include "tls/s2n_tls.h" |
| 21 |
#include "tls/s2n_tls_parameters.h" |
| 22 |
#include "utils/s2n_safety.h" |
| 23 |
|
| 24 |
static bool s2n_client_max_frag_len_should_send(struct s2n_connection *conn); |
| 25 |
static int s2n_client_max_frag_len_send(struct s2n_connection *conn, struct s2n_stuffer *out); |
| 26 |
static int s2n_client_max_frag_len_recv(struct s2n_connection *conn, struct s2n_stuffer *extension); |
| 27 |
|
| 28 |
const s2n_extension_type s2n_client_max_frag_len_extension = { |
| 29 |
.iana_value = TLS_EXTENSION_MAX_FRAG_LEN, |
| 30 |
.is_response = false, |
| 31 |
.send = s2n_client_max_frag_len_send, |
| 32 |
.recv = s2n_client_max_frag_len_recv, |
| 33 |
.should_send = s2n_client_max_frag_len_should_send, |
| 34 |
.if_missing = s2n_extension_noop_if_missing, |
| 35 |
}; |
| 36 |
|
| 37 |
static bool s2n_client_max_frag_len_should_send(struct s2n_connection *conn) |
| 38 |
{ |
| 39 |
return conn->config->mfl_code != S2N_TLS_MAX_FRAG_LEN_EXT_NONE; |
| 40 |
} |
| 41 |
|
| 42 |
static int s2n_client_max_frag_len_send(struct s2n_connection *conn, struct s2n_stuffer *out) |
| 43 |
{ |
| 44 |
return s2n_stuffer_write_uint8(out, conn->config->mfl_code); |
| 45 |
} |
| 46 |
|
| 47 |
static int s2n_client_max_frag_len_recv(struct s2n_connection *conn, struct s2n_stuffer *extension) |
| 48 |
{ |
| 49 |
if (!conn->config->accept_mfl) { |
| 50 |
return S2N_SUCCESS; |
| 51 |
} |
| 52 |
|
| 53 |
uint8_t mfl_code = 0; |
| 54 |
POSIX_GUARD(s2n_stuffer_read_uint8(extension, &mfl_code)); |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
if (mfl_code >= s2n_array_len(mfl_code_to_length) || mfl_code_to_length[mfl_code] > S2N_TLS_MAXIMUM_FRAGMENT_LENGTH) { |
| 65 |
return S2N_SUCCESS; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
conn->negotiated_mfl_code = mfl_code; |
| 76 |
POSIX_GUARD_RESULT(s2n_connection_set_max_fragment_length(conn, mfl_code_to_length[mfl_code])); |
| 77 |
return S2N_SUCCESS; |
| 78 |
} |