Skip to content

Commit

Permalink
tests: pin tests to a numbered TLS1.2 policy (#4905)
Browse files Browse the repository at this point in the history
  • Loading branch information
toidiu authored Nov 19, 2024
1 parent a540887 commit e826931
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 22 deletions.
4 changes: 2 additions & 2 deletions tests/unit/s2n_alerts_protocol_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,13 @@ int main(int argc, char **argv)
s2n_connection_ptr_free);
EXPECT_SUCCESS(s2n_connection_set_blinding(server, S2N_SELF_SERVICE_BLINDING));
EXPECT_SUCCESS(s2n_connection_set_config(server, config));
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(server, "default"));
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(server, "20240501"));

DEFER_CLEANUP(struct s2n_connection *client = s2n_connection_new(S2N_CLIENT),
s2n_connection_ptr_free);
EXPECT_SUCCESS(s2n_connection_set_blinding(client, S2N_SELF_SERVICE_BLINDING));
EXPECT_SUCCESS(s2n_connection_set_config(client, config));
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(client, "default"));
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(client, "20240501"));

DEFER_CLEANUP(struct s2n_test_io_stuffer_pair io_pair = { 0 }, s2n_io_stuffer_pair_free);
EXPECT_OK(s2n_io_stuffer_pair_init(&io_pair));
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/s2n_client_hello_request_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ int main(int argc, char **argv)

DEFER_CLEANUP(struct s2n_config *config = s2n_config_new(), s2n_config_ptr_free);
EXPECT_NOT_NULL(config);
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "default"));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "20240501"));
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(config));
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, chain_and_key));

DEFER_CLEANUP(struct s2n_config *config_with_reneg_cb = s2n_config_new(), s2n_config_ptr_free);
EXPECT_NOT_NULL(config_with_reneg_cb);
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config_with_reneg_cb, "default"));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config_with_reneg_cb, "20240501"));
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(config_with_reneg_cb));
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config_with_reneg_cb, chain_and_key));
EXPECT_SUCCESS(s2n_config_set_renegotiate_request_cb(config_with_reneg_cb, s2n_test_reneg_req_cb, NULL));
Expand Down Expand Up @@ -167,7 +167,7 @@ int main(int argc, char **argv)
{
DEFER_CLEANUP(struct s2n_config *config_with_warns = s2n_config_new(), s2n_config_ptr_free);
EXPECT_NOT_NULL(config_with_warns);
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config_with_warns, "default"));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config_with_warns, "20240501"));
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(config_with_warns));
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config_with_warns, chain_and_key));
EXPECT_SUCCESS(s2n_config_set_alert_behavior(config_with_warns, S2N_ALERT_IGNORE_WARNINGS));
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/s2n_client_hello_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ int main(int argc, char **argv)
struct s2n_connection *conn = NULL;
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
EXPECT_SUCCESS(s2n_connection_set_config(conn, config));
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(conn, "default"));
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(conn, "20240501"));

const struct s2n_security_policy *security_policy = NULL;
POSIX_GUARD(s2n_connection_get_security_policy(conn, &security_policy));
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/s2n_connection_serialize_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ int main(int argc, char **argv)
S2N_DEFAULT_TEST_CERT_CHAIN, S2N_DEFAULT_TEST_PRIVATE_KEY));

DEFER_CLEANUP(struct s2n_config *tls12_config = s2n_config_new(), s2n_config_ptr_free);
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(tls12_config, "20240501"));
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(tls12_config, chain_and_key));
EXPECT_SUCCESS(s2n_config_disable_x509_verification(tls12_config));
EXPECT_SUCCESS(s2n_config_set_serialization_version(tls12_config, S2N_SERIALIZED_CONN_V1));
Expand Down Expand Up @@ -594,6 +595,7 @@ int main(int argc, char **argv)
/* Self-talk: Test interaction between TLS1.2 session resumption and serialization */
{
DEFER_CLEANUP(struct s2n_config *resumption_config = s2n_config_new(), s2n_config_ptr_free);
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(resumption_config, "20240501"));
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(resumption_config, chain_and_key));
EXPECT_SUCCESS(s2n_config_disable_x509_verification(resumption_config));
EXPECT_SUCCESS(s2n_config_set_serialization_version(resumption_config, S2N_SERIALIZED_CONN_V1));
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/s2n_extended_master_secret_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ int main(int argc, char **argv)
EXPECT_NOT_NULL(config);

/* TLS1.2 cipher preferences */
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "default"));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "20240501"));
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(config));
struct s2n_cert_chain_and_key *chain_and_key = NULL;
EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&chain_and_key,
Expand Down Expand Up @@ -208,7 +208,7 @@ int main(int argc, char **argv)
struct s2n_config *config = s2n_config_new();
EXPECT_NOT_NULL(config);

EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "default"));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "20240501"));
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(config));
struct s2n_cert_chain_and_key *chain_and_key = NULL;
EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&chain_and_key,
Expand Down Expand Up @@ -253,7 +253,7 @@ int main(int argc, char **argv)
struct s2n_config *config = s2n_config_new();
EXPECT_NOT_NULL(config);

EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "default"));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "20240501"));
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(config));
struct s2n_cert_chain_and_key *chain_and_key = NULL;
EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&chain_and_key,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/s2n_renegotiate_io_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int main(int argc, char *argv[])
EXPECT_NOT_NULL(config);
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(config));
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, chain_and_key));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "default"));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "20240501"));

uint8_t app_data[] = "test application data";

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/s2n_renegotiate_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ int main(int argc, char *argv[])
EXPECT_NOT_NULL(config);
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(config));
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, chain_and_key));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "default"));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "20240501"));

uint8_t app_data[] = "smaller hello world";
uint8_t large_app_data[S2N_TLS_MAXIMUM_FRAGMENT_LENGTH] = "hello world and a lot of zeroes";
Expand Down Expand Up @@ -275,15 +275,15 @@ int main(int argc, char *argv[])
EXPECT_NOT_NULL(small_frag_config);
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(small_frag_config));
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(small_frag_config, chain_and_key));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(small_frag_config, "default"));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(small_frag_config, "20240501"));
EXPECT_SUCCESS(s2n_config_accept_max_fragment_length(small_frag_config));
EXPECT_SUCCESS(s2n_config_send_max_fragment_length(small_frag_config, S2N_TLS_MAX_FRAG_LEN_512));

DEFER_CLEANUP(struct s2n_config *larger_frag_config = s2n_config_new(), s2n_config_ptr_free);
EXPECT_NOT_NULL(larger_frag_config);
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(larger_frag_config));
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(larger_frag_config, chain_and_key));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(larger_frag_config, "default"));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(larger_frag_config, "20240501"));
EXPECT_SUCCESS(s2n_config_accept_max_fragment_length(larger_frag_config));
EXPECT_SUCCESS(s2n_config_send_max_fragment_length(larger_frag_config, S2N_TLS_MAX_FRAG_LEN_4096));

Expand Down
3 changes: 2 additions & 1 deletion tests/unit/s2n_self_talk_alerts_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ int mock_client(struct s2n_test_io_pair *io_pair, s2n_alert_behavior alert_behav

conn = s2n_connection_new(S2N_CLIENT);
config = s2n_config_new();
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "20240501"));
s2n_config_disable_x509_verification(config);
s2n_config_set_alert_behavior(config, alert_behavior);
s2n_connection_set_config(conn, config);
Expand Down Expand Up @@ -177,7 +178,7 @@ int main(int argc, char **argv)
DEFER_CLEANUP(struct s2n_config *config = s2n_config_new(),
s2n_config_ptr_free);
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, chain_and_key));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "default"));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "20240501"));

/* Set up the callback to send an alert after receiving ClientHello */
struct alert_ctx warning_alert = { .write_fd = io_pair.server, .invoked = 0, .count = 2, .level = TLS_ALERT_LEVEL_WARNING, .code = TLS_ALERT_UNRECOGNIZED_NAME };
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/s2n_self_talk_broken_pipe_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ int main(int argc, char **argv)
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));

EXPECT_NOT_NULL(config = s2n_config_new());
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "default"));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "20240501"));
for (int cert = 0; cert < SUPPORTED_CERTIFICATE_FORMATS; cert++) {
EXPECT_SUCCESS(s2n_read_test_pem(certificate_paths[cert], cert_chain_pem, S2N_MAX_TEST_PEM_SIZE));
EXPECT_SUCCESS(s2n_read_test_pem(private_key_paths[cert], private_key_pem, S2N_MAX_TEST_PEM_SIZE));
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/s2n_self_talk_key_log_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ int main(int argc, char **argv)
S2N_DEFAULT_TEST_CERT_CHAIN, S2N_DEFAULT_TEST_PRIVATE_KEY));
struct s2n_config *client_config = NULL;
EXPECT_NOT_NULL(client_config = s2n_config_new());
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(client_config, "default"));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(client_config, "20240501"));
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(client_config));
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(client_config, chain_and_key));
DEFER_CLEANUP(struct s2n_stuffer client_key_log, s2n_stuffer_free);
Expand All @@ -87,7 +87,7 @@ int main(int argc, char **argv)

struct s2n_config *server_config = NULL;
EXPECT_NOT_NULL(server_config = s2n_config_new());
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(server_config, "default"));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(server_config, "20240501"));
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(server_config));
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, chain_and_key));
DEFER_CLEANUP(struct s2n_stuffer server_key_log, s2n_stuffer_free);
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/s2n_self_talk_npn_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int main(int argc, char **argv)
DEFER_CLEANUP(struct s2n_config *config = s2n_config_new(), s2n_config_ptr_free);
EXPECT_NOT_NULL(config);
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(config));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "default"));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "20240501"));
struct s2n_cert_chain_and_key *chain_and_key = NULL;
EXPECT_SUCCESS(s2n_test_cert_chain_and_key_new(&chain_and_key, S2N_DEFAULT_TEST_CERT_CHAIN, S2N_DEFAULT_TEST_PRIVATE_KEY));
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, chain_and_key));
Expand All @@ -61,7 +61,7 @@ int main(int argc, char **argv)
DEFER_CLEANUP(struct s2n_config *npn_config = s2n_config_new(), s2n_config_ptr_free);
EXPECT_NOT_NULL(npn_config);
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(npn_config));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(npn_config, "default"));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(npn_config, "20240501"));
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(npn_config, chain_and_key));
EXPECT_SUCCESS(s2n_config_set_protocol_preferences(npn_config, protocols, protocols_count));
EXPECT_SUCCESS(s2n_config_set_client_hello_cb(npn_config, s2n_wipe_alpn_ext, NULL));
Expand Down Expand Up @@ -135,7 +135,7 @@ int main(int argc, char **argv)
DEFER_CLEANUP(struct s2n_config *different_config = s2n_config_new(), s2n_config_ptr_free);
EXPECT_NOT_NULL(different_config);
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(different_config));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(different_config, "default"));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(different_config, "20240501"));
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(different_config, chain_and_key));
EXPECT_SUCCESS(s2n_config_set_protocol_preferences(different_config, server_protocols, server_protocols_count));
EXPECT_SUCCESS(s2n_config_set_client_hello_cb(different_config, s2n_wipe_alpn_ext, NULL));
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/s2n_self_talk_session_id_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ void mock_client(struct s2n_test_io_pair *io_pair)
/* Initial handshake */
conn = s2n_connection_new(S2N_CLIENT);
config = s2n_config_new();
s2n_config_set_cipher_preferences(config, "20240501");
s2n_config_disable_x509_verification(config);
s2n_connection_set_config(conn, config);

Expand Down Expand Up @@ -338,7 +339,7 @@ int main(int argc, char **argv)
initialize_cache();
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));
EXPECT_NOT_NULL(config = s2n_config_new());
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "default"));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "20240501"));

EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_CERT_CHAIN, cert_chain_pem, S2N_MAX_TEST_PEM_SIZE));
EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_PRIVATE_KEY, private_key_pem, S2N_MAX_TEST_PEM_SIZE));
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/s2n_session_ticket_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ int main(int argc, char **argv)
EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
EXPECT_SUCCESS(s2n_connection_set_blinding(server_conn, S2N_SELF_SERVICE_BLINDING));
EXPECT_SUCCESS(s2n_connection_set_config(server_conn, config));
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(server_conn, "default"));
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(server_conn, "20240501"));

EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
Expand Down Expand Up @@ -1446,13 +1446,15 @@ int main(int argc, char **argv)
EXPECT_NOT_NULL(client_configuration);
EXPECT_SUCCESS(s2n_config_set_session_tickets_onoff(client_configuration, 1));
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(client_configuration));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(client_configuration, "20240501"));

DEFER_CLEANUP(struct s2n_config *server_configuration = s2n_config_new(),
s2n_config_ptr_free);
EXPECT_NOT_NULL(server_configuration);
EXPECT_SUCCESS(s2n_config_set_session_tickets_onoff(server_configuration, 1));
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_configuration,
chain_and_key));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(server_configuration, "20240501"));

EXPECT_SUCCESS(s2n_config_add_ticket_crypto_key(server_configuration, ticket_key_name1,
s2n_array_len(ticket_key_name1), ticket_key1, s2n_array_len(ticket_key1), 0));
Expand Down

0 comments on commit e826931

Please sign in to comment.