| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include <fcntl.h> |
| 17 |
#include <stdint.h> |
| 18 |
#include <stdlib.h> |
| 19 |
|
| 20 |
#include "api/s2n.h" |
| 21 |
#include "s2n_test.h" |
| 22 |
#include "stuffer/s2n_stuffer.h" |
| 23 |
#include "testlib/s2n_testlib.h" |
| 24 |
#include "tls/s2n_config.h" |
| 25 |
#include "tls/s2n_connection.h" |
| 26 |
#include "tls/s2n_handshake_io.c" |
| 27 |
#include "tls/s2n_record.h" |
| 28 |
#include "tls/s2n_tls.h" |
| 29 |
#include "tls/s2n_tls13.h" |
| 30 |
#include "utils/s2n_safety.h" |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
const char tls13_zero_length_application_record_hex[] = "170303000117"; |
| 36 |
const char tls13_zero_length_handshake_record_hex[] = "1603030000"; |
| 37 |
const char tls13_zero_length_alert_record_hex[] = "1503030000"; |
| 38 |
|
| 39 |
int main(int argc, char **argv) |
| 40 |
{ |
| 41 |
BEGIN_TEST(); |
| 42 |
|
| 43 |
EXPECT_SUCCESS(s2n_enable_tls13_in_test()); |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
{ |
| 53 |
struct s2n_connection *server_conn = NULL; |
| 54 |
EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER)); |
| 55 |
server_conn->actual_protocol_version = S2N_TLS13; |
| 56 |
EXPECT_OK(s2n_connection_set_secrets(server_conn)); |
| 57 |
|
| 58 |
struct s2n_connection *client_conn = NULL; |
| 59 |
EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT)); |
| 60 |
client_conn->actual_protocol_version = S2N_TLS13; |
| 61 |
EXPECT_OK(s2n_connection_set_secrets(client_conn)); |
| 62 |
|
| 63 |
struct s2n_blob zero_length_data = { 0 }; |
| 64 |
s2n_blocked_status blocked = S2N_NOT_BLOCKED; |
| 65 |
|
| 66 |
DEFER_CLEANUP(struct s2n_stuffer client_to_server = { 0 }, s2n_stuffer_free); |
| 67 |
DEFER_CLEANUP(struct s2n_stuffer server_to_client = { 0 }, s2n_stuffer_free); |
| 68 |
|
| 69 |
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&client_to_server, 0)); |
| 70 |
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&server_to_client, 0)); |
| 71 |
|
| 72 |
EXPECT_SUCCESS(s2n_connection_set_io_stuffers(&client_to_server, &server_to_client, server_conn)); |
| 73 |
EXPECT_SUCCESS(s2n_connection_set_io_stuffers(&server_to_client, &client_to_server, client_conn)); |
| 74 |
|
| 75 |
EXPECT_OK(s2n_record_write(client_conn, TLS_APPLICATION_DATA, &zero_length_data)); |
| 76 |
EXPECT_SUCCESS(s2n_flush(client_conn, &blocked)); |
| 77 |
EXPECT_TRUE(s2n_stuffer_data_available(&client_to_server) > 0); |
| 78 |
|
| 79 |
EXPECT_OK(s2n_record_write(server_conn, TLS_APPLICATION_DATA, &zero_length_data)); |
| 80 |
EXPECT_SUCCESS(s2n_flush(server_conn, &blocked)); |
| 81 |
EXPECT_TRUE(s2n_stuffer_data_available(&server_to_client) > 0); |
| 82 |
|
| 83 |
uint8_t record_type = 0; |
| 84 |
int isSSLv2 = 0; |
| 85 |
|
| 86 |
EXPECT_SUCCESS(s2n_read_full_record(server_conn, &record_type, &isSSLv2)); |
| 87 |
EXPECT_EQUAL(record_type, TLS_APPLICATION_DATA); |
| 88 |
record_type = 0; |
| 89 |
EXPECT_SUCCESS(s2n_read_full_record(client_conn, &record_type, &isSSLv2)); |
| 90 |
EXPECT_EQUAL(record_type, TLS_APPLICATION_DATA); |
| 91 |
|
| 92 |
EXPECT_SUCCESS(s2n_connection_free(server_conn)); |
| 93 |
EXPECT_SUCCESS(s2n_connection_free(client_conn)); |
| 94 |
}; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
{ |
| 105 |
struct s2n_connection *server_conn = NULL; |
| 106 |
EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER)); |
| 107 |
server_conn->actual_protocol_version = S2N_TLS13; |
| 108 |
|
| 109 |
struct s2n_connection *client_conn = NULL; |
| 110 |
EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT)); |
| 111 |
client_conn->actual_protocol_version = S2N_TLS13; |
| 112 |
|
| 113 |
DEFER_CLEANUP(struct s2n_stuffer client_to_server = { 0 }, s2n_stuffer_free); |
| 114 |
DEFER_CLEANUP(struct s2n_stuffer server_to_client = { 0 }, s2n_stuffer_free); |
| 115 |
|
| 116 |
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&client_to_server, 0)); |
| 117 |
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&server_to_client, 0)); |
| 118 |
|
| 119 |
EXPECT_SUCCESS(s2n_connection_set_io_stuffers(&client_to_server, &server_to_client, server_conn)); |
| 120 |
EXPECT_SUCCESS(s2n_connection_set_io_stuffers(&server_to_client, &client_to_server, client_conn)); |
| 121 |
|
| 122 |
S2N_BLOB_FROM_HEX(record_header_blob, tls13_zero_length_handshake_record_hex); |
| 123 |
EXPECT_SUCCESS(s2n_stuffer_write_bytes(&client_to_server, record_header_blob.data, record_header_blob.size)); |
| 124 |
EXPECT_SUCCESS(s2n_stuffer_write_bytes(&server_to_client, record_header_blob.data, record_header_blob.size)); |
| 125 |
EXPECT_EQUAL(s2n_stuffer_data_available(&client_to_server), S2N_TLS_RECORD_HEADER_LENGTH); |
| 126 |
EXPECT_EQUAL(s2n_stuffer_data_available(&server_to_client), S2N_TLS_RECORD_HEADER_LENGTH); |
| 127 |
|
| 128 |
EXPECT_FAILURE_WITH_ERRNO(s2n_handshake_read_io(server_conn), S2N_ERR_BAD_MESSAGE); |
| 129 |
EXPECT_FAILURE_WITH_ERRNO(s2n_handshake_read_io(client_conn), S2N_ERR_BAD_MESSAGE); |
| 130 |
|
| 131 |
EXPECT_SUCCESS(s2n_connection_free(server_conn)); |
| 132 |
EXPECT_SUCCESS(s2n_connection_free(client_conn)); |
| 133 |
}; |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
{ |
| 144 |
struct s2n_connection *server_conn = NULL; |
| 145 |
EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER)); |
| 146 |
server_conn->actual_protocol_version = S2N_TLS13; |
| 147 |
|
| 148 |
struct s2n_connection *client_conn = NULL; |
| 149 |
EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT)); |
| 150 |
client_conn->actual_protocol_version = S2N_TLS13; |
| 151 |
|
| 152 |
DEFER_CLEANUP(struct s2n_stuffer client_to_server = { 0 }, s2n_stuffer_free); |
| 153 |
DEFER_CLEANUP(struct s2n_stuffer server_to_client = { 0 }, s2n_stuffer_free); |
| 154 |
|
| 155 |
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&client_to_server, 0)); |
| 156 |
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&server_to_client, 0)); |
| 157 |
|
| 158 |
EXPECT_SUCCESS(s2n_connection_set_io_stuffers(&client_to_server, &server_to_client, server_conn)); |
| 159 |
EXPECT_SUCCESS(s2n_connection_set_io_stuffers(&server_to_client, &client_to_server, client_conn)); |
| 160 |
|
| 161 |
S2N_BLOB_FROM_HEX(record_header_blob, tls13_zero_length_alert_record_hex); |
| 162 |
EXPECT_SUCCESS(s2n_stuffer_write_bytes(&client_to_server, record_header_blob.data, record_header_blob.size)); |
| 163 |
EXPECT_SUCCESS(s2n_stuffer_write_bytes(&server_to_client, record_header_blob.data, record_header_blob.size)); |
| 164 |
EXPECT_EQUAL(s2n_stuffer_data_available(&client_to_server), S2N_TLS_RECORD_HEADER_LENGTH); |
| 165 |
EXPECT_EQUAL(s2n_stuffer_data_available(&server_to_client), S2N_TLS_RECORD_HEADER_LENGTH); |
| 166 |
|
| 167 |
EXPECT_FAILURE_WITH_ERRNO(s2n_handshake_read_io(server_conn), S2N_ERR_BAD_MESSAGE); |
| 168 |
EXPECT_FAILURE_WITH_ERRNO(s2n_handshake_read_io(client_conn), S2N_ERR_BAD_MESSAGE); |
| 169 |
|
| 170 |
EXPECT_SUCCESS(s2n_connection_free(server_conn)); |
| 171 |
EXPECT_SUCCESS(s2n_connection_free(client_conn)); |
| 172 |
}; |
| 173 |
|
| 174 |
END_TEST(); |
| 175 |
|
| 176 |
return 0; |
| 177 |
} |