Verify signed time independently of job admission for passive Windows clients
Rust development slice / linux (push) Failing after 7s
Rust development slice / linux (push) Failing after 7s
This commit is contained in:
@@ -10,6 +10,29 @@ use uuid::Uuid;
|
||||
const SECOND_NS: u64 = 1_000_000_000;
|
||||
const MAX_BASE_ERROR_NS: u64 = 10_000_000;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum SamplingMode {
|
||||
Passive,
|
||||
Jobs,
|
||||
}
|
||||
impl SamplingMode {
|
||||
pub fn configured(jobs: bool, profile: &std::path::Path) -> std::io::Result<Option<Self>> {
|
||||
if jobs {
|
||||
return Ok(Some(Self::Jobs));
|
||||
}
|
||||
Ok(profile.try_exists()?.then_some(Self::Passive))
|
||||
}
|
||||
|
||||
pub fn interval(self, verified: bool) -> std::time::Duration {
|
||||
use std::time::Duration;
|
||||
match (self, verified) {
|
||||
(Self::Passive, _) => Duration::from_secs(30),
|
||||
(Self::Jobs, true) => Duration::from_millis(20),
|
||||
(Self::Jobs, false) => Duration::from_millis(500),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn independent_time_key(time_key_hex: &str, job_key_hex: &str) -> Result<[u8; 32]> {
|
||||
fn decode(value: &str) -> Result<[u8; 32]> {
|
||||
ensure!(
|
||||
@@ -1137,6 +1160,30 @@ pub use installed::{BoundClock, CONFIG_PATH, Comparison, RuntimeClock, SignedClo
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn passive_sampling_requires_a_profile_and_uses_heartbeat_cadence() {
|
||||
let dir = std::env::temp_dir().join(Uuid::new_v4().to_string());
|
||||
std::fs::create_dir(&dir).unwrap();
|
||||
let profile = dir.join("time-attestation.json");
|
||||
assert_eq!(SamplingMode::configured(false, &profile).unwrap(), None);
|
||||
assert_eq!(
|
||||
SamplingMode::configured(true, &profile).unwrap(),
|
||||
Some(SamplingMode::Jobs)
|
||||
);
|
||||
std::fs::write(&profile, b"{}").unwrap();
|
||||
assert_eq!(
|
||||
SamplingMode::configured(false, &profile).unwrap(),
|
||||
Some(SamplingMode::Passive)
|
||||
);
|
||||
for verified in [false, true] {
|
||||
assert_eq!(
|
||||
SamplingMode::Passive.interval(verified),
|
||||
std::time::Duration::from_secs(30)
|
||||
);
|
||||
}
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
fn sample(ns: u64) -> Sample {
|
||||
Sample {
|
||||
wall_utc_ns: 1_800_000_000_000_000_000 + ns as i64,
|
||||
|
||||
Reference in New Issue
Block a user