Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(s2n_session_ticket_test): correct clock mocking #4602

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions tests/unit/s2n_session_ticket_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1241,17 +1241,18 @@ int main(int argc, char **argv)
if (s2n_is_tls13_fully_supported()) {
struct s2n_config *config = s2n_config_new();
EXPECT_NOT_NULL(config);

/* Freeze time */
POSIX_GUARD(config->wall_clock(config->sys_clock_ctx, &now));
EXPECT_OK(s2n_config_mock_wall_clock(config, &now));

EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, ecdsa_chain_and_key));
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(config));
EXPECT_SUCCESS(s2n_config_set_session_tickets_onoff(config, 1));
EXPECT_SUCCESS(s2n_config_add_ticket_crypto_key(config, ticket_key_name1, s2n_array_len(ticket_key_name1),
ticket_key1, s2n_array_len(ticket_key1), 0));
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "default_tls13"));

/* Freeze time */
POSIX_GUARD(config->wall_clock(config->sys_clock_ctx, &now));
EXPECT_OK(s2n_config_mock_wall_clock(config, &now));

/* Send one NewSessionTicket */
cb_session_data_len = 0;
EXPECT_SUCCESS(s2n_config_set_session_ticket_cb(config, s2n_test_session_ticket_callback, NULL));
Expand Down
5 changes: 4 additions & 1 deletion tls/s2n_resume.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,10 @@ struct s2n_ticket_key *s2n_get_ticket_encrypt_decrypt_key(struct s2n_config *con
PTR_GUARD_RESULT(s2n_set_get(config->ticket_keys, idx, (void **) &ticket_key));
uint64_t key_intro_time = ticket_key->intro_timestamp;

if (key_intro_time < now
/* A key can be used at its intro time (<=) and it can be used up to (<)
* its expiration time.
*/
if (key_intro_time <= now
&& now < key_intro_time + config->encrypt_decrypt_key_lifetime_in_nanos) {
encrypt_decrypt_keys_index[num_encrypt_decrypt_keys] = idx;
num_encrypt_decrypt_keys++;
Expand Down
Loading