fix(managed): bind inspection evidence to artifact identity
This commit is contained in:
@@ -10,7 +10,10 @@ import {
|
||||
compareManagedMemberPaths,
|
||||
} from "../../../../src/application/managed/ManagedMemberComparisonService.js";
|
||||
import { parseBinaryTarget } from "../../../../src/application/BinaryTargetResolver.js";
|
||||
import { managedMemberComparisonResultSchema } from "../../../../src/domain/managed/managedMemberComparison.js";
|
||||
import {
|
||||
managedMemberComparisonResultSchema,
|
||||
parseManagedMemberEvidence,
|
||||
} from "../../../../src/domain/managed/managedMemberComparison.js";
|
||||
import { createEvidence } from "../../../../src/domain/evidence.js";
|
||||
import { projectAnalysisError } from "../../../../src/domain/analysisErrorProjection.js";
|
||||
import { jsonValueSchema } from "../../../../src/domain/jsonValue.js";
|
||||
@@ -54,6 +57,71 @@ it.each([
|
||||
},
|
||||
);
|
||||
|
||||
describe("managed member comparison subject identity", () => {
|
||||
it("rejects authenticated member Evidence whose subject digest differs from its artifact", () => {
|
||||
const bytes = buildManagedPeFixture();
|
||||
const target = managedPeFixtureTarget(bytes, "/fixture/mismatch.dll");
|
||||
const inspection = inspectManagedMembersBytes(bytes, target);
|
||||
const otherDigest = "b".repeat(64);
|
||||
const mismatched = createEvidence(
|
||||
target,
|
||||
{
|
||||
id: "partial-fixture",
|
||||
name: "Partial fixture",
|
||||
version: "1",
|
||||
},
|
||||
{
|
||||
operation: "inspect_managed_members",
|
||||
parameters: {},
|
||||
result: jsonValueSchema.parse({
|
||||
...inspection,
|
||||
artifact: { ...inspection.artifact, sha256: otherDigest },
|
||||
identity_scope: {
|
||||
...inspection.identity_scope,
|
||||
requires_artifact_sha256: otherDigest,
|
||||
},
|
||||
}),
|
||||
},
|
||||
);
|
||||
const aligned = createEvidence(
|
||||
target,
|
||||
{
|
||||
id: "partial-fixture",
|
||||
name: "Partial fixture",
|
||||
version: "1",
|
||||
},
|
||||
{
|
||||
operation: "inspect_managed_members",
|
||||
parameters: {},
|
||||
result: inspection,
|
||||
},
|
||||
);
|
||||
const unavailableSubject = createEvidence(
|
||||
undefined,
|
||||
{
|
||||
id: "partial-fixture",
|
||||
name: "Partial fixture",
|
||||
version: "1",
|
||||
},
|
||||
{
|
||||
operation: "inspect_managed_members",
|
||||
parameters: {},
|
||||
result: inspection,
|
||||
},
|
||||
);
|
||||
|
||||
expect(() => parseManagedMemberEvidence(mismatched)).toThrow(
|
||||
`Managed Evidence inspect_managed_members (${mismatched.evidence_id}) subject SHA-256 ${target.sha256} does not match normalized artifact SHA-256 ${otherDigest}`,
|
||||
);
|
||||
expect(parseManagedMemberEvidence(aligned).result.artifact.sha256).toBe(
|
||||
target.sha256,
|
||||
);
|
||||
expect(
|
||||
parseManagedMemberEvidence(unavailableSubject).result.artifact.sha256,
|
||||
).toBe(target.sha256);
|
||||
});
|
||||
});
|
||||
|
||||
describe("managed member comparison path workflow", () => {
|
||||
it("preserves undecoded signatures as unknown through content-addressed partial Evidence", () => {
|
||||
const observe = (signature: number, path: string) => {
|
||||
|
||||
@@ -167,6 +167,48 @@ describe("managed application graph request", () => {
|
||||
});
|
||||
|
||||
describe("managed application graph coverage", () => {
|
||||
it("rejects managed Evidence digest mismatch and discloses missing artifact observations", () => {
|
||||
const bytes = buildManagedPeFixture();
|
||||
const binary = managedPeFixtureTarget(bytes, "/fixture/Mismatch.dll");
|
||||
const members = inspectManagedMembersBytes(bytes, binary);
|
||||
const mismatched = createEvidence(binary, MANAGED_STATIC_PROVIDER, {
|
||||
operation: "inspect_managed_members",
|
||||
parameters: {},
|
||||
result: {
|
||||
...members,
|
||||
artifact: { ...members.artifact, sha256: "b".repeat(64) },
|
||||
identity_scope: {
|
||||
...members.identity_scope,
|
||||
requires_artifact_sha256: "b".repeat(64),
|
||||
},
|
||||
},
|
||||
});
|
||||
const rejected = projectManagedApplicationGraphEvidence({
|
||||
managed_members: mismatched,
|
||||
});
|
||||
expect(rejected.ok).toBe(false);
|
||||
if (rejected.ok) throw new Error("mismatched managed Evidence accepted");
|
||||
expect(JSON.stringify(rejected.error)).toContain(
|
||||
`Managed Evidence inspect_managed_members (${mismatched.evidence_id}) subject SHA-256 ${binary.sha256} does not match normalized artifact SHA-256 ${"b".repeat(64)}`,
|
||||
);
|
||||
|
||||
const aligned = createEvidence(binary, MANAGED_STATIC_PROVIDER, {
|
||||
operation: "inspect_managed_members",
|
||||
parameters: {},
|
||||
result: members,
|
||||
});
|
||||
const projected = projectManagedApplicationGraphEvidence({
|
||||
managed_members: aligned,
|
||||
});
|
||||
if (!projected.ok) throw projected.error;
|
||||
const result = managedApplicationGraphResultSchema.parse(
|
||||
parseEvidence(projected.value).normalized_result,
|
||||
);
|
||||
expect(result.limitations).toContain(
|
||||
"Managed artifact Evidence was not supplied; assembly identity observations are absent.",
|
||||
);
|
||||
});
|
||||
|
||||
it("preserves partial parser coverage in graph and per-fact coverage", () => {
|
||||
const bytes = buildManagedPeFixture();
|
||||
const binary = managedPeFixtureTarget(bytes, "/fixture/ManagedInterop.exe");
|
||||
|
||||
@@ -60,6 +60,54 @@ const nativeEvidenceWithExports = (names: readonly string[]) => {
|
||||
);
|
||||
};
|
||||
|
||||
describe("managed/native boundary Evidence identity", () => {
|
||||
it("rejects managed boundary Evidence whose subject digest differs from its artifact", () => {
|
||||
const input = exampleInput();
|
||||
const managed = input.managed_boundaries;
|
||||
const result = managedNativeBoundaryInspectionSchema.parse(
|
||||
managed.normalized_result,
|
||||
);
|
||||
const otherDigest = "b".repeat(64);
|
||||
const mismatched = createEvidence(
|
||||
{
|
||||
path: result.artifact.path,
|
||||
sha256: result.artifact.sha256,
|
||||
format: "pe",
|
||||
},
|
||||
managed.provider,
|
||||
{
|
||||
operation: managed.operation,
|
||||
parameters: managed.parameters,
|
||||
result: {
|
||||
...result,
|
||||
artifact: { ...result.artifact, sha256: otherDigest },
|
||||
identity_scope: {
|
||||
...result.identity_scope,
|
||||
requires_artifact_sha256: otherDigest,
|
||||
},
|
||||
},
|
||||
rawResult: managed.raw_result,
|
||||
confidence: managed.confidence,
|
||||
authority: managed.authority,
|
||||
environment: managed.environment,
|
||||
limitations: managed.limitations,
|
||||
locations: managed.locations,
|
||||
evidenceLinks: managed.evidence_links,
|
||||
},
|
||||
);
|
||||
|
||||
expect(() =>
|
||||
verifyManagedNativeBoundaries({
|
||||
...input,
|
||||
managed_boundaries: mismatched,
|
||||
}),
|
||||
).toThrow(
|
||||
`Managed Evidence inspect_managed_native_boundaries (${mismatched.evidence_id}) subject SHA-256 ${result.artifact.sha256} does not match normalized artifact SHA-256 ${otherDigest}`,
|
||||
);
|
||||
expect(verifyManagedNativeBoundaries(input).summary.verified).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("managed/native boundary verification", () => {
|
||||
it("verifies a P/Invoke declaration against native export Evidence", () => {
|
||||
const result = verifyManagedNativeBoundaries(exampleInput());
|
||||
|
||||
Reference in New Issue
Block a user