fix(evidence): authenticate identities and retain extraction provenance

Authenticate residual unknown IDs against their immutable identity fields. Permit valid empty ZIP extraction manifests and join firmware child provenance to parent-owned chunk and multi-file reports without inventing missing source ranges.

Validated with focused identity, archive, cleanup, and firmware normalization tests. Firmware joins were checked against the pinned Unblob producer; no real Unblob extraction was run.
This commit is contained in:
morluto
2026-10-12 14:12:19 +08:00
parent 4573e8cf35
commit 6bae774328
8 changed files with 334 additions and 41 deletions
@@ -1,3 +1,6 @@
import { createHash } from "node:crypto";
import canonicalize from "canonicalize";
import { describe, expect, it } from "vitest";
import { EvidenceLedger } from "./EvidenceLedger.js";
@@ -373,3 +376,47 @@ describe("residual unknown registry resolution and history", () => {
expect(serializeEvidenceBundle(base.export())).toBe(before);
});
});
describe("residual unknown imported identity", () => {
it("rejects a rehashed wrong ID atomically and accepts valid history", () => {
const store = ledger();
const created = store.recordUnknown(
input("Stable question?"),
mutation("stable"),
);
if (!created.ok) throw created.error;
const initialBundle = store.export();
const mutationEvidenceId = created.value.mutation_evidence_ids[0];
if (mutationEvidenceId === undefined)
throw new Error("Missing mutation Evidence ID");
const otherId = createResidualUnknown(
input("Different question?"),
mutationEvidenceId,
created.value.scope_digest,
).unknown_id;
const { revision_digest: _revisionDigest, ...revision } = created.value;
const incorrectIdentity = { ...revision, unknown_id: otherId };
const encoded = canonicalize(incorrectIdentity);
if (encoded === undefined) throw new Error("Could not encode revision");
const tampered = {
...incorrectIdentity,
revision_digest: createHash("sha256").update(encoded).digest("hex"),
};
const invalidBundle = createEvidenceBundle(initialBundle.records, [
tampered,
]);
const before = serializeEvidenceBundle(initialBundle);
expect(() => parseEvidenceBundle(invalidBundle)).toThrow();
expect(store.import(invalidBundle).ok).toBe(false);
expect(serializeEvidenceBundle(store.export())).toBe(before);
expect(
store.updateUnknown(update(created.value), mutation("stable-update")).ok,
).toBe(true);
const validHistory = store.export();
const imported = ledger();
expect(imported.import(validHistory).ok).toBe(true);
expect(imported.export()).toEqual(validHistory);
});
});