fix(hopper): recover provenance-verified Spotlight exits

Verify the native helper's sealed identifier and pinned Apple signing team in BridgeLauncher, then carry that provenance to HopperClient. Only a verified native helper's complete not-found exit confirms no document handoff, allowing runtime and target-lease cleanup and retry; wrappers retain unknown document state.

Share publisher identity with setup through the domain contract. Correct fixture teardown ordering and parameterized MCP coverage. Validation: 54 focused tests passed across boundary, CLI, MCP acceptance, diagnostics and installer coverage (one Linux-only case skipped); check:fast passed. Real codesign verification accepted the installed official Hopper helper; Spotlight failures and bridge recovery used process fixtures.
This commit is contained in:
morluto
2026-10-14 06:19:47 +08:00
parent 4d98123279
commit 4acda94b76
13 changed files with 286 additions and 112 deletions
+6 -23
View File
@@ -15,6 +15,8 @@ import { promisify } from "node:util";
import { z } from "zod";
import { homeDirectoryFromEnvironment } from "../config/homeDirectory.js";
import { HOPPER_PUBLISHER } from "../domain/hopperPublisher.js";
import { macDeveloperIdRequirement } from "../process/MacCodeSignature.js";
import {
downloadHopperPackage,
HOPPER_DOWNLOAD_BYTES,
@@ -24,29 +26,10 @@ const execFileAsync = promisify(execFile);
const RELEASES_URL =
"https://www.hopperapp.com/include/files-api.php?request=releases&public=true";
const DOWNLOAD_PREFIX = "https://www.hopperapp.com:443/downloader/public/";
/**
* Apple publisher identity pinned for the official Hopper macOS bundle. The
* team identifier was captured from `Hopper-6.6.0-demo.dmg` at
* `https://www.hopperapp.com:443/downloader/public/Hopper-6.6.0-demo.dmg`
* (34846271 bytes, SHA-1 0be530f038249742590992199c7b042ea20ca955) with
* `codesign -dvvv`, which reported
* `Authority=Developer ID Application: Cryptic Apps (2AMA2753NF)`.
*/
export const HOPPER_PUBLISHER = Object.freeze({
bundleIdentifier: "com.cryptic-apps.hopper-web-4",
teamIdentifier: "2AMA2753NF",
});
/**
* Code requirement enforcing the bundle identifier and signing team together.
* The identifier is read from the sealed CodeDirectory, so it cannot be changed
* by editing `Info.plist` the way the previous string comparison could.
*/
const HOPPER_PUBLISHER_REQUIREMENT =
`= identifier "${HOPPER_PUBLISHER.bundleIdentifier}"` +
` and anchor apple generic` +
` and certificate leaf[subject.OU] = "${HOPPER_PUBLISHER.teamIdentifier}"`;
const HOPPER_PUBLISHER_REQUIREMENT = macDeveloperIdRequirement(
HOPPER_PUBLISHER.bundleIdentifier,
HOPPER_PUBLISHER.teamIdentifier,
);
/** Outcome of reading a mounted bundle's signature and publisher identity. */
export type MacHopperBundleVerification =
+1 -1
View File
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import { HOPPER_PUBLISHER } from "./MacHopper.js";
import { HOPPER_PUBLISHER } from "../domain/hopperPublisher.js";
import { setupInstallFailure } from "./SetupInstallFailure.js";
describe("macOS Hopper setup failure projection", () => {
+1 -1
View File
@@ -1,4 +1,4 @@
import { HOPPER_PUBLISHER } from "./MacHopper.js";
import { HOPPER_PUBLISHER } from "../domain/hopperPublisher.js";
export type SetupFailureCode =
| "unsupported_host"
+12
View File
@@ -0,0 +1,12 @@
/**
* Apple publisher identity pinned for the official Hopper macOS bundle. The
* team identifier was captured from `Hopper-6.6.0-demo.dmg` at
* `https://www.hopperapp.com:443/downloader/public/Hopper-6.6.0-demo.dmg`
* (34846271 bytes, SHA-1 0be530f038249742590992199c7b042ea20ca955) with
* `codesign -dvvv`, which reported
* `Authority=Developer ID Application: Cryptic Apps (2AMA2753NF)`.
*/
export const HOPPER_PUBLISHER = Object.freeze({
bundleIdentifier: "com.cryptic-apps.hopper-web-4",
teamIdentifier: "2AMA2753NF",
});
+14
View File
@@ -33,6 +33,7 @@ import {
} from "./HopperTargetLease.js";
import type { HopperTargetLease } from "./HopperTargetLease.js";
import { HOPPER_SHUTDOWN_TIMEOUT_MS } from "./HopperSessionValues.js";
import { verifyMacHopperNativeHelper } from "./HopperMacPublisher.js";
const execFileAsync = promisify(execFile);
const HOPPER_BACKGROUND_STARTUP_MS = 5_000;
@@ -47,6 +48,8 @@ export interface BridgeSession {
/** Process handle returned by a bridge launcher. */
export type BridgeLaunch = {
/** Verified publisher and sealed native-helper identity; omission is unknown. */
readonly nativeHelperVerified?: true;
/** Only literal native-helper arguments support a pre-handoff denial conclusion. */
readonly authorizationDenialBeforeHandoff?: true;
/** Release application/target exclusivity only after verified document and process cleanup. */
@@ -106,6 +109,7 @@ export type HopperApplicationLauncherOptions =
});
export interface HopperApplicationLauncherDependencies {
readonly verifyNativeHelper?: typeof verifyMacHopperNativeHelper;
readonly platform?: NodeJS.Platform;
readonly acquireTargetLease?: typeof acquireHopperTargetLease;
readonly acquireApplicationLease?: typeof acquireLinuxHopperApplicationLease;
@@ -213,6 +217,13 @@ export class HopperApplicationLauncher implements BridgeLauncher {
if (signal?.aborted === true) return err(new HopperCancelledError());
const display = await this.#privateDisplay(signal);
if (!display.ok) return err(display.error);
const nativeHelperVerified =
(this.dependencies.platform ?? process.platform) === "darwin" &&
this.options.launchMode === "native" &&
(await (
this.dependencies.verifyNativeHelper ?? verifyMacHopperNativeHelper
)(this.options.launcherPath, this.options.environment, signal)) ===
"verified";
const prepared = await prepareHopperApplication(
this.options.launcherPath,
this.options.environment,
@@ -257,6 +268,9 @@ export class HopperApplicationLauncher implements BridgeLauncher {
...ownedLauncher,
providerLifetime: "external-application",
shutdownMode: "bridge-request",
...(nativeHelperVerified
? { nativeHelperVerified: true as const }
: {}),
// The vendor helper interpolates these values into AppleScript
// literals without escaping. Preserve them, but withhold the
// pre-handoff conclusion when they can alter that script.
+4
View File
@@ -770,6 +770,10 @@ export class HopperClient {
});
}
if (hopperLauncherReportedApplicationNotFound(launcherFailure)) {
// Only the verified native helper's Spotlight exit precedes any target
// handoff. Wrappers can forward the same message after opening a document.
if (this.#resources.launch?.nativeHelperVerified === true)
this.#resources.shutdownConfirmed = true;
return new HopperStartError({
userMessage:
"Hopper's launcher could not find Hopper because it relies on Spotlight. Enable Spotlight indexing for the volume that contains Hopper (for example: sudo mdutil -i on /System/Volumes/Data), wait for indexing to finish, then retry opening the target.",
+36
View File
@@ -0,0 +1,36 @@
import { HOPPER_PUBLISHER } from "../domain/hopperPublisher.js";
import { macDeveloperIdRequirement } from "../process/MacCodeSignature.js";
import { execFileOutput } from "../process/ExecFileOutput.js";
/** Failure or unavailable verification leaves custom/native provenance unknown. */
export const verifyMacHopperNativeHelper = async (
launcherPath: string,
environment: Readonly<NodeJS.ProcessEnv>,
signal?: AbortSignal,
): Promise<"verified" | "unknown"> => {
// codesign treats a bare name as a local file, while spawn searches PATH.
// Without an explicit path they need not identify the same executable.
if (!launcherPath.includes("/")) return "unknown";
try {
await execFileOutput(
"/usr/bin/codesign",
[
"--verify",
"--strict",
`-R${macDeveloperIdRequirement("hopper", HOPPER_PUBLISHER.teamIdentifier)}`,
launcherPath,
],
{
env: environment,
...(signal === undefined ? {} : { signal }),
timeout: 5_000,
stopSignal: "SIGKILL",
},
);
return "verified";
} catch (cause: unknown) {
// Optional provenance: a failed check must never authorize lease release.
void cause;
return "unknown";
}
};
+7
View File
@@ -0,0 +1,7 @@
/** Require a sealed identifier and Apple Developer ID signing team together. */
export const macDeveloperIdRequirement = (
identifier: string,
teamIdentifier: string,
): string =>
`= identifier "${identifier}" and anchor apple generic` +
` and certificate leaf[subject.OU] = "${teamIdentifier}"`;