| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "s2n_test.h" |
| 17 |
#include "testlib/s2n_testlib.h" |
| 18 |
|
| 19 |
static S2N_RESULT s2n_test_pem_paths_from_intent_dir(const char *intent_cert_dir, char *cert_chain_path, |
| 20 |
char *leaf_key_path, char *root_cert_path) |
| 21 |
{ |
| 22 |
sprintf(cert_chain_path, "%s/cert-chain.pem", intent_cert_dir); |
| 23 |
sprintf(leaf_key_path, "%s/leaf-key.pem", intent_cert_dir); |
| 24 |
sprintf(root_cert_path, "%s/root-cert.pem", intent_cert_dir); |
| 25 |
return S2N_RESULT_OK; |
| 26 |
} |
| 27 |
|
| 28 |
int main(int argc, char *argv[]) |
| 29 |
{ |
| 30 |
BEGIN_TEST(); |
| 31 |
|
| 32 |
|
| 33 |
{ |
| 34 |
|
| 35 |
{ |
| 36 |
EXPECT_FAILURE_WITH_ERRNO(s2n_config_disable_x509_intent_verification(NULL), S2N_ERR_INVALID_ARGUMENT); |
| 37 |
|
| 38 |
DEFER_CLEANUP(struct s2n_config *config = s2n_config_new_minimal(), s2n_config_ptr_free); |
| 39 |
EXPECT_SUCCESS(s2n_config_disable_x509_intent_verification(config)); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
{ |
| 44 |
DEFER_CLEANUP(struct s2n_config *config = s2n_config_new_minimal(), s2n_config_ptr_free); |
| 45 |
EXPECT_NOT_NULL(config); |
| 46 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), s2n_connection_ptr_free); |
| 47 |
EXPECT_NOT_NULL(conn); |
| 48 |
|
| 49 |
EXPECT_FALSE(config->disable_x509_intent_verification); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
{ |
| 54 |
DEFER_CLEANUP(struct s2n_config *config = s2n_config_new_minimal(), s2n_config_ptr_free); |
| 55 |
EXPECT_NOT_NULL(config); |
| 56 |
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), s2n_connection_ptr_free); |
| 57 |
EXPECT_NOT_NULL(conn); |
| 58 |
|
| 59 |
EXPECT_FALSE(config->disable_x509_intent_verification); |
| 60 |
EXPECT_SUCCESS(s2n_config_disable_x509_intent_verification(config)); |
| 61 |
EXPECT_TRUE(config->disable_x509_intent_verification); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
{ |
| 67 |
struct { |
| 68 |
const char *cert_chain_dir; |
| 69 |
s2n_error expected_client_error; |
| 70 |
s2n_error expected_server_error; |
| 71 |
} test_cases[] = { |
| 72 |
{ |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
.cert_chain_dir = "../pems/intent/cert_chains/no_intent", |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
.expected_client_error = S2N_ERR_OK, |
| 83 |
.expected_server_error = S2N_ERR_OK, |
| 84 |
}, |
| 85 |
{ |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
.cert_chain_dir = "../pems/intent/cert_chains/ku_digital_signature_leaf", |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
.expected_client_error = S2N_ERR_OK, |
| 94 |
.expected_server_error = S2N_ERR_OK, |
| 95 |
}, |
| 96 |
#if !defined(LIBRESSL_VERSION_NUMBER) |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
{ |
| 102 |
|
| 103 |
.cert_chain_dir = "../pems/intent/cert_chains/ku_key_agreement_leaf", |
| 104 |
|
| 105 |
.expected_client_error = S2N_ERR_OK, |
| 106 |
.expected_server_error = S2N_ERR_OK, |
| 107 |
}, |
| 108 |
#endif |
| 109 |
{ |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
.cert_chain_dir = "../pems/intent/cert_chains/ku_digital_signature_and_key_agreement_leaf", |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
.expected_client_error = S2N_ERR_OK, |
| 118 |
.expected_server_error = S2N_ERR_OK, |
| 119 |
}, |
| 120 |
{ |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
.cert_chain_dir = "../pems/intent/cert_chains/ku_digital_signature_and_content_commitment_leaf", |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
.expected_client_error = S2N_ERR_OK, |
| 130 |
.expected_server_error = S2N_ERR_OK, |
| 131 |
}, |
| 132 |
{ |
| 133 |
|
| 134 |
.cert_chain_dir = "../pems/intent/cert_chains/ku_key_encipherment_leaf", |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
.expected_client_error = S2N_ERR_OK, |
| 139 |
.expected_server_error = S2N_ERR_CERT_INTENT_INVALID, |
| 140 |
}, |
| 141 |
{ |
| 142 |
|
| 143 |
.cert_chain_dir = "../pems/intent/cert_chains/ku_key_cert_sign_leaf", |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
.expected_client_error = S2N_ERR_CERT_INTENT_INVALID, |
| 148 |
.expected_server_error = S2N_ERR_CERT_INTENT_INVALID, |
| 149 |
}, |
| 150 |
{ |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
.cert_chain_dir = "../pems/intent/cert_chains/ku_key_cert_sign_intermediate", |
| 155 |
|
| 156 |
.expected_client_error = S2N_ERR_OK, |
| 157 |
.expected_server_error = S2N_ERR_OK, |
| 158 |
}, |
| 159 |
{ |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
.cert_chain_dir = "../pems/intent/cert_chains/ku_key_cert_sign_and_content_commitment_intermediate", |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
.expected_client_error = S2N_ERR_OK, |
| 168 |
.expected_server_error = S2N_ERR_OK, |
| 169 |
}, |
| 170 |
{ |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
.cert_chain_dir = "../pems/intent/cert_chains/eku_clientAuth_and_serverAuth_leaf", |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
.expected_client_error = S2N_ERR_OK, |
| 179 |
.expected_server_error = S2N_ERR_OK, |
| 180 |
}, |
| 181 |
{ |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
.cert_chain_dir = "../pems/intent/cert_chains/eku_clientAuth_and_serverAuth_intermediate", |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
.expected_client_error = S2N_ERR_OK, |
| 190 |
.expected_server_error = S2N_ERR_OK, |
| 191 |
}, |
| 192 |
{ |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
.cert_chain_dir = "../pems/intent/cert_chains/eku_clientAuth_and_serverAuth_and_emailProtection_leaf", |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
.expected_client_error = S2N_ERR_OK, |
| 202 |
.expected_server_error = S2N_ERR_OK, |
| 203 |
}, |
| 204 |
{ |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
.cert_chain_dir = "../pems/intent/cert_chains/eku_clientAuth_and_serverAuth_and_emailProtection_intermediate", |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
.expected_client_error = S2N_ERR_OK, |
| 214 |
.expected_server_error = S2N_ERR_OK, |
| 215 |
}, |
| 216 |
{ |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
.cert_chain_dir = "../pems/intent/cert_chains/eku_clientAuth_leaf", |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
.expected_client_error = S2N_ERR_CERT_INTENT_INVALID, |
| 225 |
.expected_server_error = S2N_ERR_OK, |
| 226 |
}, |
| 227 |
{ |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
.cert_chain_dir = "../pems/intent/cert_chains/eku_clientAuth_intermediate", |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
.expected_client_error = S2N_ERR_CERT_INTENT_INVALID, |
| 236 |
.expected_server_error = S2N_ERR_OK, |
| 237 |
}, |
| 238 |
{ |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
.cert_chain_dir = "../pems/intent/cert_chains/eku_serverAuth_leaf", |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
.expected_client_error = S2N_ERR_OK, |
| 247 |
.expected_server_error = S2N_ERR_CERT_INTENT_INVALID, |
| 248 |
}, |
| 249 |
{ |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
.cert_chain_dir = "../pems/intent/cert_chains/eku_serverAuth_intermediate", |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
.expected_client_error = S2N_ERR_OK, |
| 258 |
.expected_server_error = S2N_ERR_CERT_INTENT_INVALID, |
| 259 |
}, |
| 260 |
{ |
| 261 |
|
| 262 |
.cert_chain_dir = "../pems/intent/cert_chains/eku_codeSigning_leaf", |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
.expected_client_error = S2N_ERR_CERT_INTENT_INVALID, |
| 267 |
.expected_server_error = S2N_ERR_CERT_INTENT_INVALID, |
| 268 |
}, |
| 269 |
{ |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
.cert_chain_dir = "../pems/intent/cert_chains/eku_codeSigning_intermediate", |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
.expected_client_error = S2N_ERR_CERT_INTENT_INVALID, |
| 278 |
.expected_server_error = S2N_ERR_CERT_INTENT_INVALID, |
| 279 |
}, |
| 280 |
{ |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
.cert_chain_dir = "../pems/intent/cert_chains/eku_codeSigning_intermediate_long", |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
.expected_client_error = S2N_ERR_CERT_INTENT_INVALID, |
| 289 |
.expected_server_error = S2N_ERR_CERT_INTENT_INVALID, |
| 290 |
}, |
| 291 |
{ |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
.cert_chain_dir = "../pems/intent/cert_chains/ku_crl_sign_leaf_non_critical", |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
.expected_client_error = S2N_ERR_CERT_INTENT_INVALID, |
| 301 |
.expected_server_error = S2N_ERR_CERT_INTENT_INVALID, |
| 302 |
}, |
| 303 |
{ |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
.cert_chain_dir = "../pems/intent/cert_chains/eku_code_signing_intermediate_non_critical", |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
.expected_client_error = S2N_ERR_CERT_INTENT_INVALID, |
| 313 |
.expected_server_error = S2N_ERR_CERT_INTENT_INVALID, |
| 314 |
}, |
| 315 |
}; |
| 316 |
|
| 317 |
for (size_t test_idx = 0; test_idx < s2n_array_len(test_cases); test_idx++) { |
| 318 |
char cert_chain_path[S2N_MAX_TEST_PEM_PATH_LENGTH] = { 0 }; |
| 319 |
char leaf_key_path[S2N_MAX_TEST_PEM_PATH_LENGTH] = { 0 }; |
| 320 |
char root_cert_path[S2N_MAX_TEST_PEM_PATH_LENGTH] = { 0 }; |
| 321 |
EXPECT_OK(s2n_test_pem_paths_from_intent_dir(test_cases[test_idx].cert_chain_dir, cert_chain_path, |
| 322 |
leaf_key_path, root_cert_path)); |
| 323 |
|
| 324 |
|
| 325 |
for (size_t disable_intent_verification = 0; disable_intent_verification <= 1; disable_intent_verification++) { |
| 326 |
DEFER_CLEANUP(struct s2n_cert_chain_and_key *chain_and_key = NULL, s2n_cert_chain_and_key_ptr_free); |
| 327 |
EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&chain_and_key, |
| 328 |
cert_chain_path, leaf_key_path)); |
| 329 |
|
| 330 |
DEFER_CLEANUP(struct s2n_config *config = s2n_config_new_minimal(), s2n_config_ptr_free); |
| 331 |
EXPECT_SUCCESS(s2n_config_set_verification_ca_location(config, root_cert_path, NULL)); |
| 332 |
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, chain_and_key)); |
| 333 |
|
| 334 |
DEFER_CLEANUP(struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER), |
| 335 |
s2n_connection_ptr_free); |
| 336 |
EXPECT_NOT_NULL(server_conn); |
| 337 |
EXPECT_SUCCESS(s2n_connection_set_config(server_conn, config)); |
| 338 |
|
| 339 |
DEFER_CLEANUP(struct s2n_connection *client_conn = s2n_connection_new(S2N_CLIENT), |
| 340 |
s2n_connection_ptr_free); |
| 341 |
EXPECT_NOT_NULL(client_conn); |
| 342 |
EXPECT_SUCCESS(s2n_connection_set_config(client_conn, config)); |
| 343 |
EXPECT_SUCCESS(s2n_set_server_name(client_conn, "localhost")); |
| 344 |
EXPECT_SUCCESS(s2n_connection_set_blinding(client_conn, S2N_SELF_SERVICE_BLINDING)); |
| 345 |
|
| 346 |
if (disable_intent_verification) { |
| 347 |
EXPECT_SUCCESS(s2n_config_disable_x509_intent_verification(config)); |
| 348 |
} |
| 349 |
|
| 350 |
DEFER_CLEANUP(struct s2n_test_io_pair io_pair = { 0 }, s2n_io_pair_close); |
| 351 |
EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair)); |
| 352 |
EXPECT_SUCCESS(s2n_connection_set_io_pair(client_conn, &io_pair)); |
| 353 |
EXPECT_SUCCESS(s2n_connection_set_io_pair(server_conn, &io_pair)); |
| 354 |
|
| 355 |
int ret = s2n_negotiate_test_server_and_client(server_conn, client_conn); |
| 356 |
|
| 357 |
s2n_error expected_error = test_cases[test_idx].expected_client_error; |
| 358 |
if (disable_intent_verification) { |
| 359 |
EXPECT_SUCCESS(ret); |
| 360 |
} else { |
| 361 |
if (expected_error == S2N_ERR_OK) { |
| 362 |
EXPECT_SUCCESS(ret); |
| 363 |
} else { |
| 364 |
EXPECT_FAILURE_WITH_ERRNO(ret, expected_error); |
| 365 |
} |
| 366 |
} |
| 367 |
} |
| 368 |
|
| 369 |
|
| 370 |
for (size_t disable_intent_verification = 0; disable_intent_verification <= 1; disable_intent_verification++) { |
| 371 |
DEFER_CLEANUP(struct s2n_cert_chain_and_key *server_chain_and_key = NULL, |
| 372 |
s2n_cert_chain_and_key_ptr_free); |
| 373 |
EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&server_chain_and_key, |
| 374 |
S2N_DEFAULT_TEST_CERT_CHAIN, S2N_DEFAULT_TEST_PRIVATE_KEY)); |
| 375 |
|
| 376 |
DEFER_CLEANUP(struct s2n_cert_chain_and_key *client_chain_and_key = NULL, |
| 377 |
s2n_cert_chain_and_key_ptr_free); |
| 378 |
EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&client_chain_and_key, |
| 379 |
cert_chain_path, leaf_key_path)); |
| 380 |
|
| 381 |
DEFER_CLEANUP(struct s2n_config *server_config = s2n_config_new(), s2n_config_ptr_free); |
| 382 |
EXPECT_NOT_NULL(server_config); |
| 383 |
EXPECT_SUCCESS(s2n_config_set_verification_ca_location(server_config, root_cert_path, NULL)); |
| 384 |
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, server_chain_and_key)); |
| 385 |
EXPECT_SUCCESS(s2n_config_set_client_auth_type(server_config, S2N_CERT_AUTH_REQUIRED)); |
| 386 |
|
| 387 |
if (disable_intent_verification) { |
| 388 |
EXPECT_SUCCESS(s2n_config_disable_x509_intent_verification(server_config)); |
| 389 |
} |
| 390 |
|
| 391 |
DEFER_CLEANUP(struct s2n_config *client_config = s2n_config_new(), s2n_config_ptr_free); |
| 392 |
EXPECT_NOT_NULL(client_config); |
| 393 |
EXPECT_SUCCESS(s2n_config_set_verification_ca_location(client_config, |
| 394 |
S2N_DEFAULT_TEST_CERT_CHAIN, NULL)); |
| 395 |
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(client_config, client_chain_and_key)); |
| 396 |
EXPECT_SUCCESS(s2n_config_set_client_auth_type(client_config, S2N_CERT_AUTH_OPTIONAL)); |
| 397 |
|
| 398 |
DEFER_CLEANUP(struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER), |
| 399 |
s2n_connection_ptr_free); |
| 400 |
EXPECT_NOT_NULL(server_conn); |
| 401 |
EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config)); |
| 402 |
EXPECT_SUCCESS(s2n_connection_set_blinding(server_conn, S2N_SELF_SERVICE_BLINDING)); |
| 403 |
|
| 404 |
DEFER_CLEANUP(struct s2n_connection *client_conn = s2n_connection_new(S2N_CLIENT), |
| 405 |
s2n_connection_ptr_free); |
| 406 |
EXPECT_NOT_NULL(client_conn); |
| 407 |
EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config)); |
| 408 |
EXPECT_SUCCESS(s2n_set_server_name(client_conn, "localhost")); |
| 409 |
|
| 410 |
DEFER_CLEANUP(struct s2n_test_io_pair io_pair = { 0 }, s2n_io_pair_close); |
| 411 |
EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair)); |
| 412 |
EXPECT_SUCCESS(s2n_connection_set_io_pair(client_conn, &io_pair)); |
| 413 |
EXPECT_SUCCESS(s2n_connection_set_io_pair(server_conn, &io_pair)); |
| 414 |
|
| 415 |
int ret = s2n_negotiate_test_server_and_client(server_conn, client_conn); |
| 416 |
|
| 417 |
s2n_error expected_error = test_cases[test_idx].expected_server_error; |
| 418 |
if (disable_intent_verification) { |
| 419 |
EXPECT_SUCCESS(ret); |
| 420 |
} else { |
| 421 |
if (expected_error == S2N_ERR_OK) { |
| 422 |
EXPECT_SUCCESS(ret); |
| 423 |
} else { |
| 424 |
EXPECT_FAILURE_WITH_ERRNO(ret, expected_error); |
| 425 |
} |
| 426 |
} |
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
uint8_t *client_cert_chain = NULL; |
| 433 |
uint32_t client_cert_chain_len = 0; |
| 434 |
EXPECT_SUCCESS(s2n_connection_get_client_cert_chain(server_conn, &client_cert_chain, |
| 435 |
&client_cert_chain_len)); |
| 436 |
EXPECT_TRUE(client_cert_chain_len > 0); |
| 437 |
} |
| 438 |
} |
| 439 |
} |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
{ |
| 448 |
struct { |
| 449 |
const char *cert_chain_dir; |
| 450 |
} test_cases[] = { |
| 451 |
{ |
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
.cert_chain_dir = "../pems/intent/cert_chains/bc_non_ca_intermediate", |
| 458 |
}, |
| 459 |
{ |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
.cert_chain_dir = "../pems/intent/cert_chains/ku_digital_signature_intermediate", |
| 467 |
}, |
| 468 |
{ |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
.cert_chain_dir = "../pems/intent/cert_chains/ku_digital_signature_intermediate_long", |
| 476 |
}, |
| 477 |
}; |
| 478 |
|
| 479 |
for (size_t test_idx = 0; test_idx < s2n_array_len(test_cases); test_idx++) { |
| 480 |
char cert_chain_path[S2N_MAX_TEST_PEM_PATH_LENGTH] = { 0 }; |
| 481 |
char leaf_key_path[S2N_MAX_TEST_PEM_PATH_LENGTH] = { 0 }; |
| 482 |
char root_cert_path[S2N_MAX_TEST_PEM_PATH_LENGTH] = { 0 }; |
| 483 |
EXPECT_OK(s2n_test_pem_paths_from_intent_dir(test_cases[test_idx].cert_chain_dir, cert_chain_path, |
| 484 |
leaf_key_path, root_cert_path)); |
| 485 |
|
| 486 |
DEFER_CLEANUP(struct s2n_cert_chain_and_key *chain_and_key = NULL, s2n_cert_chain_and_key_ptr_free); |
| 487 |
EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&chain_and_key, cert_chain_path, leaf_key_path)); |
| 488 |
|
| 489 |
DEFER_CLEANUP(struct s2n_config *config = s2n_config_new_minimal(), s2n_config_ptr_free); |
| 490 |
EXPECT_SUCCESS(s2n_config_set_verification_ca_location(config, root_cert_path, NULL)); |
| 491 |
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, chain_and_key)); |
| 492 |
|
| 493 |
DEFER_CLEANUP(struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER), |
| 494 |
s2n_connection_ptr_free); |
| 495 |
EXPECT_NOT_NULL(server_conn); |
| 496 |
EXPECT_SUCCESS(s2n_connection_set_config(server_conn, config)); |
| 497 |
|
| 498 |
DEFER_CLEANUP(struct s2n_connection *client_conn = s2n_connection_new(S2N_CLIENT), |
| 499 |
s2n_connection_ptr_free); |
| 500 |
EXPECT_NOT_NULL(client_conn); |
| 501 |
EXPECT_SUCCESS(s2n_connection_set_config(client_conn, config)); |
| 502 |
EXPECT_SUCCESS(s2n_set_server_name(client_conn, "localhost")); |
| 503 |
EXPECT_SUCCESS(s2n_connection_set_blinding(client_conn, S2N_SELF_SERVICE_BLINDING)); |
| 504 |
|
| 505 |
DEFER_CLEANUP(struct s2n_test_io_pair io_pair = { 0 }, s2n_io_pair_close); |
| 506 |
EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair)); |
| 507 |
EXPECT_SUCCESS(s2n_connection_set_io_pair(client_conn, &io_pair)); |
| 508 |
EXPECT_SUCCESS(s2n_connection_set_io_pair(server_conn, &io_pair)); |
| 509 |
|
| 510 |
EXPECT_FAILURE_WITH_ERRNO(s2n_negotiate_test_server_and_client(server_conn, client_conn), |
| 511 |
S2N_ERR_CERT_UNTRUSTED); |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
{ |
| 522 |
struct { |
| 523 |
const char *cert_chain_path; |
| 524 |
const char *leaf_key_path; |
| 525 |
const char *trust_anchor_path; |
| 526 |
s2n_error expected_error; |
| 527 |
} test_cases[] = { |
| 528 |
{ |
| 529 |
|
| 530 |
.cert_chain_path = "../pems/intent/cert_chains/eku_codeSigning_leaf/cert-chain.pem", |
| 531 |
.leaf_key_path = "../pems/intent/cert_chains/eku_codeSigning_leaf/leaf-key.pem", |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
.trust_anchor_path = "../pems/intent/cert_chains/eku_codeSigning_leaf/root-cert.pem", |
| 536 |
.expected_error = S2N_ERR_CERT_INTENT_INVALID, |
| 537 |
}, |
| 538 |
{ |
| 539 |
|
| 540 |
.cert_chain_path = "../pems/intent/cert_chains/eku_codeSigning_leaf/cert-chain.pem", |
| 541 |
.leaf_key_path = "../pems/intent/cert_chains/eku_codeSigning_leaf/leaf-key.pem", |
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
.trust_anchor_path = "../pems/intent/cert_chains/eku_codeSigning_leaf/leaf-cert.pem", |
| 546 |
.expected_error = S2N_ERR_OK, |
| 547 |
}, |
| 548 |
{ |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
.cert_chain_path = "../pems/intent/cert_chains/eku_codeSigning_intermediate/cert-chain.pem", |
| 553 |
.leaf_key_path = "../pems/intent/cert_chains/eku_codeSigning_intermediate/leaf-key.pem", |
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
.trust_anchor_path = "../pems/intent/cert_chains/eku_codeSigning_intermediate/root-cert.pem", |
| 558 |
.expected_error = S2N_ERR_CERT_INTENT_INVALID, |
| 559 |
}, |
| 560 |
{ |
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
.cert_chain_path = "../pems/intent/cert_chains/eku_codeSigning_intermediate/cert-chain.pem", |
| 565 |
.leaf_key_path = "../pems/intent/cert_chains/eku_codeSigning_intermediate/leaf-key.pem", |
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
.trust_anchor_path = "../pems/intent/cert_chains/eku_codeSigning_intermediate/intermediate_1-cert.pem", |
| 570 |
.expected_error = S2N_ERR_OK, |
| 571 |
}, |
| 572 |
{ |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
.cert_chain_path = "../pems/intent/cert_chains/eku_codeSigning_intermediate/cert-chain.pem", |
| 577 |
.leaf_key_path = "../pems/intent/cert_chains/eku_codeSigning_intermediate/leaf-key.pem", |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
.trust_anchor_path = "../pems/intent/cert_chains/eku_codeSigning_intermediate/leaf-cert.pem", |
| 583 |
.expected_error = S2N_ERR_OK, |
| 584 |
}, |
| 585 |
{ |
| 586 |
|
| 587 |
.cert_chain_path = "../pems/intent/cert_chains/eku_email_protection_root/cert-chain.pem", |
| 588 |
.leaf_key_path = "../pems/intent/cert_chains/eku_email_protection_root/leaf-key.pem", |
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
.trust_anchor_path = "../pems/intent/cert_chains/eku_email_protection_root/root-cert.pem", |
| 593 |
.expected_error = S2N_ERR_OK, |
| 594 |
}, |
| 595 |
}; |
| 596 |
|
| 597 |
for (size_t test_idx = 0; test_idx < s2n_array_len(test_cases); test_idx++) { |
| 598 |
DEFER_CLEANUP(struct s2n_cert_chain_and_key *chain_and_key = NULL, s2n_cert_chain_and_key_ptr_free); |
| 599 |
EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&chain_and_key, |
| 600 |
test_cases[test_idx].cert_chain_path, test_cases[test_idx].leaf_key_path)); |
| 601 |
|
| 602 |
DEFER_CLEANUP(struct s2n_config *config = s2n_config_new_minimal(), s2n_config_ptr_free); |
| 603 |
EXPECT_SUCCESS(s2n_config_set_verification_ca_location(config, |
| 604 |
test_cases[test_idx].trust_anchor_path, NULL)); |
| 605 |
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, chain_and_key)); |
| 606 |
|
| 607 |
DEFER_CLEANUP(struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER), |
| 608 |
s2n_connection_ptr_free); |
| 609 |
EXPECT_NOT_NULL(server_conn); |
| 610 |
EXPECT_SUCCESS(s2n_connection_set_config(server_conn, config)); |
| 611 |
|
| 612 |
DEFER_CLEANUP(struct s2n_connection *client_conn = s2n_connection_new(S2N_CLIENT), |
| 613 |
s2n_connection_ptr_free); |
| 614 |
EXPECT_NOT_NULL(client_conn); |
| 615 |
EXPECT_SUCCESS(s2n_connection_set_config(client_conn, config)); |
| 616 |
EXPECT_SUCCESS(s2n_connection_set_blinding(client_conn, S2N_SELF_SERVICE_BLINDING)); |
| 617 |
EXPECT_SUCCESS(s2n_set_server_name(client_conn, "localhost")); |
| 618 |
|
| 619 |
DEFER_CLEANUP(struct s2n_test_io_pair io_pair = { 0 }, s2n_io_pair_close); |
| 620 |
EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair)); |
| 621 |
EXPECT_SUCCESS(s2n_connection_set_io_pair(client_conn, &io_pair)); |
| 622 |
EXPECT_SUCCESS(s2n_connection_set_io_pair(server_conn, &io_pair)); |
| 623 |
|
| 624 |
int ret = s2n_negotiate_test_server_and_client(server_conn, client_conn); |
| 625 |
|
| 626 |
s2n_error expected_error = test_cases[test_idx].expected_error; |
| 627 |
if (expected_error == S2N_ERR_OK) { |
| 628 |
EXPECT_SUCCESS(ret); |
| 629 |
} else { |
| 630 |
EXPECT_FAILURE_WITH_ERRNO(ret, expected_error); |
| 631 |
} |
| 632 |
} |
| 633 |
} |
| 634 |
|
| 635 |
END_TEST(); |
| 636 |
} |