| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include <errno.h> |
| 17 |
#include <fcntl.h> |
| 18 |
#include <stdint.h> |
| 19 |
#include <unistd.h> |
| 20 |
|
| 21 |
#include "api/s2n.h" |
| 22 |
#include "s2n_test.h" |
| 23 |
#include "testlib/s2n_testlib.h" |
| 24 |
#include "tls/s2n_connection.h" |
| 25 |
#include "tls/s2n_handshake.h" |
| 26 |
#include "tls/s2n_tls.h" |
| 27 |
#include "tls/s2n_tls_parameters.h" |
| 28 |
|
| 29 |
#define ZERO_TO_THIRTY_ONE 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, \ |
| 30 |
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F |
| 31 |
|
| 32 |
int main(int argc, char **argv) |
| 33 |
{ |
| 34 |
char *cert_chain = NULL; |
| 35 |
char *private_key = NULL; |
| 36 |
BEGIN_TEST(); |
| 37 |
EXPECT_SUCCESS(s2n_disable_tls13_in_test()); |
| 38 |
|
| 39 |
EXPECT_NOT_NULL(cert_chain = malloc(S2N_MAX_TEST_PEM_SIZE)); |
| 40 |
EXPECT_NOT_NULL(private_key = malloc(S2N_MAX_TEST_PEM_SIZE)); |
| 41 |
EXPECT_SUCCESS(setenv("S2N_DONT_MLOCK", "1", 0)); |
| 42 |
|
| 43 |
|
| 44 |
{ |
| 45 |
struct s2n_connection *client_conn = NULL; |
| 46 |
struct s2n_config *client_config = NULL; |
| 47 |
s2n_blocked_status client_blocked; |
| 48 |
|
| 49 |
uint8_t server_extensions[] = { |
| 50 |
|
| 51 |
0xff, |
| 52 |
0x01, |
| 53 |
|
| 54 |
0x00, |
| 55 |
0x01, |
| 56 |
|
| 57 |
0x00, |
| 58 |
}; |
| 59 |
int server_extensions_len = sizeof(server_extensions); |
| 60 |
uint8_t server_hello_message[] = { |
| 61 |
|
| 62 |
0x03, |
| 63 |
0x03, |
| 64 |
|
| 65 |
ZERO_TO_THIRTY_ONE, |
| 66 |
|
| 67 |
0x20, |
| 68 |
|
| 69 |
ZERO_TO_THIRTY_ONE, |
| 70 |
|
| 71 |
0x00, |
| 72 |
0x3C, |
| 73 |
|
| 74 |
0x00, |
| 75 |
|
| 76 |
(server_extensions_len >> 8) & 0xff, |
| 77 |
(server_extensions_len & 0xff), |
| 78 |
}; |
| 79 |
int body_len = sizeof(server_hello_message) + server_extensions_len; |
| 80 |
uint8_t message_header[] = { |
| 81 |
|
| 82 |
0x02, |
| 83 |
|
| 84 |
(body_len >> 16) & 0xff, |
| 85 |
(body_len >> 8) & 0xff, |
| 86 |
(body_len & 0xff), |
| 87 |
}; |
| 88 |
int message_len = sizeof(message_header) + body_len; |
| 89 |
uint8_t record_header[] = { |
| 90 |
|
| 91 |
0x16, |
| 92 |
|
| 93 |
0x03, |
| 94 |
0x03, |
| 95 |
|
| 96 |
(message_len >> 8) & 0xff, |
| 97 |
(message_len & 0xff), |
| 98 |
}; |
| 99 |
|
| 100 |
|
| 101 |
struct s2n_test_io_pair io_pair; |
| 102 |
EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair)); |
| 103 |
|
| 104 |
EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT)); |
| 105 |
EXPECT_SUCCESS(s2n_connection_set_io_pair(client_conn, &io_pair)); |
| 106 |
|
| 107 |
EXPECT_NOT_NULL(client_config = s2n_config_new()); |
| 108 |
|
| 109 |
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(client_config, "test_all")); |
| 110 |
EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config)); |
| 111 |
|
| 112 |
|
| 113 |
EXPECT_EQUAL(s2n_negotiate(client_conn, &client_blocked), -1); |
| 114 |
EXPECT_EQUAL(s2n_errno, S2N_ERR_IO_BLOCKED); |
| 115 |
EXPECT_EQUAL(client_blocked, S2N_BLOCKED_ON_READ); |
| 116 |
|
| 117 |
|
| 118 |
EXPECT_EQUAL(s2n_test_send(io_pair.server, record_header, sizeof(record_header)), sizeof(record_header)); |
| 119 |
EXPECT_EQUAL(s2n_test_send(io_pair.server, message_header, sizeof(message_header)), sizeof(message_header)); |
| 120 |
EXPECT_EQUAL(s2n_test_send(io_pair.server, server_hello_message, sizeof(server_hello_message)), sizeof(server_hello_message)); |
| 121 |
EXPECT_EQUAL(s2n_test_send(io_pair.server, server_extensions, sizeof(server_extensions)), sizeof(server_extensions)); |
| 122 |
|
| 123 |
|
| 124 |
EXPECT_EQUAL(s2n_negotiate(client_conn, &client_blocked), -1); |
| 125 |
EXPECT_EQUAL(s2n_errno, S2N_ERR_IO_BLOCKED); |
| 126 |
EXPECT_EQUAL(client_blocked, S2N_BLOCKED_ON_READ); |
| 127 |
|
| 128 |
|
| 129 |
EXPECT_EQUAL(client_conn->secure_renegotiation, 1); |
| 130 |
|
| 131 |
EXPECT_SUCCESS(s2n_io_pair_close(&io_pair)); |
| 132 |
EXPECT_SUCCESS(s2n_connection_free(client_conn)); |
| 133 |
EXPECT_SUCCESS(s2n_config_free(client_config)); |
| 134 |
}; |
| 135 |
|
| 136 |
|
| 137 |
{ |
| 138 |
struct s2n_connection *client_conn = NULL; |
| 139 |
struct s2n_config *client_config = NULL; |
| 140 |
s2n_blocked_status client_blocked; |
| 141 |
|
| 142 |
uint8_t server_hello_message[] = { |
| 143 |
|
| 144 |
0x03, 0x03, |
| 145 |
|
| 146 |
ZERO_TO_THIRTY_ONE, |
| 147 |
|
| 148 |
0x20, |
| 149 |
|
| 150 |
ZERO_TO_THIRTY_ONE, |
| 151 |
|
| 152 |
0x00, 0x3C, |
| 153 |
|
| 154 |
0x00, |
| 155 |
|
| 156 |
0x00, 0x00 |
| 157 |
}; |
| 158 |
int body_len = sizeof(server_hello_message); |
| 159 |
uint8_t message_header[] = { |
| 160 |
|
| 161 |
0x02, |
| 162 |
|
| 163 |
(body_len >> 16) & 0xff, |
| 164 |
(body_len >> 8) & 0xff, |
| 165 |
(body_len & 0xff), |
| 166 |
}; |
| 167 |
int message_len = sizeof(message_header) + body_len; |
| 168 |
uint8_t record_header[] = { |
| 169 |
|
| 170 |
0x16, |
| 171 |
|
| 172 |
0x03, |
| 173 |
0x03, |
| 174 |
|
| 175 |
(message_len >> 8) & 0xff, |
| 176 |
(message_len & 0xff), |
| 177 |
}; |
| 178 |
|
| 179 |
|
| 180 |
struct s2n_test_io_pair io_pair; |
| 181 |
EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair)); |
| 182 |
|
| 183 |
EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT)); |
| 184 |
EXPECT_SUCCESS(s2n_connection_set_io_pair(client_conn, &io_pair)); |
| 185 |
|
| 186 |
EXPECT_NOT_NULL(client_config = s2n_config_new()); |
| 187 |
|
| 188 |
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(client_config, "test_all")); |
| 189 |
EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config)); |
| 190 |
|
| 191 |
|
| 192 |
EXPECT_EQUAL(s2n_negotiate(client_conn, &client_blocked), -1); |
| 193 |
EXPECT_EQUAL(s2n_errno, S2N_ERR_IO_BLOCKED); |
| 194 |
EXPECT_EQUAL(client_blocked, S2N_BLOCKED_ON_READ); |
| 195 |
|
| 196 |
|
| 197 |
EXPECT_EQUAL(s2n_test_send(io_pair.server, record_header, sizeof(record_header)), sizeof(record_header)); |
| 198 |
EXPECT_EQUAL(s2n_test_send(io_pair.server, message_header, sizeof(message_header)), sizeof(message_header)); |
| 199 |
EXPECT_EQUAL(s2n_test_send(io_pair.server, server_hello_message, sizeof(server_hello_message)), sizeof(server_hello_message)); |
| 200 |
|
| 201 |
|
| 202 |
EXPECT_EQUAL(s2n_negotiate(client_conn, &client_blocked), -1); |
| 203 |
EXPECT_EQUAL(s2n_errno, S2N_ERR_IO_BLOCKED); |
| 204 |
EXPECT_EQUAL(client_blocked, S2N_BLOCKED_ON_READ); |
| 205 |
|
| 206 |
|
| 207 |
EXPECT_EQUAL(client_conn->secure_renegotiation, 0); |
| 208 |
|
| 209 |
EXPECT_SUCCESS(s2n_io_pair_close(&io_pair)); |
| 210 |
EXPECT_SUCCESS(s2n_connection_free(client_conn)); |
| 211 |
EXPECT_SUCCESS(s2n_config_free(client_config)); |
| 212 |
}; |
| 213 |
|
| 214 |
|
| 215 |
{ |
| 216 |
struct s2n_connection *client_conn = NULL; |
| 217 |
struct s2n_config *client_config = NULL; |
| 218 |
s2n_blocked_status client_blocked; |
| 219 |
|
| 220 |
uint8_t server_extensions[] = { |
| 221 |
|
| 222 |
0xff, |
| 223 |
0x01, |
| 224 |
|
| 225 |
0x00, |
| 226 |
0x21, |
| 227 |
|
| 228 |
0x20, |
| 229 |
|
| 230 |
ZERO_TO_THIRTY_ONE, |
| 231 |
}; |
| 232 |
int server_extensions_len = sizeof(server_extensions); |
| 233 |
uint8_t server_hello_message[] = { |
| 234 |
|
| 235 |
0x03, |
| 236 |
0x03, |
| 237 |
|
| 238 |
ZERO_TO_THIRTY_ONE, |
| 239 |
|
| 240 |
0x20, |
| 241 |
|
| 242 |
ZERO_TO_THIRTY_ONE, |
| 243 |
|
| 244 |
0x00, |
| 245 |
0x3C, |
| 246 |
|
| 247 |
0x00, |
| 248 |
|
| 249 |
(server_extensions_len >> 8) & 0xff, |
| 250 |
(server_extensions_len & 0xff), |
| 251 |
}; |
| 252 |
int body_len = sizeof(server_hello_message) + server_extensions_len; |
| 253 |
uint8_t message_header[] = { |
| 254 |
|
| 255 |
0x02, |
| 256 |
|
| 257 |
(body_len >> 16) & 0xff, |
| 258 |
(body_len >> 8) & 0xff, |
| 259 |
(body_len & 0xff), |
| 260 |
}; |
| 261 |
int message_len = sizeof(message_header) + body_len; |
| 262 |
uint8_t record_header[] = { |
| 263 |
|
| 264 |
0x16, |
| 265 |
|
| 266 |
0x03, |
| 267 |
0x03, |
| 268 |
|
| 269 |
(message_len >> 8) & 0xff, |
| 270 |
(message_len & 0xff), |
| 271 |
}; |
| 272 |
|
| 273 |
|
| 274 |
struct s2n_test_io_pair io_pair; |
| 275 |
EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair)); |
| 276 |
|
| 277 |
EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT)); |
| 278 |
EXPECT_SUCCESS(s2n_connection_set_io_pair(client_conn, &io_pair)); |
| 279 |
|
| 280 |
EXPECT_NOT_NULL(client_config = s2n_config_new()); |
| 281 |
EXPECT_OK(s2n_config_set_tls12_security_policy(client_config)); |
| 282 |
EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config)); |
| 283 |
|
| 284 |
|
| 285 |
EXPECT_EQUAL(s2n_negotiate(client_conn, &client_blocked), -1); |
| 286 |
EXPECT_EQUAL(s2n_errno, S2N_ERR_IO_BLOCKED); |
| 287 |
EXPECT_EQUAL(client_blocked, S2N_BLOCKED_ON_READ); |
| 288 |
|
| 289 |
|
| 290 |
EXPECT_EQUAL(s2n_test_send(io_pair.server, record_header, sizeof(record_header)), sizeof(record_header)); |
| 291 |
EXPECT_EQUAL(s2n_test_send(io_pair.server, message_header, sizeof(message_header)), sizeof(message_header)); |
| 292 |
EXPECT_EQUAL(s2n_test_send(io_pair.server, server_hello_message, sizeof(server_hello_message)), sizeof(server_hello_message)); |
| 293 |
EXPECT_EQUAL(s2n_test_send(io_pair.server, server_extensions, sizeof(server_extensions)), sizeof(server_extensions)); |
| 294 |
|
| 295 |
|
| 296 |
EXPECT_SUCCESS(s2n_connection_set_blinding(client_conn, S2N_SELF_SERVICE_BLINDING)); |
| 297 |
EXPECT_EQUAL(s2n_negotiate(client_conn, &client_blocked), -1); |
| 298 |
EXPECT_EQUAL(s2n_errno, S2N_ERR_NON_EMPTY_RENEGOTIATION_INFO); |
| 299 |
|
| 300 |
EXPECT_SUCCESS(s2n_io_pair_close(&io_pair)); |
| 301 |
EXPECT_SUCCESS(s2n_connection_free(client_conn)); |
| 302 |
EXPECT_SUCCESS(s2n_config_free(client_config)); |
| 303 |
}; |
| 304 |
|
| 305 |
free(cert_chain); |
| 306 |
free(private_key); |
| 307 |
END_TEST(); |
| 308 |
} |