Implement and natively verify the human-reviewed Windows recovery tool
Rust development slice / linux (push) Failing after 7s
Rust development slice / linux (push) Failing after 7s
This commit is contained in:
@@ -11,3 +11,4 @@ pub mod reconcile;
|
||||
pub mod update_handoff;
|
||||
pub mod update_health_inventory;
|
||||
pub mod update_health_sync;
|
||||
pub mod windows_sync_history;
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
//! Public, read-only comparison of the three Windows journals for the November 2026 incident.
|
||||
use crate::{
|
||||
auth::Binding,
|
||||
crypto::DalekVerifier,
|
||||
helper_reconcile::SignedResponse,
|
||||
reconcile::{Channel, verify_response_with},
|
||||
};
|
||||
use anyhow::{Result, ensure};
|
||||
use prost::Message;
|
||||
use rmm_domain::{jobs::hash, reconciliation::ReconcileDecisionPayload};
|
||||
use rmm_protocol::{Envelope, Payload, SyncRequest, SyncResponse};
|
||||
use rusqlite::{Connection, params};
|
||||
use uuid::Uuid;
|
||||
pub const AGENT: &str = "63ea15b2-0643-403d-b5b4-cba1288dbea3";
|
||||
pub const BOOT: &str = "a9ad0895-5a96-8f2c-8fb6-cfdc2d5225ea";
|
||||
pub const FIRST: &str = "b6a3101f-68ad-41c8-be4e-4c7c2bc963d6";
|
||||
pub const LAST: &str = "0633a4de-7e52-4e5d-a2a1-59fb134817fe";
|
||||
pub const FAULT: &str = "HELPER_CHECKPOINT_REQUIRED";
|
||||
pub const BINDING_SHA256: &str = "9239ee9f4142735867e77451478bf309fbf449d730a0ede6c958bc8018830dde";
|
||||
pub const CASES: [(&str, &str, u64); 2] = [
|
||||
("1418b4a3-8370-404d-b29a-920ba9f0f4d7", FIRST, 6755),
|
||||
("9eba037c-825f-4a96-be14-cca130c1e83d", LAST, 6756),
|
||||
];
|
||||
|
||||
pub fn verify_local_history(
|
||||
agent: &Connection,
|
||||
local: &Connection,
|
||||
helper: &Connection,
|
||||
binding: &Binding,
|
||||
helper_binding: &Binding,
|
||||
expected_fault: Option<&str>,
|
||||
) -> Result<Vec<serde_json::Value>> {
|
||||
let count = |db: &Connection, sql| -> Result<i64> { Ok(db.query_row(sql, [], |r| r.get(0))?) };
|
||||
ensure!(
|
||||
count(agent, "SELECT count(*) FROM reconcile_requests")? == 2
|
||||
&& count(local, "SELECT count(*) FROM reconcile_consumption")? == 2
|
||||
&& count(helper, "SELECT count(*) FROM helper_sync_decisions")? == 1,
|
||||
"history length"
|
||||
);
|
||||
ensure!(
|
||||
count(
|
||||
agent,
|
||||
"SELECT (SELECT count(*) FROM job_attempts)+(SELECT count(*) FROM reconcile_outcomes)+(SELECT count(*) FROM reconcile_results)"
|
||||
)? == 0
|
||||
&& count(
|
||||
local,
|
||||
"SELECT (SELECT count(*) FROM consumed)+(SELECT count(*) FROM execution_evidence)"
|
||||
)? == 0
|
||||
&& count(
|
||||
helper,
|
||||
"SELECT (SELECT count(*) FROM consumed)+(SELECT count(*) FROM execution_evidence)"
|
||||
)? == 0,
|
||||
"nonempty execution history"
|
||||
);
|
||||
|
||||
let chan = Channel {
|
||||
connection_generation: 150,
|
||||
boot_id: Uuid::parse_str(BOOT)?,
|
||||
};
|
||||
let mut decisions = Vec::with_capacity(CASES.len());
|
||||
for (request_id, decision_id, checkpoint) in CASES {
|
||||
let (raw_request, envelope_bytes, raw_response): (Vec<u8>, Vec<u8>, Vec<u8>) = agent.query_row(
|
||||
"SELECT request,envelope,response FROM reconcile_requests WHERE id=? AND generation=150 AND length(request) BETWEEN 1 AND 524288 AND length(envelope) BETWEEN 1 AND 524288 AND length(response) BETWEEN 1 AND 524288",
|
||||
[request_id], |r| Ok((r.get(0)?,r.get(1)?,r.get(2)?)))?;
|
||||
let request = SyncRequest::decode(raw_request.as_slice())?;
|
||||
let envelope = Envelope::decode(envelope_bytes.as_slice())?;
|
||||
let response = SyncResponse::decode(raw_response.as_slice())?;
|
||||
ensure!(
|
||||
request.encode_to_vec() == raw_request && response.encode_to_vec() == raw_response,
|
||||
"noncanonical original record"
|
||||
);
|
||||
ensure!(
|
||||
envelope.protocol_major == 1
|
||||
&& envelope.protocol_minor == 0
|
||||
&& envelope.agent_id == AGENT
|
||||
&& envelope.enrollment_generation == 1
|
||||
&& envelope.connection_generation == 150
|
||||
&& envelope.boot_id == BOOT
|
||||
&& envelope.sequence == checkpoint
|
||||
&& envelope.payload == Some(Payload::SyncRequest(request.clone())),
|
||||
"envelope binding"
|
||||
);
|
||||
let first = decision_id == FIRST;
|
||||
ensure!(
|
||||
request.request_id == request_id
|
||||
&& request.checkpoint == checkpoint
|
||||
&& request.assignment_version == 1
|
||||
&& request.helper_checkpoint == 1
|
||||
&& request.journal_complete
|
||||
&& request.previous_decision_id == if first { "" } else { FIRST }
|
||||
&& request.previous_request_id.is_empty()
|
||||
&& request.helper_previous_decision_id.is_empty()
|
||||
&& request.attempts.is_empty(),
|
||||
"request history"
|
||||
);
|
||||
// Historical validation uses the signed issue time, never a present-day lease.
|
||||
let historical: ReconcileDecisionPayload =
|
||||
serde_json::from_slice(&response.decision_bytes)?;
|
||||
let d = verify_response_with(
|
||||
&DalekVerifier,
|
||||
binding,
|
||||
&request,
|
||||
&chan,
|
||||
&response,
|
||||
historical.issued_at,
|
||||
)?;
|
||||
ensure!(
|
||||
d.decision_id.to_string() == decision_id
|
||||
&& d.attempts.is_empty()
|
||||
&& d.ready == first
|
||||
&& d.helper_ready == first
|
||||
&& d.reason == if first { "CONSISTENT" } else { FAULT },
|
||||
"signed decision"
|
||||
);
|
||||
let ledger_response: Vec<u8> = local.query_row("SELECT response FROM reconcile_consumption WHERE decision_id=? AND length(response) BETWEEN 1 AND 524288", [decision_id], |r|r.get(0))?;
|
||||
ensure!(
|
||||
ledger_response == raw_response,
|
||||
"consumption decision differs"
|
||||
);
|
||||
if !first {
|
||||
let (helper_raw, helper_request): (Vec<u8>, Vec<u8>) = helper.query_row(
|
||||
"SELECT response,request FROM helper_sync_decisions WHERE decision_id=? AND checkpoint=1 AND length(response) BETWEEN 1 AND 2097152 AND length(request) BETWEEN 1 AND 524288",
|
||||
[decision_id], |r|Ok((r.get(0)?,r.get(1)?)))?;
|
||||
let h: SignedResponse = serde_json::from_slice(&helper_raw)?;
|
||||
ensure!(
|
||||
helper_request == raw_request
|
||||
&& h.decision_bytes == response.decision_bytes
|
||||
&& h.signature == response.signature,
|
||||
"helper signed history"
|
||||
);
|
||||
// The helper configuration provides its own protected trust binding.
|
||||
let helper_signed = SyncResponse {
|
||||
decision_bytes: h.decision_bytes,
|
||||
signature: h.signature,
|
||||
};
|
||||
verify_response_with(
|
||||
&DalekVerifier,
|
||||
helper_binding,
|
||||
&request,
|
||||
&chan,
|
||||
&helper_signed,
|
||||
historical.issued_at,
|
||||
)?;
|
||||
let head: bool = agent.query_row("SELECT EXISTS(SELECT 1 FROM reconcile_meta WHERE id=1 AND journal_id=?1 AND checkpoint=6756 AND generation=150 AND last_decision=?2 AND pending_request IS NULL AND helper_id=?3 AND helper_checkpoint=1 AND fault IS ?4)",params![request.journal_id, LAST, request.helper_journal_id, expected_fault], |r|r.get(0))?;
|
||||
let helper_head: bool = helper.query_row("SELECT EXISTS(SELECT 1 FROM helper_sync_meta WHERE id=1 AND journal_id=?1 AND checkpoint>=1 AND generation=150 AND last_decision=?2 AND agent_journal_id=?3 AND agent_checkpoint=6756 AND fault IS NULL)",params![request.helper_journal_id,LAST,request.journal_id],|r|r.get(0))?;
|
||||
ensure!(head && helper_head, "live reconciliation heads differ");
|
||||
}
|
||||
decisions.push(serde_json::json!({
|
||||
"checkpoint": checkpoint, "request_id": request_id, "request_sha256": hash(&raw_request),
|
||||
"decision_id": decision_id, "payload_sha256": hash(&response.decision_bytes),
|
||||
"signature_sha256": hash(&response.signature), "reason": d.reason
|
||||
}));
|
||||
}
|
||||
Ok(decisions)
|
||||
}
|
||||
Reference in New Issue
Block a user