Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(spaces): sign and notarize the Electron macOS build and its disk images (#4928)

ddupontf4a7f5ef2f90
diff --git a/.github/scripts/tests/test_cua_sdk_release_repository.py b/.github/scripts/tests/test_cua_sdk_release_repository.py
index 6f50ec7fc2..df8726899e 100644
--- a/.github/scripts/tests/test_cua_sdk_release_repository.py
+++ b/.github/scripts/tests/test_cua_sdk_release_repository.py
@@ -140,7 +140,16 @@ def test_spaces_electron_builds_only_for_prereleases_and_dry_runs() -> None:
assert "pnpm native -- --target x86_64-apple-darwin" in mac
assert "pnpm notch" in mac
assert mac.index("pnpm notch") < mac.index("pnpm dist:mac")
- assert 'CSC_LINK="$APPLICATION_CERT_BASE64"' in mac and 'APPLE_TEAM_ID="$TEAM_ID"' in mac
+ # Signed with the Developer ID identity of a keychain the job imports
+ # (electron-builder's own CSC_LINK keychain fails on macos-26).
+ assert "security import" in mac and "set-key-partition-list" in mac
+ assert 'CSC_NAME="$SIGNING_NAME" CSC_KEYCHAIN="$SIGNING_KEYCHAIN"' in mac and 'APPLE_TEAM_ID="$TEAM_ID"' in mac
+ assert "CSC_LINK" not in mac
+ assert mac.index("security import") < mac.index("pnpm dist:mac") < mac.index("security delete-keychain")
+ # The disk images are signed, notarized and stapled after electron-builder,
+ # their feed entries made again, and then checked like the SwiftUI app's.
+ assert mac.index("pnpm dist:mac") < mac.index("scripts/notarize.sh") < mac.index("xcrun stapler staple")
+ assert mac.index("xcrun stapler staple") < mac.index("refresh-update-info.mjs") < mac.index('spctl -a -vv -t install "$dmg"')
assert "com.trycua.spaces.macos" in mac
windows = "\n".join(s.get("run", "") for s in steps("cd-cua-spaces.yml", "electron-windows"))
assert "pnpm native -- --target x86_64-pc-windows-msvc" in windows
diff --git a/.github/workflows/cd-cua-spaces.yml b/.github/workflows/cd-cua-spaces.yml
index 4b3042d6dd..467a1965f8 100644
--- a/.github/workflows/cd-cua-spaces.yml
+++ b/.github/workflows/cd-cua-spaces.yml
@@ -963,14 +963,51 @@ jobs:
run: |
pnpm native -- --target aarch64-apple-darwin --skip-build --check-bindings
pnpm test
+ # The Developer ID Application identity in a throwaway keychain, as
+ # build-macos imports it. electron-builder's own keychain from CSC_LINK
+ # fails on the macos-26 runners (`security set-key-partition-list`:
+ # "SecKeychainUnlock: The user name or passphrase you entered is not
+ # correct"), so it signs with this keychain's identity (CSC_NAME,
+ # CSC_KEYCHAIN) instead.
+ - name: Import the Developer ID Application certificate
+ id: keychain
+ if: steps.signing.outputs.apple == 'true'
+ env:
+ APPLICATION_CERT_BASE64: ${{ secrets.APPLICATION_CERT_BASE64 }}
+ CERT_PASSWORD: ${{ secrets.CERT_PASSWORD }}
+ run: |
+ set -euo pipefail
+ kc="$RUNNER_TEMP/electron-signing.keychain-db"
+ kc_password="$(uuidgen)"
+ security create-keychain -p "$kc_password" "$kc"
+ security set-keychain-settings -lut 21600 "$kc"
+ security unlock-keychain -p "$kc_password" "$kc"
+ printf '%s' "$APPLICATION_CERT_BASE64" | base64 --decode > "$RUNNER_TEMP/electron-application.p12"
+ security import "$RUNNER_TEMP/electron-application.p12" -k "$kc" -P "$CERT_PASSWORD" \
+ -T /usr/bin/codesign >/dev/null
+ rm -f "$RUNNER_TEMP/electron-application.p12"
+ security set-key-partition-list -S apple-tool:,apple:,codesign: \
+ -s -k "$kc_password" "$kc" >/dev/null
+ existing=()
+ while IFS= read -r keychain; do existing+=("$keychain"); done \
+ < <(security list-keychains -d user | tr -d '"' | sed 's/^ *//')
+ security list-keychains -d user -s "$kc" "${existing[@]}"
+ # electron-builder takes the name without the certificate type.
+ name="$(security find-identity -v -p codesigning "$kc" \
+ | sed -n 's/.*"Developer ID Application: \(.*\)"$/\1/p' | head -n 1)"
+ test -n "$name"
+ {
+ echo "keychain=$kc"
+ echo "name=$name"
+ } >> "$GITHUB_OUTPUT"
- name: Build, sign and notarize (electron-builder)
working-directory: apps/cua-spaces-desktop
env:
SIGNED: ${{ steps.signing.outputs.apple }}
CUA_SPACES_VERSION: ${{ needs.electron-plan.outputs.version }}
CUA_SPACES_BUILD_NUMBER: ${{ github.run_number }}
- APPLICATION_CERT_BASE64: ${{ secrets.APPLICATION_CERT_BASE64 }}
- CERT_PASSWORD: ${{ secrets.CERT_PASSWORD }}
+ SIGNING_KEYCHAIN: ${{ steps.keychain.outputs.keychain }}
+ SIGNING_NAME: ${{ steps.keychain.outputs.name }}
APPLE_ID: ${{ secrets.APPLE_ID }}
APP_SPECIFIC_PASSWORD: ${{ secrets.APP_SPECIFIC_PASSWORD }}
TEAM_ID: ${{ secrets.TEAM_ID }}
@@ -978,13 +1015,35 @@ jobs:
set -euo pipefail
if [ "$SIGNED" = true ]; then
# electron-builder's names for the same identities.
- export CSC_LINK="$APPLICATION_CERT_BASE64" CSC_KEY_PASSWORD="$CERT_PASSWORD"
+ export CSC_NAME="$SIGNING_NAME" CSC_KEYCHAIN="$SIGNING_KEYCHAIN"
export APPLE_APP_SPECIFIC_PASSWORD="$APP_SPECIFIC_PASSWORD" APPLE_TEAM_ID="$TEAM_ID"
else
export CSC_IDENTITY_AUTO_DISCOVERY=false
unset APPLE_ID
fi
pnpm dist:mac
+ # electron-builder signs and notarizes the apps, not the disk images:
+ # each is signed (with a timestamp), notarized and stapled here like the
+ # SwiftUI app's, then its blockmap and its entry in the update feed
+ # files are made again for the stapled bytes.
+ - name: Sign, notarize and staple the disk images
+ if: steps.signing.outputs.apple == 'true'
+ working-directory: apps/cua-spaces-desktop
+ env:
+ SIGNING_KEYCHAIN: ${{ steps.keychain.outputs.keychain }}
+ SIGNING_NAME: ${{ steps.keychain.outputs.name }}
+ APPLE_ID: ${{ secrets.APPLE_ID }}
+ APPLE_PASSWORD: ${{ secrets.APP_SPECIFIC_PASSWORD }}
+ APPLE_TEAM_ID: ${{ secrets.TEAM_ID }}
+ run: |
+ set -euo pipefail
+ for dmg in dist/*.dmg; do
+ codesign --force --timestamp --keychain "$SIGNING_KEYCHAIN" \
+ --sign "Developer ID Application: $SIGNING_NAME" "$dmg"
+ ../cua-spaces-macos/scripts/notarize.sh "$dmg"
+ xcrun stapler staple "$dmg"
+ done
+ node scripts/refresh-update-info.mjs dist/*.dmg
- name: Verify the apps and collect the assets
working-directory: apps/cua-spaces-desktop
env:
@@ -1000,6 +1059,13 @@ jobs:
spctl -a -vv "$app"
fi
done
+ if [ "$SIGNED" = true ]; then
+ for dmg in dist/*.dmg; do
+ codesign --verify --strict "$dmg"
+ xcrun stapler validate "$dmg"
+ spctl -a -vv -t install "$dmg"
+ done
+ fi
pnpm check:fuses
mkdir -p electron-assets
cp dist/*.dmg dist/*.zip dist/*.blockmap electron-assets/
@@ -1056,6 +1122,12 @@ jobs:
path: appcast/cua-spaces-appcast.xml
if-no-files-found: error
retention-days: 7
+ - name: Remove the signing keychain
+ if: always()
+ run: |
+ kc="$RUNNER_TEMP/electron-signing.keychain-db"
+ [ -f "$kc" ] && security delete-keychain "$kc" || true
+ rm -f "$RUNNER_TEMP/electron-application.p12"
electron-windows:
name: Electron windows (x64, arm64)
diff --git a/apps/cua-spaces-desktop/packaging/sign-mac.cjs b/apps/cua-spaces-desktop/packaging/sign-mac.cjs
index 06191b14bd..1563de45c1 100644
--- a/apps/cua-spaces-desktop/packaging/sign-mac.cjs
+++ b/apps/cua-spaces-desktop/packaging/sign-mac.cjs
@@ -42,12 +42,24 @@ function osxSign() {
return require(require.resolve("@electron/osx-sign", { paths: [path.dirname(lib)] }));
}
-/** @param {import("@electron/osx-sign/dist/cjs/types").SignOptions} opts */
-async function sign(opts, load = osxSign) {
+/**
+ * Signs with `load()`'s `signAsync` (`@electron/osx-sign` in a build, a stand-in in tests).
+ * @param {import("@electron/osx-sign/dist/cjs/types").SignOptions} opts
+ */
+async function signWith(opts, load) {
if (!fs.existsSync(DAEMON_ENTITLEMENTS)) throw new Error(`missing ${DAEMON_ENTITLEMENTS}`);
const optionsForFile = opts.optionsForFile;
const { signAsync } = load();
await signAsync({ ...opts, optionsForFile: (file) => withDaemonIdentity(optionsForFile ? optionsForFile(file) : {}, file) });
}
-module.exports = { sign, withDaemonIdentity, isDaemon, DAEMON_IDENTIFIER, DAEMON_ENTITLEMENTS };
+/**
+ * electron-builder's `mac.sign` hook. It is called as `sign(opts, packager)`;
+ * the packager is not used.
+ * @param {import("@electron/osx-sign/dist/cjs/types").SignOptions} opts
+ */
+async function sign(opts) {
+ await signWith(opts, osxSign);
+}
+
+module.exports = { sign, signWith, withDaemonIdentity, isDaemon, DAEMON_IDENTIFIER, DAEMON_ENTITLEMENTS };
diff --git a/apps/cua-spaces-desktop/scripts/refresh-update-info.mjs b/apps/cua-spaces-desktop/scripts/refresh-update-info.mjs
new file mode 100755
index 0000000000..1b9bfcd7be
--- /dev/null
+++ b/apps/cua-spaces-desktop/scripts/refresh-update-info.mjs
@@ -0,0 +1,66 @@
+#!/usr/bin/env node
+// SPDX-License-Identifier: FSL-1.1-MIT
+// Copyright (c) 2026 Cua AI, Inc.
+
+/**
+ * `node scripts/refresh-update-info.mjs <file>...`
+ *
+ * After an installer electron-builder already made is changed (the release
+ * signs, notarizes and staples the macOS disk images, which changes their
+ * bytes), rebuilds each file's blockmap (`<file>.blockmap`, electron-builder's
+ * own `buildBlockMap`) and updates its `sha512` and `size` (and
+ * `blockMapSize`) in the update feed files next to it (dist/*.yml), so the
+ * feed describes the file that is published. Fails when a file is not named
+ * by any feed file.
+ */
+import { readdirSync, readFileSync, writeFileSync } from "node:fs";
+import { createRequire } from "node:module";
+import { basename, dirname, join } from "node:path";
+
+const require = createRequire(import.meta.url);
+/** app-builder-lib (electron-builder's), which this project does not depend on directly. */
+function builderLib(subpath) {
+ const builder = require.resolve("electron-builder/package.json");
+ const lib = dirname(require.resolve("app-builder-lib/package.json", { paths: [dirname(builder)] }));
+ return require(join(lib, subpath));
+}
+
+export async function refresh(files, { buildBlockMap = builderLib("out/targets/blockmap/blockmap.js").buildBlockMap, yaml = require(require.resolve("js-yaml", { paths: [dirname(require.resolve("electron-builder/package.json"))] })) } = {}) {
+ for (const file of files) {
+ const info = await buildBlockMap(file, "gzip", `${file}.blockmap`);
+ const name = basename(file);
+ const dir = dirname(file);
+ let found = false;
+ for (const feed of readdirSync(dir).filter((f) => f.endsWith(".yml"))) {
+ const path = join(dir, feed);
+ const doc = yaml.load(readFileSync(path, "utf8"));
+ let changed = false;
+ for (const entry of doc?.files ?? []) {
+ if (entry.url !== name) continue;
+ entry.sha512 = info.sha512;
+ entry.size = info.size;
+ if (entry.blockMapSize !== undefined || info.blockMapSize !== undefined) entry.blockMapSize = info.blockMapSize;
+ changed = true;
+ }
+ if (doc?.path === name) {
+ doc.sha512 = info.sha512;
+ changed = true;
+ }
+ if (changed) {
+ writeFileSync(path, yaml.dump(doc, { lineWidth: 8000 }));
+ found = true;
+ console.log(`${feed}: ${name} sha512 ${info.sha512.slice(0, 16)}… size ${info.size}`);
+ }
+ }
+ if (!found) throw new Error(`no update feed file in ${dir} names ${name}`);
+ }
+}
+
+if (import.meta.url === `file://${process.argv[1]}`) {
+ const files = process.argv.slice(2);
+ if (!files.length) {
+ console.error("usage: refresh-update-info.mjs <file>...");
+ process.exit(2);
+ }
+ await refresh(files);
+}
diff --git a/apps/cua-spaces-desktop/test/refresh-update-info.test.ts b/apps/cua-spaces-desktop/test/refresh-update-info.test.ts
new file mode 100644
index 0000000000..f695988aba
--- /dev/null
+++ b/apps/cua-spaces-desktop/test/refresh-update-info.test.ts
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: FSL-1.1-MIT
+// Copyright (c) 2026 Cua AI, Inc.
+
+// scripts/refresh-update-info.mjs: after the release staples a disk image,
+// its blockmap and its entry in the update feed describe the new bytes.
+import { createHash } from "node:crypto";
+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import * as path from "node:path";
+import { afterEach, describe, expect, it } from "vitest";
+// @ts-expect-error: a plain .mjs script, no types
+import { refresh } from "../scripts/refresh-update-info.mjs";
+
+const dirs: string[] = [];
+afterEach(() => dirs.splice(0).forEach((d) => rmSync(d, { recursive: true, force: true })));
+
+describe("refresh-update-info", () => {
+ it("rewrites the stapled disk image's sha512 and size in the feed, and its blockmap", async () => {
+ const dir = mkdtempSync(path.join(tmpdir(), "refresh-"));
+ dirs.push(dir);
+ const dmg = path.join(dir, "Cua-Spaces-0.8.0-beta.2-universal.dmg");
+ const bytes = Buffer.alloc(200_000, 7);
+ writeFileSync(dmg, bytes);
+ const feed = path.join(dir, "beta-mac.yml");
+ writeFileSync(
+ feed,
+ [
+ "version: 0.8.0-beta.2",
+ "files:",
+ " - url: Cua-Spaces-0.8.0-beta.2-universal-mac.zip",
+ " sha512: zip",
+ " size: 10",
+ " - url: Cua-Spaces-0.8.0-beta.2-universal.dmg",
+ " sha512: old",
+ " size: 1",
+ "path: Cua-Spaces-0.8.0-beta.2-universal-mac.zip",
+ "sha512: zip",
+ "",
+ ].join("\n"),
+ );
+ await refresh([dmg]);
+ const text = readFileSync(feed, "utf8");
+ const sha = createHash("sha512").update(bytes).digest("base64");
+ expect(text).toContain(`sha512: ${sha}`);
+ expect(text).toContain("size: 200000");
+ // The zip (what electron-updater installs on macOS) is untouched.
+ expect(text).toContain("sha512: zip\n size: 10");
+ expect(readFileSync(`${dmg}.blockmap`).length).toBeGreaterThan(0);
+ });
+
+ it("fails when no feed file names the file", async () => {
+ const dir = mkdtempSync(path.join(tmpdir(), "refresh-"));
+ dirs.push(dir);
+ const dmg = path.join(dir, "Other.dmg");
+ writeFileSync(dmg, "x");
+ writeFileSync(path.join(dir, "beta-mac.yml"), "files: []\n");
+ await expect(refresh([dmg])).rejects.toThrow(/no update feed file/);
+ });
+});
diff --git a/apps/cua-spaces-desktop/test/vault-identity.test.ts b/apps/cua-spaces-desktop/test/vault-identity.test.ts
index 3cdb07ef01..7978fccadc 100644
--- a/apps/cua-spaces-desktop/test/vault-identity.test.ts
+++ b/apps/cua-spaces-desktop/test/vault-identity.test.ts
@@ -18,7 +18,8 @@ interface FileOptions {
additionalArguments?: string[];
}
const signer = require("../packaging/sign-mac.cjs") as {
- sign(opts: unknown, load?: () => unknown): Promise<void>;
+ sign(opts: unknown, packager?: unknown): Promise<void>;
+ signWith(opts: unknown, load: () => unknown): Promise<void>;
withDaemonIdentity(base: FileOptions, file: string): FileOptions;
isDaemon(file: string): boolean;
DAEMON_IDENTIFIER: string;
@@ -51,10 +52,20 @@ describe("the bundled daemon's signature", () => {
expect(signer.isDaemon(`${daemon}.bak`)).toBe(false);
});
+ // electron-builder calls a custom mac.sign as sign(opts, packager)
+ // (app-builder-lib macPackager.doSign); the packager is not a loader.
+ it("is the hook electron-builder calls with its packager", async () => {
+ const err = await signer.sign({ app: path.join(tmpdir(), "no-such-dir", "Cua Spaces.app") }, { packager: true }).then(
+ () => null,
+ (e: unknown) => e,
+ );
+ expect(String(err)).not.toMatch(/is not a function/);
+ });
+
it("signs the whole app the default way, through the daemon's options", async () => {
let received: { optionsForFile: (f: string) => FileOptions; app: string } | undefined;
const opts = { app, identity: "Developer ID Application: Cua", optionsForFile: () => ({ entitlements: "inherit.plist", additionalArguments: [] }) };
- await signer.sign(opts, () => ({ signAsync: async (o: typeof received) => void (received = o) }));
+ await signer.signWith(opts, () => ({ signAsync: async (o: typeof received) => void (received = o) }));
expect(received?.app).toBe(app);
expect(received?.optionsForFile(daemon).additionalArguments).toEqual(["--identifier", "com.trycua.cua"]);
expect(received?.optionsForFile(`${app}/Contents/MacOS/Cua Spaces`)).toEqual({ entitlements: "inherit.plist", additionalArguments: [] });