fix(reconstruction): authenticate obligation proof boundaries
This commit is contained in:
@@ -4,6 +4,50 @@ import type { ReconstructionObligation } from "../domain/reconstructionObligatio
|
||||
type ProofAuthority = ReconstructionObligation["required_fixture_authority"];
|
||||
type OriginalAuthority =
|
||||
ReconstructionObligation["required_original_authority"];
|
||||
type ProofEvidenceShape = readonly [predicate: string, operation: string];
|
||||
|
||||
const proofEvidenceShapes: Readonly<
|
||||
Record<ProofAuthority, readonly ProofEvidenceShape[]>
|
||||
> = {
|
||||
unit: [["rea.fixture-verification/v1", "run_fixture_verifier"]],
|
||||
integration: [["rea.fixture-verification/v1", "run_fixture_verifier"]],
|
||||
protocol: [["rea.protocol-observation/v1", "observe_protocol"]],
|
||||
renderer: [
|
||||
["rea.browser-scenario-capture/v1", "capture_browser_scenario"],
|
||||
["rea.electron-page-inspection/v1", "inspect_electron_page"],
|
||||
],
|
||||
"packaged-process": [
|
||||
["rea.process-capture/v4", "capture_process_scenario"],
|
||||
[
|
||||
"rea.reconstruction-readiness-fixture/v1",
|
||||
"run_reconstruction_readiness_fixture",
|
||||
],
|
||||
],
|
||||
"native-abi": [
|
||||
["rea.managed-native-verification/v1", "verify_managed_native_boundaries"],
|
||||
],
|
||||
"live-observation": [
|
||||
["javascript-controlled-replay-observation", "run_controlled_replay"],
|
||||
["rea.browser-scenario-capture/v1", "capture_browser_scenario"],
|
||||
["rea.electron-page-inspection/v1", "inspect_electron_page"],
|
||||
["rea.javascript-runtime-observation/v1", "observe_javascript_runtime"],
|
||||
["rea.runtime-characterization/v1", "execute_node_characterization"],
|
||||
],
|
||||
external: [["rea.protocol-observation/v1", "observe_protocol"]],
|
||||
};
|
||||
|
||||
const proofEvidenceAuthorities: Readonly<
|
||||
Record<ProofAuthority, readonly Evidence["authority"][]>
|
||||
> = {
|
||||
unit: ["shipped-artifact", "controlled-replay"],
|
||||
integration: ["controlled-replay"],
|
||||
protocol: ["controlled-replay", "external-service"],
|
||||
renderer: ["controlled-replay", "external-service"],
|
||||
"packaged-process": ["controlled-replay"],
|
||||
"native-abi": ["shipped-artifact", "controlled-replay"],
|
||||
"live-observation": ["controlled-replay", "external-service"],
|
||||
external: ["external-service"],
|
||||
};
|
||||
|
||||
/** Return whether an actual reconstruction proof is comparable to a requirement. */
|
||||
export const proofAuthoritySatisfies = (
|
||||
@@ -46,9 +90,11 @@ export const evidenceAuthoritySupportsProof = (
|
||||
authority: ProofAuthority,
|
||||
): boolean =>
|
||||
evidence.confidence === "observed" &&
|
||||
(authority === "external"
|
||||
? evidence.authority === "external-service"
|
||||
: ["shipped-artifact", "controlled-replay"].includes(evidence.authority));
|
||||
proofEvidenceAuthorities[authority].includes(evidence.authority) &&
|
||||
proofEvidenceShapes[authority].some(
|
||||
([predicate, operation]) =>
|
||||
evidence.predicate_type === predicate && evidence.operation === operation,
|
||||
);
|
||||
|
||||
/** Check that Evidence observes the original at the required boundary. */
|
||||
export const evidenceSupportsOriginalAuthority = (
|
||||
|
||||
@@ -454,35 +454,31 @@ const applyDependencyDiagnostics = (
|
||||
obligations: readonly ReconstructionObligation[],
|
||||
context: EvaluationContext,
|
||||
): ReconstructionObligation[] => {
|
||||
const statuses = new Map(
|
||||
obligations.map((obligation) => [
|
||||
obligation.obligation_id,
|
||||
obligation.status,
|
||||
]),
|
||||
);
|
||||
return obligations.map((obligation) => {
|
||||
const diagnostics = [...obligation.diagnostics];
|
||||
for (const dependencyId of obligation.dependency_obligation_ids) {
|
||||
if (!context.candidates.has(dependencyId))
|
||||
addDiagnostic(
|
||||
diagnostics,
|
||||
"dependency-missing",
|
||||
`Dependency obligation is missing: ${dependencyId}.`,
|
||||
);
|
||||
else if (statuses.get(dependencyId) !== "verified")
|
||||
addDiagnostic(
|
||||
diagnostics,
|
||||
"dependency-open",
|
||||
`Dependency obligation is not verified: ${dependencyId}.`,
|
||||
);
|
||||
}
|
||||
const normalized = uniqueDiagnostics(diagnostics);
|
||||
return {
|
||||
...obligation,
|
||||
status: dependencyStatus(obligation.status, normalized),
|
||||
diagnostics: normalized,
|
||||
};
|
||||
});
|
||||
let evaluated = [...obligations];
|
||||
for (let pass = 0; pass < obligations.length; pass += 1) {
|
||||
const statuses = new Map(
|
||||
evaluated.map(({ obligation_id: id, status }) => [id, status]),
|
||||
);
|
||||
let changed = false;
|
||||
evaluated = evaluated.map((obligation) => {
|
||||
const diagnostics = [...obligation.diagnostics];
|
||||
for (const dependencyId of obligation.dependency_obligation_ids) {
|
||||
const missing = !context.candidates.has(dependencyId);
|
||||
if (missing || statuses.get(dependencyId) !== "verified")
|
||||
addDiagnostic(
|
||||
diagnostics,
|
||||
missing ? "dependency-missing" : "dependency-open",
|
||||
`Dependency obligation is ${missing ? "missing" : "not verified"}: ${dependencyId}.`,
|
||||
);
|
||||
}
|
||||
const normalized = uniqueDiagnostics(diagnostics);
|
||||
const status = dependencyStatus(obligation.status, normalized);
|
||||
changed ||= status !== obligation.status;
|
||||
return { ...obligation, status, diagnostics: normalized };
|
||||
});
|
||||
if (!changed) break;
|
||||
}
|
||||
return evaluated;
|
||||
};
|
||||
|
||||
const obligationStatus = (
|
||||
|
||||
Reference in New Issue
Block a user