Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions .github/workflows/desktop-prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,6 @@ jobs:
LING_CUA_DRIVER_PACKAGE_PROVIDER: "0"
LING_PLUGIN_EXTERNAL_ONLY: ${{ inputs.plugin_mode == 'on-demand' && '1' || '0' }}
LING_CUA_DRIVER_CATALOG_MANAGED: ${{ inputs.catalog_managed_cua && '1' || '0' }}
LING_CUA_DARWIN_EXPECTED_TEAM_ID: ${{ inputs.catalog_managed_cua && vars.LING_CUA_DARWIN_EXPECTED_TEAM_ID || '' }}
LING_CUA_PROVIDER_SIGNER_SUBJECT: ${{ inputs.catalog_managed_cua && vars.LING_CUA_PROVIDER_SIGNER_SUBJECT || '' }}
LING_CUA_PROVIDER_SIGNER_SHA256: ${{ inputs.catalog_managed_cua && vars.LING_CUA_PROVIDER_SIGNER_SHA256 || '' }}
LING_CUA_CATALOG_SIGNER_SUBJECT: ${{ inputs.catalog_managed_cua && vars.LING_CUA_CATALOG_SIGNER_SUBJECT || '' }}
LING_CUA_CATALOG_SIGNER_SHA256: ${{ inputs.catalog_managed_cua && vars.LING_CUA_CATALOG_SIGNER_SHA256 || '' }}
defaults:
run:
shell: bash
Expand All @@ -186,7 +181,7 @@ jobs:
with:
node-version: 22.22.1
cache: pnpm
- name: Validate Cua Driver catalog signer configuration
- name: Validate the Cua Driver catalog runtime policy
if: env.LING_CUA_DRIVER_CATALOG_MANAGED == '1'
run: |
node --input-type=module <<'NODE'
Expand All @@ -195,13 +190,10 @@ jobs:
packageAuthorityInputFromEnvironment,
} from "./apps/desktop/scripts/cua-driver-package-runtime-policy.mjs";
const platform = process.env.DESKTOP_TARGET === "macos-arm64" ? "darwin" : "win32-x64";
createCuaDriverPackageAuthorityDocuments(packageAuthorityInputFromEnvironment(platform, {
...process.env,
LING_CUA_SIGNING_TIER: "production_signed",
LING_CUA_DISTRIBUTION_CHANNEL: "production",
LING_CUA_SIGNING_FIXTURE: "0",
LING_CUA_TEST_AUTHORITY_KIND: undefined,
}));
createCuaDriverPackageAuthorityDocuments({
...packageAuthorityInputFromEnvironment(platform),
providerSource: "official-cache",
});
NODE
- uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73
if: runner.os == 'Windows' && env.LING_PLUGIN_EXTERNAL_ONLY != '1'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/plugin-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
type: choice
options: [assemble, verify-keys]
sources:
description: Stable Release tags, source commits and asset SHA-256 digests required for assembly
description: One or more stable Release pins per plugin with exact source commits and asset SHA-256 digests
required: false
type: string
publish:
Expand Down
35 changes: 26 additions & 9 deletions apps/desktop/main/cua-driver/adapters/darwin-identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,17 @@ export function createDarwinExecFileCommandRunner(options: {
});
}

export type DarwinCuaDriverSignaturePolicy =
| { readonly expectedTeamId: string; readonly signatureMode?: never }
| { readonly expectedTeamId?: never; readonly signatureMode: "ad-hoc" };

export class DarwinCuaDriverIdentityVerifier implements CuaDriverPlatformIdentityVerifier {
private readonly runner: DarwinIdentityCommandRunner;

constructor(private readonly options: {
readonly expectedTeamId: string;
constructor(private readonly options: DarwinCuaDriverSignaturePolicy & {
readonly runner?: DarwinIdentityCommandRunner;
}) {
if (!/^[A-Z0-9]{10}$/u.test(options.expectedTeamId)) {
if (options.signatureMode !== "ad-hoc" && !/^[A-Z0-9]{10}$/u.test(options.expectedTeamId)) {
throw new Error("darwin_cua_driver_expected_team_id_invalid");
}
this.runner = options.runner ?? createDarwinExecFileCommandRunner();
Expand All @@ -178,11 +181,13 @@ export class DarwinCuaDriverIdentityVerifier implements CuaDriverPlatformIdentit
throw new Error("darwin_cua_driver_identity_platform_mismatch");
}
const seal = input.seal;
const adHoc = this.options.signatureMode === "ad-hoc";
const expectedTeamId = adHoc ? "not set" : this.options.expectedTeamId;
const platformLock = platformLockFor(input.lock, "darwin");
if (platformLock.componentId !== "cua-driver-darwin") {
throw new Error("darwin_cua_driver_lock_platform_mismatch");
}
if (seal.teamId !== this.options.expectedTeamId) {
if (seal.teamId !== expectedTeamId || seal.hardenedRuntime !== !adHoc) {
throw new Error("darwin_cua_driver_seal_team_id_mismatch");
}

Expand Down Expand Up @@ -217,9 +222,10 @@ export class DarwinCuaDriverIdentityVerifier implements CuaDriverPlatformIdentit
args: ["--display", "--verbose=4", "--arch", architecture, input.paths.executablePath],
});
const details = parseCodesignDetails(`${detailsResult.stdout}\n${detailsResult.stderr}`);
if (details.teamId !== this.options.expectedTeamId
if (details.teamId !== expectedTeamId
|| details.identifier !== seal.codeIdentifier
|| details.hardenedRuntime !== true
|| details.hardenedRuntime !== !adHoc
|| details.adHoc !== adHoc
|| details.cdhash !== seal.cdhashes[architecture]) {
throw new Error("darwin_cua_driver_codesign_identity_mismatch");
}
Expand All @@ -234,6 +240,7 @@ export class DarwinCuaDriverIdentityVerifier implements CuaDriverPlatformIdentit
});
const requirement = normalizeDesignatedRequirement(
`${requirementResult.stdout}\n${requirementResult.stderr}`,
adHoc,
);
if (requirement !== seal.designatedRequirement
|| sha256Utf8(requirement) !== seal.designatedRequirementSha256) {
Expand All @@ -248,6 +255,14 @@ export class DarwinCuaDriverIdentityVerifier implements CuaDriverPlatformIdentit
executable: DARWIN_SYSTEM_TOOLS.codesign,
args: ["--display", "--entitlements", "-", "--xml", "--arch", architecture, input.paths.executablePath],
});
if (adHoc) {
const reportedEntitlements = `${entitlementsResult.stdout}\n${entitlementsResult.stderr}`
.split(/\r?\n/u).some((line) => line.trim() && !line.startsWith("Executable="));
if (reportedEntitlements || seal.entitlementsCanonicalSha256 !== sha256Utf8("{}")) {
throw new Error("darwin_cua_driver_ad_hoc_entitlements_mismatch");
}
continue;
}
const entitlementsPlist = extractPlist(entitlementsResult.stdout, entitlementsResult.stderr);
const entitlementsJson = await this.runner.run({
executable: DARWIN_SYSTEM_TOOLS.plutil,
Expand Down Expand Up @@ -297,6 +312,7 @@ function parseCodesignDetails(output: string): {
readonly teamId: string;
readonly cdhash: string;
readonly hardenedRuntime: boolean;
readonly adHoc: boolean;
} {
const lines = output.split(/\r?\n/u).map((line) => line.trim()).filter(Boolean);
const valueFor = (prefix: string): string | undefined =>
Expand All @@ -313,18 +329,19 @@ function parseCodesignDetails(output: string): {
teamId,
cdhash,
hardenedRuntime: /(?:\(|,)runtime(?:\)|,)/u.test(codeDirectory),
adHoc: valueFor("Signature=") === "adhoc",
};
}

function normalizeDesignatedRequirement(output: string): string {
function normalizeDesignatedRequirement(output: string, adHoc: boolean): string {
const line = output
.split(/\r?\n/u)
.map((value) => value.trim())
.find((value) => value.startsWith("designated =>"));
.find((value) => value.startsWith(adHoc ? "# designated =>" : "designated =>"));
if (!line) {
throw new Error("darwin_cua_driver_designated_requirement_missing");
}
return line.replace(/^designated\s*=>\s*/u, "").trim();
return line.replace(/^(?:# )?designated\s*=>\s*/u, "").trim();
}

function extractPlist(stdout: string, stderr: string): string {
Expand Down
8 changes: 5 additions & 3 deletions apps/desktop/main/cua-driver/adapters/darwin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { DarwinCuaDriverPlatformBinding } from "../platform-binding.js";
import {
DarwinCuaDriverIdentityVerifier,
type DarwinCuaDriverSignaturePolicy,
type DarwinIdentityCommandRunner,
} from "./darwin-identity.js";
import {
Expand All @@ -27,8 +28,7 @@ export interface DarwinCuaDriverAdapter {
* and stop monitoring with requested enablement, then rotate the provider
* generation from `onPermissionChanged`.
*/
export function createDarwinCuaDriverAdapter(options: {
readonly expectedTeamId: string;
export function createDarwinCuaDriverAdapter(options: DarwinCuaDriverSignaturePolicy & {
readonly identityCommandRunner?: DarwinIdentityCommandRunner;
readonly spawn?: DarwinDirectSpawn;
readonly permissionPort?: DarwinHostPermissionPort;
Expand All @@ -51,7 +51,9 @@ export function createDarwinCuaDriverAdapter(options: {
platform: "darwin",
availability: Object.freeze({ status: "available" as const }),
platformIdentityVerifier: new DarwinCuaDriverIdentityVerifier({
expectedTeamId: options.expectedTeamId,
...(options.signatureMode === "ad-hoc"
? { signatureMode: "ad-hoc" as const }
: { expectedTeamId: options.expectedTeamId }),
...(options.identityCommandRunner ? { runner: options.identityCommandRunner } : {}),
}),
processLifecycle: createDarwinCuaDriverProcessLifecycle({
Expand Down
6 changes: 6 additions & 0 deletions apps/desktop/main/cua-driver/coordinator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ export interface CuaDriverCoordinatorOptions {
readonly featureFlags?: CuaDriverFeatureFlags;
readonly packaged?: boolean;
readonly requireReleaseEvidence?: boolean;
readonly runtimeChecksums?: Readonly<Record<string, string>>;
readonly catalogSourceBuild?: boolean;
/** Negotiated with the daemon; old daemons must not receive detail fields. */
readonly readinessDetailsV1?: boolean;
/** Preferred production composition boundary for one coherent OS adapter. */
Expand Down Expand Up @@ -559,6 +561,8 @@ export class CuaDriverDesktopCoordinator {
lock,
platformIdentityVerifier: this.platformIdentityVerifier,
requirePlatformIdentityVerification: this.options.packaged === true,
runtimeChecksums: this.options.runtimeChecksums,
catalogSourceBuild: this.options.catalogSourceBuild,
});
this.assertHostNotDraining();
const stateRoot = await createCuaDriverStateRoot({
Expand Down Expand Up @@ -600,6 +604,8 @@ export class CuaDriverDesktopCoordinator {
lock: liveLock,
platformIdentityVerifier: this.platformIdentityVerifier,
requirePlatformIdentityVerification: this.options.packaged === true,
runtimeChecksums: this.options.runtimeChecksums,
catalogSourceBuild: this.options.catalogSourceBuild,
});
signal.throwIfAborted();
if (
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/main/cua-driver/packaged-startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface DesktopCuaDriverPackagedStartupAuthority {
readonly runtimeEligible: boolean;
readonly policy?: CuaDriverRuntimeTrustPolicyV1;
readonly providerResourcesPath?: string;
readonly runtimeChecksums?: Readonly<Record<string, string>>;
readonly failure?: unknown;
}

Expand Down Expand Up @@ -122,6 +123,7 @@ export async function resolveDesktopCuaDriverPackagedStartupAuthority(
return Object.freeze({
authority, featureFlags, policy, runtimeEligible: true,
providerResourcesPath: join(runtime.root, "runtime"),
runtimeChecksums: runtime.runtimeChecksums,
});
}
return Object.freeze({ authority, featureFlags, policy, runtimeEligible: true });
Expand Down
4 changes: 3 additions & 1 deletion apps/desktop/main/cua-driver/platform-owner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ export function createCuaDriverDesktopPlatformOwner(
throw new CuaDriverDesktopPlatformOwnerError("platform_mismatch", options.platform);
}
const adapter = createDarwinCuaDriverAdapter({
expectedTeamId: options.policy.expectedTeamId,
...(options.policy.signatureMode === "ad-hoc"
? { signatureMode: "ad-hoc" as const }
: { expectedTeamId: options.policy.expectedTeamId }),
...(options.identityCommandRunner ? { identityCommandRunner: options.identityCommandRunner } : {}),
...(options.spawn ? { spawn: options.spawn } : {}),
...(options.permissionPort ? { permissionPort: options.permissionPort } : {}),
Expand Down
Loading
Loading