Relax signed time evidence to five minutes with advancing lower bound; keep held evidence across failed refreshes (user decision, spec 1.32)
Rust development slice / linux (push) Failing after 7s
Rust development slice / linux (push) Failing after 7s
This commit is contained in:
@@ -10,7 +10,13 @@ use uuid::Uuid;
|
||||
|
||||
pub const ENDPOINT: &str = "https://discovery.ease-technologies.de/agent/v1/time-attestation";
|
||||
pub const MAX_RTT_NS: u64 = 1_000_000_000;
|
||||
pub const MAX_RECEIVED_AGE_NS: u64 = 100_000_000;
|
||||
/// Held evidence stays usable for five minutes after receipt (operator
|
||||
/// decision 2026-11-17, spec 1.32). The interval stays tight because its lower
|
||||
/// bound advances with the monotonic counter time elapsed since receipt.
|
||||
pub const MAX_RECEIVED_AGE_NS: u64 = 300_000_000_000;
|
||||
/// Conservative counter-rate allowance against UTC for long-held evidence,
|
||||
/// far above real guest timer drift (1000 ppm = 0.1 %).
|
||||
pub const COUNTER_DRIFT_PPM: u64 = 1_000;
|
||||
pub const MAX_CAPTURE_ERROR_NS: u64 = 50_000_000;
|
||||
pub const MAX_SERVER_ERROR_NS: u64 = 500_000_000;
|
||||
pub const MAX_SYNC_AGE_NS: u64 = 3_600_000_000_000;
|
||||
@@ -410,6 +416,11 @@ impl Verifier {
|
||||
.interrupt_ns
|
||||
.checked_sub(evidence.received.interrupt_ns)
|
||||
.ok_or_else(|| anyhow::anyhow!("TIME_COUNTER"))?;
|
||||
let rtt = evidence
|
||||
.received
|
||||
.interrupt_ns
|
||||
.checked_sub(evidence.begin.interrupt_ns)
|
||||
.ok_or_else(|| anyhow::anyhow!("TIME_COUNTER"))?;
|
||||
// Include every local capture/timer budget conservatively, never RTT/2.
|
||||
let delta = evidence
|
||||
.begin
|
||||
@@ -421,14 +432,16 @@ impl Verifier {
|
||||
// Use the same full qualified uncertainty for freshness as for UTC-U.
|
||||
// The begin budget is deliberately overcounted for receive age: no
|
||||
// endpoint or timer-underread allowance can disappear at either gate.
|
||||
let upper_elapsed = elapsed
|
||||
// The one-second bound applies to the signed round trip itself; the
|
||||
// held evidence then ages against MAX_RECEIVED_AGE_NS.
|
||||
let upper_rtt = rtt
|
||||
.checked_add(delta)
|
||||
.ok_or_else(|| anyhow::anyhow!("TIME_ERROR_OVERFLOW"))?;
|
||||
let upper_age = age
|
||||
.checked_add(delta)
|
||||
.ok_or_else(|| anyhow::anyhow!("TIME_ERROR_OVERFLOW"))?;
|
||||
ensure!(
|
||||
upper_elapsed <= MAX_RTT_NS && upper_age <= MAX_RECEIVED_AGE_NS,
|
||||
upper_rtt <= MAX_RTT_NS && upper_age <= MAX_RECEIVED_AGE_NS,
|
||||
"TIME_STALE_RESPONSE"
|
||||
);
|
||||
ensure!(
|
||||
@@ -438,11 +451,20 @@ impl Verifier {
|
||||
.is_some_and(|v| v <= MAX_SYNC_AGE_NS),
|
||||
"TIME_SOURCE_AGE_AT_CHECK"
|
||||
);
|
||||
let lower = i128::from(p.captured_utc_ns) - i128::from(p.server_error_ns);
|
||||
// The server captured before this verifier received the reply, so at
|
||||
// least the counter time since receipt has passed since the capture.
|
||||
// Both sides carry every capture budget plus the counter drift allowance.
|
||||
let drift = |ns: u64| u128::from(ns) * u128::from(COUNTER_DRIFT_PPM) / 1_000_000;
|
||||
let since_capture_min = u128::from(age)
|
||||
.saturating_sub(u128::from(delta))
|
||||
.saturating_sub(drift(age));
|
||||
let lower = i128::from(p.captured_utc_ns) - i128::from(p.server_error_ns)
|
||||
+ i128::try_from(since_capture_min)?;
|
||||
let upper = i128::from(p.captured_utc_ns)
|
||||
+ i128::from(p.server_error_ns)
|
||||
+ i128::from(elapsed)
|
||||
+ i128::from(delta);
|
||||
+ i128::from(delta)
|
||||
+ i128::try_from(drift(elapsed.saturating_add(delta)))?;
|
||||
let wall = i128::from(checked.wall_utc_ns);
|
||||
ensure!(
|
||||
(wall - lower).abs().max((wall - upper).abs()) <= 2_000_000_000,
|
||||
@@ -537,11 +559,14 @@ mod tests {
|
||||
let result = v
|
||||
.finish(c, &signed, sample(70_000_000), || Ok(sample(80_000_000)))
|
||||
.unwrap();
|
||||
assert_eq!(result.lower_utc_ns(), T + 10_000_000);
|
||||
assert_eq!(result.upper_utc_ns(), T + 113_000_000);
|
||||
// Lower: capture - server error + (age 10 ms - 3 ms budgets - drift).
|
||||
assert_eq!(result.lower_utc_ns(), T + 16_990_000);
|
||||
// Upper: capture + server error + elapsed 80 ms + 3 ms + drift.
|
||||
assert_eq!(result.upper_utc_ns(), T + 113_083_000);
|
||||
assert!(result.allows_start(T, T + 114_000_000));
|
||||
assert!(!result.allows_start(T, T + 113_000_000));
|
||||
assert!(!result.allows_start(T + 11_000_000, T + 114_000_000));
|
||||
assert!(result.allows_start(T + 16_990_000, T + 114_000_000));
|
||||
assert!(!result.allows_start(T + 16_990_001, T + 114_000_000));
|
||||
}
|
||||
#[test]
|
||||
fn updater_uses_own_role_image_nonce_and_preserves_legacy_context_bytes() {
|
||||
@@ -609,10 +634,13 @@ mod tests {
|
||||
let other = SigningKey::from_bytes(&rand::random());
|
||||
signed = reply(&c, &other, server);
|
||||
}
|
||||
3 => checked = sample(MAX_RTT_NS + 1),
|
||||
3 => {
|
||||
received = sample(MAX_RTT_NS + 1);
|
||||
checked = sample(MAX_RTT_NS + 2);
|
||||
}
|
||||
4 => {
|
||||
received = sample(10_000_000);
|
||||
checked = sample(110_000_001);
|
||||
checked = sample(10_000_000 + MAX_RECEIVED_AGE_NS + 1);
|
||||
}
|
||||
5 => {
|
||||
let mut p: Payload = serde_json::from_str(&signed.payload).unwrap();
|
||||
@@ -690,8 +718,7 @@ mod tests {
|
||||
let next_reply = reply(&next, &key, server);
|
||||
let later = v.check_evidence(&evidence, sample(110_000_000)).unwrap();
|
||||
assert!(later.upper_utc_ns() > initial.upper_utc_ns());
|
||||
assert!(v.check_evidence(&evidence, sample(167_000_000)).is_ok());
|
||||
assert!(v.check_evidence(&evidence, sample(167_000_001)).is_err());
|
||||
assert!(later.lower_utc_ns() > initial.lower_utc_ns());
|
||||
assert_eq!(
|
||||
v.pending_nonce.as_deref(),
|
||||
Some(next.request().nonce.as_str())
|
||||
@@ -702,19 +729,35 @@ mod tests {
|
||||
})
|
||||
.unwrap();
|
||||
assert!(v.check_evidence(&fresh, sample(200_000_000)).is_ok());
|
||||
assert!(v.check_evidence(&evidence, sample(201_000_000)).is_err());
|
||||
|
||||
// The one-second bound starts at the original challenge, even when
|
||||
// the complete response itself was received less than100ms ago.
|
||||
let c = v.begin(sample(300_000_000)).unwrap();
|
||||
let signed = reply(&c, &key, server);
|
||||
let (evidence, _) = v
|
||||
.finish_evidence(c, &signed, sample(1_240_000_000), || {
|
||||
Ok(sample(1_250_000_000))
|
||||
})
|
||||
.unwrap();
|
||||
assert!(v.check_evidence(&evidence, sample(1_297_000_000)).is_ok());
|
||||
assert!(v.check_evidence(&evidence, sample(1_297_000_001)).is_err());
|
||||
// Held evidence ages only against its own receipt, up to five minutes,
|
||||
// and its interval stays narrow because the lower bound advances.
|
||||
let limit = 70_000_000 + MAX_RECEIVED_AGE_NS - 3_000_000;
|
||||
let held = v.check_evidence(&evidence, sample(limit)).unwrap();
|
||||
assert!(held.upper_utc_ns() - held.lower_utc_ns() < 1_000_000_000);
|
||||
assert_eq!(
|
||||
v.check_evidence(&evidence, sample(limit + 1))
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
"TIME_STALE_RESPONSE"
|
||||
);
|
||||
// The one-second bound applies to the signed round trip itself.
|
||||
for (index, (after, ok)) in [
|
||||
(MAX_RTT_NS - 3_000_000, true),
|
||||
(MAX_RTT_NS - 3_000_000 + 1, false),
|
||||
]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
let base = limit + (index as u64 + 1) * 10_000_000_000;
|
||||
let c = v.begin(sample(base)).unwrap();
|
||||
let mut p: Payload = serde_json::from_str(&reply(&c, &key, server).payload).unwrap();
|
||||
p.captured_utc_ns = T + base as i64 + 20_000_000;
|
||||
let signed = sign(&p, &key).unwrap();
|
||||
let result = v.finish_evidence(c, &signed, sample(base + after), || {
|
||||
Ok(sample(base + after + 1))
|
||||
});
|
||||
assert_eq!(result.is_ok(), ok, "round trip {after}");
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn challenge_freshness_includes_all_capture_budgets_at_one_second() {
|
||||
@@ -727,25 +770,26 @@ mod tests {
|
||||
begin.capture_error_ns = 7_000_000;
|
||||
let c = v.begin(begin).unwrap();
|
||||
let signed = reply(&c, &key, server);
|
||||
let mut received = sample(MAX_RTT_NS - delta - 1_000_000);
|
||||
let mut received = sample(MAX_RTT_NS - delta + excess);
|
||||
received.capture_error_ns = 11_000_000;
|
||||
let mut checked = sample(MAX_RTT_NS - delta + excess);
|
||||
let mut checked = sample(MAX_RTT_NS - delta + excess + 10_000_000);
|
||||
checked.capture_error_ns = 13_000_000;
|
||||
let result = v.finish_evidence(c, &signed, received, || Ok(checked));
|
||||
assert!(v.pending_nonce.is_none());
|
||||
if excess == 0 {
|
||||
let (evidence, _) = result.unwrap();
|
||||
assert!(v.check_evidence(&evidence, checked).is_ok());
|
||||
let mut later = sample(MAX_RTT_NS - delta + 1);
|
||||
// A round trip completed within one second stays usable later.
|
||||
let mut later = sample(MAX_RTT_NS - delta + 60_000_000_000);
|
||||
later.capture_error_ns = checked.capture_error_ns;
|
||||
assert!(v.check_evidence(&evidence, later).is_err());
|
||||
assert!(v.check_evidence(&evidence, later).is_ok());
|
||||
} else {
|
||||
assert_eq!(result.err().unwrap().to_string(), "TIME_STALE_RESPONSE");
|
||||
}
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn receive_freshness_includes_all_capture_budgets_at_one_hundred_ms() {
|
||||
fn receive_freshness_includes_all_capture_budgets_at_five_minutes() {
|
||||
let delta = 31_000_000;
|
||||
for excess in [0, 1] {
|
||||
let (mut v, key, server) = fixture(context(Role::SystemHelper));
|
||||
|
||||
Reference in New Issue
Block a user