Files
rea/scripts/verify/managed/completion-report.mjs

175 lines
5.4 KiB
JavaScript

import { createEvidence } from "#dist/domain/evidence.js";
import { unknownTarget } from "#dist/domain/targetIdentity.js";
/** @typedef {import("#dist/domain/binaryTargetTypes.js").BinaryTarget} BinaryTarget */
/** @typedef {import("#dist/domain/evidence.js").EvidenceSubjectTarget} EvidenceSubjectTarget */
/**
* A verified file as the manifest verifier and ILSpy oracle report it.
* @typedef {{ readonly file_name: string; readonly sha256: string }} ReportedTarget
*/
/**
* A source-owned fixture the conformance run wrote and resolved.
* @typedef {{ readonly target: BinaryTarget }} ResolvedFixture
*/
/**
* The completed conformance observations the claims are projected from.
* @typedef {{
* readonly modern: ResolvedFixture;
* readonly framework: ResolvedFixture;
* readonly nativeFunctionTarget: EvidenceSubjectTarget;
* readonly readyToRun: ResolvedFixture;
* readonly obfuscated: ResolvedFixture;
* readonly left: ResolvedFixture;
* readonly right: ResolvedFixture;
* readonly nativeOnly: ResolvedFixture;
* readonly malformed: ResolvedFixture;
* readonly manifestSelfTest: { readonly target: ReportedTarget };
* readonly operatorManifest: { readonly target: ReportedTarget } | null;
* readonly ilspyOracle: { readonly fixture: ReportedTarget } | null;
* }} ManagedCompletionReportInput
*/
const COMPLETION_PROVIDER = {
id: "rea-managed-conformance",
name: "REA managed conformance verifier",
version: "1",
};
/**
* @param {string} scenarioId
* @param {readonly (BinaryTarget | EvidenceSubjectTarget)[]} targets
* @param {{
* readonly claimId?: string;
* readonly status?: "pass" | "unsupported";
* readonly limitations?: readonly string[];
* }} options
*/
const completionClaim = (
scenarioId,
targets,
{ claimId = `managed.${scenarioId}`, status = "pass", limitations = [] } = {},
) => {
const artifactSha256s = [
...new Set(targets.map(({ sha256: digest }) => digest)),
].sort();
const evidence = createEvidence(
// A claim without an observed artifact (an unsupported optional
// scenario) names no file.
targets[0] ?? unknownTarget("not-observed"),
COMPLETION_PROVIDER,
{
predicateType: "rea.verification",
operation: "verify_managed_conformance",
parameters: {
scenario_id: scenarioId,
scenario_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,
},
status,
evidence_ids: [evidence.evidence_id],
};
};
/**
* @param {ReportedTarget | undefined} target
* @returns {EvidenceSubjectTarget[]}
*/
const optionalTarget = (target) =>
target === undefined
? []
: [{ path: target.file_name, sha256: target.sha256, format: "pe" }];
/** @param {ManagedCompletionReportInput} input */
const sourceOwnedClaims = ({
modern,
framework,
nativeFunctionTarget,
readyToRun,
obfuscated,
left,
right,
nativeOnly,
malformed,
manifestSelfTest,
}) => [
completionClaim("modern-dotnet-anycpu", [modern.target]),
completionClaim("dotnet-framework-x86-pinvoke", [framework.target]),
completionClaim("x64-ready-to-run-native-body", [readyToRun.target]),
completionClaim("managed-native-verification", [
framework.target,
nativeFunctionTarget,
]),
completionClaim("managed-application-graph-projection", [framework.target], {
claimId: "managed.application-graph-projection",
}),
completionClaim("unicode-obfuscated-identifiers", [obfuscated.target]),
completionClaim("decompiler-reconstruction-import", [obfuscated.target]),
completionClaim("mvid-and-token-drift", [left.target, right.target]),
completionClaim("not-managed", [nativeOnly.target]),
completionClaim("malformed-metadata", [malformed.target]),
completionClaim("operator-manifest-self-test", [
{
path: manifestSelfTest.target.file_name,
sha256: manifestSelfTest.target.sha256,
format: "pe",
},
]),
];
/** @param {ManagedCompletionReportInput} input */
const optionalClaims = ({ operatorManifest, ilspyOracle }) => [
completionClaim(
"operator-local-manifest",
optionalTarget(operatorManifest?.target),
{
status: operatorManifest === null ? "unsupported" : "pass",
limitations:
operatorManifest === null
? ["REA_MANAGED_APP_MANIFEST_PATH is not configured."]
: [],
},
),
completionClaim(
"ilspy-reconstruction-oracle",
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.
* @param {ManagedCompletionReportInput} input
* @param {unknown} verifierRun The completed run record, reported unchanged.
*/
export const createManagedCompletionReport = (input, verifierRun) => ({
verifier: {
id: COMPLETION_PROVIDER.id,
version: COMPLETION_PROVIDER.version,
},
verifier_run: verifierRun,
environment: {
platform: process.platform,
architecture: process.arch,
runtime: "node",
runtime_version: process.versions.node.split(".")[0],
},
claims: [...sourceOwnedClaims(input), ...optionalClaims(input)],
});