提交记录修改scripts/build-app.sh+4 −0看文件
修改scripts/guest-os/package-macos-guest.sh+3 −0看文件
新增scripts/guest-os/sign-macos-guest.sh+37 −0看文件
新增scripts/guest-os/sshfs.entitlements+6 −0看文件
修改scripts/test-macos-install.mjs+26 −6看文件
| @@ -36,6 +36,7 @@ short_version="${version%%-*}" | ||
| 36 | 36 | build_version="${CAGE_BUILD_NUMBER:-1}" |
| 37 | 37 | if [[ ! "$build_version" =~ ^[0-9]+(\.[0-9]+){0,2}$ ]]; then echo 'Invalid CAGE_BUILD_NUMBER.' >&2; exit 1; fi |
| 38 | 38 | identity="${CAGE_SIGNING_IDENTITY:--}" |
| 39 | 新增:export CAGE_SIGNING_IDENTITY="$identity" | |
| 39 | 40 | # The host SDK may default to the developer's newer macOS version. Set the |
| 40 | 41 | # deployment target for the Go/cgo helper as well as the Swift launcher. |
| 41 | 42 | export MACOSX_DEPLOYMENT_TARGET=14.0 |
| @@ -59,6 +60,9 @@ cp _output/bin/cage "$bundle/Contents/Resources/cage" | ||
| 59 | 60 | if [[ "$(uname -m)" == arm64 ]]; then "$bundle/Contents/Resources/cage" verify-macos-guest; fi |
| 60 | 61 | if [[ "$(uname -m)" == arm64 ]]; then |
| 61 | 62 | bash scripts/guest-os/package-macos-guest.sh "$bundle/Contents/Resources/guest-os" |
| 63 | 新增: # The kit signs all nested native code before this outer App is sealed. | |
| 64 | 新增: # Do not generate or reuse an unsigned component manifest here: installation | |
| 65 | 新增: # hashes the final signed kit, including each nested bundle's CodeResources. | |
| 62 | 66 | fi |
| 63 | 67 | node scripts/bundle-cloud-kit.mjs "$bundle/Contents/Resources" |
| 64 | 68 | cp _output/proxy-core/mihomo "$bundle/Contents/Resources/mihomo" |
| @@ -33,3 +33,6 @@ cp "$src/../../internal/cage/claude-account.py" "$src/../../internal/workbench/" | ||
| 33 | 33 | # Shared component maintenance is installed separately from first-run accounts. |
| 34 | 34 | cp "$src/maintain-macos-workbench.sh" "$src/native-component-manifest.pl" "$dest/" |
| 35 | 35 | cp "$src/configure-macos-session.sh" "$dest/" |
| 36 | 新增:# Final signing runs after every helper has been built. Component manifests are | |
| 37 | 新增:# computed from these final bytes by RequiredNativeComponents at installation. | |
| 38 | 新增:bash "$src/sign-macos-guest.sh" "$dest" "${CAGE_SIGNING_IDENTITY:--}" | |
| @@ -0,0 +1,37 @@ | ||
| 1 | 新增:#!/bin/bash | |
| 2 | 新增:# Sign only the guest kit's Mach-O code, inside out. Source and foreign payloads | |
| 3 | 新增:# are data; every native executable is refreshed even if a cache was ad-hoc signed. | |
| 4 | 新增:set -euo pipefail | |
| 5 | 新增:[[ $# == 2 && -d $1 ]] || { echo 'Usage: sign-macos-guest.sh /guest-kit signing-identity' >&2; exit 2; } | |
| 6 | 新增:kit=$1 identity=$2 | |
| 7 | 新增:src=$(cd "$(dirname "$0")" && pwd) | |
| 8 | 新增:sign=(/usr/bin/codesign --force --sign "$identity") | |
| 9 | 新增:if [[ $identity != - ]]; then | |
| 10 | 新增: [[ $identity == 'Developer ID Application:'* || $identity =~ ^[[:xdigit:]]{40}$ ]] || { echo 'Guest release code requires a Developer ID Application name or certificate fingerprint.' >&2; exit 2; } | |
| 11 | 新增: sign+=(--timestamp --options runtime) | |
| 12 | 新增:fi | |
| 13 | 新增:count=0 | |
| 14 | 新增:while IFS= read -r -d '' executable; do | |
| 15 | 新增: kind=$(/usr/bin/file -b "$executable") | |
| 16 | 新增: [[ $kind == *Mach-O* ]] || continue | |
| 17 | 新增: if [[ $executable == "$kit/project/cage-sshfs" ]]; then | |
| 18 | 新增: # macFUSE is installed in the guest by its own publisher, outside our team. | |
| 19 | 新增: "${sign[@]}" --entitlements "$src/sshfs.entitlements" "$executable" | |
| 20 | 新增: else | |
| 21 | 新增: "${sign[@]}" "$executable" | |
| 22 | 新增: fi | |
| 23 | 新增: /usr/bin/codesign --verify --strict "$executable" | |
| 24 | 新增: if [[ $identity != - ]]; then | |
| 25 | 新增: metadata=$(/usr/bin/codesign -d --verbose=4 "$executable" 2>&1) | |
| 26 | 新增: grep -q '^Authority=Developer ID Application:' <<< "$metadata" | |
| 27 | 新增: grep -q 'flags=.*runtime' <<< "$metadata" | |
| 28 | 新增: grep -q '^Timestamp=' <<< "$metadata" | |
| 29 | 新增: fi | |
| 30 | 新增: count=$((count+1)) | |
| 31 | 新增:done < <(/usr/bin/find "$kit" -type f -print0) | |
| 32 | 新增:[[ $count -gt 0 ]] || { echo 'Guest kit contains no native executable.' >&2; exit 1; } | |
| 33 | 新增:while IFS= read -r -d '' app; do | |
| 34 | 新增: "${sign[@]}" "$app" | |
| 35 | 新增: /usr/bin/codesign --verify --deep --strict "$app" | |
| 36 | 新增:done < <(/usr/bin/find "$kit" -depth -type d -name '*.app' -print0) | |
| 37 | 新增:printf 'Signed and verified %s guest Mach-O files.\n' "$count" | |
| @@ -0,0 +1,6 @@ | ||
| 1 | 新增:<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | 新增:<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| 3 | 新增:<plist version="1.0"><dict> | |
| 4 | 新增:<!-- macFUSE's signed system-installed library belongs to a different team. --> | |
| 5 | 新增:<key>com.apple.security.cs.disable-library-validation</key><true/> | |
| 6 | 新增:</dict></plist> | |
| @@ -28,6 +28,8 @@ const run = (exe, args, options = {}) => execFileSync(exe, args, { encoding: "ut | ||
| 28 | 28 | const cli = (...args) => run(path.join(installed, "Contents/Resources/cage"), args, { env }); |
| 29 | 29 | const hash = async file => createHash("sha256").update(await fs.readFile(file)).digest("hex"); |
| 30 | 30 | const password = randomUUID() + "7z"; |
| 31 | 新增:const username = "install_smoke"; | |
| 32 | 新增:const evidence = process.env.CAGE_REMOTE_QA_DIR; | |
| 31 | 33 | let browser, mounted = false, running = false; |
| 32 | 34 | |
| 33 | 35 | try { |
| @@ -45,10 +47,13 @@ try { | ||
| 45 | 47 | launcher_sha256: await hash(path.join(source, "Contents/MacOS/Cage")), |
| 46 | 48 | }; |
| 47 | 49 | |
| 48 | 删除: browser = await chromium.launch({ headless: true }); | |
| 50 | 新增: if (evidence) await fs.mkdir(evidence, { recursive: true }); | |
| 51 | 新增: browser = await chromium.launch({ headless: true, executablePath: process.env.CAGE_TEST_BROWSER_PATH }); | |
| 52 | 新增: let savedAccountHash; | |
| 49 | 53 | for (const phase of ["install", "reinstall"]) { |
| 50 | 54 | if (phase === "reinstall") await fs.rm(installed, { recursive: true }); |
| 51 | 55 | run("ditto", [path.join(mount, "Cage.app"), installed]); |
| 56 | 新增: if (savedAccountHash) assert.equal(await hash(path.join(profile, "account.json")), savedAccountHash, "reinstall changed the account file"); | |
| 52 | 57 | run("codesign", ["--verify", "--deep", "--strict", installed]); |
| 53 | 58 | assert.equal(await hash(path.join(installed, "Contents/Resources/cage")), result.backend_sha256); |
| 54 | 59 | cli("verify-web-assets"); |
| @@ -57,12 +62,14 @@ try { | ||
| 57 | 62 | const entry = JSON.parse(cli("desktop", "--json")); |
| 58 | 63 | assert.equal(entry.status, "ready"); |
| 59 | 64 | const page = await browser.newPage(); |
| 65 | 新增: const errors = []; | |
| 66 | 新增: page.on("pageerror", error => errors.push(error.message)); | |
| 60 | 67 | try { |
| 61 | 68 | await page.goto(entry.url); |
| 62 | 69 | if (phase === "install") { |
| 63 | 删除: await page.getByRole("button", { name: "使用用户名和密码", exact: true }).click(); | |
| 70 | 新增: await page.getByRole("heading", { name: "注册 Cage 账户", exact: true }).waitFor(); | |
| 64 | 71 | await page.getByRole("checkbox", { name: /^记住我/ }).uncheck(); |
| 65 | 删除: await page.getByLabel("用户名", { exact: true }).fill("整包验收"); | |
| 72 | 新增: await page.getByLabel("用户名", { exact: true }).fill(username); | |
| 66 | 73 | await page.getByLabel("设置密码", { exact: true }).fill(password); |
| 67 | 74 | await page.getByLabel("确认密码", { exact: true }).fill(password); |
| 68 | 75 | await page.getByRole("button", { name: "创建本地账户", exact: true }).click(); |
| @@ -70,24 +77,37 @@ try { | ||
| 70 | 77 | await page.getByLabel("账户密码", { exact: true }).fill(password); |
| 71 | 78 | await page.getByRole("button", { name: "解锁 Cage", exact: true }).click(); |
| 72 | 79 | } |
| 73 | 删除: await page.getByRole("button", { name: "设置", exact: true }).waitFor(); | |
| 80 | 新增: await page.getByRole("heading", { name: "为 Cage 准备独立环境", exact: true }).waitFor(); | |
| 81 | 新增: assert.equal(await page.getByRole("navigation", { name: "主导航" }).count(), 0, "workbench must remain hidden before initialization"); | |
| 82 | 新增: if (evidence) await page.screenshot({ animations: "disabled", path: path.join(evidence, `${phase}-initialization.png`) }); | |
| 83 | 新增: await page.getByRole("button", { name: "下一步:配置代理", exact: true }).click(); | |
| 84 | 新增: await page.getByRole("heading", { name: "连接你的网络代理", exact: true }).waitFor(); | |
| 85 | 新增: assert.ok(await page.getByRole("button", { name: "开始安装", exact: true }).isDisabled(), "a fresh profile must require a proxy before installing"); | |
| 86 | 新增: // Do not start a VM or configure real network credentials in package-preservation QA. | |
| 87 | 新增: await page.getByRole("button", { name: "上一步", exact: true }).click(); | |
| 88 | 新增: await page.getByRole("heading", { name: "为 Cage 准备独立环境", exact: true }).waitFor(); | |
| 74 | 89 | const account = await page.evaluate(async () => { |
| 75 | 90 | const context = await (await fetch("/api/client/context")).json(); |
| 76 | 91 | return (await fetch("/api/account", { headers: { "X-Cage-Connection": context.connection_id } })).json(); |
| 77 | 92 | }); |
| 78 | 删除: assert.equal(account.username, "整包验收"); | |
| 93 | 新增: assert.equal(account.username, username); | |
| 79 | 94 | assert.equal(account.unlocked, true); |
| 80 | 删除: result[phase] = { original_account: true, preserved: await verify(qaHome, manifest) }; | |
| 95 | 新增: const status = await page.evaluate(async () => (await fetch("/api/client/local-status")).json()); | |
| 96 | 新增: assert.ok(status.known && status.service_running && !status.running, "installation QA must leave the VM stopped"); | |
| 97 | 新增: assert.deepEqual(errors, []); | |
| 98 | 新增: result[phase] = { original_account: true, initialization_wizard: true, proxy_required: true, vm_stopped: true, preserved: await verify(qaHome, manifest) }; | |
| 81 | 99 | } finally { |
| 82 | 100 | await page.close(); |
| 83 | 101 | } |
| 84 | 102 | cli("prepare-update", "--json"); |
| 85 | 103 | running = false; |
| 104 | 新增: savedAccountHash = await hash(path.join(profile, "account.json")); | |
| 86 | 105 | } |
| 87 | 106 | const accountHash = await hash(path.join(profile, "account.json")); |
| 88 | 107 | await fs.rm(installed, { recursive: true }); |
| 89 | 108 | assert.equal(await hash(path.join(profile, "account.json")), accountHash); |
| 90 | 109 | result.uninstall = { account_preserved: true, preserved: await verify(qaHome, manifest) }; |
| 110 | 新增: if (evidence) await fs.writeFile(path.join(evidence, "result.json"), JSON.stringify(result, null, 2)); | |
| 91 | 111 | console.log(JSON.stringify(result, null, 2)); |
| 92 | 112 | } finally { |
| 93 | 113 | try { |

