| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "tls/extensions/s2n_server_supported_versions.h" |
| 17 |
|
| 18 |
#include <stdint.h> |
| 19 |
|
| 20 |
#include "tls/extensions/s2n_supported_versions.h" |
| 21 |
#include "tls/s2n_alerts.h" |
| 22 |
#include "tls/s2n_cipher_preferences.h" |
| 23 |
#include "tls/s2n_tls.h" |
| 24 |
#include "tls/s2n_tls_parameters.h" |
| 25 |
#include "utils/s2n_safety.h" |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
static int s2n_server_supported_versions_send(struct s2n_connection *conn, struct s2n_stuffer *out); |
| 41 |
static int s2n_server_supported_versions_recv(struct s2n_connection *conn, struct s2n_stuffer *in); |
| 42 |
|
| 43 |
const s2n_extension_type s2n_server_supported_versions_extension = { |
| 44 |
.iana_value = TLS_EXTENSION_SUPPORTED_VERSIONS, |
| 45 |
.is_response = true, |
| 46 |
.send = s2n_server_supported_versions_send, |
| 47 |
.recv = s2n_server_supported_versions_recv, |
| 48 |
.should_send = s2n_extension_send_if_tls13_connection, |
| 49 |
.if_missing = s2n_extension_noop_if_missing, |
| 50 |
}; |
| 51 |
|
| 52 |
static int s2n_server_supported_versions_send(struct s2n_connection *conn, struct s2n_stuffer *out) |
| 53 |
{ |
| 54 |
POSIX_GUARD(s2n_stuffer_write_uint8(out, conn->server_protocol_version / 10)); |
| 55 |
POSIX_GUARD(s2n_stuffer_write_uint8(out, conn->server_protocol_version % 10)); |
| 56 |
|
| 57 |
return S2N_SUCCESS; |
| 58 |
} |
| 59 |
|
| 60 |
static int s2n_extensions_server_supported_versions_process(struct s2n_connection *conn, struct s2n_stuffer *extension) |
| 61 |
{ |
| 62 |
uint8_t highest_supported_version = conn->client_protocol_version; |
| 63 |
uint8_t minimum_supported_version = s2n_unknown_protocol_version; |
| 64 |
POSIX_GUARD_RESULT(s2n_connection_get_minimum_supported_version(conn, &minimum_supported_version)); |
| 65 |
POSIX_ENSURE(highest_supported_version >= minimum_supported_version, S2N_ERR_PROTOCOL_VERSION_UNSUPPORTED); |
| 66 |
|
| 67 |
uint8_t server_version_parts[S2N_TLS_PROTOCOL_VERSION_LEN]; |
| 68 |
POSIX_GUARD(s2n_stuffer_read_bytes(extension, server_version_parts, S2N_TLS_PROTOCOL_VERSION_LEN)); |
| 69 |
|
| 70 |
uint16_t server_version = (server_version_parts[0] * 10) + server_version_parts[1]; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
if (s2n_is_hello_retry_handshake(conn) && !s2n_is_hello_retry_message(conn)) { |
| 80 |
POSIX_ENSURE(conn->server_protocol_version == server_version, |
| 81 |
S2N_ERR_BAD_MESSAGE); |
| 82 |
} |
| 83 |
|
| 84 |
POSIX_ENSURE_GTE(server_version, S2N_TLS13); |
| 85 |
POSIX_ENSURE_LTE(server_version, highest_supported_version); |
| 86 |
POSIX_ENSURE_GTE(server_version, minimum_supported_version); |
| 87 |
|
| 88 |
conn->server_protocol_version = server_version; |
| 89 |
|
| 90 |
return S2N_SUCCESS; |
| 91 |
} |
| 92 |
|
| 93 |
static int s2n_server_supported_versions_recv(struct s2n_connection *conn, struct s2n_stuffer *in) |
| 94 |
{ |
| 95 |
if (s2n_connection_get_protocol_version(conn) < S2N_TLS13) { |
| 96 |
return S2N_SUCCESS; |
| 97 |
} |
| 98 |
|
| 99 |
S2N_ERROR_IF(s2n_extensions_server_supported_versions_process(conn, in) < 0, S2N_ERR_BAD_MESSAGE); |
| 100 |
return S2N_SUCCESS; |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
int s2n_extensions_server_supported_versions_size(struct s2n_connection *conn) |
| 106 |
{ |
| 107 |
return 6; |
| 108 |
} |
| 109 |
|
| 110 |
int s2n_extensions_server_supported_versions_recv(struct s2n_connection *conn, struct s2n_stuffer *extension) |
| 111 |
{ |
| 112 |
return s2n_extension_recv(&s2n_server_supported_versions_extension, conn, extension); |
| 113 |
} |