Verify the archived Windows 205 closure through a separate read-only native path
Rust development slice / linux (push) Failing after 7s

This commit is contained in:
2026-11-16 13:33:26 +01:00
parent 760b706d40
commit 090fcdffda
2 changed files with 130 additions and 7 deletions
@@ -525,3 +525,117 @@ pub fn apply(
tx.commit()?;
Ok(())
}
/// Independent read-only confirmation after the one reviewed closure. No
/// normal apply, transaction, readiness, receipt use, or history change occurs.
pub fn verify_applied(
local: &Local<'_>,
guard: &impl ClosedPairGuard,
raw: &[u8],
) -> Result<Value> {
guard.check()?;
let envelope = signed(local.binding, raw)?;
signed(local.helper_binding, raw)?;
let receipt: Receipt = serde_json::from_slice(&envelope.payload)?;
ensure!(
receipt.valid(receipt.issued_at) && receipt.witness.boot_id == guard.boot()?,
"ALIGN_APPLIED_HISTORICAL_RECEIPT"
);
let schema: String = local.helper.query_row(
"SELECT sql FROM sqlite_schema WHERE name=?1",
[TABLE],
|r| r.get(0),
)?;
ensure!(
schema == DDL
&& number(
local.helper,
"SELECT count(*) FROM sqlite_schema WHERE tbl_name='windows_sync_admin_closed_alignment_205'"
)? == 4,
"ALIGN_APPLIED_ARCHIVE_SCHEMA"
);
for (name, kind) in [
("no_replace", "INSERT"),
("no_update", "UPDATE"),
("no_delete", "DELETE"),
] {
let condition = if kind == "INSERT" {
" WHEN EXISTS(SELECT 1 FROM windows_sync_admin_closed_alignment_205)"
} else {
""
};
let expected = format!(
"CREATE TRIGGER windows_alignment_205_{name} BEFORE {kind} ON {TABLE}{condition} BEGIN SELECT RAISE(ABORT,'WINDOWS_ALIGNMENT_205_IMMUTABLE'); END"
);
let actual: String = local.helper.query_row(
"SELECT sql FROM sqlite_schema WHERE name=?1",
[format!("windows_alignment_205_{name}")],
|r| r.get(0),
)?;
ensure!(actual == expected, "ALIGN_APPLIED_IMMUTABLE_TRIGGERS");
}
let(stored,digest,applied):(Vec<u8>,String,String)=local.helper.query_row("SELECT original_receipt,witness_sha256,actual_applied_at FROM windows_sync_admin_closed_alignment_205 WHERE id=1 AND receipt_id=?1 AND ready=0 AND helper_ready=0 AND unlock=0",[receipt.receipt_id.to_string()],|r|Ok((r.get(0)?,r.get(1)?,r.get(2)?)))?;
let applied_at = DateTime::parse_from_rfc3339(&applied)?.with_timezone(&Utc);
ensure!(
stored == raw
&& digest == receipt.witness_sha256
&& applied_at >= receipt.issued_at
&& applied_at < receipt.valid_until,
"ALIGN_APPLIED_ORIGINAL_RECEIPT"
);
let w = &receipt.witness;
ensure!(local.helper.query_row("SELECT EXISTS(SELECT 1 FROM helper_sync_meta WHERE id=1 AND journal_id=?1 AND checkpoint=?2 AND generation=205 AND last_decision=?3 AND agent_journal_id=?4 AND agent_checkpoint=10137 AND fault IS NULL)",params![w.helper_journal_id.to_string(),w.helper_checkpoint,dto::SECOND.to_string(),w.agent_journal_id.to_string()],|r|r.get::<_,bool>(0))?,"ALIGN_APPLIED_EXACT_HELPER_HEAD");
let files = guard.files()?;
for (index, (current, before)) in files.iter().zip(&w.files).enumerate() {
ensure!(
current.role == before.role
&& current.file_id == before.file_id
&& (index == 3 || current.sha256 == before.sha256),
"ALIGN_APPLIED_ORIGINAL_FILES"
);
}
ensure!(
inventory(local.agent, &[])? == w.agent_inventory_sha256
&& inventory(local.consumption, &[])? == w.consumption_inventory_sha256,
"ALIGN_APPLIED_UNCHANGED_AGENT_JOURNALS"
);
ensure!(
number(local.agent, "SELECT count(*) FROM job_attempts")? == 2
&& number(local.consumption, "SELECT count(*) FROM consumed")? == 1
&& number(
local.consumption,
"SELECT count(*) FROM execution_evidence WHERE outcome IS NOT NULL"
)? == 1
&& number(local.helper, "SELECT count(*) FROM consumed")? == 0
&& number(local.helper, "SELECT count(*) FROM execution_evidence")? == 0
&& number(
local.intents,
"SELECT (SELECT count(*) FROM system_intents)+(SELECT count(*) FROM system_intent_mirrors)+(SELECT count(*) FROM system_intent_denial_resumes)"
)? == 0,
"ALIGN_APPLIED_SAME_EFFECT_COUNTS"
);
let (response, request, checkpoint): (Vec<u8>, Vec<u8>, u64) = local.helper.query_row(
"SELECT response,request,checkpoint FROM helper_sync_decisions WHERE decision_id=?1",
[dto::SECOND.to_string()],
|r| Ok((r.get(0)?, r.get(1)?, r.get(2)?)),
)?;
let response: SignedResponse = serde_json::from_slice(&response)?;
ensure!(
checkpoint == 135
&& request == w.original_requests[1]
&& response.decision_bytes == w.original_responses[1].decision_bytes
&& response.signature == w.original_responses[1].signature,
"ALIGN_APPLIED_SECOND_ORIGINAL_BYTES"
);
helper_reconcile::verify_checkpoint_repair_history_with(
local.helper,
local.helper_binding,
None,
HelperIdentity::System,
&DalekVerifier,
)?;
guard.check()?;
Ok(
json!({"schema_version":1,"read_only":true,"admin_archive_verified":true,"receipt_id":receipt.receipt_id,"witness_sha256":receipt.witness_sha256,"actual_applied_at":applied_at,"helper_checkpoint":w.helper_checkpoint,"agent_checkpoint":10137,"helper_last_decision":dto::SECOND,"counts":w.counts,"ready":false,"helper_ready":false,"unlock":false,"fresh_normal_signed_sync_required":true}),
)
}
@@ -312,10 +312,15 @@ mod platform {
pub fn run() -> Result<()> {
let args = std::env::args().skip(1).collect::<Vec<_>>();
ensure!(
args.len() == 1 && matches!(args[0].as_str(), "--witness" | "--apply-reviewed-receipt"),
args.len() == 1
&& matches!(
args[0].as_str(),
"--witness" | "--apply-reviewed-receipt" | "--verify-applied"
),
"ALIGN_FIXED_ARGUMENTS"
);
let apply = args[0] == "--apply-reviewed-receipt";
let verify_applied = args[0] == "--verify-applied";
phase(1);
admin()?;
both()?;
@@ -428,7 +433,7 @@ mod platform {
"ALIGN_HELPER_ORIGINAL_LEDGER_LOCK_IDENTITY"
);
phase(11);
if apply {
if apply || verify_applied {
let receipt = PinnedFile::open(Path::new(RECEIPT), false, &[], &[], false)?;
let raw = bytes(&receipt.file, 4 * 1024 * 1024)?;
let helper_read = Db::open(PATHS[3], false)?;
@@ -440,11 +445,15 @@ mod platform {
binding: &binding,
helper_binding: &settings.binding,
};
recovery::apply(&local, &mut h.db, &guard, &raw, chrono::Utc::now())?;
println!(
"{}",
serde_json::json!({"schema_version":1,"closed_admin_alignment_applied":true,"actual_applied_at":chrono::Utc::now(),"ready":false,"helper_ready":false,"unlock":false,"fresh_normal_signed_sync_required":true})
);
if verify_applied {
println!("{}", recovery::verify_applied(&local, &guard, &raw)?);
} else {
recovery::apply(&local, &mut h.db, &guard, &raw, chrono::Utc::now())?;
println!(
"{}",
serde_json::json!({"schema_version":1,"closed_admin_alignment_applied":true,"actual_applied_at":chrono::Utc::now(),"ready":false,"helper_ready":false,"unlock":false,"fresh_normal_signed_sync_required":true})
);
}
} else {
let local = Local {
agent: &a.db,