Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
ci(cua-spaces): verify the signed release before publishing; list every artifact in the release manifests (#5114)
ddupontbf29872f9a7d
diff --git a/.github/scripts/tests/test_cua_spaces_release_wiring.py b/.github/scripts/tests/test_cua_spaces_release_wiring.pyindex 3462a76fa4..4b7a3aa600 100644--- a/.github/scripts/tests/test_cua_spaces_release_wiring.py+++ b/.github/scripts/tests/test_cua_spaces_release_wiring.py@@ -89,6 +89,45 @@ class TestCuaSpacesReleaseWiring(unittest.TestCase):self.assertIn("release_please_spaces_preview.cjs", ci)self.assertIn(f'"{MACOS}/VERSION"', ci)+ def test_nothing_is_published_before_verify_release_passes(self) -> None:+ workflow = (REPO_ROOT / ".github/workflows/cd-cua-spaces.yml").read_text()+ verify = workflow.split("\n verify-release:\n", 1)[1].split("\n installer-manifest:\n", 1)[0]+ # It runs on the signed and notarized build of every platform.+ self.assertIn(+ "needs: [build-macos, electron-plan, electron-mac, electron-windows, electron-publish]",+ verify,+ )+ self.assertIn("runs-on: macos-26", verify)+ self.assertIn(f"{MACOS}/scripts/verify-release.sh --dir release", verify)+ self.assertIn('--repo "$GITHUB_REPOSITORY"', verify)+ self.assertIn("brew install osslsigncode", verify)+ # installer-manifest publishes the release and the feeds only after it.+ publish = workflow.split("\n installer-manifest:\n", 1)[1]+ self.assertIn("verify-release]", publish.split("\n", 3)[1])+ self.assertIn("needs.verify-release.result == 'success'", publish)+ # checksums.txt and release-artifacts.json cover every asset, the+ # Electron Windows and Linux installers included (CUA-1507).+ self.assertIn('gh release download "$TAG" --dir assets', publish)+ self.assertIn("scripts/install/check_release_manifest.py --dir assets --component app", publish)+ # verify-release reads the macOS build on tag runs too.+ self.assertNotIn("Keep the macOS build (manual runs)", workflow)+ script = (REPO_ROOT / MACOS / "scripts/verify-release.sh").read_text()+ for check in (+ "spctl -a -vv -t install",+ "xcrun stapler validate",+ "codesign --verify --deep --strict",+ "osslsigncode verify",+ "verify-appcast.sh",+ ):+ self.assertIn(check, script)+ self.assertTrue((REPO_ROOT / MACOS / "scripts/certs/microsoft-identity-verification-root-2020.pem").is_file())++ def test_cla_never_locks_a_release_please_pull_request(self) -> None:+ # Release Please comments on the merged release PR when it tags the+ # release; a locked one fails every run ("issue is locked").+ cla = (REPO_ROOT / ".github/workflows/cla.yml").read_text()+ self.assertIn("lock-pullrequest-aftermerge: false", cla)+if __name__ == "__main__":unittest.main()diff --git a/.github/workflows/cd-cua-spaces.yml b/.github/workflows/cd-cua-spaces.ymlindex 467a1965f8..28260ffd48 100644--- a/.github/workflows/cd-cua-spaces.yml+++ b/.github/workflows/cd-cua-spaces.yml@@ -38,6 +38,11 @@ name: "CD: Cua Spaces"# items are Beta only). Two releases publishing at once could drop one# item; the next release adds it back.#+# Before anything is published, verify-release runs+# apps/cua-spaces-macos/scripts/verify-release.sh on the signed build: the+# disk images, the apps, the Windows installers, the Sparkle appcast and the+# Electron feeds.+## Linux and Windows (disabled for now, see above): the Tauri app# (apps/cua-spaces), with Tauri auto-updater# artifacts (.sig) and a `latest.json` update feed that lists only those@@ -213,6 +218,7 @@ jobs:version: ${{ steps.version.outputs.version }}prerelease: ${{ steps.version.outputs.prerelease }}appcast: ${{ steps.appcast.outputs.made }}+ signed: ${{ steps.signing.outputs.apple }}steps:- name: Checkoutuses: actions/checkout@v4@@ -518,9 +524,8 @@ jobs:if-no-files-found: errorretention-days: 7- # A manual run from a branch publishes nothing; keep its build.- - name: Keep the macOS build (manual runs)- if: "!startsWith(github.ref, 'refs/tags/')"+ # For verify-release, and a manual run from a branch publishes nothing.+ - name: Keep the macOS builduses: actions/upload-artifact@v4with:name: cua-spaces-darwin-universal@@ -892,6 +897,7 @@ jobs:working-directory: .outputs:appcast: ${{ steps.appcast.outputs.made }}+ signed: ${{ steps.signing.outputs.apple }}env:CARGO_BUILD_JOBS: 4VERSION: ${{ needs.electron-plan.outputs.version }}@@ -1140,6 +1146,8 @@ jobs:permissions:contents: readid-token: write+ outputs:+ signed: ${{ steps.signing.outputs.azure }}defaults:run:working-directory: apps/cua-spaces-desktop@@ -1386,17 +1394,111 @@ jobs:path: signing/if-no-files-found: error+ # The signed build as users will get it, before anything is published:+ # apps/cua-spaces-macos/scripts/verify-release.sh on the SwiftUI disk image+ # (Gatekeeper, stapled tickets, strict signatures, bundle id and versions,+ # launch, Keyvault smoke), the Electron disk images, the Windows installers+ # (Authenticode by "Cua AI, Inc." with a timestamp), the Sparkle appcast+ # (prereleases on the beta channel only) and the Electron feeds (this+ # version, this repository, the files' sha512). installer-manifest publishes+ # only after it passes; a manual run from a branch runs it on the build.+ # Unsigned parts (allowed off trycua/cua) are skipped with a warning.+ verify-release:+ name: Verify the signed release+ needs: [build-macos, electron-plan, electron-mac, electron-windows, electron-publish]+ if: >-+ !cancelled() && needs.build-macos.result == 'success'+ && (needs.electron-plan.outputs.build != 'true'+ || (needs.electron-mac.result == 'success' && needs.electron-windows.result == 'success'))+ && (needs.electron-plan.outputs.publish != 'true' || needs.electron-publish.result == 'success')+ runs-on: macos-26+ timeout-minutes: 60+ defaults:+ run:+ working-directory: .+ permissions:+ contents: read+ env:+ VERSION: ${{ needs.build-macos.outputs.version }}+ ELECTRON: ${{ needs.electron-plan.outputs.build }}+ SWIFT_SIGNED: ${{ needs.build-macos.outputs.signed }}+ ELECTRON_MAC_SIGNED: ${{ needs.electron-mac.outputs.signed }}+ ELECTRON_WINDOWS_SIGNED: ${{ needs.electron-windows.outputs.signed }}+ APPCAST: ${{ needs.build-macos.outputs.appcast == 'true' || needs.electron-mac.outputs.appcast == 'true' }}+ steps:+ - uses: actions/checkout@v4+ - uses: actions/download-artifact@v4+ with:+ name: cua-spaces-darwin-universal+ path: release+ - if: needs.electron-plan.outputs.build == 'true'+ uses: actions/download-artifact@v4+ with:+ name: electron-darwin+ path: release+ - if: needs.electron-plan.outputs.build == 'true'+ uses: actions/download-artifact@v4+ with:+ name: electron-windows+ path: release+ # The published feed (absolute URLs) replaces the build's.+ - if: needs.electron-publish.result == 'success'+ uses: actions/download-artifact@v4+ with:+ name: electron-feed+ path: release+ - if: env.APPCAST == 'true'+ uses: actions/download-artifact@v4+ with:+ name: sparkle-appcast+ path: release+ - name: Install osslsigncode (Windows Authenticode)+ if: needs.electron-plan.outputs.build == 'true' && env.ELECTRON_WINDOWS_SIGNED == 'true'+ run: brew install osslsigncode+ - name: verify-release.sh+ run: |+ set -euo pipefail+ expect=()+ if [ "$SWIFT_SIGNED" = true ]; then+ expect+=(swift)+ else+ echo "::warning::the SwiftUI build is unsigned: not verified"+ rm -f release/cua-spaces-*.dmg+ fi+ if [ "$ELECTRON" = true ]; then+ expect+=(feed)+ if [ "$ELECTRON_MAC_SIGNED" = true ]; then expect+=(electron); else+ echo "::warning::the Electron macOS build is unsigned: not verified"+ rm -f release/Cua-Spaces-*.dmg+ fi+ if [ "$ELECTRON_WINDOWS_SIGNED" = true ]; then expect+=(windows); else+ echo "::warning::the Electron Windows build is unsigned: not verified"+ rm -f release/Cua-Spaces-Setup-*.exe+ fi+ fi+ [ "$APPCAST" = true ] && expect+=(appcast)+ if [ ${#expect[@]} -eq 0 ]; then+ echo "::warning::nothing in this build is signed: no release verification"+ exit 0+ fi+ ls -la release+ kinds="$(IFS=,; echo "${expect[*]}")"+ apps/cua-spaces-macos/scripts/verify-release.sh --dir release --version "$VERSION" \+ --repo "$GITHUB_REPOSITORY" --expect "$kinds"+installer-manifest:name: release-artifacts.json, latest.json, publish- needs: [build-macos, build-linux-windows, electron-plan, electron-mac, electron-publish]+ needs: [build-macos, build-linux-windows, electron-plan, electron-mac, electron-publish, verify-release]# Only a release tag publishes: the Sigstore identity the installers and# the updater feed trust is cd-cua-spaces.yml at refs/tags/cua-spaces-v*.# A manual run from a tag re-publishes; from a branch it only builds.# build-linux-windows may be skipped (disabled: macOS only), never failed.# A prerelease waits for its Electron installers (electron-publish).+ # Nothing is published unless verify-release passed.if: >-!cancelled() && startsWith(github.ref, 'refs/tags/cua-spaces-v')&& needs.build-macos.result == 'success'+ && needs.verify-release.result == 'success'&& (needs.build-linux-windows.result == 'success' || needs.build-linux-windows.result == 'skipped')&& (needs.electron-plan.outputs.publish != 'true' || needs.electron-publish.result == 'success')runs-on: ubuntu-latest@@ -1431,19 +1533,28 @@ jobs:set -euo pipefailBASE="https://github.com/$GITHUB_REPOSITORY/releases/download/$TAG"mkdir -p assets previous- gh release download "$TAG" --pattern "cua-spaces-$VERSION-*" --dir assets --repo "$GITHUB_REPOSITORY"+ # Every asset: the SwiftUI app's, and a prerelease's Electron+ # installers for macOS, Windows and Linux (electron-publish).+ gh release download "$TAG" --dir assets --repo "$GITHUB_REPOSITORY"+ rm -f assets/checksums.txt assets/release-artifacts.json assets/latest.json assets/*.sigstore.json# Keyless Sigstore bundles next to each installer (install.sh and# install.ps1 verify them with cosign when it is installed).- for f in assets/cua-spaces-*; do- case "$f" in *.sig|*.sigstore.json) continue ;; esac+ for f in assets/*; do+ case "$f" in *.sig|*.blockmap) continue ;; esaccosign sign-blob --yes --bundle "$f.sigstore.json" "$f" >/dev/nulldone- (cd assets && sha256sum cua-spaces-* | sort > checksums.txt)+ # Every asset of the release, signatures included.+ (cd assets && find . -maxdepth 1 -type f -printf '%f\n' | LC_ALL=C sort \+ | xargs -d '\n' sha256sum > "$RUNNER_TEMP/checksums.txt")+ mv "$RUNNER_TEMP/checksums.txt" assets/checksums.txtgh release download cua-install-latest --pattern release-artifacts.json \--dir previous --repo "$GITHUB_REPOSITORY" 2>/dev/null || truepython3 scripts/install/release_manifest.py --component app --version "$VERSION" \--dir assets --base-url "$BASE" \--repo "$GITHUB_REPOSITORY" --merge previous/release-artifacts.json --out assets/release-artifacts.json+ # Every published artifact is listed, with its checksum (CUA-1507).+ python3 scripts/install/check_release_manifest.py --dir assets --component app \+ --version "$VERSION" --base-url "$BASE"# The Tauri updater feed: Linux and Windows only (the macOS app is# the SwiftUI app, which updates through the Sparkle appcast). With# any Linux/Windows artifact on the release it fails when one ofdiff --git a/apps/cua-spaces-macos/README.md b/apps/cua-spaces-macos/README.mdindex b103257d80..f0d9829ede 100644--- a/apps/cua-spaces-macos/README.md+++ b/apps/cua-spaces-macos/README.md@@ -299,8 +299,13 @@ commits under this directory.scripts/build-release.sh --version 0.2.0 --out /tmp/spaces-release # ad hoc signed, universalscripts/package-dmg.sh --app "/tmp/spaces-release/Cua Spaces.app" --out /tmp/cua-spaces.dmgscripts/verify-release.sh cua-spaces-0.2.0-darwin-universal.dmg # a downloaded release+scripts/verify-release.sh --dir assets --version 0.8.0-beta.6 \+ --expect swift,electron,windows,appcast,feed # every asset of a release```+CD (`cd-cua-spaces.yml`, job `verify-release`) runs `verify-release.sh` on the+signed and notarized build before anything is published.+The disk image window is the spaces.cua.ai hero with the blue Cua Spaces keymissing. The app, whose icon is that key, sits on the left. The Applicationsalias, whose icon is the key's outline with an Applications glyph, sits wherediff --git a/apps/cua-spaces-macos/scripts/certs/microsoft-identity-verification-root-2020.pem b/apps/cua-spaces-macos/scripts/certs/microsoft-identity-verification-root-2020.pemnew file mode 100644index 0000000000..c18eb3995d--- /dev/null+++ b/apps/cua-spaces-macos/scripts/certs/microsoft-identity-verification-root-2020.pem@@ -0,0 +1,38 @@+# Microsoft Identity Verification Root Certificate Authority 2020: the root of+# Azure Artifact Signing's code signing and timestamping chains (Windows+# installers). verify-release.sh passes it to osslsigncode.+# Source: http://www.microsoft.com/pkiops/certs/Microsoft%20Identity%20Verification%20Root%20Certificate%20Authority%202020.crt+# SHA-256: 53:67:F2:0C:7A:DE:0E:2B:CA:79:09:15:05:6D:08:6B:72:0C:33:C1:FA:2A:26:61:AC:F7:87:E3:29:2E:12:70+-----BEGIN CERTIFICATE-----+MIIFzDCCA7SgAwIBAgIQVJjS0dRbGZVIE3nIEcCHmTANBgkqhkiG9w0BAQwFADB3+MQswCQYDVQQGEwJVUzEeMBwGA1UEChMVTWljcm9zb2Z0IENvcnBvcmF0aW9uMUgw+RgYDVQQDEz9NaWNyb3NvZnQgSWRlbnRpdHkgVmVyaWZpY2F0aW9uIFJvb3QgQ2Vy+dGlmaWNhdGUgQXV0aG9yaXR5IDIwMjAwHhcNMjAwNDE2MTgzNjE2WhcNNDUwNDE2+MTg0NDQwWjB3MQswCQYDVQQGEwJVUzEeMBwGA1UEChMVTWljcm9zb2Z0IENvcnBv+cmF0aW9uMUgwRgYDVQQDEz9NaWNyb3NvZnQgSWRlbnRpdHkgVmVyaWZpY2F0aW9u+IFJvb3QgQ2VydGlmaWNhdGUgQXV0aG9yaXR5IDIwMjAwggIiMA0GCSqGSIb3DQEB+AQUAA4ICDwAwggIKAoICAQCzkSoHgwZn/Z6d4MfAt6TmQgR/D6bbX/vVWtdFoPt3+C/CA86ZtWk15U9ighoRXRSDHolT7x6K/isduNfOiFcQvTuNKhZZJDf++mdgU9rwn+B+5Cmyv1C5IG5P1pE2WokXLymITrgz0O5NdxEkghyw3t9kdJt5v5yccXtoRP/7is+mtdzZ0mF44a9N0DQJYbU3rXCbWJq1al4vC1vSfnlbBQU/RTH02UWN97LbrxeKY39+YpsVLNYF5rmJMjOjYsfX1lJnCMQu9FYrnguHzOyntKaq6wXNGVelOgsEJxyRZ54t+Yi0vHr7awCDLBBnKM/uJvpjicqByNb554ZyDb+RtF2+Q8z0AhnU4jtDgSZq729P4+MMrVV4hoTXLTv21/cdj9vQ2ukmRIt1tveSa1zZuVIYTR7w8yPXtXjPNFB0x84F4Y+DjV2i22eyzZ0qwX44HNdMlaUZ5clCsY1PZSX58FEi4D9wfj0dBnlMPYG+yFXPgYc+i2sVhidJe4KTylnodUfoPzj0x1N5oLa04lxR771fOMET5ngMlVouxUBZKMwPJMDs+ugl3I5k4prYc2se6ILbXN9h/N68I4ztx225zG32ZcrDkhjNZdLUWAHtQbcaGE9r9+xDmCPSQAmmDaupTABVEsNKxQmROHu7MFgLJNMAJcuCaDXbRjc++uI5VPYCi+N9Vb+pQIDAQABo1QwUjAOBgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNV+HQ4EFgQUyH7SaoUqG8oZmAQHJ89QEE9oqKIwEAYJKwYBBAGCNxUBBAMCAQAwDQYJ+KoZIhvcNAQEMBQADggIBAK9q3eYZ5y2UQxlOy+lQlWSlA5ECi+I2gDsVolLCFhm2+alpddEMw9Jv/YHQJsSEekBZtxSSPXGaIY/RPzH3yEkxAEIsBn9qpyK7ylRvPnQXr+ST50oGhb5VYsZRyCflPaVtlGF3mSRcQQNghSKRfLL6byftRpJIoej7BzDcwcSquy+qu2nkWMBZCKoMrh+MiizZ3MtkbTcMQEL90cKpvHXSu1WYMQsCKN7QLC8dCdSh9a++iN03ioluZ4gd9cldoP62qzqA1xqXPBc2IkEerE3Vg+Y8OL1PMOlUqdO2BMMydmG7+sBjFKxizwIDVt5WwXlFNIvzsWKro2JS0pS7tkt7nGHwhV91VY/e/bc0f0qZ3KHDH+4ls6WwjSW07IAJaz4YM2r4YKZVx09ursemp0oPBL7u+Uo6xQ8oft1zowg8n7fVe++5eP4QcrlZK6zo+xY7IWazO+56vNWGLlcc5qvxXcXg1nbNxoYclSlQdK2I3WjQ5rl+d3yWebdBjb/s3ICgn9F3dVhfNRPgJRpnC33OJfoHCuRhIdjUHOUHxjaZ9JbQxhX++Ts3Xroud2xb9BMaSvdSI5qmjqrv3ZDg7X8wM0DW+dBkDpsWqTKJhNoI+HfMrvJdd+20t4Oy31O+9gI+j17AsjNpWvmGa/U9N7uGlKKpZmacSUxvRfbqyYeIiABlyisu2i+-----END CERTIFICATE-----diff --git a/apps/cua-spaces-macos/scripts/verify-release.sh b/apps/cua-spaces-macos/scripts/verify-release.shindex 91f1bd720d..bd05458780 100755--- a/apps/cua-spaces-macos/scripts/verify-release.sh+++ b/apps/cua-spaces-macos/scripts/verify-release.sh@@ -2,44 +2,112 @@# SPDX-License-Identifier: FSL-1.1-MIT# Copyright (c) 2026 Cua AI, Inc.-# Checks a downloaded Cua Spaces for macOS disk image the way Gatekeeper and-# the Keyvault will: the image and the app are Developer ID signed,-# notarized and stapled; the app, its bundled `cua`, the SDK library and the+# Checks a Cua Spaces release the way Gatekeeper, Windows, the updaters and+# the Keyvault will see it. CD runs it on the signed build before anything is+# published; it also runs on a downloaded release. It mounts disk images+# read-only and installs nothing.+#+# SwiftUI disk image: the image and the app are Developer ID signed,+# notarized and stapled (spctl -t install, stapler validate, strict codesign;+# the image's com.apple.FinderInfo on the app bundle's root is the one+# allowed detritus); the app, its bundled `cua`, the SDK library and the# updater (Sparkle.framework, its XPC services, Autoupdate and Updater.app)-# carry the Cua team, the hardened runtime and the expected identifiers and-# entitlements; the updater's feed and key are set; and every binary has-# both architectures. It mounts the image read-only and installs nothing.+# carry the Cua team, the hardened runtime, a secure timestamp and the+# expected identifiers and entitlements; bundle id and versions; the+# updater's feed and key; both architectures. It then launches the app+# (scripts/check-launch.sh, no window) and runs a Keyvault smoke: the bundled+# `cua daemon` with a throwaway CUA_HOME (under ~/.cache, deleted afterwards;+# never ~/.cua, no loopback port, telemetry off) answers the bundled+# `cua keyvault status`, so client and daemon verify each other as Cua. It+# reads no keychain and creates no vault.+#+# Electron disk images (Cua-Spaces-<v>-<arch>.dmg): the same image and app+# signature checks, bundle id, versions, architectures, the bundled `cua`'s+# Keyvault requirement, and the updater feed baked into app-update.yml.+#+# Windows installers (Cua-Spaces-Setup-<v>*.exe): Authenticode verifies with+# osslsigncode (chain to the pinned Microsoft Identity Verification Root+# 2020, certs/), the signer is "Cua AI, Inc." and it has a timestamp.+#+# Sparkle appcast (cua-spaces-appcast.xml): every X.Y.Z-suffix item is on the+# beta channel and every X.Y.Z item on none (so Stable apps never see a+# prerelease), and this release's item passes scripts/verify-appcast.sh.+#+# Electron feeds (beta*.yml / latest*.yml): each names this version, its+# files are this version's (and match the local files' sha512 and size), and+# a prerelease's feeds are beta*.yml.#-# Keyvault smoke: it then starts the bundled `cua daemon` with a throwaway-# CUA_HOME (under ~/.cache, deleted afterwards; never ~/.cua, no loopback-# port, telemetry off) and runs the bundled `cua keyvault status` against-# it. The client refuses a daemon that fails the Keyvault's production-# requirement ("not the Cua daemon"), and the daemon refuses a client that-# is not first party, so a status answer means both halves pass. It reads-# no keychain and creates no vault. --no-keyvault-smoke skips it.+# Release manifest (--dir holding every asset of the published release):+# checksums.txt and release-artifacts.json list every artifact, Windows and+# Linux included, with its sha256 (scripts/install/check_release_manifest.py).#-# scripts/verify-release.sh cua-spaces-0.2.0-darwin-universal.dmg [--team YCK386LBJ7]-# [--arch universal|arm64|x86_64] [--no-keyvault-smoke]+# scripts/verify-release.sh cua-spaces-0.8.0-darwin-universal.dmg+# scripts/verify-release.sh --dir DIR --version 0.8.0-beta.6 [--expect swift,electron,windows,appcast,feed,manifest]+# [--repo trycua/cua] [--team YCK386LBJ7] [--arch universal|arm64|x86_64]+# [--windows-signer "Cua AI, Inc."] [--no-launch] [--no-keyvault-smoke]+#+# --dir finds every asset of --version in DIR by its release name; --expect+# lists the kinds that must be there (default: swift). Single files:+# --swift-dmg, --electron-dmg, --windows-exe, --appcast, --feed (repeatable).+# --repo checks that both updaters' feeds are that repository's.## Exits non-zero when any check fails; prints every check either way.set -uo pipefail-dmg=""+here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"team="YCK386LBJ7"arch=universalsmoke=1+launch=1+version=""+repo=""+dir=""+expect="swift"+signer="Cua AI, Inc."+swift_dmg=""+electron_dmgs=()+windows_exes=()+appcast=""+feeds=()while [ $# -gt 0 ]; docase "$1" in--team) team="$2"; shift ;;--arch) arch="$2"; shift ;;+ --version) version="$2"; shift ;;+ --repo) repo="$2"; shift ;;+ --dir) dir="$2"; shift ;;+ --expect) expect="$2"; shift ;;+ --windows-signer) signer="$2"; shift ;;+ --swift-dmg) swift_dmg="$2"; shift ;;+ --electron-dmg) electron_dmgs+=("$2"); shift ;;+ --windows-exe) windows_exes+=("$2"); shift ;;+ --appcast) appcast="$2"; shift ;;+ --feed) feeds+=("$2"); shift ;;--no-keyvault-smoke) smoke=0 ;;- -h | --help) sed -n '5,24p' "$0"; exit 0 ;;+ --no-launch) launch=0 ;;+ -h | --help) sed -n '5,52p' "$0"; exit 0 ;;-*) echo "unknown option: $1" >&2; exit 2 ;;- *) dmg="$1" ;;+ *) swift_dmg="$1" ;;esacshiftdone-[ -f "$dmg" ] || { echo "usage: $0 <path/to.dmg> [--team TEAMID]" >&2; exit 2; }case "$arch" in universal) archs="arm64 x86_64" ;; arm64 | x86_64) archs="$arch" ;; *) echo "bad --arch" >&2; exit 2 ;; esac+if [ -n "$dir" ]; then+ [ -d "$dir" ] || { echo "no directory $dir" >&2; exit 2; }+ [ -n "$version" ] || { echo "--dir needs --version" >&2; exit 2; }+ [ -f "$dir/cua-spaces-$version-darwin-universal.dmg" ] && swift_dmg="$dir/cua-spaces-$version-darwin-universal.dmg"+ for f in "$dir/Cua-Spaces-$version"-*.dmg; do [ -f "$f" ] && electron_dmgs+=("$f"); done+ for f in "$dir/Cua-Spaces-Setup-$version".exe "$dir/Cua-Spaces-Setup-$version"-*.exe; do+ [ -f "$f" ] && windows_exes+=("$f")+ done+ [ -f "$dir/cua-spaces-appcast.xml" ] && appcast="$dir/cua-spaces-appcast.xml"+ for f in "$dir"/beta*.yml "$dir"/latest*.yml; do [ -f "$f" ] && feeds+=("$f"); done+fi+if [ -z "$swift_dmg$appcast" ] && [ ${#electron_dmgs[@]} -eq 0 ] && [ ${#windows_exes[@]} -eq 0 ] &&+ [ ${#feeds[@]} -eq 0 ]; then+ echo "usage: $0 <path/to.dmg> | --dir DIR --version V (see --help)" >&2+ exit 2+fi+[ -z "$swift_dmg" ] || [ -f "$swift_dmg" ] || { echo "no file $swift_dmg" >&2; exit 2; }failed=0section() { printf '\n== %s\n' "$1"; }@@ -51,109 +119,408 @@ check() { # check NAME CMD...: run CMD, show its output, record the result[ -n "$output" ] && printf '%s\n' "$output" | sed 's/^/ /'if [ $rc -eq 0 ]; then echo "PASS $name"; else echo "FAIL $name"; failed=1; fi}+fail() { echo "FAIL $1"; failed=1; }+plist_key() { /usr/libexec/PlistBuddy -c "Print :$1" "$2" 2>/dev/null; }-mnt="$(mktemp -d)"+mounts=()+tmp="$(mktemp -d)"kv_home=""daemon_pid=""+unmount_all() {+ local m+ for m in ${mounts[@]+"${mounts[@]}"}; do+ hdiutil detach -quiet "$m" >/dev/null 2>&1 || hdiutil detach -force -quiet "$m" >/dev/null 2>&1+ rmdir "$m" 2>/dev/null+ done+ mounts=()+}cleanup() {[ -n "$daemon_pid" ] && kill "$daemon_pid" 2>/dev/null && wait "$daemon_pid" 2>/dev/null[ -n "$kv_home" ] && rm -rf "$kv_home"- hdiutil detach -quiet "$mnt" >/dev/null 2>&1- rmdir "$mnt" 2>/dev/null+ unmount_all+ # Never recurse into an image that is still mounted.+ mount | grep -qF "$tmp/" || rm -rf "$tmp"}trap cleanup EXIT-section "disk image: $dmg"-check "image signature (codesign --verify)" codesign --verify --strict --verbose=2 "$dmg"-check "image Gatekeeper, install assessment (spctl -t install)" spctl -a -vv -t install "$dmg"-check "image Gatekeeper, primary signature (spctl -t open)" \- spctl -a -vv -t open --context context:primary-signature "$dmg"-check "image notarization ticket stapled" xcrun stapler validate "$dmg"-check "image team is $team" sh -c "codesign -dvv '$dmg' 2>&1 | grep -qx 'TeamIdentifier=$team'"--hdiutil attach -quiet -readonly -nobrowse -noautoopen -mountpoint "$mnt" "$dmg" ||- { echo "FAIL could not mount $dmg"; exit 1; }-app="$(find "$mnt" -maxdepth 1 -name '*.app' | head -n 1)"-[ -n "$app" ] || { echo "FAIL no .app in $dmg"; exit 1; }--section "app: ${app##*/}"-printf ' version %s (%s), %s\n' \- "$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$app/Contents/Info.plist")" \- "$(/usr/libexec/PlistBuddy -c 'Print :CFBundleVersion' "$app/Contents/Info.plist")" \- "$(/usr/libexec/PlistBuddy -c 'Print :CuaVersion' "$app/Contents/Info.plist" 2>/dev/null || echo 'no CuaVersion')"-check "app signature, deep and strict" codesign --verify --deep --strict --verbose=2 "$app"-check "app Gatekeeper (spctl)" spctl -a -vv "$app"-check "app notarization ticket stapled" xcrun stapler validate "$app"-# The Keyvault's production caller requirement (cua-keyvault caller.rs).-check "app meets the Keyvault requirement (team $team, com.trycua.spaces.macos)" \- codesign --verify -R="anchor apple generic and certificate leaf[subject.OU] = \"$team\" and identifier \"com.trycua.spaces.macos\"" "$app"-check "bundled cua meets the Keyvault requirement (team $team, com.trycua.cua)" \- codesign --verify -R="anchor apple generic and certificate leaf[subject.OU] = \"$team\" and identifier \"com.trycua.cua\"" "$app/Contents/MacOS/cua"--section "updater (Sparkle)"-plist="$app/Contents/Info.plist"-feed="$(/usr/libexec/PlistBuddy -c 'Print :SUFeedURL' "$plist" 2>/dev/null)"-printf ' SUFeedURL %s\n' "${feed:-(none)}"-check "SUFeedURL is https" sh -c "case '$feed' in https://*) exit 0 ;; *) exit 1 ;; esac"-check "SUPublicEDKey is a 32-byte Ed25519 key" \- sh -c "/usr/libexec/PlistBuddy -c 'Print :SUPublicEDKey' '$plist' | base64 -d 2>/dev/null | wc -c | grep -qx ' *32'"-sparkle="$app/Contents/Frameworks/Sparkle.framework"-sparkle_parts=(- "$sparkle/Versions/B/XPCServices/Installer.xpc"- "$sparkle/Versions/B/XPCServices/Downloader.xpc"- "$sparkle/Versions/B/Autoupdate"- "$sparkle/Versions/B/Updater.app"- "$sparkle"-)-for f in "${sparkle_parts[@]}"; do check "present: ${f#"$app"/}" test -e "$f"; done--for f in "$app" "$app/Contents/MacOS/cua" "$app/Contents/Frameworks/libcua_sdk.dylib" "${sparkle_parts[@]}"; do- section "signature: ${f#"$mnt"/}"- info="$(codesign -dvv "$f" 2>&1)"+# mount_dmg DMG: mounts it read-only at $mnt. One image at a time: each+# section unmounts its own (verify-appcast.sh mounts the image again).+mount_dmg() {+ mnt="$(mktemp -d "$tmp/mnt.XXXXXX")"+ hdiutil attach -quiet -readonly -nobrowse -noautoopen -mountpoint "$mnt" "$1" >/dev/null || return 1+ mounts+=("$mnt")+}++# Strict, deep codesign. A disk image's Finder layout leaves+# com.apple.FinderInfo on the app bundle's root, which strict verification+# calls detritus although Gatekeeper accepts it; check a copy without that one+# attribute (everything else, nested attributes included, stays strict).+strict_app() {+ codesign --verify --deep --strict --verbose=2 "$1" && return 0+ xattr -p com.apple.FinderInfo "$1" >/dev/null 2>&1 || return 1+ echo "(retrying without the bundle root's com.apple.FinderInfo, the disk image's layout)"+ local copy+ copy="$(mktemp -d "$tmp/copy.XXXXXX")/${1##*/}"+ ditto "$1" "$copy" && xattr -d com.apple.FinderInfo "$copy" &&+ codesign --verify --deep --strict --verbose=2 "$copy"+}++image_checks() { # image_checks DMG+ check "image signature (codesign --verify --strict)" codesign --verify --strict --verbose=2 "$1"+ check "image Gatekeeper, install assessment (spctl -t install)" spctl -a -vv -t install "$1"+ check "image Gatekeeper, primary signature (spctl -t open)" \+ spctl -a -vv -t open --context context:primary-signature "$1"+ check "image notarization ticket stapled" xcrun stapler validate "$1"+ check "image team is $team" sh -c "codesign -dvv \"\$1\" 2>&1 | grep -qx 'TeamIdentifier=$team'" _ "$1"+}++signature_checks() { # signature_checks PATH LABEL+ section "signature: $2"+ local info+ info="$(codesign -dvv "$1" 2>&1)"printf '%s\n' "$info" | grep -E '^(Identifier|Format|CodeDirectory|Authority|Timestamp|TeamIdentifier|Runtime Version)' | sed 's/^/ /'check "Developer ID Application authority" sh -c "printf '%s\n' \"\$1\" | grep -q '^Authority=Developer ID Application: .*($team)$'" _ "$info"check "team $team" sh -c "printf '%s\n' \"\$1\" | grep -qx 'TeamIdentifier=$team'" _ "$info"check "hardened runtime" sh -c "printf '%s\n' \"\$1\" | grep -q '^CodeDirectory.*flags=.*runtime'" _ "$info"check "secure timestamp" sh -c "printf '%s\n' \"\$1\" | grep -q '^Timestamp='" _ "$info"-done+}-for f in "$app" "$app/Contents/MacOS/cua"; do- section "entitlements: ${f#"$mnt"/}"- ents="$(codesign -d --entitlements - --xml "$f" 2>/dev/null | plutil -convert xml1 -o - - 2>/dev/null)"- printf '%s\n' "${ents:- (none)}" | sed 's/^/ /'- check "no get-task-allow (debuggable builds are not notarizable)" \- sh -c "! printf '%s' \"\$1\" | grep -q 'get-task-allow'" _ "$ents"-done+keyvault_requirement() { # keyvault_requirement PATH IDENTIFIER+ codesign --verify -R="anchor apple generic and certificate leaf[subject.OU] = \"$team\" and identifier \"$2\"" "$1"+}-section "launch"-# Libraries resolve inside the bundle and pass library validation; the app-# starts and exits before any window (throwaway HOME, telemetry off).-check "the app launches (scripts/check-launch.sh)" "$(dirname "$0")/check-launch.sh" "$app"+expect_eq() { # expect_eq NAME GOT WANT+ if [ "$2" = "$3" ]; then echo "PASS $1 ($2)"; else fail "$1: got '$2', want '$3'"; fi+}-section "architectures"-for f in "$app/Contents/MacOS/CuaSpacesMac" "$app/Contents/MacOS/cua" "$app/Contents/Frameworks/libcua_sdk.dylib" \- "$sparkle/Versions/B/Sparkle" "$sparkle/Versions/B/Autoupdate"; do- for a in $archs; do check "${f##*/} has $a ($(lipo -archs "$f"))" lipo "$f" -verify_arch "$a"; done+# Versions every app carries: CuaVersion is the full version, CFBundleVersion+# X.Y.Z.<build>, CFBundleShortVersionString X.Y.Z (SwiftUI) or the full+# version (Electron).+version_checks() { # version_checks PLIST SHORT_WANTED+ local short bundle cua+ short="$(plist_key CFBundleShortVersionString "$1")"+ bundle="$(plist_key CFBundleVersion "$1")"+ cua="$(plist_key CuaVersion "$1")"+ printf ' version %s (%s), CuaVersion %s\n' "$short" "$bundle" "${cua:-(none)}"+ expect_eq "bundle id" "$(plist_key CFBundleIdentifier "$1")" "com.trycua.spaces.macos"+ if [ -n "$version" ]; then+ expect_eq "CuaVersion is the release version" "$cua" "$version"+ expect_eq "CFBundleShortVersionString" "$short" "$2"+ expect_eq "CFBundleVersion is X.Y.Z.<build>" \+ "$(sed -E 's/^([0-9]+\.[0-9]+\.[0-9]+)\.[0-9]+$/\1/' <<<"$bundle")" "${version%%-*}"+ fi+}++# --- SwiftUI app --------------------------------------------------------------+swift_app=""+if [ -n "$swift_dmg" ]; then+ section "SwiftUI disk image: $swift_dmg"+ image_checks "$swift_dmg"+ if ! mount_dmg "$swift_dmg"; then+ fail "could not mount $swift_dmg"+ else+ swift_app="$(find "$mnt" -maxdepth 1 -name '*.app' | head -n 1)"+ fi+ if [ -z "$swift_app" ]; then+ fail "no .app in $swift_dmg"+ else+ app="$swift_app"+ [ -z "$version" ] && version="$(plist_key CuaVersion "$app/Contents/Info.plist")"+ section "SwiftUI app: ${app##*/}"+ version_checks "$app/Contents/Info.plist" "${version%%-*}"+ check "app signature, deep and strict" strict_app "$app"+ check "app Gatekeeper (spctl)" spctl -a -vv "$app"+ check "app notarization ticket stapled" xcrun stapler validate "$app"+ # The Keyvault's production caller requirement (cua-keyvault caller.rs).+ check "app meets the Keyvault requirement (team $team, com.trycua.spaces.macos)" \+ keyvault_requirement "$app" com.trycua.spaces.macos+ check "bundled cua meets the Keyvault requirement (team $team, com.trycua.cua)" \+ keyvault_requirement "$app/Contents/MacOS/cua" com.trycua.cua++ section "updater (Sparkle)"+ plist="$app/Contents/Info.plist"+ feed="$(plist_key SUFeedURL "$plist")"+ printf ' SUFeedURL %s\n' "${feed:-(none)}"+ check "SUFeedURL is https" sh -c "case '$feed' in https://*) exit 0 ;; *) exit 1 ;; esac"+ if [ -n "$repo" ]; then+ expect_eq "SUFeedURL is $repo's" "$feed" \+ "https://github.com/$repo/releases/download/cua-spaces-latest/cua-spaces-appcast.xml"+ fi+ check "SUPublicEDKey is a 32-byte Ed25519 key" \+ sh -c "/usr/libexec/PlistBuddy -c 'Print :SUPublicEDKey' '$plist' | base64 -d 2>/dev/null | wc -c | grep -qx ' *32'"+ sparkle="$app/Contents/Frameworks/Sparkle.framework"+ sparkle_parts=(+ "$sparkle/Versions/B/XPCServices/Installer.xpc"+ "$sparkle/Versions/B/XPCServices/Downloader.xpc"+ "$sparkle/Versions/B/Autoupdate"+ "$sparkle/Versions/B/Updater.app"+ "$sparkle"+ )+ for f in "${sparkle_parts[@]}"; do check "present: ${f#"$app"/}" test -e "$f"; done++ for f in "$app" "$app/Contents/MacOS/cua" "$app/Contents/Frameworks/libcua_sdk.dylib" "${sparkle_parts[@]}"; do+ signature_checks "$f" "${f#"$mnt"/}"+ done++ for f in "$app" "$app/Contents/MacOS/cua"; do+ section "entitlements: ${f#"$mnt"/}"+ ents="$(codesign -d --entitlements - --xml "$f" 2>/dev/null | plutil -convert xml1 -o - - 2>/dev/null)"+ printf '%s\n' "${ents:- (none)}" | sed 's/^/ /'+ check "no get-task-allow (debuggable builds are not notarizable)" \+ sh -c "! printf '%s' \"\$1\" | grep -q 'get-task-allow'" _ "$ents"+ done++ if [ "$launch" = 1 ]; then+ section "launch"+ # Libraries resolve inside the bundle and pass library validation; the+ # app starts and exits before any window (throwaway HOME, telemetry off).+ check "the app launches (scripts/check-launch.sh)" "$here/check-launch.sh" "$app"+ fi++ section "architectures"+ for f in "$app/Contents/MacOS/CuaSpacesMac" "$app/Contents/MacOS/cua" "$app/Contents/Frameworks/libcua_sdk.dylib" \+ "$sparkle/Versions/B/Sparkle" "$sparkle/Versions/B/Autoupdate"; do+ for a in $archs; do check "${f##*/} has $a ($(lipo -archs "$f"))" lipo "$f" -verify_arch "$a"; done+ done++ if [ "$smoke" = 1 ]; then+ section "Keyvault smoke (bundled cua daemon, throwaway CUA_HOME)"+ cua="$app/Contents/MacOS/cua"+ mkdir -p "$HOME/.cache"+ # Inside the real home: the Keyvault distrusts a CUA_HOME outside it.+ kv_home="$(mktemp -d "$HOME/.cache/cua-verify-release.XXXXXX")"+ chmod 700 "$kv_home"+ CUA_HOME="$kv_home" CUA_TELEMETRY=0 DO_NOT_TRACK=1 \+ "$cua" daemon start --foreground --socket "$kv_home/cua.sock" --loopback off \+ >"$kv_home/daemon.out" 2>&1 &+ daemon_pid=$!+ for _ in $(seq 1 80); do [ -S "$kv_home/keyvault.sock" ] && break; sleep 0.25; done+ check "the bundled daemon serves the Keyvault socket" test -S "$kv_home/keyvault.sock"+ check "cua keyvault status: client and daemon verify each other as Cua" \+ env CUA_HOME="$kv_home" CUA_TELEMETRY=0 DO_NOT_TRACK=1 \+ "$cua" keyvault status --daemon "$kv_home/cua.sock"+ kill "$daemon_pid" 2>/dev/null && wait "$daemon_pid" 2>/dev/null+ daemon_pid=""+ fi+ fi+ unmount_all+fi++# --- Electron app -------------------------------------------------------------+for dmg in ${electron_dmgs[@]+"${electron_dmgs[@]}"}; do+ section "Electron disk image: $dmg"+ image_checks "$dmg"+ case "$dmg" in *-arm64.dmg) e_archs="arm64" ;; *-x64.dmg | *-x86_64.dmg) e_archs="x86_64" ;; *) e_archs="arm64 x86_64" ;; esac+ if ! mount_dmg "$dmg"; then fail "could not mount $dmg"; continue; fi+ app="$mnt/Cua Spaces.app"+ [ -d "$app" ] || { fail "no Cua Spaces.app in $dmg"; unmount_all; continue; }+ section "Electron app: ${dmg##*/}"+ version_checks "$app/Contents/Info.plist" "$version"+ check "app signature, deep and strict" strict_app "$app"+ check "app Gatekeeper (spctl)" spctl -a -vv "$app"+ check "app notarization ticket stapled" xcrun stapler validate "$app"+ check "app meets the Keyvault requirement (team $team, com.trycua.spaces.macos)" \+ keyvault_requirement "$app" com.trycua.spaces.macos+ e_cua="$app/Contents/Resources/native/cua"+ check "bundled cua meets the Keyvault requirement (team $team, com.trycua.cua)" \+ keyvault_requirement "$e_cua" com.trycua.cua+ signature_checks "$app" "${dmg##*/}: Cua Spaces.app"+ signature_checks "$e_cua" "${dmg##*/}: Contents/Resources/native/cua"+ section "Electron updater (app-update.yml)"+ update_yml="$app/Contents/Resources/app-update.yml"+ sed 's/^/ /' "$update_yml" 2>/dev/null+ e_url="$(sed -n 's/^url: *//p' "$update_yml" 2>/dev/null | tr -d "'\"")"+ check "feed URL is https" sh -c "case '$e_url' in https://*) exit 0 ;; *) exit 1 ;; esac"+ [ -n "$repo" ] && expect_eq "feed URL is $repo's" "$e_url" "https://github.com/$repo/releases/download/cua-spaces-latest"+ section "Electron architectures: ${dmg##*/}"+ for f in "$app/Contents/MacOS/Cua Spaces" "$e_cua"; do+ for a in $e_archs; do check "${f##*/} has $a ($(lipo -archs "$f"))" lipo "$f" -verify_arch "$a"; done+ done+ unmount_alldone-if [ "$smoke" = 1 ]; then- section "Keyvault smoke (bundled cua daemon, throwaway CUA_HOME)"- cua="$app/Contents/MacOS/cua"- mkdir -p "$HOME/.cache"- # Inside the real home: the Keyvault distrusts a CUA_HOME outside it.- kv_home="$(mktemp -d "$HOME/.cache/cua-verify-release.XXXXXX")"- chmod 700 "$kv_home"- CUA_HOME="$kv_home" CUA_TELEMETRY=0 DO_NOT_TRACK=1 \- "$cua" daemon start --foreground --socket "$kv_home/cua.sock" --loopback off \- >"$kv_home/daemon.out" 2>&1 &- daemon_pid=$!- for _ in $(seq 1 80); do [ -S "$kv_home/keyvault.sock" ] && break; sleep 0.25; done- check "the bundled daemon serves the Keyvault socket" test -S "$kv_home/keyvault.sock"- check "cua keyvault status: client and daemon verify each other as Cua" \- env CUA_HOME="$kv_home" CUA_TELEMETRY=0 DO_NOT_TRACK=1 \- "$cua" keyvault status --daemon "$kv_home/cua.sock"+# --- Windows installers -------------------------------------------------------+if [ ${#windows_exes[@]} -gt 0 ]; then+ root_ca="$here/certs/microsoft-identity-verification-root-2020.pem"+ if ! command -v osslsigncode >/dev/null; then+ section "Windows installers"+ fail "osslsigncode is not installed (brew install osslsigncode)"+ fi+ for exe in "${windows_exes[@]}"; do+ command -v osslsigncode >/dev/null || break+ section "Windows installer: $exe"+ out="$(osslsigncode verify -CAfile "$root_ca" -TSA-CAfile "$root_ca" -in "$exe" 2>&1)"+ rc=$?+ printf '%s\n' "$out" | grep -E "Subject:|Issuer :|Timestamp time:|verification:|^(Succeeded|Failed)" | sort -u | sed 's/^/ /'+ [ $rc -eq 0 ] && echo "PASS Authenticode signature and chain verify (osslsigncode)" ||+ fail "Authenticode signature and chain verify (osslsigncode, exit $rc)"+ # The leaf: the first Subject after "Signer's certificate".+ leaf="$(printf '%s\n' "$out" | awk '/^Signer.s certificate:/ {s=1} s && /Subject:/ {sub(/^[ \t]*Subject: */, ""); print; exit}')"+ want_cn="CN=$(printf '%s' "$signer" | sed 's/,/\\,/g'),"+ case "$leaf" in+ "$want_cn"*) echo "PASS signer is $signer" ;;+ *) fail "signer is $signer: got '$leaf'" ;;+ esac+ printf '%s\n' "$out" | grep -q "Timestamp time:" && echo "PASS timestamped" || fail "no timestamp"+ case "${exe##*/}" in *"$version"*) echo "PASS file name carries $version" ;; *) fail "file name does not carry $version" ;; esac+ donefi+# --- Sparkle appcast ----------------------------------------------------------+if [ -n "$appcast" ]; then+ section "Sparkle appcast: $appcast"+ item_url="$(python3 - "$appcast" "$version" <<'PY'+import sys+import xml.etree.ElementTree as ET+path, version = sys.argv[1:]+SP = "{http://www.andymatuschak.org/xml-namespaces/sparkle}"+bad = 0+found = []+for item in ET.parse(path).iter("item"):+ short = (item.findtext(SP + "shortVersionString") or "").strip()+ channel = (item.findtext(SP + "channel") or "").strip()+ want = "beta" if "-" in short else ""+ if channel != want:+ print(f"FAIL item {short}: channel '{channel}', want '{want}' (prereleases are Beta only)", file=sys.stderr)+ bad = 1+ if short == version:+ enclosure = item.find("enclosure")+ found.append(enclosure.get("url") if enclosure is not None else "")+if version and len(found) != 1:+ print(f"FAIL expected one item for {version}, found {len(found)}", file=sys.stderr)+ bad = 1+elif found:+ print(found[0])+sys.exit(bad)+PY+)"+ rc=$?+ [ $rc -eq 0 ] && echo "PASS only X.Y.Z-suffix items are on the beta channel, and one item is $version" ||+ { fail "appcast channels or this release's item"; }+ if [ -n "$item_url" ]; then+ echo " item: $item_url"+ item_dmg=""+ electron_flag=()+ case "${item_url##*/}" in+ "cua-spaces-$version-darwin-universal.dmg") item_dmg="$swift_dmg" ;;+ "Cua-Spaces-$version-universal.dmg")+ electron_flag=(--electron)+ for f in ${electron_dmgs[@]+"${electron_dmgs[@]}"}; do [ "${f##*/}" = "${item_url##*/}" ] && item_dmg="$f"; done ;;+ esac+ if [ -n "$repo" ]; then+ expect_eq "item downloads from $repo" "${item_url%/*}/" "https://github.com/$repo/releases/download/cua-spaces-v$version/"+ fi+ if [ -n "$item_dmg" ] && [ -f "$item_dmg" ]; then+ check "this release's item (scripts/verify-appcast.sh)" "$here/verify-appcast.sh" \+ --appcast "$appcast" --dmg "$item_dmg" --url "$item_url" --version "$version" ${electron_flag[@]+"${electron_flag[@]}"}+ else+ fail "the item's disk image ${item_url##*/} is not here to verify"+ fi+ fi+fi++# --- Electron update feeds ----------------------------------------------------+if [ ${#feeds[@]} -gt 0 ]; then+ section "Electron update feeds"+ # Local copies of the files the feeds name, to compare sha512 and size.+ locals=()+ for f in ${electron_dmgs[@]+"${electron_dmgs[@]}"} ${windows_exes[@]+"${windows_exes[@]}"}; do locals+=("$f"); done+ [ -n "$dir" ] && for f in "$dir"/*.zip "$dir"/*.AppImage "$dir"/*.deb; do [ -f "$f" ] && locals+=("$f"); done+ check "feeds name $version and its files" python3 - "$version" "$repo" ${locals[@]+"${locals[@]}"} -- "${feeds[@]}" <<'PY'+import base64, hashlib, os, re, sys+args = sys.argv[1:]+version, repo = args[0], args[1]+split = args.index("--")+local = {os.path.basename(p): p for p in args[2:split]}+feeds = args[split + 1:]+prerelease = "-" in version+bad = 0+def fail(msg):+ global bad+ print(f"FAIL {msg}")+ bad = 1+for feed in feeds:+ name = os.path.basename(feed)+ text = open(feed).read()+ top = dict(re.findall(r"^(version|path|sha512|releaseDate): *'?([^'\n]*)'?$", text, re.M))+ files = []+ # The files: list, up to the next top-level key.+ section = re.search(r"^files:\n((?:[ -].*\n?)*)", text, re.M)+ for block in re.split(r"^ - ", section.group(1) if section else "", flags=re.M)[1:]:+ entry = dict(re.findall(r"(url|sha512|size): *([^\n]+)", block))+ files.append(entry)+ if name.startswith("beta") != prerelease and name.startswith(("beta", "latest")):+ # A prerelease writes beta*.yml; a stable release (the cutover) latest*.yml.+ fail(f"{name}: a {'prerelease' if prerelease else 'stable release'} must not write it")+ if top.get("version") != version:+ fail(f"{name}: version {top.get('version')!r}, want {version!r}")+ if not files:+ fail(f"{name}: no files")+ for entry in files:+ url = entry.get("url", "")+ base = url.rsplit("/", 1)[-1]+ if version not in base:+ fail(f"{name}: {base} is not a {version} file")+ if "://" in url:+ want = f"/cua-spaces-v{version}/"+ if want not in url:+ fail(f"{name}: {url} is not on the cua-spaces-v{version} release")+ if repo and not url.startswith(f"https://github.com/{repo}/releases/download/"):+ fail(f"{name}: {url} is not on {repo}")+ if base in local:+ data = open(local[base], "rb").read()+ digest = base64.b64encode(hashlib.sha512(data).digest()).decode()+ if digest != entry.get("sha512", "").strip():+ fail(f"{name}: {base} sha512 does not match the file")+ elif str(len(data)) != entry.get("size", "").strip():+ fail(f"{name}: {base} size does not match the file")+ else:+ print(f" {name}: {base} sha512 and size match")+ path = top.get("path", "")+ if path and path.rsplit("/", 1)[-1] not in {e.get("url", "").rsplit("/", 1)[-1] for e in files}:+ fail(f"{name}: path {path} is not one of its files")+ print(f" {name}: version {top.get('version')}, {len(files)} files")+sys.exit(bad)+PY+ channel=latest+ [[ "$version" == *-* ]] && channel=beta+ have=" "+ for f in "${feeds[@]}"; do have="$have${f##*/} "; done+ # The feed of each platform whose installers are here.+ wants=()+ [ ${#electron_dmgs[@]} -gt 0 ] && wants+=("$channel-mac.yml")+ [ ${#windows_exes[@]} -gt 0 ] && wants+=("$channel.yml")+ for want in ${wants[@]+"${wants[@]}"}; do+ case "$have" in *" $want "*) echo "PASS feed present: $want" ;; *) fail "feed missing: $want" ;; esac+ done+fi++# --- checksums.txt and release-artifacts.json -------------------------------+manifest=""+if [ -n "$dir" ] && { [ -f "$dir/release-artifacts.json" ] || [ -f "$dir/checksums.txt" ]; }; then+ manifest=1+ section "release manifest: checksums.txt, release-artifacts.json"+ base_args=()+ [ -n "$repo" ] && base_args=(--base-url "https://github.com/$repo/releases/download/cua-spaces-v$version")+ check "every published artifact is listed with its sha256" \+ python3 "$here/../../../scripts/install/check_release_manifest.py" --dir "$dir" --component app \+ --version "$version" ${base_args[@]+"${base_args[@]}"}+fi++# --- What had to be there -----------------------------------------------------+section "expected assets ($expect)"+for kind in ${expect//,/ }; do+ case "$kind" in+ swift) [ -n "$swift_dmg" ] && echo "PASS SwiftUI disk image" || fail "no SwiftUI disk image" ;;+ electron) [ ${#electron_dmgs[@]} -gt 0 ] && echo "PASS Electron disk images (${#electron_dmgs[@]})" || fail "no Electron disk images" ;;+ windows) [ ${#windows_exes[@]} -gt 0 ] && echo "PASS Windows installers (${#windows_exes[@]})" || fail "no Windows installers" ;;+ appcast) [ -n "$appcast" ] && echo "PASS Sparkle appcast" || fail "no Sparkle appcast" ;;+ feed) [ ${#feeds[@]} -gt 0 ] && echo "PASS Electron feeds (${#feeds[@]})" || fail "no Electron feeds" ;;+ manifest) [ -n "$manifest" ] && echo "PASS release manifest" || fail "no checksums.txt or release-artifacts.json" ;;+ *) fail "unknown --expect kind: $kind" ;;+ esac+done+echoif [ $failed -eq 0 ]; then echo "ALL CHECKS PASSED"; else echo "SOME CHECKS FAILED"; fiexit $faileddiff --git a/scripts/install/check_release_manifest.py b/scripts/install/check_release_manifest.pynew file mode 100644index 0000000000..1d63dbfbc7--- /dev/null+++ b/scripts/install/check_release_manifest.py@@ -0,0 +1,117 @@+#!/usr/bin/env python3+"""Check a release's `checksums.txt` and `release-artifacts.json` against its files.++ check_release_manifest.py --dir release/ --component app --version 0.8.0 \+ [--base-url https://github.com/trycua/cua/releases/download/cua-spaces-v0.8.0]++DIR holds every asset of the release (as `gh release download` writes them).+It fails unless:++- every asset (all but checksums.txt, release-artifacts.json and latest.json;+ signatures included) has a line in checksums.txt whose sha256 is the+ file's, and every line names an asset that is here;+- every installable asset of COMPONENT at VERSION (each name release_manifest.py+ recognises: the SwiftUI, Electron, Tauri and CLI artifacts) is listed in+ release-artifacts.json under that component and version, with the file's+ sha256 and size and, with --base-url, its download URL; and every listed+ artifact of that component names an asset that is here.+"""++from __future__ import annotations++import argparse+import json+import sys+from pathlib import Path++sys.path.insert(0, str(Path(__file__).resolve().parent))+from release_manifest import classify, sha256 # noqa: E402++META = {"checksums.txt", "release-artifacts.json", "latest.json"}+++def check(directory: Path, component: str, version: str, base_url: str | None) -> list[str]:+ errors: list[str] = []+ assets = {+ p.name: p+ for p in sorted(directory.iterdir())+ if p.is_file() and p.name not in META+ }+ digests = {name: sha256(path) for name, path in assets.items()}++ checksums_path = directory / "checksums.txt"+ if not checksums_path.is_file():+ errors.append("no checksums.txt")+ else:+ listed: dict[str, str] = {}+ for line in checksums_path.read_text().splitlines():+ if not line.strip():+ continue+ digest, _, name = line.partition(" ")+ listed[name.lstrip("*").strip()] = digest.strip()+ for name, digest in digests.items():+ if name not in listed:+ errors.append(f"checksums.txt does not list {name}")+ elif listed[name] != digest:+ errors.append(f"checksums.txt: {name} sha256 {listed[name]} is not the file's {digest}")+ for name in listed:+ if name not in assets:+ errors.append(f"checksums.txt lists {name}, which is not on the release")++ manifest_path = directory / "release-artifacts.json"+ if not manifest_path.is_file():+ errors.append("no release-artifacts.json")+ return errors+ manifest = json.loads(manifest_path.read_text())+ if manifest.get("versions", {}).get(component) != version:+ errors.append(f"release-artifacts.json: {component} version {manifest.get('versions', {}).get(component)!r}, want {version!r}")+ entries = [a for a in manifest.get("artifacts", []) if a.get("component") == component]+ by_name: dict[str, list[dict]] = {}+ for entry in entries:+ by_name.setdefault(entry.get("name", ""), []).append(entry)+ for name, path in assets.items():+ found = classify(name)+ if not found or found[0] != component:+ continue+ if found[3] != version:+ errors.append(f"{name} is not a {version} artifact")+ continue+ rows = by_name.get(name)+ if not rows:+ errors.append(f"release-artifacts.json does not list {name}")+ continue+ size = path.stat().st_size+ for row in rows:+ where = f"release-artifacts.json: {name} ({row.get('platform')})"+ if row.get("sha256") != digests[name]:+ errors.append(f"{where} sha256 {row.get('sha256')} is not the file's {digests[name]}")+ if row.get("size") != size:+ errors.append(f"{where} size {row.get('size')} is not the file's {size}")+ if row.get("version") != version:+ errors.append(f"{where} version {row.get('version')!r}, want {version!r}")+ if base_url and row.get("url") != f"{base_url.rstrip('/')}/{name}":+ errors.append(f"{where} url {row.get('url')} is not {base_url.rstrip('/')}/{name}")+ for name in by_name:+ if name not in assets:+ errors.append(f"release-artifacts.json lists {name}, which is not on the release")+ return errors+++def main(argv: list[str] | None = None) -> int:+ parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)+ parser.add_argument("--dir", required=True)+ parser.add_argument("--component", choices=("cli", "app"), required=True)+ parser.add_argument("--version", required=True)+ parser.add_argument("--base-url")+ args = parser.parse_args(argv)+ errors = check(Path(args.dir), args.component, args.version, args.base_url)+ for error in errors:+ print(f"FAIL {error}")+ if errors:+ return 1+ print(f"checksums.txt and release-artifacts.json list every {args.component} {args.version} asset with its sha256")+ return 0+++if __name__ == "__main__":+ sys.exit(main())diff --git a/scripts/install/release_manifest.py b/scripts/install/release_manifest.pyindex 099fb2a732..813cb22c40 100644--- a/scripts/install/release_manifest.py+++ b/scripts/install/release_manifest.py@@ -14,9 +14,17 @@ Artifact names it recognises (anything else in --dir is ignored):app: cua-spaces-<version>-darwin-universal.dmg / .pkgcua-spaces-<version>-linux-<arch>.AppImage / .debcua-spaces-<version>-windows-<arch>.msi / -setup.exe+ the Electron app (electron-builder names, kinds electron-*):+ Cua-Spaces-<version>-<arm64|universal>.dmg / -mac.zip,+ Cua-Spaces-<version>-<x86_64|arm64>.AppImage,+ cua-spaces_<version>_<amd64|arm64>.deb,+ Cua-Spaces-Setup-<version>[-<x64|arm64>].exe<platform> is darwin-arm64, darwin-x64, linux-x64, linux-arm64, windows-x64 or-windows-arm64; a darwin-universal app is listed under both macOS platforms.+windows-arm64; a darwin-universal app is listed under both macOS platforms,+and a universal Electron app (kind electron-*-universal) under both macOS or+both Windows platforms. The installers pick only the dmg, pkg, appimage, deb,+msi and nsis kinds, so the Electron entries never change what they install.Optional signatures next to an artifact: `<name>.minisig` (minisign) and`<name>.sigstore.json` (cosign bundle).@@ -37,6 +45,8 @@ from pathlib import PathSCHEMA = 1PLATFORMS = ("darwin-arm64", "darwin-x64", "linux-x64", "linux-arm64", "windows-x64", "windows-arm64")VERSION = r"(?P<version>\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)"+# Lazy: electron-builder puts an optional architecture after the version.+EVERSION = r"(?P<version>\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+?)?)"PATTERNS = [("cli", "tar.gz", re.compile(rf"^cua-cli-{VERSION}-(?P<platform>(?:darwin|linux)-(?:x64|arm64))\.tar\.gz$")),@@ -47,8 +57,27 @@ PATTERNS = [("app", "deb", re.compile(rf"^cua-spaces-{VERSION}-(?P<platform>linux-(?:x64|arm64))\.deb$")),("app", "msi", re.compile(rf"^cua-spaces-{VERSION}-(?P<platform>windows-(?:x64|arm64))\.msi$")),("app", "nsis", re.compile(rf"^cua-spaces-{VERSION}-(?P<platform>windows-(?:x64|arm64))-setup\.exe$")),+ # The Electron app (apps/cua-spaces-desktop), named by electron-builder.+ ("app", "electron-dmg", re.compile(rf"^Cua-Spaces-{EVERSION}-(?P<arch>arm64|universal)\.dmg$")),+ ("app", "electron-zip", re.compile(rf"^Cua-Spaces-{EVERSION}-(?P<arch>arm64|universal)-mac\.zip$")),+ ("app", "electron-appimage", re.compile(rf"^Cua-Spaces-{EVERSION}-(?P<arch>x86_64|arm64)\.AppImage$")),+ ("app", "electron-deb", re.compile(rf"^cua-spaces_{EVERSION}_(?P<arch>amd64|arm64)\.deb$")),+ ("app", "electron-nsis", re.compile(rf"^Cua-Spaces-Setup-{EVERSION}(?:-(?P<arch>x64|arm64))?\.exe$")),]+# Electron's architecture names, per kind, as platforms.+ELECTRON_PLATFORMS = {+ "electron-dmg": {"arm64": "darwin-arm64", "universal": "darwin-universal"},+ "electron-zip": {"arm64": "darwin-arm64", "universal": "darwin-universal"},+ "electron-appimage": {"x86_64": "linux-x64", "arm64": "linux-arm64"},+ "electron-deb": {"amd64": "linux-x64", "arm64": "linux-arm64"},+ "electron-nsis": {"x64": "windows-x64", "arm64": "windows-arm64", None: "windows-universal"},+}+UNIVERSAL = {+ "darwin-universal": ["darwin-arm64", "darwin-x64"],+ "windows-universal": ["windows-x64", "windows-arm64"],+}+SAFE = re.compile(r'^[^"\\\x00-\x1f]*$')@@ -56,7 +85,13 @@ def classify(name: str):for component, kind, pattern in PATTERNS:match = pattern.match(name)if match:- return component, kind, match.group("platform"), match.group("version")+ if kind in ELECTRON_PLATFORMS:+ platform = ELECTRON_PLATFORMS[kind][match.group("arch")]+ if platform in UNIVERSAL:+ kind = f"{kind}-universal"+ else:+ platform = match.group("platform")+ return component, kind, platform, match.group("version")return None@@ -83,7 +118,7 @@ def scan(component: str, version: str, directory: Path, base_url: str | None) ->_, kind, platform, file_version = foundif file_version != version:raise SystemExit(f"{path.name}: version {file_version} does not match --version {version}")- platforms = ["darwin-arm64", "darwin-x64"] if platform == "darwin-universal" else [platform]+ platforms = UNIVERSAL.get(platform, [platform])common = {"name": path.name,"url": url_for(base_url, path.name),diff --git a/scripts/install/tests/test_check_release_manifest.py b/scripts/install/tests/test_check_release_manifest.pynew file mode 100644index 0000000000..ba3eabdced--- /dev/null+++ b/scripts/install/tests/test_check_release_manifest.py@@ -0,0 +1,91 @@+"""Unit tests for check_release_manifest.py (python3 -m unittest discover -s scripts/install/tests)."""++import hashlib+import json+import subprocess+import sys+import tempfile+import unittest+from pathlib import Path++HERE = Path(__file__).resolve().parent.parent+CHECK = HERE / "check_release_manifest.py"+BUILD = HERE / "release_manifest.py"+V = "0.8.0-beta.6"+BASE = f"https://github.com/trycua/cua/releases/download/cua-spaces-v{V}"+++class CheckReleaseManifestTest(unittest.TestCase):+ def setUp(self):+ self.tmp = tempfile.TemporaryDirectory()+ self.dir = Path(self.tmp.name)+ for name in (+ f"cua-spaces-{V}-darwin-universal.dmg",+ f"cua-spaces-{V}-darwin-universal.dmg.sigstore.json",+ f"Cua-Spaces-{V}-universal.dmg",+ f"Cua-Spaces-{V}-universal.dmg.blockmap",+ f"Cua-Spaces-Setup-{V}-x64.exe",+ f"Cua-Spaces-{V}-x86_64.AppImage",+ f"cua-spaces_{V}_arm64.deb",+ ):+ (self.dir / name).write_bytes(name.encode())++ def tearDown(self):+ self.tmp.cleanup()++ def publish(self):+ lines = [+ f"{hashlib.sha256(p.read_bytes()).hexdigest()} {p.name}"+ for p in sorted(self.dir.iterdir())+ if p.name not in ("checksums.txt", "release-artifacts.json")+ ]+ (self.dir / "checksums.txt").write_text("\n".join(lines) + "\n")+ out = subprocess.run(+ [sys.executable, str(BUILD), "--component", "app", "--version", V, "--dir", str(self.dir),+ "--base-url", BASE, "--out", str(self.dir / "release-artifacts.json")],+ capture_output=True, text=True,+ )+ self.assertEqual(out.returncode, 0, out.stderr)++ def check(self):+ return subprocess.run(+ [sys.executable, str(CHECK), "--dir", str(self.dir), "--component", "app", "--version", V, "--base-url", BASE],+ capture_output=True, text=True,+ )++ def test_a_complete_release_passes(self):+ self.publish()+ out = self.check()+ self.assertEqual(out.returncode, 0, out.stdout)++ def test_an_unlisted_windows_installer_fails(self):+ # CUA-1507: the manifests listed only the SwiftUI app's assets.+ self.publish()+ manifest = json.loads((self.dir / "release-artifacts.json").read_text())+ manifest["artifacts"] = [a for a in manifest["artifacts"] if not a["name"].endswith(".exe")]+ (self.dir / "release-artifacts.json").write_text(json.dumps(manifest))+ lines = (self.dir / "checksums.txt").read_text().splitlines()+ (self.dir / "checksums.txt").write_text("\n".join(line for line in lines if ".exe" not in line) + "\n")+ out = self.check()+ self.assertEqual(out.returncode, 1)+ self.assertIn(f"FAIL checksums.txt does not list Cua-Spaces-Setup-{V}-x64.exe", out.stdout)+ self.assertIn(f"FAIL release-artifacts.json does not list Cua-Spaces-Setup-{V}-x64.exe", out.stdout)++ def test_a_changed_file_fails_both_checksums(self):+ self.publish()+ (self.dir / f"Cua-Spaces-{V}-x86_64.AppImage").write_bytes(b"changed")+ out = self.check()+ self.assertEqual(out.returncode, 1)+ self.assertIn(f"FAIL checksums.txt: Cua-Spaces-{V}-x86_64.AppImage sha256", out.stdout)+ self.assertIn(f"FAIL release-artifacts.json: Cua-Spaces-{V}-x86_64.AppImage (linux-x64) sha256", out.stdout)++ def test_a_listed_file_missing_from_the_release_fails(self):+ self.publish()+ (self.dir / f"cua-spaces_{V}_arm64.deb").unlink()+ out = self.check()+ self.assertEqual(out.returncode, 1)+ self.assertIn(f"FAIL release-artifacts.json lists cua-spaces_{V}_arm64.deb, which is not on the release", out.stdout)+++if __name__ == "__main__":+ unittest.main()diff --git a/scripts/install/tests/test_release_manifest.py b/scripts/install/tests/test_release_manifest.pyindex 67296d8f7e..3e8f615c0b 100644--- a/scripts/install/tests/test_release_manifest.py+++ b/scripts/install/tests/test_release_manifest.py@@ -61,6 +61,37 @@ class ReleaseManifestTest(unittest.TestCase):self.assertIn(("app", "windows-x64", "nsis"), kinds)self.assertIn(("cli", "darwin-arm64", "tar.gz"), kinds)+ def test_electron_installers_for_every_platform_under_their_own_kinds(self):+ # CUA-1507: a prerelease's Electron installers were missing.+ v = "0.8.0-beta.6"+ names = {+ f"cua-spaces-{v}-darwin-universal.dmg": [("darwin-arm64", "dmg"), ("darwin-x64", "dmg")],+ f"Cua-Spaces-{v}-arm64.dmg": [("darwin-arm64", "electron-dmg")],+ f"Cua-Spaces-{v}-universal.dmg": [("darwin-arm64", "electron-dmg-universal"), ("darwin-x64", "electron-dmg-universal")],+ f"Cua-Spaces-{v}-arm64-mac.zip": [("darwin-arm64", "electron-zip")],+ f"Cua-Spaces-{v}-universal-mac.zip": [("darwin-arm64", "electron-zip-universal"), ("darwin-x64", "electron-zip-universal")],+ f"Cua-Spaces-{v}-x86_64.AppImage": [("linux-x64", "electron-appimage")],+ f"Cua-Spaces-{v}-arm64.AppImage": [("linux-arm64", "electron-appimage")],+ f"cua-spaces_{v}_amd64.deb": [("linux-x64", "electron-deb")],+ f"cua-spaces_{v}_arm64.deb": [("linux-arm64", "electron-deb")],+ f"Cua-Spaces-Setup-{v}.exe": [("windows-x64", "electron-nsis-universal"), ("windows-arm64", "electron-nsis-universal")],+ f"Cua-Spaces-Setup-{v}-x64.exe": [("windows-x64", "electron-nsis")],+ f"Cua-Spaces-Setup-{v}-arm64.exe": [("windows-arm64", "electron-nsis")],+ }+ for name in names:+ self.touch(name)+ self.touch(f"Cua-Spaces-{v}-arm64.dmg.blockmap")+ out = run("--component", "app", "--version", v, "--dir", str(self.dir))+ self.assertEqual(out.returncode, 0, out.stderr)+ got: dict = {}+ for a in json.loads(out.stdout)["artifacts"]:+ self.assertEqual(a["version"], v)+ got.setdefault(a["name"], []).append((a["platform"], a["kind"]))+ self.assertEqual({k: sorted(x) for k, x in got.items()}, {k: sorted(x) for k, x in names.items()})+ # The installers' kinds still name exactly one artifact per platform.+ kinds = [(p, k) for rows in got.values() for p, k in rows]+ self.assertEqual(len(kinds), len(set(kinds)))+def test_version_mismatch_and_empty_dir_fail(self):self.touch("cua-cli-1.0.0-linux-x64.tar.gz")self.assertNotEqual(run("--component", "cli", "--version", "1.0.1", "--dir", str(self.dir)).returncode, 0)