fix(native): verify nested code and keep ticket read failures local
Address review findings in inspect_signature: - Verify with `codesign --verify --deep --strict`. Shallow verification misses a file added inside a nested XPC service, or a modified dylib inside a framework. verify:code-signature now tampers inside the nested XPC service and requires `invalid`. - Classify verification as `unsigned` only when the top-level target is unsigned. Unsigned nested code inside a signed bundle is `invalid`. - Report a stapled ticket that exists but cannot be read as `unreadable`, with the error code in a new `reason` field, instead of failing the whole signature inspection. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
25ca63f231
commit
37824e8c46
@@ -1,5 +1,5 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { chmod, mkdir, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
@@ -72,6 +72,7 @@ describe("native signature posture", () => {
|
||||
path: "Contents/CodeResources",
|
||||
sha256: createHash("sha256").update(ticket).digest("hex"),
|
||||
size: ticket.length,
|
||||
reason: null,
|
||||
});
|
||||
expect(
|
||||
Object.fromEntries(
|
||||
@@ -132,4 +133,64 @@ describe("native signature posture", () => {
|
||||
stapled_ticket: { status: "not-applicable" },
|
||||
});
|
||||
});
|
||||
|
||||
it.skipIf(process.getuid?.() === 0)(
|
||||
"keeps inspecting when the stapled ticket cannot be read",
|
||||
async () => {
|
||||
const { app, executable } = await fixtureApp("ticket");
|
||||
const ticket = join(app, "Contents/CodeResources");
|
||||
await chmod(ticket, 0o000);
|
||||
try {
|
||||
const signature = await new NativeMacOSProvider(
|
||||
new FixtureRunner(),
|
||||
"darwin",
|
||||
)
|
||||
.createClient(machoTarget(executable, app))
|
||||
.execute("inspect_signature", {});
|
||||
expect(signature.ok && signature.value.result).toMatchObject({
|
||||
stapled_ticket: {
|
||||
status: "unreadable",
|
||||
path: "Contents/CodeResources",
|
||||
sha256: null,
|
||||
reason: "EACCES",
|
||||
},
|
||||
verification: { status: "valid" },
|
||||
});
|
||||
} finally {
|
||||
await chmod(ticket, 0o644);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it("reports unsigned nested code inside a signed bundle as invalid", async () => {
|
||||
const { app, executable } = await fixtureApp(undefined);
|
||||
const signature = await new NativeMacOSProvider(
|
||||
new UnsignedNestedRunner(),
|
||||
"darwin",
|
||||
)
|
||||
.createClient(machoTarget(executable, app))
|
||||
.execute("inspect_signature", {});
|
||||
expect(signature.ok && signature.value.result).toMatchObject({
|
||||
signed: true,
|
||||
verification: { status: "invalid", exit_code: 1 },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/** A signed bundle whose nested helper is unsigned. */
|
||||
class UnsignedNestedRunner extends FixtureRunner {
|
||||
override async run(tool: string, arguments_: readonly string[]) {
|
||||
const result = await super.run(tool, arguments_);
|
||||
if (!result.ok || arguments_[0] !== "--verify") return result;
|
||||
const stderr =
|
||||
"/Applications/Fixture.app/Contents/Helpers/tool: code object is not signed at all\nIn subcomponent: /Applications/Fixture.app/Contents/Helpers/tool\n";
|
||||
return ok({
|
||||
...result.value,
|
||||
stdout: "",
|
||||
stderr,
|
||||
stdoutBytes: 0,
|
||||
stderrBytes: Buffer.byteLength(stderr),
|
||||
exitCode: 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user