Files
rust-discovery/crates/domain/src/windows_sync_history.rs
T
2026-11-15 23:27:14 +01:00

67 lines
2.4 KiB
Rust

//! Public historical reference for the human-reviewed Windows incident of 15 November 2026.
use chrono::{DateTime, Duration, Utc};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use uuid::Uuid;
pub const RECEIPT_DOMAIN: &str = "rmm.sync.windows-helper-checkpoint-human-repair";
/// Observed on the named server and guest. This reference cannot establish present readiness.
pub fn case_witness() -> Value {
serde_json::from_str(include_str!("windows_sync_history_case.json"))
.expect("checked-in Windows witness")
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Receipt {
pub domain: String,
pub schema_version: u32,
pub request_id: Uuid,
pub receipt_id: Uuid,
pub witness_sha256: String,
pub witness: Value,
pub key_id: String,
pub issued_at: DateTime<Utc>,
pub valid_until: DateTime<Utc>,
pub confirmed_by: String,
pub approval_origin: String,
pub testsimulation: bool,
pub ready: bool,
pub helper_ready: bool,
pub unlock: bool,
}
impl Receipt {
pub fn matches_human_review(&self, now: DateTime<Utc>) -> bool {
self.matches_reviewed_witness(&case_witness(), now)
}
/// Compare a receipt to an independently produced historical witness, after signature verification.
pub fn matches_reviewed_witness(&self, expected: &Value, now: DateTime<Utc>) -> bool {
let principal = self.confirmed_by.strip_prefix("oidc:");
self.domain == RECEIPT_DOMAIN
&& self.schema_version == 1
&& !self.receipt_id.is_nil()
&& !self.request_id.is_nil()
&& self.request_id != self.receipt_id
&& !self.testsimulation
&& !self.ready
&& !self.helper_ready
&& !self.unlock
&& self.approval_origin == "human_webui"
&& principal.is_some_and(|s| {
s.len() == 64
&& s.bytes()
.all(|c| c.is_ascii_digit() || (b'a'..=b'f').contains(&c))
})
&& self.issued_at <= now
&& now < self.valid_until
&& self.valid_until - self.issued_at <= Duration::minutes(10)
&& self.key_id == expected["verification_key_id"]
&& &self.witness == expected
&& crate::checkpoint_repair::inventory_sha256(expected)
.is_ok_and(|h| h == self.witness_sha256)
}
}