| 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 |
int main(int argc, char **argv) |
| 20 |
{ |
| 21 |
BEGIN_TEST(); |
| 22 |
|
| 23 |
char dhparams_pem[S2N_MAX_TEST_PEM_SIZE] = { 0 }; |
| 24 |
EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_DHPARAMS, dhparams_pem, S2N_MAX_TEST_PEM_SIZE)); |
| 25 |
|
| 26 |
DEFER_CLEANUP(struct s2n_cert_chain_and_key *rsa_chain_and_key = NULL, s2n_cert_chain_and_key_ptr_free); |
| 27 |
EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&rsa_chain_and_key, |
| 28 |
S2N_DEFAULT_TEST_CERT_CHAIN, S2N_DEFAULT_TEST_PRIVATE_KEY)); |
| 29 |
|
| 30 |
DEFER_CLEANUP(struct s2n_cert_chain_and_key *ecdsa_chain_and_key = NULL, s2n_cert_chain_and_key_ptr_free); |
| 31 |
EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&ecdsa_chain_and_key, |
| 32 |
S2N_DEFAULT_ECDSA_TEST_CERT_CHAIN, S2N_DEFAULT_ECDSA_TEST_PRIVATE_KEY)); |
| 33 |
|
| 34 |
|
| 35 |
{ |
| 36 |
DEFER_CLEANUP(struct s2n_config *client_config = s2n_config_new_minimal(), s2n_config_ptr_free); |
| 37 |
EXPECT_NOT_NULL(client_config); |
| 38 |
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(client_config)); |
| 39 |
|
| 40 |
DEFER_CLEANUP(struct s2n_config *server_config = s2n_config_new_minimal(), s2n_config_ptr_free); |
| 41 |
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, rsa_chain_and_key)); |
| 42 |
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, ecdsa_chain_and_key)); |
| 43 |
EXPECT_SUCCESS(s2n_config_add_dhparams(server_config, dhparams_pem)); |
| 44 |
|
| 45 |
|
| 46 |
size_t record_algs_tested = 0; |
| 47 |
for (size_t cipher_suite_idx = 0; cipher_suite_idx < cipher_preferences_test_all.count; cipher_suite_idx++) { |
| 48 |
uint8_t record_algs = cipher_preferences_test_all.suites[cipher_suite_idx]->num_record_algs; |
| 49 |
for (size_t record_alg_idx = 0; record_alg_idx < record_algs; record_alg_idx++) { |
| 50 |
struct s2n_cipher_suite test_cipher_suite = *cipher_preferences_test_all.suites[cipher_suite_idx]; |
| 51 |
test_cipher_suite.record_alg = test_cipher_suite.all_record_algs[record_alg_idx]; |
| 52 |
|
| 53 |
|
| 54 |
uint8_t cipher = test_cipher_suite.record_alg->cipher->type; |
| 55 |
if (cipher != S2N_CBC && cipher != S2N_COMPOSITE) { |
| 56 |
continue; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
if (!test_cipher_suite.record_alg->cipher->is_available()) { |
| 61 |
continue; |
| 62 |
} |
| 63 |
|
| 64 |
struct s2n_cipher_suite *test_cipher_suite_ptr = &test_cipher_suite; |
| 65 |
struct s2n_cipher_preferences test_cipher_preferences = { |
| 66 |
.count = 1, |
| 67 |
.suites = &test_cipher_suite_ptr, |
| 68 |
}; |
| 69 |
|
| 70 |
struct s2n_security_policy test_security_policy = security_policy_test_all; |
| 71 |
test_security_policy.cipher_preferences = &test_cipher_preferences; |
| 72 |
|
| 73 |
DEFER_CLEANUP(struct s2n_connection *client = s2n_connection_new(S2N_CLIENT), |
| 74 |
s2n_connection_ptr_free); |
| 75 |
EXPECT_NOT_NULL(client); |
| 76 |
EXPECT_SUCCESS(s2n_connection_set_config(client, client_config)); |
| 77 |
client->security_policy_override = &test_security_policy; |
| 78 |
|
| 79 |
DEFER_CLEANUP(struct s2n_connection *server = s2n_connection_new(S2N_SERVER), |
| 80 |
s2n_connection_ptr_free); |
| 81 |
EXPECT_NOT_NULL(server); |
| 82 |
EXPECT_SUCCESS(s2n_connection_set_config(server, server_config)); |
| 83 |
server->security_policy_override = &test_security_policy; |
| 84 |
|
| 85 |
DEFER_CLEANUP(struct s2n_test_io_pair io_pair = { 0 }, s2n_io_pair_close); |
| 86 |
EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair)); |
| 87 |
EXPECT_SUCCESS(s2n_connection_set_io_pair(client, &io_pair)); |
| 88 |
EXPECT_SUCCESS(s2n_connection_set_io_pair(server, &io_pair)); |
| 89 |
|
| 90 |
EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server, client)); |
| 91 |
|
| 92 |
uint8_t negotiated_cipher_suite[S2N_TLS_CIPHER_SUITE_LEN] = { 0 }; |
| 93 |
EXPECT_SUCCESS(s2n_connection_get_cipher_iana_value(server, negotiated_cipher_suite, |
| 94 |
negotiated_cipher_suite + 1)); |
| 95 |
EXPECT_BYTEARRAY_EQUAL(negotiated_cipher_suite, test_cipher_suite.iana_value, |
| 96 |
S2N_TLS_CIPHER_SUITE_LEN); |
| 97 |
|
| 98 |
EXPECT_OK(s2n_send_and_recv_test(client, server)); |
| 99 |
EXPECT_OK(s2n_send_and_recv_test(server, client)); |
| 100 |
|
| 101 |
record_algs_tested += 1; |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
EXPECT_TRUE(record_algs_tested > 0); |
| 106 |
} |
| 107 |
|
| 108 |
END_TEST(); |
| 109 |
} |