fix(native): preserve definitive failures alongside operational diagnostics
This commit is contained in:
@@ -4,7 +4,7 @@ import type { NativeCommandCapture } from "./CommandRunner.js";
|
||||
/** Strip the diagnostic's echoed pathname for classification, keeping the raw line elsewhere. */
|
||||
export const codesignReason = (line: string, path: string): string => {
|
||||
if (line.startsWith(`${path}: `)) return line.slice(path.length + 2);
|
||||
if (line.startsWith("/")) {
|
||||
if (line.startsWith("/") || line.startsWith(`${path}/`)) {
|
||||
const delimiter = line.lastIndexOf(": ");
|
||||
return delimiter >= 0 ? line.slice(delimiter + 2) : "";
|
||||
}
|
||||
@@ -26,26 +26,28 @@ export const codesignReasons = (
|
||||
};
|
||||
|
||||
/** Classify only explicit diagnostic reasons; nonzero exit alone proves no invalidity. */
|
||||
const operationalReason = (reason: string): boolean =>
|
||||
/^(?:permission denied|operation not permitted|EACCES\b|EPERM\b|I\/O error|input\/output error)/iu.test(
|
||||
reason,
|
||||
);
|
||||
|
||||
/** Operational diagnostics can coexist with an independently proven invalid component. */
|
||||
export const codesignOperationalFailure = (
|
||||
capture: NativeCommandCapture,
|
||||
path: string,
|
||||
): boolean => codesignReasons(capture, path).some(operationalReason);
|
||||
|
||||
const verificationStatus = (
|
||||
capture: NativeCommandCapture,
|
||||
reasons: readonly string[],
|
||||
unsigned: boolean,
|
||||
): NonNullable<InspectSignature["verification"]>["status"] => {
|
||||
if (capture.exitCode === 0) return "valid";
|
||||
if (
|
||||
reasons.some((reason) =>
|
||||
/^(?:permission denied|operation not permitted|EACCES\b|EPERM\b|I\/O error|input\/output error)/iu.test(
|
||||
reason,
|
||||
),
|
||||
)
|
||||
)
|
||||
return "unknown";
|
||||
const unsignedReason = reasons.some((reason) =>
|
||||
/^(?:code object is not signed at all|code object is not signed|not signed at all)/iu.test(
|
||||
reason,
|
||||
),
|
||||
);
|
||||
if (unsignedReason) return unsigned ? "unsigned" : "invalid";
|
||||
if (
|
||||
reasons.some((reason) =>
|
||||
/^(?:a sealed resource is missing or invalid|code or signature modified|invalid signature|invalid or unsupported format|resource envelope is obsolete|signature is invalid|unsealed contents present|file modified:|file added:|a resource envelope is obsolete)/iu.test(
|
||||
@@ -54,6 +56,9 @@ const verificationStatus = (
|
||||
)
|
||||
)
|
||||
return "invalid";
|
||||
if (unsignedReason && !unsigned) return "invalid";
|
||||
if (reasons.some(operationalReason)) return "unknown";
|
||||
if (unsignedReason) return "unsigned";
|
||||
return "unknown";
|
||||
};
|
||||
|
||||
|
||||
@@ -20,7 +20,10 @@ import {
|
||||
} from "./CommandRunner.js";
|
||||
import { NATIVE_MACOS_PROVIDER_IDENTITY } from "./NativeMacOSProviderMetadata.js";
|
||||
import type { NativeObservation } from "./NativeObservation.js";
|
||||
import { signatureVerification } from "./CodesignVerification.js";
|
||||
import {
|
||||
signatureVerification,
|
||||
codesignOperationalFailure,
|
||||
} from "./CodesignVerification.js";
|
||||
import { parseCodeSignature } from "./parsers/codesign.js";
|
||||
import { parseSignatureEntitlements } from "./NativeSignatureEntitlements.js";
|
||||
import {
|
||||
@@ -153,6 +156,10 @@ export const inspectNativeSignature = async (options: {
|
||||
limitations.push(
|
||||
"Signature verification is inconclusive (permission, I/O or unrecognized diagnostic); this is not a proven broken signature.",
|
||||
);
|
||||
else if (codesignOperationalFailure(verified.value, code))
|
||||
limitations.push(
|
||||
"Some code could not be verified due to operational diagnostics; definitive signature failures elsewhere still prove invalidity.",
|
||||
);
|
||||
let mainInvalid =
|
||||
verification.status === "invalid" || verification.status === "unknown";
|
||||
if (mainInvalid && !unsigned && code !== target.path) {
|
||||
|
||||
@@ -64,3 +64,23 @@ it("excludes complete selected paths with embedded newlines before classifying r
|
||||
expect(result.status).toBe("invalid");
|
||||
expect(result.diagnostics.join("\n")).toContain(path);
|
||||
});
|
||||
|
||||
it("preserves definitive invalidity when other components have operational failures", async () => {
|
||||
const path = "/Applications/Fixture.app";
|
||||
const capture = await new NativeFixtureRunner().run("codesign", [
|
||||
"--verify",
|
||||
path,
|
||||
]);
|
||||
if (!capture.ok) throw capture.error;
|
||||
const observed = signatureVerification(
|
||||
{
|
||||
...capture.value,
|
||||
exitCode: 1,
|
||||
stderr: `${path}/Contents/Helpers/one: permission denied\n${path}/Contents/Helpers/two: invalid signature\n`,
|
||||
},
|
||||
path,
|
||||
false,
|
||||
);
|
||||
expect(observed.status).toBe("invalid");
|
||||
expect(observed.diagnostics).toHaveLength(2);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user