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

timeless hotfix (#275) #14739

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 7 additions & 4 deletions types/src/keyless/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ impl KeylessSignature {
}

pub fn verify_expiry(&self, current_time_microseconds: u64) -> anyhow::Result<()> {
let block_time = UNIX_EPOCH + Duration::from_micros(current_time_microseconds);
let expiry_time = seconds_from_epoch(self.exp_date_secs);
let block_time = UNIX_EPOCH.checked_add(Duration::from_micros(current_time_microseconds))
.ok_or_else(|| anyhow::anyhow!("Overflowed on UNIX_EPOCH + current_time_microseconds when checking exp_date_secs"))?;
let expiry_time = seconds_from_epoch(self.exp_date_secs)?;

if block_time > expiry_time {
bail!("Keyless signature is expired");
Expand Down Expand Up @@ -428,8 +429,10 @@ fn base64url_decode_as_str(b64: &str) -> anyhow::Result<String> {
Ok(str)
}

fn seconds_from_epoch(secs: u64) -> SystemTime {
UNIX_EPOCH + Duration::from_secs(secs)
fn seconds_from_epoch(secs: u64) -> anyhow::Result<SystemTime> {
Ok(UNIX_EPOCH
.checked_add(Duration::from_secs(secs))
.ok_or_else(|| anyhow::anyhow!("Overflowed on UNIX_EPOCH + secs in seconds_from_epoch"))?)
}

#[cfg(test)]
Expand Down
13 changes: 10 additions & 3 deletions types/src/keyless/openid_sig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,16 @@ impl OpenIdSig {
) -> anyhow::Result<()> {
let claims: Claims = serde_json::from_str(&self.jwt_payload_json)?;

let max_expiration_date =
seconds_from_epoch(claims.oidc_claims.iat + config.max_exp_horizon_secs);
let expiration_date = seconds_from_epoch(exp_timestamp_secs);
let max_expiration_date = seconds_from_epoch(
claims
.oidc_claims
.iat
.checked_add(config.max_exp_horizon_secs)
.ok_or_else(|| {
anyhow::anyhow!("Overflow when adding iat and max_exp_horizon_secs")
})?,
)?;
let expiration_date = seconds_from_epoch(exp_timestamp_secs)?;

ensure!(
expiration_date < max_expiration_date,
Expand Down
Loading