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: allow for clock skew in resumption #4650

Merged
merged 9 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 12 additions & 2 deletions tests/unit/s2n_resume_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1253,13 +1253,23 @@ int main(int argc, char **argv)

/* s2n_validate_ticket_age */
{
/* Ticket issue time is in the future */
/* Ticket issue time is unreasonably far in the future */
{
uint64_t current_time = SECONDS_TO_NANOS(0);
uint64_t issue_time = 10;
uint64_t issue_time = SECONDS_TO_NANOS(ONE_WEEK_IN_SEC + 1);
EXPECT_ERROR_WITH_ERRNO(s2n_validate_ticket_age(current_time, issue_time), S2N_ERR_INVALID_SESSION_TICKET);
};

/* Ticket issue time is in the future
* Distributed deployments with clock skew may see a ticket issue time in
* the future.
*/
{
uint64_t current_time = SECONDS_TO_NANOS(0);
uint64_t issue_time = 10;
EXPECT_OK(s2n_validate_ticket_age(current_time, issue_time));
};

/** Ticket age is longer than a week
*= https://www.rfc-editor.org/rfc/rfc8446#section-4.6.1
*= type=test
Expand Down
23 changes: 19 additions & 4 deletions tls/s2n_resume.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,27 @@ static S2N_RESULT s2n_tls12_client_deserialize_session_state(struct s2n_connecti
return S2N_RESULT_OK;
}

/* `s2n_validate_ticket_age` is a best effort check that the session ticket is
* less than one week old.
*
* Clock skew between hosts or the possibility of a clock jump prevent this from
* being a precise check.
*/
static S2N_RESULT s2n_validate_ticket_age(uint64_t current_time, uint64_t ticket_issue_time)
{
RESULT_ENSURE(current_time >= ticket_issue_time, S2N_ERR_INVALID_SESSION_TICKET);
uint64_t ticket_age_in_nanos = current_time - ticket_issue_time;
uint64_t ticket_age_in_sec = ticket_age_in_nanos / ONE_SEC_IN_NANOS;
RESULT_ENSURE(ticket_age_in_sec <= ONE_WEEK_IN_SEC, S2N_ERR_INVALID_SESSION_TICKET);
/* If the `ticket_issue_time` is in the future, then we are observing clock skew.
* We shouldn't fully reject the ticket, but we assert that the clock skew is
* less than some very generous bound (one week)
*/
if (current_time < ticket_issue_time) {
uint64_t clock_skew_in_nanos = ticket_issue_time - current_time;
uint64_t clock_skew_in_seconds = clock_skew_in_nanos / ONE_SEC_IN_NANOS;
RESULT_ENSURE(clock_skew_in_seconds <= ONE_WEEK_IN_SEC, S2N_ERR_INVALID_SESSION_TICKET);
} else {
uint64_t ticket_age_in_nanos = current_time - ticket_issue_time;
uint64_t ticket_age_in_sec = ticket_age_in_nanos / ONE_SEC_IN_NANOS;
RESULT_ENSURE(ticket_age_in_sec <= ONE_WEEK_IN_SEC, S2N_ERR_INVALID_SESSION_TICKET);
}
return S2N_RESULT_OK;
}

Expand Down
Loading