Skip to content

Commit

Permalink
fix(s2n_session_ticket_test): correct clock mocking (#4602)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmayclin authored Jun 17, 2024
1 parent c8a0444 commit 38cb293
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
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

0 comments on commit 38cb293

Please sign in to comment.