Integrate independent signed Windows clocks with native Linux lease guards
Rust development slice / linux (push) Failing after 6s

This commit is contained in:
2026-11-15 10:26:24 +01:00
parent 6ddfc95fff
commit 09f7e5af84
13 changed files with 1093 additions and 37 deletions
+123 -4
View File
@@ -1,6 +1,7 @@
//! Independent signed time comparison for the Windows agent and SYSTEM helper.
//! This module does not implement SyncClock, advertise a capability, start a job,
//! change W32Time or replace the still-closed legacy NativeClock adapter.
//! Runtime readers use only their own fresh evidence and protected connection.
//! No provisioning, W32Time change or job authorization occurs here; the legacy
//! RPC adapter remains closed and is never a runtime fallback.
#![cfg(any(test, all(windows, feature = "system-helper")))]
use anyhow::{Result, ensure};
use rmm_time_attestation::Sample;
@@ -414,7 +415,7 @@ mod installed {
collections::BTreeMap,
io::Read,
path::Path,
sync::{Mutex, OnceLock},
sync::{Arc, Mutex, OnceLock},
};
pub const CONFIG_PATH: &str = r"C:\ProgramData\RustDiscoverySystem\time-attestation.json";
@@ -812,6 +813,122 @@ mod installed {
}
}
/// Shared only inside one installed process. HTTP/IPC receives no access to
/// this slot or to its clock readings; its control surface is nonce/bytes.
#[derive(Clone)]
pub struct RuntimeClock {
role: Role,
state: Arc<Mutex<Option<(u64, SignedClock)>>>,
}
#[derive(Clone)]
pub struct BoundClock {
source: RuntimeClock,
generation: u64,
}
impl RuntimeClock {
pub fn new(role: Role) -> Self {
Self {
role,
state: Arc::new(Mutex::new(None)),
}
}
pub fn for_generation(&self, generation: u64) -> BoundClock {
BoundClock {
source: self.clone(),
generation,
}
}
pub fn configured_for(&self, generation: u64) -> bool {
self.state
.lock()
.is_ok_and(|state| state.as_ref().is_some_and(|(held, _)| *held == generation))
}
pub async fn open_connection(&self, generation: u64) -> Result<()> {
ensure!(generation > 0, "TIME_RUNTIME_GENERATION");
self.close()?;
let clock = SignedClock::open(self.role, generation).await?;
let mut state = self
.state
.lock()
.map_err(|_| anyhow::anyhow!("TIME_RUNTIME_POISONED"))?;
*state = Some((generation, clock));
Ok(())
}
pub fn begin(&self, generation: u64) -> Result<Request> {
let mut state = self
.state
.lock()
.map_err(|_| anyhow::anyhow!("TIME_RUNTIME_POISONED"))?;
let (held, clock) = state.as_mut().context("TIME_RUNTIME_NOT_CONFIGURED")?;
ensure!(*held == generation, "TIME_RUNTIME_CONNECTION_CHANGED");
clock.begin(generation)
}
pub fn complete(&self, generation: u64, bytes: &[u8]) -> Result<()> {
let mut state = self
.state
.lock()
.map_err(|_| anyhow::anyhow!("TIME_RUNTIME_POISONED"))?;
let (held, clock) = state.as_mut().context("TIME_RUNTIME_NOT_CONFIGURED")?;
ensure!(*held == generation, "TIME_RUNTIME_CONNECTION_CHANGED");
clock.complete(bytes, |_| Ok(()))
}
pub fn close_generation(&self, generation: u64) -> Result<()> {
let mut state = self
.state
.lock()
.map_err(|_| anyhow::anyhow!("TIME_RUNTIME_POISONED"))?;
if state.as_ref().is_some_and(|(held, _)| *held == generation) {
state.take(); // Drop fences this instance's pending/evidence.
}
Ok(())
}
pub fn close(&self) -> Result<()> {
self.state
.lock()
.map_err(|_| anyhow::anyhow!("TIME_RUNTIME_POISONED"))?
.take();
Ok(())
}
}
impl BoundClock {
pub fn source(&self) -> RuntimeClock {
self.source.clone()
}
pub fn for_generation(&self, generation: u64) -> Self {
self.source.for_generation(generation)
}
pub fn require_generation(&self, generation: u64) -> Result<()> {
ensure!(
self.generation == generation && generation > 0,
"TIME_RUNTIME_GENERATION"
);
Ok(())
}
}
impl rmm_agent_core::reconcile::SyncClock for BoundClock {
fn now(&self) -> Result<chrono::DateTime<chrono::Utc>> {
Ok(self.reading()?.own_wall)
}
fn reading(&self) -> Result<rmm_agent_core::reconcile::ClockReading> {
ensure!(self.generation > 0, "TIME_RUNTIME_NO_CONNECTION");
let mut state = self
.source
.state
.lock()
.map_err(|_| anyhow::anyhow!("TIME_RUNTIME_POISONED"))?;
let (held, clock) = state.as_mut().context("TIME_RUNTIME_NO_EVIDENCE")?;
ensure!(*held == self.generation, "TIME_RUNTIME_CONNECTION_CHANGED");
clock.with_current_comparison(|value| {
let own_wall = chrono::DateTime::from_timestamp_nanos(value.wall_utc_ns());
let upper = chrono::DateTime::from_timestamp_nanos(value.interval().upper_utc_ns());
Ok(rmm_agent_core::reconcile::ClockReading {
own_wall,
upper: upper.max(own_wall),
})
})
}
}
/// Borrowed only inside a completion/current-comparison callback, never returned as a
/// storable clock/lease/permit. Runtime callers must retain all job gates.
pub struct Comparison {
@@ -828,7 +945,9 @@ mod installed {
}
}
#[cfg(all(windows, feature = "system-helper"))]
pub use installed::{CONFIG_PATH, Calibration, Comparison, Configuration, SignedClock};
pub use installed::{
BoundClock, CONFIG_PATH, Calibration, Comparison, Configuration, RuntimeClock, SignedClock,
};
#[cfg(test)]
mod tests {