Apply reviewed Windows generation 205 closure while preserving original history
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -1308,7 +1308,7 @@ fn ledger_rows(db: &Connection) -> Result<Vec<LedgerRow>> {
|
||||
})?
|
||||
.collect::<rusqlite::Result<_>>()?)
|
||||
}
|
||||
fn ledger_fingerprint(db: &Connection) -> Result<String> {
|
||||
pub(crate) fn ledger_fingerprint(db: &Connection) -> Result<String> {
|
||||
let rows = ledger_rows(db)?;
|
||||
let exists:bool=db.query_row("SELECT EXISTS(SELECT 1 FROM sqlite_master WHERE type='table' AND name='agent_update_handoffs')",[],|r|r.get(0))?;
|
||||
if exists {
|
||||
|
||||
@@ -12,3 +12,5 @@ pub mod update_handoff;
|
||||
pub mod update_health_inventory;
|
||||
pub mod update_health_sync;
|
||||
pub mod windows_sync_history;
|
||||
|
||||
pub mod windows_sync_alignment;
|
||||
|
||||
@@ -0,0 +1,527 @@
|
||||
//! Closed, append-only administrator closure of the explicitly approved G205
|
||||
//! incident. Never calls HelperSync::apply, creates a lease, or touches effects.
|
||||
use crate::{
|
||||
auth::{Binding, HelperIdentity, Request},
|
||||
crypto::{DalekVerifier, Ed25519Verifier},
|
||||
helper_reconcile::{self, SignedResponse, Snapshot},
|
||||
reconcile::{Channel, verify_response_with},
|
||||
};
|
||||
use anyhow::{Context, Result, ensure};
|
||||
use chrono::{DateTime, Utc};
|
||||
use prost::Message;
|
||||
use rmm_domain::{
|
||||
checkpoint_repair::{SignedDecision, SignedReceipt, inventory_sha256},
|
||||
jobs::{ExecutionPermitPayload, JobPayload, hash},
|
||||
windows_echo_completion,
|
||||
windows_sync_alignment::{self as dto, Counts, NativeFile, Receipt, Witness},
|
||||
};
|
||||
use rmm_protocol::{Envelope, JobOffer, Payload, SyncRequest, SyncResponse};
|
||||
use rusqlite::{Connection, TransactionBehavior, params, types::ValueRef};
|
||||
use serde_json::{Value, json};
|
||||
use uuid::Uuid;
|
||||
const TABLE: &str = "windows_sync_admin_closed_alignment_205";
|
||||
const DDL: &str = "CREATE TABLE windows_sync_admin_closed_alignment_205(id INTEGER PRIMARY KEY CHECK(id=1),receipt_id TEXT NOT NULL,original_receipt BLOB NOT NULL,witness_sha256 TEXT NOT NULL,actual_applied_at TEXT NOT NULL,ready INTEGER NOT NULL CHECK(ready=0),helper_ready INTEGER NOT NULL CHECK(helper_ready=0),unlock INTEGER NOT NULL CHECK(unlock=0))";
|
||||
pub trait ClosedPairGuard {
|
||||
fn check(&self) -> Result<()>;
|
||||
fn files(&self) -> Result<[NativeFile; 6]>;
|
||||
fn boot(&self) -> Result<Uuid>;
|
||||
}
|
||||
pub struct Local<'a> {
|
||||
pub agent: &'a Connection,
|
||||
pub consumption: &'a Connection,
|
||||
pub helper: &'a Connection,
|
||||
pub intents: &'a Connection,
|
||||
pub binding: &'a Binding,
|
||||
pub helper_binding: &'a Binding,
|
||||
}
|
||||
fn number(db: &Connection, sql: &str) -> Result<u64> {
|
||||
Ok(db.query_row(sql, [], |r| r.get(0))?)
|
||||
}
|
||||
/// Canonical bounded complete logical schema/row inventory. Bytes never leave
|
||||
/// the process; only the digest is published. No executable SQL is read/run.
|
||||
pub fn inventory(db: &Connection, excluded: &[&str]) -> Result<String> {
|
||||
ensure!(
|
||||
db.query_row("PRAGMA integrity_check", [], |r| r.get::<_, String>(0))? == "ok",
|
||||
"ALIGN_JOURNAL_INTEGRITY"
|
||||
);
|
||||
let mut q =
|
||||
db.prepare("SELECT type,name,tbl_name,sql FROM sqlite_schema ORDER BY type,name")?;
|
||||
let entries = q
|
||||
.query_map([], |r| {
|
||||
Ok((
|
||||
r.get::<_, String>(0)?,
|
||||
r.get::<_, String>(1)?,
|
||||
r.get::<_, String>(2)?,
|
||||
r.get::<_, Option<String>>(3)?,
|
||||
))
|
||||
})?
|
||||
.collect::<rusqlite::Result<Vec<_>>>()?;
|
||||
let mut doc = vec![];
|
||||
let mut size = 0usize;
|
||||
let mut rows_total = 0usize;
|
||||
for (kind, name, table, sql) in entries {
|
||||
if excluded.contains(&table.as_str()) {
|
||||
continue;
|
||||
}
|
||||
ensure!(
|
||||
matches!(kind.as_str(), "table" | "index" | "trigger")
|
||||
&& !sql
|
||||
.as_deref()
|
||||
.unwrap_or_default()
|
||||
.to_ascii_uppercase()
|
||||
.contains("VIRTUAL TABLE"),
|
||||
"ALIGN_UNEXPECTED_SCHEMA"
|
||||
);
|
||||
doc.push(json!([kind, name, table, sql]));
|
||||
if kind != "table" {
|
||||
continue;
|
||||
}
|
||||
ensure!(
|
||||
!name.is_empty() && name.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'_'),
|
||||
"ALIGN_TABLE_IDENTIFIER"
|
||||
);
|
||||
let mut stmt = db.prepare(&format!("SELECT rowid,* FROM \"{name}\" ORDER BY rowid"))?;
|
||||
let cols = stmt.column_count();
|
||||
let mut rows = stmt.query([])?;
|
||||
while let Some(row) = rows.next()? {
|
||||
rows_total += 1;
|
||||
ensure!(rows_total <= 100000, "ALIGN_ROW_LIMIT");
|
||||
let mut record = vec![];
|
||||
for col in 0..cols {
|
||||
record.push(match row.get_ref(col)? {
|
||||
ValueRef::Null => json!(["null"]),
|
||||
ValueRef::Integer(n) => json!(["integer", n]),
|
||||
ValueRef::Real(n) => json!(["real", n.to_bits().to_string()]),
|
||||
ValueRef::Text(v) => {
|
||||
size += v.len();
|
||||
json!(["text", hex::encode(v)])
|
||||
}
|
||||
ValueRef::Blob(v) => {
|
||||
size += v.len();
|
||||
json!(["blob", hex::encode(v)])
|
||||
}
|
||||
});
|
||||
}
|
||||
ensure!(size <= 64 * 1024 * 1024, "ALIGN_INVENTORY_LIMIT");
|
||||
doc.push(json!([name, record]));
|
||||
}
|
||||
}
|
||||
Ok(inventory_sha256(&Value::Array(doc))?)
|
||||
}
|
||||
fn signed(binding: &Binding, raw: &[u8]) -> Result<SignedReceipt> {
|
||||
ensure!(raw.len() <= 4 * 1024 * 1024, "ALIGN_RECEIPT_SIZE");
|
||||
let r: SignedReceipt = serde_json::from_slice(raw)?;
|
||||
let key = hex::decode(&binding.public_key_hex)?;
|
||||
ensure!(
|
||||
key.len() == 32
|
||||
&& r.signature.len() == 64
|
||||
&& DalekVerifier.verify(&key, &r.payload, &r.signature)?,
|
||||
"ALIGN_RECEIPT_SIGNATURE"
|
||||
);
|
||||
Ok(r)
|
||||
}
|
||||
fn original(
|
||||
local: &Local<'_>,
|
||||
id: Uuid,
|
||||
expected: Uuid,
|
||||
cp: u64,
|
||||
hcp: u64,
|
||||
) -> Result<(Vec<u8>, SignedDecision)> {
|
||||
let (raw, envelope, response): (Vec<u8>, Vec<u8>, Vec<u8>) = local.agent.query_row(
|
||||
"SELECT request,envelope,response FROM reconcile_requests WHERE id=?1 AND generation=205",
|
||||
[id.to_string()],
|
||||
|r| Ok((r.get(0)?, r.get(1)?, r.get(2)?)),
|
||||
)?;
|
||||
ensure!(
|
||||
raw.len() <= 65536 && response.len() <= 131072 && envelope.len() <= 131072,
|
||||
"ALIGN_ORIGINAL_LIMIT"
|
||||
);
|
||||
let request = SyncRequest::decode(raw.as_slice())?;
|
||||
let env = Envelope::decode(envelope.as_slice())?;
|
||||
let reply = SyncResponse::decode(response.as_slice())?;
|
||||
ensure!(
|
||||
request.encode_to_vec() == raw
|
||||
&& env.encode_to_vec() == envelope
|
||||
&& reply.encode_to_vec() == response
|
||||
&& rmm_protocol::valid_envelope(&env, &local.binding.agent_id.to_string(), 205)
|
||||
&& env.boot_id == dto::BOOT.to_string()
|
||||
&& env.sequence == cp
|
||||
&& env.payload == Some(Payload::SyncRequest(request.clone())),
|
||||
"ALIGN_ORIGINAL_ENVELOPE"
|
||||
);
|
||||
let historical: rmm_domain::reconciliation::ReconcileDecisionPayload =
|
||||
serde_json::from_slice(&reply.decision_bytes)?;
|
||||
for binding in [local.binding, local.helper_binding] {
|
||||
let d = verify_response_with(
|
||||
&DalekVerifier,
|
||||
binding,
|
||||
&request,
|
||||
&Channel {
|
||||
connection_generation: 205,
|
||||
boot_id: dto::BOOT,
|
||||
},
|
||||
&reply,
|
||||
historical.issued_at,
|
||||
)?;
|
||||
ensure!(
|
||||
d.decision_id == expected
|
||||
&& d.request_id == id
|
||||
&& d.checkpoint == cp
|
||||
&& d.helper_checkpoint == hcp
|
||||
&& request.checkpoint == cp
|
||||
&& request.helper_checkpoint == hcp
|
||||
&& request.journal_complete
|
||||
&& request.assignment_version == 1,
|
||||
"ALIGN_ORIGINAL_BINDING"
|
||||
);
|
||||
}
|
||||
let consumed: Vec<u8> = local
|
||||
.consumption
|
||||
.query_row(
|
||||
"SELECT response FROM reconcile_consumption WHERE decision_id=?1",
|
||||
[expected.to_string()],
|
||||
|r| r.get(0),
|
||||
)
|
||||
.context("ALIGN_ORIGINAL_CONSUMPTION_REPLY_ROW")?;
|
||||
ensure!(consumed == response, "ALIGN_CONSUMPTION_ORIGINAL_REPLY");
|
||||
let captured: Vec<u8> = local
|
||||
.helper
|
||||
.query_row(
|
||||
"SELECT snapshot FROM helper_sync_captures WHERE checkpoint=?1",
|
||||
[hcp],
|
||||
|r| r.get(0),
|
||||
)
|
||||
.context("ALIGN_ORIGINAL_HELPER_CAPTURE_ROW")?;
|
||||
let capture: Snapshot = serde_json::from_slice(&captured)?;
|
||||
let current_helper: String = local.helper.query_row(
|
||||
"SELECT journal_id FROM helper_sync_meta WHERE id=1",
|
||||
[],
|
||||
|r| r.get(0),
|
||||
)?;
|
||||
let current_agent: String = local.agent.query_row(
|
||||
"SELECT journal_id FROM reconcile_meta WHERE id=1",
|
||||
[],
|
||||
|r| r.get(0),
|
||||
)?;
|
||||
ensure!(
|
||||
request.helper_journal_id == current_helper
|
||||
&& request.journal_id == current_agent
|
||||
&& capture.journal_id.to_string() == current_helper,
|
||||
"ALIGN_ORIGINAL_JOURNAL_IDENTITIES"
|
||||
);
|
||||
ensure!(
|
||||
capture.checkpoint == hcp
|
||||
&& capture.boot_id == dto::BOOT
|
||||
&& capture.captured_at <= historical.issued_at
|
||||
&& capture.attempts.is_empty()
|
||||
&& capture
|
||||
.previous_decision_id
|
||||
.map(|v| v.to_string())
|
||||
.unwrap_or_default()
|
||||
== request.helper_previous_decision_id,
|
||||
"ALIGN_ORIGINAL_HELPER_CAPTURE"
|
||||
);
|
||||
ensure!(
|
||||
[dto::ECHO_JOB, dto::EXPIRED_JOB].iter().all(|id| request
|
||||
.attempts
|
||||
.iter()
|
||||
.filter(|a| a.job_id == id.to_string())
|
||||
.count()
|
||||
== 1),
|
||||
"ALIGN_EXACT_ATTEMPT_SET"
|
||||
);
|
||||
ensure!(
|
||||
request.attempts.len() == 2
|
||||
&& request
|
||||
.attempts
|
||||
.iter()
|
||||
.all(|a| (a.job_id == dto::ECHO_JOB.to_string()
|
||||
&& a.attempt_id == dto::ECHO_ATTEMPT.to_string()
|
||||
&& a.state == "succeeded"
|
||||
&& a.consumption == "consumed")
|
||||
|| (a.job_id == dto::EXPIRED_JOB.to_string()
|
||||
&& a.attempt_id == dto::EXPIRED_ATTEMPT.to_string()
|
||||
&& a.grant_id.is_empty()
|
||||
&& a.consumption == "unconsumed"
|
||||
&& a.outcome_bytes.is_empty())),
|
||||
"ALIGN_ONLY_ORIGINAL_JOB_HISTORY"
|
||||
);
|
||||
Ok((
|
||||
raw,
|
||||
SignedDecision {
|
||||
decision_bytes: reply.decision_bytes,
|
||||
signature: reply.signature,
|
||||
},
|
||||
))
|
||||
}
|
||||
pub fn witness(local: &Local<'_>, guard: &impl ClosedPairGuard) -> Result<Witness> {
|
||||
guard.check()?;
|
||||
ensure!(guard.boot()? == dto::BOOT, "ALIGN_BOOT");
|
||||
let binding_sha256 = hash(&serde_json::to_vec(local.binding)?);
|
||||
let helper_binding_sha256 = hash(&serde_json::to_vec(local.helper_binding)?);
|
||||
ensure!(
|
||||
binding_sha256 == helper_binding_sha256,
|
||||
"ALIGN_INDEPENDENT_DEVICE_IDENTITY"
|
||||
);
|
||||
let(agent_journal,helper_journal,hcp):(String,String,u64)=local.agent.query_row("SELECT journal_id,helper_id,helper_checkpoint FROM reconcile_meta WHERE id=1 AND generation=205 AND checkpoint=10137 AND last_decision=?1 AND pending_request IS NULL AND fault IS NULL",[dto::SECOND.to_string()],|r|Ok((r.get(0)?,r.get(1)?,r.get(2)?)))?;
|
||||
ensure!(hcp == 135, "ALIGN_AGENT_HELPER_REFERENCE");
|
||||
let helper_cp:u64=local.helper.query_row("SELECT checkpoint FROM helper_sync_meta WHERE id=1 AND generation=205 AND journal_id=?1 AND last_decision=?2 AND agent_journal_id=?3 AND agent_checkpoint=10135 AND fault IS NULL",params![helper_journal,dto::FIRST.to_string(),agent_journal],|r|r.get(0))?;
|
||||
ensure!(
|
||||
number(
|
||||
local.intents,
|
||||
"SELECT (SELECT count(*) FROM system_intents)+(SELECT count(*) FROM system_intent_mirrors)+(SELECT count(*) FROM system_intent_denial_resumes)"
|
||||
)? == 0,
|
||||
"ALIGN_NO_SYSTEM_DELEGATION_HISTORY"
|
||||
);
|
||||
let counts = Counts {
|
||||
agent_jobs: number(local.agent, "SELECT count(*) FROM job_attempts")?,
|
||||
agent_consumed: number(local.consumption, "SELECT count(*) FROM consumed")?,
|
||||
agent_starts: number(local.consumption, "SELECT count(*) FROM execution_evidence")?,
|
||||
agent_outcomes: number(
|
||||
local.consumption,
|
||||
"SELECT count(*) FROM execution_evidence WHERE outcome IS NOT NULL",
|
||||
)?,
|
||||
helper_consumed: number(local.helper, "SELECT count(*) FROM consumed")?,
|
||||
helper_starts: number(local.helper, "SELECT count(*) FROM execution_evidence")?,
|
||||
helper_outcomes: number(
|
||||
local.helper,
|
||||
"SELECT count(*) FROM execution_evidence WHERE outcome IS NOT NULL",
|
||||
)?,
|
||||
system_intents: number(local.intents, "SELECT count(*) FROM system_intents")?,
|
||||
};
|
||||
let (first_req, first) = original(local, dto::FIRST_REQUEST, dto::FIRST, 10135, 134)
|
||||
.context("ALIGN_FIRST_ORIGINAL")?;
|
||||
let (second_req, second) = original(local, dto::SECOND_REQUEST, dto::SECOND, 10137, 135)
|
||||
.context("ALIGN_SECOND_ORIGINAL")?;
|
||||
let second_request = SyncRequest::decode(second_req.as_slice())?;
|
||||
ensure!(
|
||||
second_request.previous_decision_id == dto::FIRST.to_string()
|
||||
&& second_request.helper_previous_decision_id == dto::FIRST.to_string(),
|
||||
"ALIGN_EXACT_PREDECESSOR"
|
||||
);
|
||||
let(hraw,hrequest):(Vec<u8>,Vec<u8>)=local.helper.query_row("SELECT response,request FROM helper_sync_decisions WHERE decision_id=?1 AND checkpoint=134",[dto::FIRST.to_string()],|r|Ok((r.get(0)?,r.get(1)?)))?;
|
||||
let stored: SignedResponse = serde_json::from_slice(&hraw)?;
|
||||
ensure!(
|
||||
stored.decision_bytes == first.decision_bytes
|
||||
&& stored.signature == first.signature
|
||||
&& hrequest == first_req
|
||||
&& number(
|
||||
local.helper,
|
||||
"SELECT count(*) FROM helper_sync_decisions WHERE decision_id='2af359c5-5b5c-4992-b445-1c00e271a288'"
|
||||
)? == 0,
|
||||
"ALIGN_HELPER_EXACT_CONTROL_GAP"
|
||||
);
|
||||
ensure!(
|
||||
number(
|
||||
local.helper,
|
||||
"SELECT count(*) FROM sqlite_schema WHERE type='trigger' AND tbl_name IN ('helper_sync_meta','helper_sync_decisions')"
|
||||
)? == 0,
|
||||
"ALIGN_UNEXPECTED_CONTROL_TRIGGER"
|
||||
);
|
||||
helper_reconcile::verify_checkpoint_repair_history_with(
|
||||
local.helper,
|
||||
local.helper_binding,
|
||||
None,
|
||||
HelperIdentity::System,
|
||||
&DalekVerifier,
|
||||
)?;
|
||||
let (echo_offer, state, grant): (Vec<u8>, String, String) = local.agent.query_row(
|
||||
"SELECT offer,state,grant_id FROM job_attempts WHERE job=?1 AND attempt=?2",
|
||||
params![dto::ECHO_JOB.to_string(), dto::ECHO_ATTEMPT.to_string()],
|
||||
|r| Ok((r.get(0)?, r.get(1)?, r.get(2)?)),
|
||||
)?;
|
||||
ensure!(
|
||||
state == "succeeded" && !grant.is_empty(),
|
||||
"ALIGN_ECHO_STATE"
|
||||
);
|
||||
let(echo_start,echo_outcome,echo_result):(Vec<u8>,Vec<u8>,Vec<u8>)=local.consumption.query_row("SELECT e.start,e.outcome,c.result FROM execution_evidence e JOIN consumed c USING(grant_id) WHERE c.grant_id=?1 AND c.job=?2 AND c.attempt=?3",params![grant,dto::ECHO_JOB.to_string(),dto::ECHO_ATTEMPT.to_string()],|r|Ok((r.get(0)?,r.get(1)?,r.get(2)?)))?;
|
||||
let echo_completion_receipt: Vec<u8> = local.agent.query_row(
|
||||
"SELECT original_receipt FROM windows_echo_scope_completion WHERE id=1",
|
||||
[],
|
||||
|r| r.get(0),
|
||||
)?;
|
||||
let completion = signed(local.binding, &echo_completion_receipt)?;
|
||||
signed(local.helper_binding, &echo_completion_receipt)?;
|
||||
let completed: windows_echo_completion::Receipt = serde_json::from_slice(&completion.payload)?;
|
||||
ensure!(
|
||||
completed.valid(completed.issued_at),
|
||||
"ALIGN_COMPLETION_HISTORY"
|
||||
);
|
||||
let offer = JobOffer::decode(echo_offer.as_slice())?;
|
||||
let job: JobPayload = local.binding.job(&offer.payload_bytes)?;
|
||||
let start: Value = serde_json::from_slice(&echo_start)?;
|
||||
let request: Request = serde_json::from_value(start["request"].clone())?;
|
||||
let permit: ExecutionPermitPayload = serde_json::from_slice(&request.permit_bytes)?;
|
||||
for b in [local.binding, local.helper_binding] {
|
||||
b.verify_with(&request, permit.not_before, &DalekVerifier)?;
|
||||
}
|
||||
let outcome: Value = serde_json::from_slice(&echo_outcome)?;
|
||||
let reserved: DateTime<Utc> = serde_json::from_value(start["reserved_at"].clone())?;
|
||||
ensure!(
|
||||
completed.witness.boot_id == dto::BOOT
|
||||
&& start["previous_boot_id"] == dto::BOOT.to_string()
|
||||
&& reserved >= permit.not_before
|
||||
&& reserved < permit.start_before
|
||||
&& start["reauthentication_required"] == true
|
||||
&& start["postconditions_passed"] == false,
|
||||
"ALIGN_ORIGINAL_ECHO_START"
|
||||
);
|
||||
ensure!(
|
||||
completed.witness.scope.matches_job(&job)
|
||||
&& request.job_bytes == offer.payload_bytes
|
||||
&& permit.grant_id.to_string() == grant
|
||||
&& hash(&request.permit_bytes) == completed.witness.grant_payload_sha256
|
||||
&& hash(&request.signature) == completed.witness.grant_signature_sha256
|
||||
&& inventory_sha256(&outcome)? == completed.witness.outcome_sha256
|
||||
&& outcome == serde_json::from_slice::<Value>(&echo_result)?
|
||||
&& windows_echo_completion::successful_outcome(&outcome),
|
||||
"ALIGN_ORIGINAL_ECHO_EVIDENCE"
|
||||
);
|
||||
let (expired_offer, expired, expired_grant): (Vec<u8>, String, String) =
|
||||
local.agent.query_row(
|
||||
"SELECT offer,state,grant_id FROM job_attempts WHERE job=?1 AND attempt=?2",
|
||||
params![
|
||||
dto::EXPIRED_JOB.to_string(),
|
||||
dto::EXPIRED_ATTEMPT.to_string()
|
||||
],
|
||||
|r| Ok((r.get(0)?, r.get(1)?, r.get(2)?)),
|
||||
)?;
|
||||
ensure!(
|
||||
expired == "expired" && expired_grant.is_empty(),
|
||||
"ALIGN_EXPIRED_NO_GRANT"
|
||||
);
|
||||
let expired = JobOffer::decode(expired_offer.as_slice())?;
|
||||
let payload = local.binding.job(&expired.payload_bytes)?;
|
||||
ensure!(
|
||||
payload.job_id == dto::EXPIRED_JOB
|
||||
&& payload.attempt_id == dto::EXPIRED_ATTEMPT
|
||||
&& expired.job_payload_hash == hash(&expired.payload_bytes),
|
||||
"ALIGN_EXPIRED_ORIGINAL_OFFER"
|
||||
);
|
||||
ensure!(
|
||||
number(local.agent, "SELECT count(*) FROM events")? == 0
|
||||
&& number(local.agent, "SELECT count(*) FROM job_events")? == 0,
|
||||
"ALIGN_NO_PENDING_EVENTS"
|
||||
);
|
||||
let w = Witness {
|
||||
schema_version: 1,
|
||||
tenant_id: local.binding.tenant_id,
|
||||
asset_id: local.binding.asset_id,
|
||||
agent_id: local.binding.agent_id,
|
||||
enrollment_generation: local.binding.enrollment_generation,
|
||||
assignment_version: local.binding.assignment_version,
|
||||
boot_id: guard.boot()?,
|
||||
connection_generation: 205,
|
||||
agent_journal_id: Uuid::parse_str(&agent_journal)?,
|
||||
helper_journal_id: Uuid::parse_str(&helper_journal)?,
|
||||
agent_checkpoint: 10137,
|
||||
helper_checkpoint: helper_cp,
|
||||
agent_last_decision: dto::SECOND,
|
||||
helper_last_decision: dto::FIRST,
|
||||
verification_key_id: hash(&hex::decode(&local.binding.public_key_hex)?),
|
||||
verification_public_key_hex: local.binding.public_key_hex.clone(),
|
||||
binding_sha256,
|
||||
helper_binding_sha256,
|
||||
files: guard.files()?,
|
||||
agent_inventory_sha256: inventory(local.agent, &[]).context("ALIGN_AGENT_INVENTORY")?,
|
||||
consumption_inventory_sha256: inventory(local.consumption, &[])
|
||||
.context("ALIGN_CONSUMPTION_INVENTORY")?,
|
||||
helper_inventory_sha256: inventory(local.helper, &[]).context("ALIGN_HELPER_INVENTORY")?,
|
||||
counts,
|
||||
original_requests: [first_req, second_req],
|
||||
original_responses: [first, second],
|
||||
echo_offer,
|
||||
echo_start,
|
||||
echo_outcome,
|
||||
echo_result,
|
||||
echo_completion_receipt,
|
||||
expired_offer,
|
||||
};
|
||||
ensure!(w.valid(), "ALIGN_WITNESS_PROFILE");
|
||||
guard.check()?;
|
||||
Ok(w)
|
||||
}
|
||||
/// Caller must keep both original process lifetime locks and all file identities
|
||||
/// held for the complete transaction. A UI receipt is never an execution grant.
|
||||
pub fn apply(
|
||||
local: &Local<'_>,
|
||||
helper: &mut Connection,
|
||||
guard: &impl ClosedPairGuard,
|
||||
raw: &[u8],
|
||||
now: DateTime<Utc>,
|
||||
) -> Result<()> {
|
||||
let signed_receipt = signed(local.binding, raw)?;
|
||||
signed(local.helper_binding, raw)?;
|
||||
let receipt: Receipt = serde_json::from_slice(&signed_receipt.payload)?;
|
||||
ensure!(receipt.valid(now), "ALIGN_FRESH_CLOSED_UI_RECEIPT");
|
||||
let tx = helper.transaction_with_behavior(TransactionBehavior::Immediate)?;
|
||||
let current = Local {
|
||||
agent: local.agent,
|
||||
consumption: local.consumption,
|
||||
helper: &tx,
|
||||
intents: local.intents,
|
||||
binding: local.binding,
|
||||
helper_binding: local.helper_binding,
|
||||
};
|
||||
ensure!(
|
||||
witness(¤t, guard)? == receipt.witness,
|
||||
"ALIGN_UI_WITNESS_CHANGED"
|
||||
);
|
||||
let untouched = inventory(&tx, &["helper_sync_decisions", "helper_sync_meta", TABLE])?;
|
||||
tx.execute(DDL, [])?;
|
||||
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 {
|
||||
""
|
||||
};
|
||||
tx.execute_batch(&format!("CREATE TRIGGER windows_alignment_205_{name} BEFORE {kind} ON {TABLE}{condition} BEGIN SELECT RAISE(ABORT,'WINDOWS_ALIGNMENT_205_IMMUTABLE'); END"))?;
|
||||
}
|
||||
let response = &receipt.witness.original_responses[1];
|
||||
let request = &receipt.witness.original_requests[1];
|
||||
let fingerprint: String = tx.query_row(
|
||||
"SELECT fingerprint FROM helper_sync_captures WHERE checkpoint=135",
|
||||
[],
|
||||
|r| r.get(0),
|
||||
)?;
|
||||
ensure!(
|
||||
fingerprint == helper_reconcile::ledger_fingerprint(&tx)?,
|
||||
"ALIGN_ORIGINAL_LEDGER_UNCHANGED"
|
||||
);
|
||||
tx.execute("INSERT INTO helper_sync_decisions(decision_id,checkpoint,response,request,fingerprint) VALUES(?1,135,?2,?3,?4)",params![dto::SECOND.to_string(),serde_json::to_vec(&SignedResponse{decision_bytes:response.decision_bytes.clone(),signature:response.signature.clone()})?,request,fingerprint])?;
|
||||
ensure!(tx.execute("UPDATE helper_sync_meta SET last_decision=?1,agent_checkpoint=10137 WHERE id=1 AND checkpoint=?2 AND generation=205 AND last_decision=?3 AND agent_checkpoint=10135 AND fault IS NULL",params![dto::SECOND.to_string(),receipt.witness.helper_checkpoint,dto::FIRST.to_string()])?==1,"ALIGN_HELPER_HEAD_CAS");
|
||||
tx.execute(
|
||||
"INSERT INTO windows_sync_admin_closed_alignment_205 VALUES(1,?1,?2,?3,?4,0,0,0)",
|
||||
params![
|
||||
receipt.receipt_id.to_string(),
|
||||
raw,
|
||||
receipt.witness_sha256,
|
||||
now.to_rfc3339()
|
||||
],
|
||||
)?;
|
||||
ensure!(tx.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![receipt.witness.helper_journal_id.to_string(),receipt.witness.helper_checkpoint,dto::SECOND.to_string(),receipt.witness.agent_journal_id.to_string()],|r|r.get::<_,bool>(0))?,"ALIGN_ONLY_FORWARD_HEAD_FIELDS");
|
||||
ensure!(
|
||||
inventory(&tx, &["helper_sync_decisions", "helper_sync_meta", TABLE])? == untouched
|
||||
&& inventory(local.agent, &[])? == receipt.witness.agent_inventory_sha256
|
||||
&& inventory(local.consumption, &[])? == receipt.witness.consumption_inventory_sha256,
|
||||
"ALIGN_UNRELATED_HISTORY_CHANGED"
|
||||
);
|
||||
helper_reconcile::verify_checkpoint_repair_history_with(
|
||||
&tx,
|
||||
local.helper_binding,
|
||||
None,
|
||||
HelperIdentity::System,
|
||||
&DalekVerifier,
|
||||
)?;
|
||||
guard.check()?;
|
||||
ensure!(
|
||||
receipt.valid(Utc::now()),
|
||||
"ALIGN_RECEIPT_EXPIRED_BEFORE_COMMIT"
|
||||
);
|
||||
tx.commit()?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,474 @@
|
||||
//! Explicit G205 bootstrap operator. No service stop/start, job, enrollment,
|
||||
//! configuration rewrite, clock bootstrap or normal HelperSync::apply.
|
||||
#[cfg(all(windows, feature = "system-helper"))]
|
||||
mod platform {
|
||||
use anyhow::{Context, Result, ensure};
|
||||
use fs2::FileExt;
|
||||
use rmm_agent_core::{
|
||||
auth::Binding,
|
||||
windows_sync_alignment::{self as recovery, ClosedPairGuard, Local},
|
||||
};
|
||||
use rmm_agent_windows::{
|
||||
SERVICE_NAME,
|
||||
helper_ipc::{self as ipc, PinnedFile},
|
||||
helper_runtime::intent,
|
||||
helper_system, native,
|
||||
};
|
||||
use rmm_domain::{
|
||||
jobs::hash,
|
||||
windows_sync_alignment::{BOOT, FILE_ROLES, NativeFile},
|
||||
};
|
||||
use rusqlite::{Connection, OpenFlags};
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
fs::{File, OpenOptions},
|
||||
io::{Read, Seek, SeekFrom},
|
||||
os::windows::{fs::OpenOptionsExt, io::AsRawHandle},
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
use uuid::Uuid;
|
||||
use windows_sys::Win32::{Security::*, Storage::FileSystem::*, System::Services::*};
|
||||
static PHASE: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
|
||||
fn phase(value: usize) {
|
||||
PHASE.store(value, std::sync::atomic::Ordering::Relaxed);
|
||||
}
|
||||
pub fn diagnostic(error: &anyhow::Error) -> serde_json::Value {
|
||||
let phases = [
|
||||
"arguments",
|
||||
"admin_and_stopped",
|
||||
"public_binding",
|
||||
"helper_settings",
|
||||
"lifetime_locks",
|
||||
"intent_acl",
|
||||
"held_file_ids",
|
||||
"boot_measurement",
|
||||
"intent_empty_snapshot",
|
||||
"journal_open",
|
||||
"original_identity_rows",
|
||||
"witness_or_apply",
|
||||
];
|
||||
let codes = error
|
||||
.chain()
|
||||
.filter_map(|cause| {
|
||||
let text = cause.to_string();
|
||||
(text.len() <= 96
|
||||
&& !text.is_empty()
|
||||
&& text
|
||||
.bytes()
|
||||
.all(|b| b.is_ascii_uppercase() || b.is_ascii_digit() || b == b'_'))
|
||||
.then_some(text)
|
||||
})
|
||||
.take(8)
|
||||
.collect::<Vec<_>>();
|
||||
let mut data = serde_json::json!({"schema_version":1,"diagnostic_only":true,"phase":phases.get(PHASE.load(std::sync::atomic::Ordering::Relaxed)).unwrap_or(&"unknown"),"codes":codes});
|
||||
for cause in error.chain() {
|
||||
if let Some(sql) = cause.downcast_ref::<rusqlite::Error>() {
|
||||
data["sqlite"] = match sql {
|
||||
rusqlite::Error::SqliteFailure(code, _) => {
|
||||
serde_json::json!({"code":"SQLITE_FAILURE","sqlite_code":format!("{:?}",code.code),"extended_code":code.extended_code})
|
||||
}
|
||||
rusqlite::Error::QueryReturnedNoRows => {
|
||||
serde_json::json!({"code":"SQLITE_NO_ROWS"})
|
||||
}
|
||||
rusqlite::Error::InvalidColumnType(index, name, _) => {
|
||||
serde_json::json!({"code":"SQLITE_COLUMN_TYPE","index":index,"column":if name.len()<=48&&name.bytes().all(|b|b.is_ascii_alphanumeric()||b==b'_'){name.as_str()}else{"redacted"}})
|
||||
}
|
||||
_ => serde_json::json!({"code":"SQLITE_READ_FAILED"}),
|
||||
};
|
||||
break;
|
||||
}
|
||||
if let Some(codec) = cause.downcast_ref::<serde_json::Error>() {
|
||||
data["codec"] = serde_json::json!({"code":"JSON_CODEC","line":codec.line(),"column":codec.column()});
|
||||
}
|
||||
if let Some(io) = cause.downcast_ref::<std::io::Error>() {
|
||||
data["io"] = serde_json::json!({"kind":format!("{:?}",io.kind()),"os_code":io.raw_os_error()});
|
||||
}
|
||||
}
|
||||
data
|
||||
}
|
||||
const ROOT: &str = r"C:\ProgramData\RustDiscovery";
|
||||
const STATE: &str = r"C:\ProgramData\RustDiscovery\state";
|
||||
const RECEIPT: &str = r"C:\ProgramData\RustDiscoveryBootstrap\windows-sync-alignment-205.json";
|
||||
const PATHS: [&str; 6] = [
|
||||
r"C:\ProgramData\RustDiscovery\state\telemetry.sqlite",
|
||||
r"C:\ProgramData\RustDiscovery\state\consumption.sqlite",
|
||||
r"C:\ProgramData\RustDiscovery\state\agent.lock",
|
||||
r"C:\ProgramData\RustDiscoverySystem\state\ledger.sqlite",
|
||||
r"C:\ProgramData\RustDiscoverySystem\state\executor.lock",
|
||||
intent::DB,
|
||||
];
|
||||
struct Sc(SC_HANDLE);
|
||||
impl Drop for Sc {
|
||||
fn drop(&mut self) {
|
||||
unsafe { CloseServiceHandle(self.0) };
|
||||
}
|
||||
}
|
||||
fn stopped(name: &str) -> Result<()> {
|
||||
let manager =
|
||||
Sc(unsafe { OpenSCManagerW(std::ptr::null(), std::ptr::null(), SC_MANAGER_CONNECT) });
|
||||
ensure!(!manager.0.is_null(), "ALIGN_SCM_MANAGER");
|
||||
let wide = name.encode_utf16().chain(Some(0)).collect::<Vec<_>>();
|
||||
let service = Sc(unsafe { OpenServiceW(manager.0, wide.as_ptr(), SERVICE_QUERY_STATUS) });
|
||||
ensure!(!service.0.is_null(), "ALIGN_SCM_SERVICE");
|
||||
let mut status: SERVICE_STATUS_PROCESS = unsafe { std::mem::zeroed() };
|
||||
let mut size = 0;
|
||||
ensure!(
|
||||
unsafe {
|
||||
QueryServiceStatusEx(
|
||||
service.0,
|
||||
SC_STATUS_PROCESS_INFO,
|
||||
(&mut status as *mut SERVICE_STATUS_PROCESS).cast(),
|
||||
std::mem::size_of::<SERVICE_STATUS_PROCESS>() as u32,
|
||||
&mut size,
|
||||
)
|
||||
} != 0
|
||||
&& status.dwCurrentState == SERVICE_STOPPED
|
||||
&& status.dwProcessId == 0,
|
||||
"ALIGN_BOTH_SERVICES_MUST_BE_STOPPED"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
fn both() -> Result<()> {
|
||||
stopped(SERVICE_NAME)?;
|
||||
stopped(ipc::HELPER_SERVICE)
|
||||
}
|
||||
fn admin() -> Result<()> {
|
||||
let mut sid = [0usize; 16];
|
||||
let mut len = std::mem::size_of_val(&sid) as u32;
|
||||
let mut member = 0;
|
||||
ensure!(
|
||||
unsafe {
|
||||
CreateWellKnownSid(
|
||||
WinBuiltinAdministratorsSid,
|
||||
std::ptr::null_mut(),
|
||||
sid.as_mut_ptr().cast(),
|
||||
&mut len,
|
||||
)
|
||||
} != 0
|
||||
&& unsafe {
|
||||
CheckTokenMembership(std::ptr::null_mut(), sid.as_mut_ptr().cast(), &mut member)
|
||||
} != 0
|
||||
&& member != 0,
|
||||
"ALIGN_ADMINISTRATOR_REQUIRED"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
fn leaf(path: &Path) -> Result<File> {
|
||||
for parent in path.ancestors() {
|
||||
ensure!(
|
||||
std::os::windows::fs::MetadataExt::file_attributes(&parent.symlink_metadata()?)
|
||||
& FILE_ATTRIBUTE_REPARSE_POINT
|
||||
== 0,
|
||||
"ALIGN_NO_REPARSE"
|
||||
);
|
||||
}
|
||||
let file = OpenOptions::new()
|
||||
.read(true)
|
||||
.share_mode(FILE_SHARE_READ | FILE_SHARE_WRITE)
|
||||
.custom_flags(FILE_FLAG_OPEN_REPARSE_POINT)
|
||||
.open(path)?;
|
||||
native_id(&file)?;
|
||||
Ok(file)
|
||||
}
|
||||
fn native_id(file: &File) -> Result<[u32; 3]> {
|
||||
let mut i: BY_HANDLE_FILE_INFORMATION = unsafe { std::mem::zeroed() };
|
||||
ensure!(
|
||||
unsafe { GetFileInformationByHandle(file.as_raw_handle(), &mut i) } != 0
|
||||
&& i.nNumberOfLinks == 1
|
||||
&& i.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_REPARSE_POINT)
|
||||
== 0,
|
||||
"ALIGN_FILE_ID"
|
||||
);
|
||||
Ok([i.dwVolumeSerialNumber, i.nFileIndexHigh, i.nFileIndexLow])
|
||||
}
|
||||
fn bytes(mut file: &File, max: u64) -> Result<Vec<u8>> {
|
||||
ensure!(file.metadata()?.len() <= max, "ALIGN_FILE_LIMIT");
|
||||
file.seek(SeekFrom::Start(0))?;
|
||||
let mut data = vec![];
|
||||
file.take(max + 1).read_to_end(&mut data)?;
|
||||
ensure!(data.len() as u64 <= max, "ALIGN_FILE_CHANGED");
|
||||
Ok(data)
|
||||
}
|
||||
struct Held {
|
||||
path: PathBuf,
|
||||
file: File,
|
||||
id: ipc::FileIdentity,
|
||||
legacy: [u32; 3],
|
||||
}
|
||||
struct Guard {
|
||||
held: Vec<Held>,
|
||||
_locks: Vec<File>,
|
||||
_settings: RefCell<Vec<PinnedFile>>,
|
||||
_public: RefCell<Vec<PinnedFile>>,
|
||||
boot: Uuid,
|
||||
intents: RefCell<intent::Store>,
|
||||
}
|
||||
impl ClosedPairGuard for Guard {
|
||||
fn check(&self) -> Result<()> {
|
||||
both()?;
|
||||
self.intents.borrow_mut().check()?;
|
||||
for file in self
|
||||
._settings
|
||||
.borrow_mut()
|
||||
.iter_mut()
|
||||
.chain(self._public.borrow_mut().iter_mut())
|
||||
{
|
||||
file.check()?;
|
||||
}
|
||||
ensure!(
|
||||
ipc::file_identity(&self._locks[0])? == self.held[2].id
|
||||
&& ipc::file_identity(&self._locks[1])? == self.held[4].id,
|
||||
"ALIGN_ORIGINAL_LOCK_OWNER_HANDLES"
|
||||
);
|
||||
for h in &self.held {
|
||||
ensure!(
|
||||
ipc::file_identity(&h.file)? == h.id
|
||||
&& native_id(&h.file)? == h.legacy
|
||||
&& ipc::file_identity(&leaf(&h.path)?)? == h.id,
|
||||
"ALIGN_ORIGINAL_FILE_REPLACED"
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn files(&self) -> Result<[NativeFile; 6]> {
|
||||
self.check()?;
|
||||
let mut out = vec![];
|
||||
for (index, (h, role)) in self.held.iter().zip(FILE_ROLES).enumerate() {
|
||||
// Read a lifetime lock ONLY through the original HANDLE that
|
||||
// owns its LockFileEx range; a second handle is correctly denied.
|
||||
let f = match index {
|
||||
2 => &self._locks[0],
|
||||
4 => &self._locks[1],
|
||||
_ => &h.file,
|
||||
};
|
||||
out.push(NativeFile {
|
||||
role: role.into(),
|
||||
file_id: Some(h.legacy),
|
||||
sha256: Some(hash(&bytes(f, 256 * 1024 * 1024).context(match index {
|
||||
0 => "ALIGN_HASH_TELEMETRY",
|
||||
1 => "ALIGN_HASH_CONSUMPTION",
|
||||
2 => "ALIGN_HASH_AGENT_LOCK",
|
||||
3 => "ALIGN_HASH_HELPER_LEDGER",
|
||||
4 => "ALIGN_HASH_HELPER_LOCK",
|
||||
_ => "ALIGN_HASH_SYSTEM_INTENTS",
|
||||
})?)),
|
||||
});
|
||||
}
|
||||
out.try_into()
|
||||
.map_err(|_| anyhow::anyhow!("ALIGN_FILE_COUNT"))
|
||||
}
|
||||
fn boot(&self) -> Result<Uuid> {
|
||||
Ok(self.boot)
|
||||
}
|
||||
}
|
||||
struct Db {
|
||||
db: Connection,
|
||||
_held: Vec<File>,
|
||||
}
|
||||
impl Db {
|
||||
fn open(path: &str, write: bool) -> Result<Self> {
|
||||
let mut file = leaf(Path::new(path))?;
|
||||
let mut header = [0; 20];
|
||||
file.read_exact(&mut header)?;
|
||||
ensure!(
|
||||
header.starts_with(b"SQLite format 3\0")
|
||||
&& header[18] == header[19]
|
||||
&& matches!(header[18], 1 | 2),
|
||||
"ALIGN_SQLITE_HEADER"
|
||||
);
|
||||
let mut held = vec![file];
|
||||
let mut wal = false;
|
||||
let mut shm = false;
|
||||
let mut journal = false;
|
||||
for (suffix, present) in [
|
||||
("-wal", &mut wal),
|
||||
("-shm", &mut shm),
|
||||
("-journal", &mut journal),
|
||||
] {
|
||||
let p = format!("{path}{suffix}");
|
||||
if Path::new(&p).try_exists()? {
|
||||
held.push(leaf(Path::new(&p))?);
|
||||
*present = true;
|
||||
}
|
||||
}
|
||||
let flags = if write {
|
||||
OpenFlags::SQLITE_OPEN_READ_WRITE
|
||||
} else {
|
||||
OpenFlags::SQLITE_OPEN_READ_ONLY
|
||||
};
|
||||
let db = if !write && header[18] == 2 && !(wal && shm) {
|
||||
ensure!(!wal && !shm && !journal, "ALIGN_ORIGINAL_WAL_INCOMPLETE");
|
||||
Connection::open_with_flags(
|
||||
format!("file:///{}?mode=ro&immutable=1", path.replace('\\', "/")),
|
||||
flags | OpenFlags::SQLITE_OPEN_URI,
|
||||
)?
|
||||
} else {
|
||||
Connection::open_with_flags(path, flags)?
|
||||
};
|
||||
db.busy_timeout(std::time::Duration::from_millis(500))?;
|
||||
Ok(Self { db, _held: held })
|
||||
}
|
||||
}
|
||||
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"),
|
||||
"ALIGN_FIXED_ARGUMENTS"
|
||||
);
|
||||
let apply = args[0] == "--apply-reviewed-receipt";
|
||||
phase(1);
|
||||
admin()?;
|
||||
both()?;
|
||||
phase(2);
|
||||
let readers = [ipc::service_sid(SERVICE_NAME)?];
|
||||
let mut public = vec![PinnedFile::open(
|
||||
Path::new(ROOT),
|
||||
true,
|
||||
&readers,
|
||||
&[],
|
||||
false,
|
||||
)?];
|
||||
let binding_file = PinnedFile::open(
|
||||
&Path::new(ROOT).join("binding.json"),
|
||||
false,
|
||||
&readers,
|
||||
&[],
|
||||
false,
|
||||
)?;
|
||||
let binding: Binding = serde_json::from_slice(&bytes(&binding_file.file, 8192)?)?;
|
||||
public.push(binding_file);
|
||||
phase(3);
|
||||
let (settings, pins) = helper_system::read_settings()?;
|
||||
ensure!(
|
||||
!settings.enable_effects && !settings.allow_reboot,
|
||||
"ALIGN_ORIGINAL_PASSIVE_HELPER_ONLY"
|
||||
);
|
||||
phase(4);
|
||||
let mut locks = vec![];
|
||||
for index in [2, 4] {
|
||||
let file = leaf(Path::new(PATHS[index]))?;
|
||||
file.try_lock_exclusive()
|
||||
.context("ALIGN_ORIGINAL_LIFETIME_LOCK_BUSY")?;
|
||||
locks.push(file);
|
||||
}
|
||||
both()?;
|
||||
native::private_path(Path::new(STATE), true)?;
|
||||
phase(5);
|
||||
let helper_writer = [ipc::service_sid(ipc::HELPER_SERVICE)?];
|
||||
let agent_writer = [ipc::service_sid(SERVICE_NAME)?];
|
||||
public.push(PinnedFile::open_read_shared(
|
||||
Path::new(intent::ROOT),
|
||||
true,
|
||||
&agent_writer,
|
||||
&[],
|
||||
)?);
|
||||
for path in [intent::DB, &format!("{}-journal", intent::DB)] {
|
||||
let proof = PinnedFile::open_read_shared(Path::new(path), false, &[], &agent_writer)?;
|
||||
public.push(proof);
|
||||
}
|
||||
phase(6);
|
||||
let mut held = vec![];
|
||||
for (index, path) in PATHS.into_iter().enumerate() {
|
||||
if matches!(index, 3 | 4) {
|
||||
let _check =
|
||||
PinnedFile::open_read_shared(Path::new(path), false, &[], &helper_writer)?;
|
||||
} else if index != 5 {
|
||||
native::private_path(Path::new(path), false)?;
|
||||
}
|
||||
let file = leaf(Path::new(path))?;
|
||||
held.push(Held {
|
||||
path: PathBuf::from(path),
|
||||
id: ipc::file_identity(&file)?,
|
||||
legacy: native_id(&file)?,
|
||||
file,
|
||||
});
|
||||
}
|
||||
phase(7);
|
||||
let boot = Uuid::parse_str(
|
||||
&tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()?
|
||||
.block_on(native::boot_id())?,
|
||||
)?;
|
||||
ensure!(boot == BOOT, "ALIGN_ORIGINAL_BOOT_REQUIRED");
|
||||
phase(8);
|
||||
let guard = Guard {
|
||||
held,
|
||||
_locks: locks,
|
||||
_settings: RefCell::new(pins),
|
||||
_public: RefCell::new(public),
|
||||
boot,
|
||||
intents: RefCell::new(intent::Store::open_empty_history_snapshot()?),
|
||||
};
|
||||
guard.check()?;
|
||||
phase(9);
|
||||
let a = Db::open(PATHS[0], false).context("ALIGN_OPEN_TELEMETRY_RO")?;
|
||||
let c = Db::open(PATHS[1], false).context("ALIGN_OPEN_CONSUMPTION_RO")?;
|
||||
let mut h = Db::open(PATHS[3], apply).context("ALIGN_OPEN_HELPER_JOURNAL")?;
|
||||
let intents = Db::open(PATHS[5], false).context("ALIGN_OPEN_INTENTS_RO")?;
|
||||
phase(10);
|
||||
let intents_identity: Vec<u8> = intents.db.query_row(
|
||||
"SELECT file_identity FROM system_intent_meta WHERE id=1",
|
||||
[],
|
||||
|r| r.get(0),
|
||||
)?;
|
||||
ensure!(
|
||||
serde_json::from_slice::<ipc::FileIdentity>(&intents_identity)? == guard.held[5].id,
|
||||
"ALIGN_ORIGINAL_INTENT_JOURNAL_IDENTITY"
|
||||
);
|
||||
let (ledger, lock, identity): (Vec<u8>, Vec<u8>, String) = h.db.query_row(
|
||||
"SELECT ledger,executor_lock,binding_sha256 FROM windows_helper_files WHERE id=1",
|
||||
[],
|
||||
|r| Ok((r.get(0)?, r.get(1)?, r.get(2)?)),
|
||||
)?;
|
||||
ensure!(
|
||||
serde_json::from_slice::<ipc::FileIdentity>(&ledger)? == guard.held[3].id
|
||||
&& serde_json::from_slice::<ipc::FileIdentity>(&lock)? == guard.held[4].id
|
||||
&& identity == ipc::binding_hash(&settings.binding)?,
|
||||
"ALIGN_HELPER_ORIGINAL_LEDGER_LOCK_IDENTITY"
|
||||
);
|
||||
phase(11);
|
||||
if apply {
|
||||
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)?;
|
||||
let local = Local {
|
||||
agent: &a.db,
|
||||
consumption: &c.db,
|
||||
helper: &helper_read.db,
|
||||
intents: &intents.db,
|
||||
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})
|
||||
);
|
||||
} else {
|
||||
let local = Local {
|
||||
agent: &a.db,
|
||||
consumption: &c.db,
|
||||
helper: &h.db,
|
||||
intents: &intents.db,
|
||||
binding: &binding,
|
||||
helper_binding: &settings.binding,
|
||||
};
|
||||
let witness = recovery::witness(&local, &guard)?;
|
||||
println!("{}", serde_json::to_string(&witness)?);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
#[cfg(all(windows, feature = "system-helper"))]
|
||||
fn main() {
|
||||
if let Err(error) = platform::run() {
|
||||
eprintln!("{}", platform::diagnostic(&error));
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
#[cfg(not(all(windows, feature = "system-helper")))]
|
||||
fn main() {
|
||||
eprintln!("Windows system-helper only");
|
||||
std::process::exit(1);
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"platform": "actual-windows-11-x86_64",
|
||||
"request_id": "84a803a4-2acc-4679-9d6d-a0db404c323a",
|
||||
"receipt_id": "5d135f00-70fd-4a6f-840c-fb65753c5805",
|
||||
"witness_sha256": "792f2f7f38a83c31cdf7f17bcd40d098df4af6f3745bf422370bd82f6ae65d16",
|
||||
"receipt_file_sha256": "b0214108fa09b91b09c9097c9fa2b561bd411f9fe88378a5509817f272616623",
|
||||
"approval_origin": "dev_test_browser_simulation",
|
||||
"testsimulation": true,
|
||||
"apply_binary_sha256": "1b095494785af558ac98ccf795f1d2689be5c621bc27f07624ab4a4c925e6125",
|
||||
"apply_exit_code": 0,
|
||||
"verifier_binary_sha256": "fea0487a4cf98dbd6e82b0f84b798c442c3d7882e39962c47e11b9517ff56f60",
|
||||
"verifier_exit_code": 0,
|
||||
"independent_read": {
|
||||
"actual_applied_at": "2026-11-16T12:30:05.460102100Z",
|
||||
"admin_archive_verified": true,
|
||||
"agent_checkpoint": 10137,
|
||||
"counts": {
|
||||
"agent_consumed": 1,
|
||||
"agent_jobs": 2,
|
||||
"agent_outcomes": 1,
|
||||
"agent_starts": 1,
|
||||
"helper_consumed": 0,
|
||||
"helper_outcomes": 0,
|
||||
"helper_starts": 0,
|
||||
"system_intents": 0
|
||||
},
|
||||
"fresh_normal_signed_sync_required": true,
|
||||
"helper_checkpoint": 201,
|
||||
"helper_last_decision": "2af359c5-5b5c-4992-b445-1c00e271a288",
|
||||
"helper_ready": false,
|
||||
"read_only": true,
|
||||
"ready": false,
|
||||
"receipt_id": "5d135f00-70fd-4a6f-840c-fb65753c5805",
|
||||
"schema_version": 1,
|
||||
"unlock": false,
|
||||
"witness_sha256": "792f2f7f38a83c31cdf7f17bcd40d098df4af6f3745bf422370bd82f6ae65d16"
|
||||
},
|
||||
"server_readback": {
|
||||
"reviews": 1,
|
||||
"receipts": 1,
|
||||
"audit": [
|
||||
{
|
||||
"event_id": "5d135f00-70fd-4a6f-840c-fb65753c5805",
|
||||
"principal": "simulated-testprincipal-a",
|
||||
"event_type": "windows_sync_admin_closed_alignment_confirmed",
|
||||
"data": {
|
||||
"ready": false,
|
||||
"unlock": false,
|
||||
"request_id": "84a803a4-2acc-4679-9d6d-a0db404c323a",
|
||||
"helper_ready": false,
|
||||
"receipt_sha256": "3a301d154251c7bd8e32b11cbd1158b7e8718454b1f39913d3e6d87abb336b46",
|
||||
"testsimulation": true,
|
||||
"witness_sha256": "792f2f7f38a83c31cdf7f17bcd40d098df4af6f3745bf422370bd82f6ae65d16",
|
||||
"approval_origin": "dev_test_browser_simulation",
|
||||
"connection_generation": 205
|
||||
}
|
||||
},
|
||||
{
|
||||
"event_id": "84a803a4-2acc-4679-9d6d-a0db404c323a",
|
||||
"principal": "simulated-testprincipal-a",
|
||||
"event_type": "windows_sync_alignment_submitted",
|
||||
"data": {
|
||||
"ready": false,
|
||||
"unlock": false,
|
||||
"helper_ready": false,
|
||||
"witness_sha256": "792f2f7f38a83c31cdf7f17bcd40d098df4af6f3745bf422370bd82f6ae65d16",
|
||||
"connection_generation": 205
|
||||
}
|
||||
}
|
||||
],
|
||||
"windows_jobs": 2,
|
||||
"windows_grants": 1,
|
||||
"windows_head": {
|
||||
"journal_id": "3dd1dfb5-d586-472a-af28-7fd4d203e90b",
|
||||
"checkpoint": 10137,
|
||||
"decision_id": "2af359c5-5b5c-4992-b445-1c00e271a288",
|
||||
"helper_journal_id": "cb4db2c6-a1b2-4fb3-be9d-1f677de0de2b",
|
||||
"helper_checkpoint": 135
|
||||
}
|
||||
},
|
||||
"product_job_created": false,
|
||||
"services_remain_stopped": true
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"actual_owner_handle_apply_binary_sha256": "1b095494785af558ac98ccf795f1d2689be5c621bc27f07624ab4a4c925e6125",
|
||||
"owner_handle_compilation_files_sha256": {
|
||||
"crates/agent-core/src/windows_sync_alignment.rs": "cf0fd593f5e84b39a6999eb4ab688cd8941a98f82fae19f264f5417f839d773f",
|
||||
"crates/agent-core/src/helper_reconcile.rs": "e7f88f71f0c85968c11789312d8fb68229a649e3fe9d6338157ac3899eacbcaf",
|
||||
"crates/agent-core/src/lib.rs": "cd8346fdb21bb052150b5902b208bb1bf95349f6330886a9363f26bd415f82fc",
|
||||
"crates/domain/src/windows_sync_alignment.rs": "cf95831893f58aaac7661673dd383c55bf30980fa0bdbb1a6b2506d3486eaa91",
|
||||
"crates/domain/src/lib.rs": "b17cb1021f6d6579e2d5d3217f1c245bde7ff6180174580a1a08931d9366734a",
|
||||
"crates/agent-windows/examples/windows_closed_alignment.rs": "f8e989084725393d5fac3b9a18e94fb40959b62161527d95feaa597079046d10"
|
||||
},
|
||||
"domain_module_export_placement_may_differ_in_later_server_snapshot": true
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"actual_platform": "windows-11-x86_64",
|
||||
"checked_at": "2026-11-16T12:09:52.7004004Z",
|
||||
"native_binary_sha256": "1b095494785af558ac98ccf795f1d2689be5c621bc27f07624ab4a4c925e6125",
|
||||
"canonical_witness_sha256": "792f2f7f38a83c31cdf7f17bcd40d098df4af6f3745bf422370bd82f6ae65d16",
|
||||
"original_receipt_sha256": "0081d73a71e08d38c25f95cc69420ac8a59da66bf5b5ae7f04e5849685685ad3",
|
||||
"witness_file_bytes": 89287,
|
||||
"connection_generation": 205,
|
||||
"agent_checkpoint": 10137,
|
||||
"helper_checkpoint": 201,
|
||||
"agent_last_decision": "2af359c5-5b5c-4992-b445-1c00e271a288",
|
||||
"helper_last_decision": "1a4758ad-0b39-449e-8551-16846851b09a",
|
||||
"counts": {
|
||||
"agent_consumed": 1,
|
||||
"agent_jobs": 2,
|
||||
"agent_outcomes": 1,
|
||||
"agent_starts": 1,
|
||||
"helper_consumed": 0,
|
||||
"helper_outcomes": 0,
|
||||
"helper_starts": 0,
|
||||
"system_intents": 0
|
||||
},
|
||||
"exit_code": 0,
|
||||
"administrative_apply_executed": false,
|
||||
"job_started": false,
|
||||
"services_remain_stopped": true
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
# Verbindung 205: tatsächlicher nativer Originalzeuge
|
||||
|
||||
Am 16. November 2026 wurde auf der Windows-Test-VM der eng auf den
|
||||
ausdrücklich genehmigten Fall 205 begrenzte native Zeuge erfolgreich erzeugt.
|
||||
Beide RMM-Dienste waren vorher normal gestoppt und die ursprünglichen Prozesse
|
||||
nachweislich beendet worden. Sie bleiben bis zum administrativen Abschluss
|
||||
gestoppt; es wurde kein neuer Hello-/Syncstand erzeugt.
|
||||
|
||||
Der Operator verifizierte die ursprünglichen Request-/Antwortsignaturen,
|
||||
beide Journalidentitäten und die ursprünglichen Datei-/Lock-IDs, die beiden
|
||||
geschützten Bindings, vollständige Inventare und die vorhandenen
|
||||
Consumption-/Start-/Outcome-Nachweise. Agentcheckpoint ist 10137,
|
||||
der tatsächliche Helpercapturecheckpoint **201**. Der Helper enthält weiterhin
|
||||
die erste, der Agent die zweite bestätigte Entscheidung. Es bestehen genau
|
||||
zwei Jobs: der einmalig erfolgreiche ursprüngliche Echojob und der abgelaufene
|
||||
Skriptjob ohne Grant. Helperwirkungen und SYSTEM-Intents sind null.
|
||||
|
||||
Der finale SDK-Hash lautet
|
||||
`1b095494785af558ac98ccf795f1d2689be5c621bc27f07624ab4a4c925e6125`;
|
||||
der kanonische Zeugenhash
|
||||
`792f2f7f38a83c31cdf7f17bcd40d098df4af6f3745bf422370bd82f6ae65d16`.
|
||||
[Zähler und genaue Ergebnisbindung](evidence/windows-sync-alignment-205-witness-20261116.json).
|
||||
|
||||
Zwei vorherige reine Lesevorbereitungen wurden korrigiert: zunächst der feste
|
||||
Pfad zum vorhandenen Intentjournal, anschließend das Lesen der Lockbytes
|
||||
über denselben bereits exklusiv gehaltenen Handle. Ein zweiter Lesehandle
|
||||
hatte korrekt einen Sharing-/Lockfehler geliefert. Weder Locks noch ACLs
|
||||
wurden abgeschwächt. Kein früherer Versuch hat den administrativen Applypfad
|
||||
aufgerufen oder Journalzeilen verändert.
|
||||
|
||||
Diese Abnahme belegt ausschließlich den Originalzustand. Tatsächlicher
|
||||
WebUI-Klick, gültige signierte Abschlussquittung, native Anwendung und
|
||||
anschließender neuer regulärer unabhängiger SignedSync stehen noch aus.
|
||||
Die exakte historische Ursache der Helperablehnung bleibt unbelegt; eine
|
||||
Timinghypothese ist kein gemessener Fehlernachweis. Es wird keine alte Lease
|
||||
verlängert oder mit einer erfundenen historischen Uhr angewandt.
|
||||
|
||||
## Tatsächlicher WebUI-Abschluss und native Anwendung
|
||||
|
||||
Um 12:29 UTC wurde der Originalzeuge über die tatsächliche WebUI eingereicht,
|
||||
angezeigt und mit der ausdrücklich aktivierten Checkbox-/Buttonbedienung des
|
||||
sichtbar simulierten Testprincipals bestätigt. Antrag
|
||||
`84a803a4-2acc-4679-9d6d-a0db404c323a`;
|
||||
Quittung `5d135f00-70fd-4a6f-840c-fb65753c5805`. Die erste reine
|
||||
Browserlesung öffnete die eingeklappten Details noch nicht und stoppte deshalb
|
||||
vor jeder Bestätigung. Der korrigierte Browserlauf öffnete sie über die normale
|
||||
Oberfläche. Es wurde keine Bestätigungs-API direkt aufgerufen.
|
||||
|
||||
Die heruntergeladene Originalquittung wurde unverändert mit privater
|
||||
SYSTEM-/Administratoren-ACL am festen Bootstrapziel bereitgestellt.
|
||||
Der ursprüngliche SDK `1b095494…` wandte sie einmalig mit Exit 0 an
|
||||
(Archivzeit **12:30:05 UTC**, Abschlussmeldung 12:30:07 UTC).
|
||||
Eine separat gebaute und um 12:30:23 UTC rein lesend ausgeführte Nachprüfung
|
||||
`fea0487a…` bestätigte mit Exit 0 die unveränderliche Archivtabelle samt
|
||||
Triggern, beide Receipt-Signaturen, die ursprünglichen Dateikennungen,
|
||||
Originalgeschichte und unveränderten Agent-/Consumption-Inventare.
|
||||
|
||||
Der Helper referenziert jetzt ebenfalls die ursprüngliche zweite Entscheidung
|
||||
`2af359c5-5b5c-4992-b445-1c00e271a288`. Sein Capturecheckpoint bleibt **201**;
|
||||
keine Rücksetzung auf den historischen Applycheckpoint 135. Alle ursprünglichen
|
||||
Jobs, Startzeugen und Verbräuche sind erhalten; null Helperwirkungen oder
|
||||
SYSTEM-Intents. `ready`, `helper_ready` und `unlock` bleiben ausdrücklich falsch.
|
||||
|
||||
Die unabhängige zentrale Nachlese bestätigte einen Prüfantrag, genau eine
|
||||
administrative Quittung und die zwei dazugehörigen Auditereignisse mit
|
||||
Testprincipal-/Simulationsbezug. Windows weiterhin zwei Jobs und ein alter
|
||||
Grant; der ursprüngliche zentrale SignedSync-Head blieb unverändert.
|
||||
Ein erster reiner SQL-Read benutzte irrtümlich `agent_id` direkt in der
|
||||
Permittabelle und brach ab; der korrigierte Read verbindet diese über ihre
|
||||
vorhandene Job-Fremdschlüsselbindung. Keine SQL-Mutation war Teil dieser
|
||||
Nachlese. Beide RMM-Dienste bleiben vor dem korrigierten Paarwechsel gestoppt.
|
||||
|
||||
[Exakte IDs, Hashes, Zähler und separate Servernachlese](evidence/windows-sync-alignment-205-applied-20261116.json).
|
||||
Ein neuer regulärer unabhängiger SignedSync und ein neuer tatsächlicher
|
||||
Skriptauftrag bleiben eigenständige nächste Abnahmen. Dieser administrative
|
||||
Abschluss genehmigt keinen Job und ist kein Produktions-Freigabenachweis.
|
||||
Reference in New Issue
Block a user