| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "tls/s2n_quic_support.h" |
| 17 |
|
| 18 |
#include "s2n_test.h" |
| 19 |
#include "tls/s2n_connection.h" |
| 20 |
|
| 21 |
static const uint8_t TEST_DATA[] = "test"; |
| 22 |
|
| 23 |
static int s2n_test_noop_secret_handler(void *context, struct s2n_connection *conn, |
| 24 |
s2n_secret_type_t secret_type, uint8_t *secret, uint8_t secret_size) |
| 25 |
{ |
| 26 |
return S2N_SUCCESS; |
| 27 |
} |
| 28 |
|
| 29 |
int main(int argc, char **argv) |
| 30 |
{ |
| 31 |
BEGIN_TEST(); |
| 32 |
|
| 33 |
|
| 34 |
if (!s2n_is_tls13_fully_supported()) { |
| 35 |
struct s2n_config *config = s2n_config_new(); |
| 36 |
EXPECT_NOT_NULL(config); |
| 37 |
EXPECT_SUCCESS(s2n_config_enable_quic(config)); |
| 38 |
|
| 39 |
struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT); |
| 40 |
EXPECT_NOT_NULL(conn); |
| 41 |
|
| 42 |
EXPECT_FAILURE_WITH_ERRNO(s2n_connection_enable_quic(conn), S2N_ERR_RSA_PSS_NOT_SUPPORTED); |
| 43 |
EXPECT_FALSE(conn->quic_enabled); |
| 44 |
|
| 45 |
EXPECT_FAILURE_WITH_ERRNO(s2n_connection_set_config(conn, config), S2N_ERR_RSA_PSS_NOT_SUPPORTED); |
| 46 |
EXPECT_NOT_EQUAL(config, conn->config); |
| 47 |
|
| 48 |
EXPECT_SUCCESS(s2n_connection_free(conn)); |
| 49 |
EXPECT_SUCCESS(s2n_config_free(config)); |
| 50 |
END_TEST(); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
{ |
| 55 |
struct s2n_config *config = s2n_config_new(); |
| 56 |
EXPECT_NOT_NULL(config); |
| 57 |
EXPECT_FALSE(config->quic_enabled); |
| 58 |
|
| 59 |
struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT); |
| 60 |
EXPECT_FALSE(s2n_connection_is_quic_enabled(conn)); |
| 61 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, config)); |
| 62 |
EXPECT_FALSE(s2n_connection_is_quic_enabled(conn)); |
| 63 |
|
| 64 |
|
| 65 |
{ |
| 66 |
EXPECT_FAILURE_WITH_ERRNO(s2n_config_enable_quic(NULL), S2N_ERR_NULL); |
| 67 |
EXPECT_FALSE(config->quic_enabled); |
| 68 |
EXPECT_FALSE(s2n_connection_is_quic_enabled(conn)); |
| 69 |
}; |
| 70 |
|
| 71 |
|
| 72 |
{ |
| 73 |
EXPECT_SUCCESS(s2n_config_enable_quic(config)); |
| 74 |
EXPECT_TRUE(config->quic_enabled); |
| 75 |
EXPECT_TRUE(s2n_connection_is_quic_enabled(conn)); |
| 76 |
|
| 77 |
|
| 78 |
EXPECT_SUCCESS(s2n_config_enable_quic(config)); |
| 79 |
EXPECT_TRUE(config->quic_enabled); |
| 80 |
EXPECT_TRUE(s2n_connection_is_quic_enabled(conn)); |
| 81 |
}; |
| 82 |
|
| 83 |
EXPECT_SUCCESS(s2n_connection_free(conn)); |
| 84 |
EXPECT_SUCCESS(s2n_config_free(config)); |
| 85 |
}; |
| 86 |
|
| 87 |
|
| 88 |
{ |
| 89 |
struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT); |
| 90 |
EXPECT_FALSE(s2n_connection_is_quic_enabled(conn)); |
| 91 |
|
| 92 |
|
| 93 |
{ |
| 94 |
EXPECT_FAILURE_WITH_ERRNO(s2n_connection_enable_quic(NULL), S2N_ERR_NULL); |
| 95 |
EXPECT_FALSE(s2n_connection_is_quic_enabled(conn)); |
| 96 |
}; |
| 97 |
|
| 98 |
|
| 99 |
{ |
| 100 |
EXPECT_SUCCESS(s2n_connection_enable_quic(conn)); |
| 101 |
EXPECT_TRUE(s2n_connection_is_quic_enabled(conn)); |
| 102 |
|
| 103 |
|
| 104 |
EXPECT_SUCCESS(s2n_connection_enable_quic(conn)); |
| 105 |
EXPECT_TRUE(s2n_connection_is_quic_enabled(conn)); |
| 106 |
}; |
| 107 |
|
| 108 |
|
| 109 |
{ |
| 110 |
struct s2n_config *config = s2n_config_new(); |
| 111 |
EXPECT_NOT_NULL(config); |
| 112 |
EXPECT_FALSE(config->quic_enabled); |
| 113 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, config)); |
| 114 |
|
| 115 |
EXPECT_SUCCESS(s2n_config_enable_quic(config)); |
| 116 |
EXPECT_TRUE(s2n_connection_is_quic_enabled(conn)); |
| 117 |
|
| 118 |
EXPECT_SUCCESS(s2n_config_free(config)); |
| 119 |
}; |
| 120 |
|
| 121 |
EXPECT_SUCCESS(s2n_connection_free(conn)); |
| 122 |
}; |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
{ |
| 128 |
struct s2n_config *non_quic_config = s2n_config_new(); |
| 129 |
EXPECT_NOT_NULL(non_quic_config); |
| 130 |
|
| 131 |
struct s2n_config *quic_config = s2n_config_new(); |
| 132 |
EXPECT_NOT_NULL(quic_config); |
| 133 |
EXPECT_SUCCESS(s2n_config_enable_quic(quic_config)); |
| 134 |
|
| 135 |
struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT); |
| 136 |
EXPECT_NOT_NULL(conn); |
| 137 |
|
| 138 |
EXPECT_FALSE(s2n_connection_is_quic_enabled(conn)); |
| 139 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, non_quic_config)); |
| 140 |
EXPECT_FALSE(s2n_connection_is_quic_enabled(conn)); |
| 141 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, quic_config)); |
| 142 |
EXPECT_TRUE(s2n_connection_is_quic_enabled(conn)); |
| 143 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, non_quic_config)); |
| 144 |
EXPECT_TRUE(s2n_connection_is_quic_enabled(conn)); |
| 145 |
|
| 146 |
EXPECT_SUCCESS(s2n_config_free(non_quic_config)); |
| 147 |
EXPECT_SUCCESS(s2n_config_free(quic_config)); |
| 148 |
EXPECT_SUCCESS(s2n_connection_free(conn)); |
| 149 |
}; |
| 150 |
|
| 151 |
|
| 152 |
{ |
| 153 |
|
| 154 |
{ |
| 155 |
struct s2n_connection conn = { 0 }; |
| 156 |
EXPECT_FAILURE_WITH_ERRNO(s2n_connection_set_quic_transport_parameters(NULL, TEST_DATA, sizeof(TEST_DATA)), |
| 157 |
S2N_ERR_NULL); |
| 158 |
EXPECT_FAILURE_WITH_ERRNO(s2n_connection_set_quic_transport_parameters(&conn, NULL, sizeof(TEST_DATA)), |
| 159 |
S2N_ERR_NULL); |
| 160 |
EXPECT_SUCCESS(s2n_connection_set_quic_transport_parameters(&conn, TEST_DATA, 0)); |
| 161 |
EXPECT_EQUAL(conn.our_quic_transport_parameters.size, 0); |
| 162 |
}; |
| 163 |
|
| 164 |
|
| 165 |
{ |
| 166 |
struct s2n_connection *conn = NULL; |
| 167 |
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT)); |
| 168 |
|
| 169 |
s2n_connection_set_quic_transport_parameters(conn, TEST_DATA, sizeof(TEST_DATA)); |
| 170 |
EXPECT_BYTEARRAY_EQUAL(conn->our_quic_transport_parameters.data, TEST_DATA, sizeof(TEST_DATA)); |
| 171 |
|
| 172 |
|
| 173 |
const uint8_t other_data[] = "other parameters"; |
| 174 |
s2n_connection_set_quic_transport_parameters(conn, other_data, sizeof(other_data)); |
| 175 |
EXPECT_BYTEARRAY_EQUAL(conn->our_quic_transport_parameters.data, other_data, sizeof(other_data)); |
| 176 |
|
| 177 |
EXPECT_SUCCESS(s2n_connection_free(conn)); |
| 178 |
}; |
| 179 |
}; |
| 180 |
|
| 181 |
|
| 182 |
{ |
| 183 |
|
| 184 |
{ |
| 185 |
struct s2n_connection conn = { 0 }; |
| 186 |
const uint8_t *data_buffer = NULL; |
| 187 |
uint16_t data_buffer_len = 0; |
| 188 |
|
| 189 |
EXPECT_FAILURE_WITH_ERRNO(s2n_connection_get_quic_transport_parameters(NULL, &data_buffer, &data_buffer_len), |
| 190 |
S2N_ERR_NULL); |
| 191 |
EXPECT_FAILURE_WITH_ERRNO(s2n_connection_get_quic_transport_parameters(&conn, NULL, &data_buffer_len), |
| 192 |
S2N_ERR_NULL); |
| 193 |
EXPECT_FAILURE_WITH_ERRNO(s2n_connection_get_quic_transport_parameters(&conn, &data_buffer, NULL), |
| 194 |
S2N_ERR_NULL); |
| 195 |
}; |
| 196 |
|
| 197 |
|
| 198 |
{ |
| 199 |
const uint8_t *data_buffer = TEST_DATA; |
| 200 |
uint16_t data_buffer_len = sizeof(TEST_DATA); |
| 201 |
|
| 202 |
struct s2n_connection *conn = NULL; |
| 203 |
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT)); |
| 204 |
|
| 205 |
EXPECT_SUCCESS(s2n_connection_get_quic_transport_parameters(conn, &data_buffer, &data_buffer_len)); |
| 206 |
EXPECT_EQUAL(data_buffer, NULL); |
| 207 |
EXPECT_EQUAL(data_buffer_len, 0); |
| 208 |
|
| 209 |
EXPECT_SUCCESS(s2n_connection_free(conn)); |
| 210 |
}; |
| 211 |
|
| 212 |
|
| 213 |
{ |
| 214 |
const uint8_t *data_buffer = NULL; |
| 215 |
uint16_t data_buffer_len = 0; |
| 216 |
|
| 217 |
struct s2n_connection *conn = NULL; |
| 218 |
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT)); |
| 219 |
|
| 220 |
EXPECT_SUCCESS(s2n_alloc(&conn->peer_quic_transport_parameters, sizeof(TEST_DATA))); |
| 221 |
EXPECT_MEMCPY_SUCCESS(conn->peer_quic_transport_parameters.data, TEST_DATA, sizeof(TEST_DATA)); |
| 222 |
|
| 223 |
EXPECT_SUCCESS(s2n_connection_get_quic_transport_parameters(conn, &data_buffer, &data_buffer_len)); |
| 224 |
EXPECT_EQUAL(data_buffer, conn->peer_quic_transport_parameters.data); |
| 225 |
EXPECT_EQUAL(data_buffer_len, conn->peer_quic_transport_parameters.size); |
| 226 |
|
| 227 |
EXPECT_SUCCESS(s2n_connection_free(conn)); |
| 228 |
}; |
| 229 |
}; |
| 230 |
|
| 231 |
|
| 232 |
{ |
| 233 |
uint8_t test_context = 0; |
| 234 |
|
| 235 |
|
| 236 |
{ |
| 237 |
struct s2n_connection *conn = NULL; |
| 238 |
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT)); |
| 239 |
|
| 240 |
EXPECT_FAILURE_WITH_ERRNO(s2n_connection_set_secret_callback(NULL, s2n_test_noop_secret_handler, &test_context), S2N_ERR_NULL); |
| 241 |
EXPECT_FAILURE_WITH_ERRNO(s2n_connection_set_secret_callback(conn, NULL, &test_context), S2N_ERR_NULL); |
| 242 |
|
| 243 |
EXPECT_EQUAL(conn->secret_cb, NULL); |
| 244 |
EXPECT_EQUAL(conn->secret_cb_context, NULL); |
| 245 |
|
| 246 |
EXPECT_SUCCESS(s2n_connection_free(conn)); |
| 247 |
}; |
| 248 |
|
| 249 |
|
| 250 |
{ |
| 251 |
struct s2n_connection *conn = NULL; |
| 252 |
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT)); |
| 253 |
EXPECT_EQUAL(conn->secret_cb, NULL); |
| 254 |
EXPECT_EQUAL(conn->secret_cb_context, NULL); |
| 255 |
|
| 256 |
EXPECT_SUCCESS(s2n_connection_set_secret_callback(conn, s2n_test_noop_secret_handler, NULL)); |
| 257 |
|
| 258 |
EXPECT_EQUAL(conn->secret_cb, s2n_test_noop_secret_handler); |
| 259 |
EXPECT_NULL(conn->secret_cb_context); |
| 260 |
|
| 261 |
EXPECT_SUCCESS(s2n_connection_free(conn)); |
| 262 |
}; |
| 263 |
|
| 264 |
|
| 265 |
{ |
| 266 |
struct s2n_connection *conn = NULL; |
| 267 |
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT)); |
| 268 |
EXPECT_EQUAL(conn->secret_cb, NULL); |
| 269 |
EXPECT_EQUAL(conn->secret_cb_context, NULL); |
| 270 |
|
| 271 |
EXPECT_SUCCESS(s2n_connection_set_secret_callback(conn, s2n_test_noop_secret_handler, &test_context)); |
| 272 |
|
| 273 |
EXPECT_EQUAL(conn->secret_cb, s2n_test_noop_secret_handler); |
| 274 |
EXPECT_EQUAL(conn->secret_cb_context, &test_context); |
| 275 |
|
| 276 |
EXPECT_SUCCESS(s2n_connection_free(conn)); |
| 277 |
}; |
| 278 |
}; |
| 279 |
|
| 280 |
|
| 281 |
{ |
| 282 |
struct s2n_config *config = NULL; |
| 283 |
EXPECT_NOT_NULL(config = s2n_config_new()); |
| 284 |
EXPECT_SUCCESS(s2n_config_enable_quic(config)); |
| 285 |
|
| 286 |
struct s2n_connection *conn = NULL; |
| 287 |
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER)); |
| 288 |
EXPECT_SUCCESS(s2n_connection_set_config(conn, config)); |
| 289 |
|
| 290 |
uint8_t buffer[10] = { 0 }; |
| 291 |
s2n_blocked_status blocked_status; |
| 292 |
|
| 293 |
EXPECT_FAILURE_WITH_ERRNO(s2n_recv(conn, buffer, sizeof(buffer), &blocked_status), S2N_ERR_UNSUPPORTED_WITH_QUIC); |
| 294 |
EXPECT_FAILURE_WITH_ERRNO(s2n_send(conn, buffer, sizeof(buffer), &blocked_status), S2N_ERR_UNSUPPORTED_WITH_QUIC); |
| 295 |
#ifndef _WIN32 |
| 296 |
|
| 297 |
struct iovec iovec_buffer = { .iov_base = buffer, .iov_len = sizeof(buffer) }; |
| 298 |
EXPECT_FAILURE_WITH_ERRNO(s2n_sendv(conn, &iovec_buffer, 1, &blocked_status), S2N_ERR_UNSUPPORTED_WITH_QUIC); |
| 299 |
EXPECT_FAILURE_WITH_ERRNO(s2n_sendv_with_offset(conn, &iovec_buffer, 1, 0, &blocked_status), S2N_ERR_UNSUPPORTED_WITH_QUIC); |
| 300 |
#endif |
| 301 |
|
| 302 |
EXPECT_SUCCESS(s2n_connection_free(conn)); |
| 303 |
EXPECT_SUCCESS(s2n_config_free(config)); |
| 304 |
}; |
| 305 |
|
| 306 |
END_TEST(); |
| 307 |
} |