跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

提交记录
修改.github/workflows/windows-build.yml+5 −4看文件
@@ -51,7 +51,7 @@ jobs:
5151 msystem: UCRT64
5252 update: true
5353 install: >-
54删除: make patch diffutils
54新增: make patch diffutils git findutils curl
5555 mingw-w64-ucrt-x86_64-gcc
5656 mingw-w64-ucrt-x86_64-glib2
5757 mingw-w64-ucrt-x86_64-pixman
@@ -131,7 +131,7 @@ jobs:
131131 msystem: UCRT64
132132 update: true
133133 install: >-
134删除: make patch diffutils
134新增: make patch diffutils git findutils curl
135135 mingw-w64-ucrt-x86_64-gcc
136136 mingw-w64-ucrt-x86_64-glib2
137137 mingw-w64-ucrt-x86_64-pixman
@@ -154,6 +154,7 @@ jobs:
154154 ./scripts/build-qemu-windows.ps1
155155 $identity = Get-Content '_output/windows-deps/qemu-cage/cage-build.json' -Raw | ConvertFrom-Json
156156 "fingerprint=$($identity.fingerprint)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
157新增: "manifest=$((Get-FileHash '_output/windows-deps/qemu-cage/cage-build.json' -Algorithm SHA256).Hash)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
157158 $collectorHash = (Get-FileHash 'scripts/bundle-qemu-sources.sh' -Algorithm SHA256).Hash + (Get-FileHash 'scripts/prepare-qemu-release.ps1' -Algorithm SHA256).Hash
158159 "collector=$collectorHash" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
159160 - name: Preserve only the completed verified runtime cache
@@ -166,7 +167,7 @@ jobs:
166167 id: qemu_sources
167168 with:
168169 path: _output/windows-qemu-sources
169删除: key: cage-qemu-sources-${{ steps.qemu_build.outputs.fingerprint }}-${{ steps.qemu_build.outputs.collector }}
170新增: key: cage-qemu-sources-${{ steps.qemu_build.outputs.fingerprint }}-${{ steps.qemu_build.outputs.manifest }}-${{ steps.qemu_build.outputs.collector }}
170171 - name: Collect and verify corresponding sources before signing
171172 env:
172173 CAGE_MSYS2_ROOT: ${{ steps.msys2.outputs.msys2-location }}
@@ -176,7 +177,7 @@ jobs:
176177 uses: actions/cache/save@v4
177178 with:
178179 path: _output/windows-qemu-sources
179删除: key: cage-qemu-sources-${{ steps.qemu_build.outputs.fingerprint }}-${{ steps.qemu_build.outputs.collector }}
180新增: key: cage-qemu-sources-${{ steps.qemu_build.outputs.fingerprint }}-${{ steps.qemu_build.outputs.manifest }}-${{ steps.qemu_build.outputs.collector }}
180181 - uses: actions/setup-java@v4
181182 with:
182183 distribution: temurin
修改scripts/bundle-qemu-sources.sh+3 −0看文件
@@ -6,6 +6,9 @@ runtime=$(cygpath -u "$2")
66archive=$(cygpath -u "$3")
77node_command=${CAGE_NODE:-node}
88if [[ -n ${CAGE_NODE:-} ]]; then node_command=$(cygpath -u "$CAGE_NODE"); fi
9新增:for tool in "$node_command" git curl tar sha256sum find sort xargs pacman-key mkdir mktemp cp mv rm grep; do
10新增: command -v "$tool" >/dev/null 2>&1 || { echo "Missing source-collection tool: $tool" >&2; exit 1; }
11新增:done
912commit=$("$node_command" -p "JSON.parse(require('fs').readFileSync(process.argv[1])).qemuSource.commit" "$repository/packaging/windows/dependencies.json")
1013[[ $commit =~ ^[a-f0-9]{40}$ && -s "$runtime/build-source-packages.txt" ]] || { echo 'QEMU source/package identity is missing.' >&2; exit 1; }
1114stage=$(mktemp -d)
修改scripts/esigner.mjs+20 −6看文件
@@ -12,6 +12,8 @@ const root = fileURLToPath(new URL('../', import.meta.url));
1212const pin = JSON.parse(await readFile(new URL('../packaging/windows/signing.json', import.meta.url), 'utf8'));
1313const configPath = 'conf/code_sign_tool.properties';
1414const secretNames = ['CAGE_ESIGNER_PASSWORD', 'CAGE_ESIGNER_TOTP_SECRET'];
15新增:const providerCodes = ['server_error', 'invalid_grant', 'invalid_client', 'access_denied', 'unauthorized', 'invalid_request', 'invalid_otp', 'malware_detected'];
16新增:const rejectedOrUncertain = /timeout|timed out|abort|cancel|invalid_grant|invalid_client|access_denied|unauthorized|(?:otp|totp|authentication|authorization|credential|password)[^\n]*(?:invalid|expired|failed|rejected)|(?:invalid|expired|failed|rejected)[^\n]*(?:otp|totp|authentication|credential|password)/i;
1517const hash = bytes => createHash('sha256').update(bytes).digest('hex');
1618const toolDirectory = () => resolve(process.env.CAGE_ESIGNER_TOOL_DIR || join(root, '_output/esigner', `CodeSignTool-v${pin.version}`));
1719
@@ -124,7 +126,19 @@ export async function invokeJava({ java = 'java', jar, config, arguments: args,
124126 if (otpError) throw otpError;
125127 const output = redact(`${stdout}\n${stderr}`, knownSecrets);
126128 if (code !== 0 || /\b(?:Error:|Exception|Missing required option|Unmatched argument)/u.test(output)) {
127删除: throw new Error(`CodeSignTool failed (exit ${code}). ${output.slice(-2500).trim()}`);
129新增: let privateLog = '';
130新增: try { privateLog = await readFile(join(temp, 'logs', 'code_signing_tool.log'), 'utf8'); } catch { /* Optional diagnostic only. */ }
131新增: const stages = { getMalwareScanResponse: 'malware-scan', getScanSettingsResponse: 'scan-settings', getCredentialsAuthorize: 'credentials-authorize', signHash: 'sign-hash', isOtpTypeOnline: 'otp-type', sendOtp: 'send-otp', getCredentialInfo: 'credentials-info', getCredentialIDs: 'credentials-list' };
132新增: const method = /^\s*at com\.ssl\.code\.signing\.tool\.csc\.CscApi\.(getMalwareScanResponse|getScanSettingsResponse|getCredentialsAuthorize|signHash|isOtpTypeOnline|sendOtp|getCredentialInfo|getCredentialIDs)\(/m.exec(privateLog)?.[1];
133新增: const failureStage = stages[method] || 'unknown';
134新增: const rawCode = /"error"\s*:\s*"([a-z_]+)"/.exec(output)?.[1];
135新增: const providerCode = providerCodes.includes(rawCode) ? rawCode : 'unclassified';
136新增: const quotaExceeded = /QuotaExceededError/.test(privateLog + output);
137新增: // Never attach the raw response or vendor log to the exception. These
138新增: // fixed classifications are the only diagnostic values leaving memory.
139新增: throw Object.assign(new Error(`CodeSignTool failed (exit ${code}). stage=${failureStage}; error=${providerCode}; quotaExceeded=${quotaExceeded}.`), {
140新增: failureStage, providerCode, quotaExceeded, nonRetryable: quotaExceeded || rejectedOrUncertain.test(output),
141新增: });
128142 }
129143 return output;
130144 } finally {
@@ -177,8 +191,9 @@ export async function invokeSigning({ invoke, outputPath, pause = ms => new Prom
177191 catch (error) {
178192 try { await access(outputPath); return ''; }
179193 catch (outputError) { if (outputError.code !== 'ENOENT') throw error; }
180删除: const uncertainOrRejected = /timeout|timed out|abort|cancel|invalid_grant|invalid_client|access_denied|unauthorized|(?:otp|totp|authentication|authorization|credential|password)[^\n]*(?:invalid|expired|failed|rejected)/i.test(error.message);
181删除: if (attempt === 2 || uncertainOrRejected || !/^CodeSignTool failed \(exit 11\)/.test(error.message) || !/"error"\s*:\s*"server_error"/.test(error.message)) throw error;
194新增: const uncertainOrRejected = error.nonRetryable || error.quotaExceeded || rejectedOrUncertain.test(error.message) || /QuotaExceededError/.test(error.message);
195新增: const serverError = error.providerCode === 'server_error' || /"error"\s*:\s*"server_error"/.test(error.message);
196新增: if (attempt === 2 || uncertainOrRejected || !/^CodeSignTool failed \(exit 11\)/.test(error.message) || !serverError) throw error;
182197 console.error(`Signing service returned server_error; retrying in ${(attempt + 1) * 15} seconds.`);
183198 await pause((attempt + 1) * 15000);
184199 }
@@ -191,9 +206,8 @@ export function credentialDiagnostic(error) {
191206 if (!error) return { operation: 'credential_info', success: true, stage: 'csc-credential-info', exitCode: 0, error: '' };
192207 const match = /^CodeSignTool failed \(exit ([0-9]{1,3})\)/.exec(error.message);
193208 const exitCode = match && Number(match[1]) <= 255 ? Number(match[1]) : null;
194删除: const code = /"error"\s*:\s*"([a-z_]+)"/.exec(error.message)?.[1];
195删除: const allowed = ['server_error', 'invalid_grant', 'invalid_client', 'access_denied', 'unauthorized', 'invalid_request'];
196删除: return { operation: 'credential_info', success: false, stage: exitCode === 1 ? 'oauth-token' : exitCode === 2 ? 'csc-credential-info' : 'client', exitCode, error: allowed.includes(code) ? code : 'unclassified' };
209新增: const code = error.providerCode || /"error"\s*:\s*"([a-z_]+)"/.exec(error.message)?.[1];
210新增: return { operation: 'credential_info', success: false, stage: exitCode === 1 ? 'oauth-token' : exitCode === 2 ? 'csc-credential-info' : 'client', exitCode, error: providerCodes.includes(code) ? code : 'unclassified' };
197211}
198212
199213async function main(argv) {
修改scripts/esigner.test.mjs+24 −1看文件
@@ -36,12 +36,15 @@ test('signing retries only declared server errors without output and remains bou
3636 count = 0;
3737 await assert.rejects(invokeSigning({ outputPath, pause: async () => {}, invoke: async () => { count++; throw failure(); } }), /server_error/);
3838 assert.equal(count, 3);
39删除: for (const message of ['OTP rejected', 'authentication failed', 'timeout', 'CodeSignTool failed (exit 1). server_error', `${failure().message}\nOTP rejected`, `${failure().message}\ntimeout`]) {
39新增: for (const message of ['OTP rejected', 'authentication failed', 'timeout', 'CodeSignTool failed (exit 1). server_error', `${failure().message}\nOTP rejected`, `${failure().message}\ninvalid otp`, `${failure().message}\ntimeout`]) {
4040 count = 0;
4141 await assert.rejects(invokeSigning({ outputPath, pause: async () => assert.fail('must not wait'), invoke: async () => { count++; throw new Error(message); } }));
4242 assert.equal(count, 1);
4343 }
4444 count = 0;
45新增: await assert.rejects(invokeSigning({ outputPath, pause: async () => assert.fail('quota is not transient'), invoke: async () => { count++; throw Object.assign(failure(), { quotaExceeded: true }); } }));
46新增: assert.equal(count, 1);
47新增: count = 0;
4548 await invokeSigning({ outputPath, pause: async () => assert.fail('output requires trust verification, never another signature'), invoke: async () => { count++; await writeFile(outputPath, 'candidate output'); throw failure(); } });
4649 assert.equal(count, 1);
4750 assert.equal(await readFile(outputPath, 'utf8'), 'candidate output');
@@ -72,6 +75,11 @@ public class Signer {
7275 String otp = new Scanner(System.in).nextLine();
7376 if (!otp.equals("123456")) System.exit(16);
7477 System.out.println(otp);
78新增: if (Arrays.asList(args).contains("quota")) {
79新增: Files.writeString(Path.of("logs", "code_signing_tool.log"), "sensitive-user sensitive-id sensitive-token\\n at com.ssl.code.signing.tool.csc.CscApi.getMalwareScanResponse(CscApi.java:1)\\nQuotaExceededError dummy-password");
80新增: System.out.println("Error: {\\\"error\\\":\\\"server_error\\\",\\\"token\\\":\\\"sensitive-token\\\"}");
81新增: System.exit(11);
82新增: }
7583 if (Arrays.asList(args).contains("fail")) { System.out.println("Error: dummy-password"); System.exit(4); }
7684 }
7785}
@@ -104,6 +112,21 @@ public class Signer {
104112 else process.env.CAGE_ESIGNER_PASSWORD = previous;
105113 }
106114 }
115新增: const quotaMarker = join(temp, 'quota-marker');
116新增: let quotaCalls = 0;
117新增: await assert.rejects(invokeSigning({ outputPath: join(temp, 'no-signed-output.exe'), pause: async () => assert.fail('quota cannot cause a second signing request'), invoke: () => {
118新增: quotaCalls++;
119新增: return invokeJava({ jar, config, arguments: [quotaMarker, 'quota'], otp: async () => '123456', secrets: ['dummy-password'] });
120新增: } }), error => {
121新增: assert.equal(error.failureStage, 'malware-scan');
122新增: assert.equal(error.providerCode, 'server_error');
123新增: assert.equal(error.quotaExceeded, true);
124新增: for (const secret of ['sensitive-user', 'sensitive-id', 'sensitive-token', 'dummy-password', '123456']) assert.ok(!`${error.message}${JSON.stringify(error)}`.includes(secret));
125新增: return true;
126新增: });
127新增: assert.equal(quotaCalls, 1);
128新增: const quotaWorking = await readFile(quotaMarker, 'utf8');
129新增: await assert.rejects(readFile(join(quotaWorking, 'logs/code_signing_tool.log')), { code: 'ENOENT' });
107130});
108131
109132test('modified vendor binaries are refused before executing Java', async t => {
修改scripts/prepare-qemu-release.ps1+3 −2看文件
@@ -11,13 +11,14 @@ if (-not $MsysDirectory) { throw 'Set CAGE_MSYS2_ROOT to the MSYS2 UCRT64 build
1111$runtime = Join-Path $repository '_output/windows-deps/qemu-cage'
1212& (Join-Path $PSScriptRoot 'build-qemu-windows.ps1') -OutputDirectory $runtime -MsysDirectory $MsysDirectory
1313$runtimeIdentity = Get-Content (Join-Path $runtime 'cage-build.json') -Raw | ConvertFrom-Json
14新增:$runtimeManifestHash = (Get-FileHash -LiteralPath (Join-Path $runtime 'cage-build.json') -Algorithm SHA256).Hash
1415$collectorHash = (Get-FileHash -LiteralPath (Join-Path $PSScriptRoot 'bundle-qemu-sources.sh') -Algorithm SHA256).Hash + (Get-FileHash -LiteralPath $PSCommandPath -Algorithm SHA256).Hash
1516$directory = Join-Path $repository '_output/windows-qemu-sources'
1617$archive = Join-Path $directory 'full-source.tar.gz'
1718$record = Join-Path $directory 'source-identity.json'
1819if ((Test-Path -LiteralPath $record) -and (Test-Path -LiteralPath $archive)) {
1920 $identity = Get-Content -LiteralPath $record -Raw | ConvertFrom-Json
20删除: if ($identity.schema -ne 1 -or $identity.fingerprint -ne $runtimeIdentity.fingerprint -or $identity.collectorHash -ne $collectorHash -or $identity.sha256 -ne (Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash) {
21新增: if ($identity.schema -ne 2 -or $identity.fingerprint -ne $runtimeIdentity.fingerprint -or $identity.runtimeManifestHash -ne $runtimeManifestHash -or $identity.collectorHash -ne $collectorHash -or $identity.sha256 -ne (Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash) {
2122 throw 'Cached QEMU sources differ from their verified runtime identity.'
2223 }
2324 Write-Host 'Verified cached QEMU corresponding sources.'
@@ -31,7 +32,7 @@ try {
3132 Invoke-BuildTool (Join-Path $MsysDirectory 'usr/bin/bash.exe') @('-l',
3233 (Join-Path $PSScriptRoot 'bundle-qemu-sources.sh'), $repository, $runtime, $archive)
3334} finally { $env:MSYSTEM = $savedMsystem; $env:CHERE_INVOKING = $savedChere; $env:CAGE_NODE = $savedNode }
34删除:$identity = @{ schema = 1; fingerprint = $runtimeIdentity.fingerprint; collectorHash = $collectorHash; sha256 = (Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash }
35新增:$identity = @{ schema = 2; fingerprint = $runtimeIdentity.fingerprint; runtimeManifestHash = $runtimeManifestHash; collectorHash = $collectorHash; sha256 = (Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash }
3536$identity | ConvertTo-Json | Set-Content -LiteralPath "$record.partial" -Encoding utf8
3637Move-Item -LiteralPath "$record.partial" -Destination $record -Force
3738Write-Host 'Collected and verified QEMU corresponding sources before application signing.'