feat(evidence): generate verifier completion ledgers

This commit is contained in:
morluto
2026-07-22 13:59:19 +00:00
parent bb2e2432a5
commit f5b3e22e72
1731 changed files with 6150 additions and 4056 deletions
+97
View File
@@ -0,0 +1,97 @@
import { createHash } from "node:crypto";
import { execFile } from "node:child_process";
import { mkdir, readFile, readdir } from "node:fs/promises";
import { dirname, join, relative, sep } from "node:path";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
import { ensureGeneratedFile } from "./lib/generated-file.mjs";
const exec = promisify(execFile);
const arguments_ = new Set(process.argv.slice(2));
for (const argument of arguments_)
if (argument !== "--check")
throw new Error(`Unknown completion ledger option: ${argument}`);
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
const outputRoot = join(root, "docs/verification");
const check = arguments_.has("--check");
const verifierEnvironment = { ...process.env };
delete verifierEnvironment.REA_MANAGED_APP_MANIFEST_PATH;
delete verifierEnvironment.REA_ILSPY_CMD_PATH;
const { stdout } = await exec(
process.execPath,
[join(root, "scripts/verify-managed-conformance.mjs")],
{
cwd: root,
env: verifierEnvironment,
maxBuffer: 20 * 1024 * 1024,
},
);
const verifierOutput = JSON.parse(stdout);
const { createCompletionLedgerArtifacts } = await import(
`../dist/domain/completionLedgerGeneration.js?${String(Date.now())}`
);
const skillDigest = await directoryDigest(
join(root, "skills/reverse-engineer-anything"),
);
const generated = createCompletionLedgerArtifacts(
verifierOutput.completionReport,
[{ skill_id: "reverse-engineer-anything", sha256: skillDigest }],
);
if (!check) await mkdir(outputRoot, { recursive: true });
await Promise.all([
ensureGeneratedFile({
path: join(outputRoot, "managed-conformance-manifest.json"),
source: `${JSON.stringify(generated.manifest, null, 2)}\n`,
check,
generateCommand: "npm run evidence:generate",
}),
ensureGeneratedFile({
path: join(outputRoot, "managed-conformance-ledger.json"),
source: `${JSON.stringify(generated.ledger, null, 2)}\n`,
check,
generateCommand: "npm run evidence:generate",
}),
]);
process.stdout.write(
`${JSON.stringify({
manifest_id: generated.manifest.manifest_id,
ledger_id: generated.ledger.ledger_id,
claims: generated.ledger.summary.total,
complete: generated.ledger.summary.complete,
})}\n`,
);
async function directoryDigest(directory) {
const paths = await filePaths(directory);
const records = await Promise.all(
paths.map(async (path) => {
const name = relative(directory, path).split(sep).join("/");
const digest = createHash("sha256")
.update(await readFile(path))
.digest("hex");
return `${name}\0${digest}\n`;
}),
);
return createHash("sha256").update(records.join("")).digest("hex");
}
async function filePaths(directory) {
const entries = await readdir(directory, { withFileTypes: true });
const paths = [];
for (const entry of entries.sort((left, right) =>
left.name < right.name ? -1 : left.name > right.name ? 1 : 0,
)) {
const path = join(directory, entry.name);
if (entry.isDirectory()) paths.push(...(await filePaths(path)));
else if (entry.isFile()) paths.push(path);
else
throw new Error(
`Completion skill digest does not admit ${entry.name}: expected a regular file or directory`,
);
}
return paths;
}
+2
View File
@@ -42,6 +42,8 @@ const SOURCE_PATHS = {
electronProvider: "dist/browser/CdpElectronProvider.js",
evidence: "dist/domain/evidence.js",
evidenceBundle: "dist/domain/evidenceBundle.js",
evidenceCompletion: "dist/domain/evidenceCompletionLedger.js",
completionGeneration: "dist/domain/completionLedgerGeneration.js",
processCapture: "dist/domain/processCapture.js",
analysisSnapshot: "dist/domain/analysisSnapshot.js",
artifactGraph: "dist/domain/artifactGraph.js",
+10
View File
@@ -56,6 +56,16 @@ const durableSchemaDefinitions = (sources) => [
sources.evidenceBundle.evidenceBundleSchema,
["bundle_version"],
],
[
"evidence_completion_ledger",
sources.evidenceCompletion.evidenceCompletionLedgerSchema,
["schema_version"],
],
[
"evidence_completion_manifest",
sources.completionGeneration.completionManifestSchema,
["schema_version"],
],
[
"investigation_run",
sources.investigationWorkspace.investigationRunSchema,
+166
View File
@@ -0,0 +1,166 @@
import { createEvidence } from "../../dist/domain/evidence.js";
const COMPLETION_PROVIDER = {
id: "rea-managed-conformance",
name: "REA managed conformance verifier",
version: "1",
};
const completionClaim = ({
claimId,
scenarioId,
targets = [],
status = "pass",
limitations = [],
}) => {
const artifactSha256s = [
...new Set(targets.map(({ sha256: digest }) => digest)),
].sort();
const evidence = createEvidence(targets[0], COMPLETION_PROVIDER, {
predicateType: "rea.verification/v1",
operation: "verify_managed_conformance",
parameters: {
scenario_id: scenarioId,
scenario_version: 1,
result_schema_version: 1,
artifact_sha256s: artifactSha256s,
},
result: { status },
rawResult: null,
limitations,
});
return {
claim_id: claimId,
scenario: { id: scenarioId, version: 1 },
artifact_sha256s: artifactSha256s,
provider: {
id: COMPLETION_PROVIDER.id,
version: COMPLETION_PROVIDER.version,
},
result_schema_version: 1,
status,
evidence_ids: [evidence.evidence_id],
};
};
const optionalTarget = (target) =>
target === undefined
? []
: [{ path: target.file_name, sha256: target.sha256, format: "pe" }];
const sourceOwnedClaims = ({
modern,
framework,
nativeFunctionTarget,
readyToRun,
obfuscated,
left,
right,
nativeOnly,
malformed,
manifestSelfTest,
}) => [
completionClaim({
claimId: "managed.modern-dotnet-anycpu",
scenarioId: "modern-dotnet-anycpu",
targets: [modern.target],
}),
completionClaim({
claimId: "managed.dotnet-framework-x86-pinvoke",
scenarioId: "dotnet-framework-x86-pinvoke",
targets: [framework.target],
}),
completionClaim({
claimId: "managed.x64-ready-to-run-native-body",
scenarioId: "x64-ready-to-run-native-body",
targets: [readyToRun.target],
}),
completionClaim({
claimId: "managed.managed-native-verification",
scenarioId: "managed-native-verification",
targets: [framework.target, nativeFunctionTarget],
}),
completionClaim({
claimId: "managed.application-graph-projection",
scenarioId: "managed-application-graph-projection",
targets: [framework.target],
}),
completionClaim({
claimId: "managed.unicode-obfuscated-identifiers",
scenarioId: "unicode-obfuscated-identifiers",
targets: [obfuscated.target],
}),
completionClaim({
claimId: "managed.decompiler-reconstruction-import",
scenarioId: "decompiler-reconstruction-import",
targets: [obfuscated.target],
}),
completionClaim({
claimId: "managed.runtime-correlation-admission-plan",
scenarioId: "runtime-correlation-admission-plan",
targets: [obfuscated.target],
}),
completionClaim({
claimId: "managed.mvid-and-token-drift",
scenarioId: "mvid-and-token-drift",
targets: [left.target, right.target],
}),
completionClaim({
claimId: "managed.not-managed",
scenarioId: "not-managed",
targets: [nativeOnly.target],
}),
completionClaim({
claimId: "managed.malformed-metadata",
scenarioId: "malformed-metadata",
targets: [malformed.target],
}),
completionClaim({
claimId: "managed.operator-manifest-self-test",
scenarioId: "operator-manifest-self-test",
targets: [
{
path: manifestSelfTest.target.file_name,
sha256: manifestSelfTest.target.sha256,
format: "pe",
},
],
}),
];
const optionalClaims = ({ operatorManifest, ilspyOracle }) => [
completionClaim({
claimId: "managed.operator-local-manifest",
scenarioId: "operator-local-manifest",
targets: optionalTarget(operatorManifest?.target),
status: operatorManifest === null ? "unsupported" : "pass",
limitations:
operatorManifest === null
? ["REA_MANAGED_APP_MANIFEST_PATH is not configured."]
: [],
}),
completionClaim({
claimId: "managed.ilspy-reconstruction-oracle",
scenarioId: "ilspy-reconstruction-oracle",
targets: optionalTarget(ilspyOracle?.fixture),
status: ilspyOracle === null ? "unsupported" : "pass",
limitations:
ilspyOracle === null ? ["REA_ILSPY_CMD_PATH is not configured."] : [],
}),
];
/** Project completed managed assertions into the standard verifier report. */
export const createManagedCompletionReport = (input) => ({
schema_version: 1,
verifier: {
id: COMPLETION_PROVIDER.id,
version: COMPLETION_PROVIDER.version,
},
environment: {
platform: process.platform,
architecture: process.arch,
runtime: "node",
runtime_version: process.versions.node.split(".")[0],
},
claims: [...sourceOwnedClaims(input), ...optionalClaims(input)],
});
+23 -6
View File
@@ -29,6 +29,7 @@ import {
memberLimits,
nativeBoundaryLimits,
} from "./lib/managed-conformance-config.mjs";
import { createManagedCompletionReport } from "./lib/managed-completion-report.mjs";
const workspace = await mkdtemp(join(tmpdir(), "rea-managed-conformance-"));
const {
@@ -145,13 +146,14 @@ try {
locations: [{ kind: "artifact-path", path: framework.target.path }],
},
);
const nativeFunctionTarget = {
path: "/system/user32.dll",
sha256: "9".repeat(64),
format: "pe",
architecture: "x86",
};
const nativeFunctionEvidence = createEvidence(
{
path: "/system/user32.dll",
sha256: "9".repeat(64),
format: "pe",
architecture: "x86",
},
nativeFunctionTarget,
{
id: "ghidra",
name: "Ghidra",
@@ -437,6 +439,20 @@ try {
const manifestSelfTest = await runManagedAppManifestSelfTest();
const operatorManifest = await runOptionalManagedAppManifest();
const ilspyOracle = await runOptionalIlspyOracle();
const completionReport = createManagedCompletionReport({
modern,
framework,
nativeFunctionTarget,
readyToRun,
obfuscated,
left,
right,
nativeOnly,
malformed,
manifestSelfTest,
operatorManifest,
ilspyOracle,
});
process.stdout.write(
`${JSON.stringify({
@@ -478,6 +494,7 @@ try {
env: "REA_ILSPY_CMD_PATH",
configured: false,
},
completionReport,
})}\n`,
);
} finally {