Bind retained updater history to qualified baseline decoder contract
Rust development slice / linux (push) Failing after 7s

This commit is contained in:
2026-11-15 13:40:16 +01:00
parent 6498fa0a02
commit c1d8eea6b8
3 changed files with 296 additions and 5 deletions
+174 -5
View File
@@ -81,7 +81,13 @@ pub fn verify_history(
let mut signed = BASELINE_SIGNATURE_DOMAIN.to_vec();
signed.extend_from_slice(&initial.payload_bytes);
verifier.verify_strict(&signed, &Signature::from_bytes(&initial.signature))?;
verify_record_release(&keyring, protected_keyring.generation, &initial.record)?;
verify_record_release(
&keyring,
protected_keyring.generation,
&initial.record,
initial_release.manifest.protocol_major,
initial_release.manifest.state_schema,
)?;
ensure!(
predecessor_records.len() < MAX_RECORDS
@@ -156,7 +162,13 @@ pub fn verify_history(
&& record.activated_at >= parent.activated_at,
"UPDATE_HISTORY_FLOOR_OR_ROLLBACK"
);
verify_record_release(&keyring, protected_keyring.generation, record)?;
verify_record_release(
&keyring,
protected_keyring.generation,
record,
initial_release.manifest.protocol_major,
initial_release.manifest.state_schema,
)?;
let grant = verify_update(db, guard, binding, raw, record, parent_digest, parent)?;
ensure!(grants.insert(grant), "UPDATE_HISTORY_REUSED_GRANT");
ensure!(*digest == hash(raw), "UPDATE_HISTORY_RECORD_CHANGED");
@@ -280,6 +292,8 @@ fn verify_record_release(
keys: &UpdateKeyring,
generation: u64,
record: &InstalledReleaseRecord,
baseline_protocol_major: u32,
baseline_state_schema: u32,
) -> Result<()> {
ensure!(
!record.rolled_back,
@@ -306,8 +320,11 @@ fn verify_record_release(
platform,
now_utc_seconds: record.activated_at,
keyring_generation: generation,
protocol_major: decoded.manifest.protocol_major,
state_schema: decoded.manifest.state_schema,
// Anchor compatibility to the separately signed, qualified
// bootstrap. A signed successor cannot attest its own decoder
// compatibility by supplying both sides of this comparison.
protocol_major: baseline_protocol_major,
state_schema: baseline_state_schema,
updater_version: 1,
minimum_release_sequence: record.activation_floor,
active_release: Some(ActiveRelease {
@@ -786,6 +803,9 @@ mod tests {
active: Vec<u8>,
}
fn fixture() -> Fixture {
fixture_target_contract(1, 1)
}
fn fixture_target_contract(protocol_major: u32, state_schema: u32) -> Fixture {
let release = SigningKey::from_bytes(&[71; 32]); // public synthetic TEST seed
let jobs = SigningKey::from_bytes(&[72; 32]);
let health = SigningKey::from_bytes(&[73; 32]);
@@ -801,8 +821,13 @@ mod tests {
let Action::UpdateAgent { update } = &mut job.action else {
panic!("fixture action")
};
let target = envelope(update.manifest().unwrap(), 2, &release);
let mut target_manifest = update.manifest().unwrap();
target_manifest.protocol_major = protocol_major;
target_manifest.state_schema = state_schema;
let target = envelope(target_manifest, 2, &release);
let mut old = target.decode().unwrap().manifest;
old.protocol_major = 1;
old.state_schema = 1;
old.release_id = update.predecessor.release_id;
old.artifacts[0].artifact_id = Uuid::from_u128(901);
old.artifacts[1].artifact_id = Uuid::from_u128(902);
@@ -1404,6 +1429,150 @@ mod tests {
);
}
#[test]
fn signed_successor_cannot_self_attest_compatibility_with_retained_baseline() {
// These fixtures contain genuine release, baseline, job and health
// signatures and a complete consumed/native publication chain. Only
// the successor's decoder contract differs from the original baseline.
for (protocol, schema, error) in [
(2, 1, "incompatible release protocol"),
(1, 2, "incompatible release state schema"),
] {
let f = fixture_target_contract(protocol, schema);
let before = f.db.total_changes();
let rejected = verify_history(
&f.db,
&f.guard,
&f.binding,
&f.keys,
&f.baseline,
&[],
&f.active,
)
.unwrap_err();
assert!(rejected.to_string().contains(error), "{rejected:#}");
assert_eq!(f.db.total_changes(), before);
assert_eq!(
InstalledReleaseRecord::from_bytes(&f.initial)
.unwrap()
.activation_floor,
1
);
assert_eq!(
InstalledReleaseRecord::from_bytes(&f.active)
.unwrap()
.activation_floor,
2
);
}
let f = fixture();
let before = f.db.total_changes();
assert_eq!(
verify_history(
&f.db,
&f.guard,
&f.binding,
&f.keys,
&f.baseline,
&[],
&f.active,
)
.unwrap()
.bytes()
.unwrap(),
f.active
);
assert_eq!(f.db.total_changes(), before);
}
#[test]
fn retained_predecessor_is_not_a_rollback_receipt_and_unknown_stays_closed() {
let f = fixture();
// Even a genuine release-signed exact predecessor with the retained
// higher floor is only metadata. V1 has no rollback activation witness.
let active = InstalledReleaseRecord::from_bytes(&f.active).unwrap();
let mut returned = InstalledReleaseRecord::from_bytes(&f.initial).unwrap();
returned.activation_floor = active.activation_floor;
returned.activated_at = active.activated_at + 1;
returned.previous_record_sha256 = Some(hash(&f.active));
returned.activation_evidence = active.activation_evidence.clone();
returned.rolled_back = true;
let returned = returned.bytes().unwrap();
let before = f.db.total_changes();
assert!(
verify_history(
&f.db,
&f.guard,
&f.binding,
&f.keys,
&f.baseline,
std::slice::from_ref(&f.active),
&returned,
)
.unwrap_err()
.to_string()
.contains("UPDATE_HISTORY_FLOOR_OR_ROLLBACK")
);
assert!(
verify_history(
&f.db,
&f.guard,
&f.binding,
&f.keys,
&f.baseline,
&[],
&f.initial,
)
.is_err()
);
assert_eq!(f.db.total_changes(), before);
assert_eq!(
InstalledReleaseRecord::from_bytes(&returned)
.unwrap()
.activation_floor,
2
);
// A previously stored Unknown is never reclassified from a retained
// healthy target or a proposed predecessor return. This is a synthetic
// local fixture mutation; the verifier itself performs no writes.
let unknown = serde_json::to_vec(&Outcome::unknown("synthetic unresolved update")).unwrap();
f.db.execute("UPDATE execution_evidence SET outcome=?1", [&unknown])
.unwrap();
f.db.execute("UPDATE consumed SET result=?1", [&unknown])
.unwrap();
let before = f.db.total_changes();
assert!(
verify_history(
&f.db,
&f.guard,
&f.binding,
&f.keys,
&f.baseline,
&[],
&f.active,
)
.is_err()
);
assert!(
verify_history(
&f.db,
&f.guard,
&f.binding,
&f.keys,
&f.baseline,
std::slice::from_ref(&f.active),
&returned,
)
.is_err()
);
let retained: Vec<u8> =
f.db.query_row("SELECT outcome FROM execution_evidence", [], |r| r.get(0))
.unwrap();
assert_eq!(retained, unknown);
assert_eq!(f.db.total_changes(), before);
}
#[test]
fn completed_history_rejects_file_only_rollback_forks_and_tampered_activation_without_writes() {
let f = fixture();