fix(native): bind signature results and preserve verification uncertainty
This commit is contained in:
@@ -43,6 +43,7 @@ it("keeps operational, unsigned, definite invalid and unrecognized failures dist
|
||||
expect(status("permission denied")).toBe("unknown");
|
||||
expect(status("I/O error")).toBe("unknown");
|
||||
expect(status("invalid signature")).toBe("invalid");
|
||||
expect(status("main executable failed strict validation")).toBe("invalid");
|
||||
expect(status("bundle format unrecognized, invalid, or unsuitable")).toBe(
|
||||
"invalid",
|
||||
);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
@@ -18,9 +19,14 @@ import { parseCodeSignature } from "../../../../src/native/parsers/codesign.js";
|
||||
import {
|
||||
NativeFixtureRunner as FixtureRunner,
|
||||
nativeFixture as fixture,
|
||||
nativeMachoTarget as machoTarget,
|
||||
nativeMachoTarget as unboundMachoTarget,
|
||||
} from "../../../fixtures/nativeCommands.js";
|
||||
|
||||
const machoTarget = (path: string, app?: string) => ({
|
||||
...unboundMachoTarget(path, app),
|
||||
sha256: createHash("sha256").update("fixture").digest("hex"),
|
||||
});
|
||||
|
||||
let directory: string | undefined;
|
||||
afterEach(async () => {
|
||||
if (directory !== undefined)
|
||||
@@ -318,10 +324,13 @@ class PrototypeEntitlementsRunner extends FixtureRunner {
|
||||
|
||||
describe("native signature entitlements", () => {
|
||||
it("reports entitlement entries keyed __proto__ that the result omits", async () => {
|
||||
directory = await createTestTempDirectory("rea-signature-entitlements-");
|
||||
const executable = join(directory, "fixture");
|
||||
await writeFile(executable, "fixture");
|
||||
const client = new NativeMacOSProvider(
|
||||
new PrototypeEntitlementsRunner(),
|
||||
"darwin",
|
||||
).createClient(machoTarget("/private/fixture"));
|
||||
).createClient(machoTarget(executable));
|
||||
|
||||
const signature = await client.execute("inspect_signature", {});
|
||||
|
||||
|
||||
@@ -106,6 +106,8 @@ describe("native signature posture", () => {
|
||||
|
||||
it("keeps a failed strict verification as an observation", async () => {
|
||||
const { app, executable } = await fixtureApp(undefined);
|
||||
await mkdir(join(app, "Contents/PlugIns/A.appex"), { recursive: true });
|
||||
await mkdir(join(app, "Contents/XPCServices/B.xpc"), { recursive: true });
|
||||
const signature = await new NativeMacOSProvider(
|
||||
new TamperedRunner(),
|
||||
"darwin",
|
||||
@@ -506,6 +508,52 @@ describe("signature architecture coverage", () => {
|
||||
});
|
||||
|
||||
describe("signature target version binding", () => {
|
||||
it("rejects a replacement before invoking signature tools", async () => {
|
||||
const { app, executable } = await fixtureApp(undefined);
|
||||
const runner = new (class extends FixtureRunner {
|
||||
calls = 0;
|
||||
override async run(tool: string, args: readonly string[]) {
|
||||
this.calls += 1;
|
||||
return super.run(tool, args);
|
||||
}
|
||||
})();
|
||||
const client = new NativeMacOSProvider(runner, "darwin").createClient(
|
||||
machoTarget(executable, app),
|
||||
);
|
||||
await writeFile(executable, "replacement bytes");
|
||||
const signature = await client.execute("inspect_signature", {});
|
||||
expect(signature.ok).toBe(false);
|
||||
if (signature.ok) throw new Error("Expected target change");
|
||||
expect(projectAnalysisError(signature.error)).toMatchObject({
|
||||
code: "artifact_changed",
|
||||
details: { path: executable },
|
||||
});
|
||||
expect(runner.calls).toBe(0);
|
||||
});
|
||||
|
||||
it.skipIf(process.getuid?.() === 0)(
|
||||
"rejects an unreadable selected executable",
|
||||
async () => {
|
||||
const { app, executable } = await fixtureApp(undefined);
|
||||
const client = new NativeMacOSProvider(
|
||||
new FixtureRunner(),
|
||||
"darwin",
|
||||
).createClient(machoTarget(executable, app));
|
||||
await chmod(executable, 0);
|
||||
try {
|
||||
const signature = await client.execute("inspect_signature", {});
|
||||
expect(signature.ok).toBe(false);
|
||||
if (signature.ok) throw new Error("Expected access denial");
|
||||
expect(projectAnalysisError(signature.error)).toMatchObject({
|
||||
code: "access_denied",
|
||||
details: { path: executable },
|
||||
});
|
||||
} finally {
|
||||
await chmod(executable, 0o600);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it("reports a regular ticket replaced by a directory as changed", async () => {
|
||||
const { app } = await fixtureApp(notarizationTicketFixture());
|
||||
const ticket = await stapledTicket(
|
||||
@@ -548,7 +596,7 @@ describe("signature target version binding", () => {
|
||||
});
|
||||
},
|
||||
);
|
||||
it("downgrades facets when the executable changes between captures", async () => {
|
||||
it("rejects observations when the executable changes between captures", async () => {
|
||||
const { app, executable } = await fixtureApp(undefined);
|
||||
const signature = await new NativeMacOSProvider(
|
||||
new ReplacingExecutableRunner(),
|
||||
@@ -556,18 +604,12 @@ describe("signature target version binding", () => {
|
||||
)
|
||||
.createClient(machoTarget(executable, app))
|
||||
.execute("inspect_signature", {});
|
||||
if (!signature.ok) throw signature.error;
|
||||
const result = inspectSignatureSchema.parse(signature.value.result);
|
||||
expect(result.verification?.status).toBe("valid");
|
||||
expect(
|
||||
result.security_facets.every(({ state }) => state === "unknown"),
|
||||
).toBe(true);
|
||||
expect(result.limitations).toContain(
|
||||
`Signature target changed during inspection: ${executable}`,
|
||||
);
|
||||
expect(result.security_facets[0]?.evidence).toContain(
|
||||
"target version not bound",
|
||||
);
|
||||
expect(signature.ok).toBe(false);
|
||||
if (signature.ok) throw new Error("Expected target change");
|
||||
expect(projectAnalysisError(signature.error)).toMatchObject({
|
||||
code: "artifact_changed",
|
||||
details: { path: executable },
|
||||
});
|
||||
});
|
||||
|
||||
it.skipIf(process.getuid?.() === 0)(
|
||||
@@ -579,13 +621,29 @@ describe("signature target version binding", () => {
|
||||
await chmod(helpers, 0);
|
||||
try {
|
||||
const signature = await new NativeMacOSProvider(
|
||||
new NewlinePathRunner(),
|
||||
new (class extends FixtureRunner {
|
||||
override async run(tool: string, args: readonly string[]) {
|
||||
const result = await super.run(tool, args);
|
||||
if (!result.ok || args[0] !== "--verify") return result;
|
||||
const stderr = `--prepared:${helpers}/odd\n${app}: invalid signature\n${app}: permission denied\n`;
|
||||
return ok({
|
||||
...result.value,
|
||||
exitCode: 1,
|
||||
stderr,
|
||||
stderrBytes: Buffer.byteLength(stderr),
|
||||
});
|
||||
}
|
||||
})(),
|
||||
"darwin",
|
||||
)
|
||||
.createClient(machoTarget(executable, app))
|
||||
.execute("inspect_signature", {});
|
||||
if (!signature.ok) throw signature.error;
|
||||
const result = inspectSignatureSchema.parse(signature.value.result);
|
||||
expect(result.verification?.status).toBe("unknown");
|
||||
expect(result.verification?.raw_stderr).toContain(
|
||||
`${app}: invalid signature`,
|
||||
);
|
||||
expect(result.limitations).toContainEqual(
|
||||
expect.stringContaining("Could not confirm completeness"),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user