跳到主要内容

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

浏览文件

check-windows-signing.ps1

61 行 · 3.8 KB历史下载
1#requires -Version 7.0
2# Explicit signing or read-only credential verification. No package, version or release writes.
3[CmdletBinding()]
4param([ValidateSet('sign', 'credential-info')][string]$Mode = 'sign')
5. (Join-Path $PSScriptRoot 'windows-common.ps1')
6if (-not $IsWindows) { throw 'This verification requires Windows trust APIs.' }
7if ($env:GITHUB_ACTIONS -ne 'true' -or $env:GITHUB_EVENT_NAME -ne 'workflow_dispatch' -or
8 $env:GITHUB_REPOSITORY -ne 'Lee-xeo/Claude-Cage' -or
9 $env:GITHUB_REF -ne 'refs/heads/main') {
10 throw 'Run the explicit main-branch signing verification workflow.'
11}
12if ($env:CAGE_WINDOWS_SIGNING_PROVIDER -ne 'esigner') { throw 'Select esigner for this verification.' }
13if ($Mode -eq 'credential-info') {
14 try { Invoke-BuildTool 'node' @((Join-Path $PSScriptRoot 'esigner.mjs'), 'diagnose') }
15 finally { Remove-Item Env:CAGE_ESIGNER_PASSWORD, Env:CAGE_ESIGNER_TOTP_SECRET -ErrorAction SilentlyContinue }
16 return
17}
18foreach ($name in @('CAGE_ESIGNER_USERNAME', 'CAGE_ESIGNER_PASSWORD', 'CAGE_ESIGNER_CREDENTIAL_ID', 'CAGE_ESIGNER_CERTIFICATE_SERIAL', 'CAGE_ESIGNER_TOTP_SECRET')) {
19 if (-not [Environment]::GetEnvironmentVariable($name)) { throw "Missing cage-release setting: $name" }
20}
21Assert-WindowsSigningConfiguration
22$repository = Split-Path $PSScriptRoot -Parent
23$reportDirectory = Join-Path $repository '_output/signing-check'
24$stage = Join-Path ([IO.Path]::GetTempPath()) ('cage-signing-check-' + [guid]::NewGuid().ToString('N'))
25$report = [ordered]@{ status = 'failed'; commit = $env:GITHUB_SHA; windowsTrustTested = $false; installationTested = $false }
26$savedCertificate = $env:CAGE_WINDOWS_CERT_SHA1
27try {
28 New-Item -ItemType Directory -Path $stage | Out-Null
29 $source = Join-Path $stage 'SigningProbe.cs'
30 @'
31using System;
32public static class SigningProbe {
33 public static void Main() { Console.WriteLine("Cage code signing verification fixture."); }
34}
35'@ | Set-Content -LiteralPath $source -Encoding utf8
36 $compiler = Join-Path $env:WINDIR 'Microsoft.NET/Framework64/v4.0.30319/csc.exe'
37 $executable = Join-Path $stage 'probe.exe'
38 Invoke-BuildTool $compiler @('/nologo', '/target:exe', "/out:$executable", $source)
39 # NSIS hands its signing hook a PE file without an extension. Exercise that path.
40 $probe = Join-Path $stage 'uninstaller-probe'
41 Move-Item -LiteralPath $executable -Destination $probe
42 $report.unsignedSHA256 = (Get-FileHash -LiteralPath $probe -Algorithm SHA256).Hash.ToLowerInvariant()
43 $env:CAGE_WINDOWS_CERT_SHA1 = $null
44 Sign-CageFile $probe (Get-SigningTool)
45 $signature = Get-AuthenticodeSignature -LiteralPath $probe
46 $report.windowsTrustTested = $true
47 $report.publisher = $signature.SignerCertificate.GetNameInfo([Security.Cryptography.X509Certificates.X509NameType]::SimpleName, $false)
48 $report.certificateSerial = $signature.SignerCertificate.SerialNumber
49 $report.certificateThumbprint = $signature.SignerCertificate.Thumbprint
50 $report.timestampAuthority = $signature.TimeStamperCertificate.Subject
51 $report.signedSHA256 = (Get-FileHash -LiteralPath $probe -Algorithm SHA256).Hash.ToLowerInvariant()
52 if ($report.unsignedSHA256 -eq $report.signedSHA256) { throw 'Signing did not change the executable.' }
53 $report.status = 'passed'
54 Write-Host 'Passed: cloud signing, configured publisher certificate, timestamp and Windows trust.'
55} finally {
56 $env:CAGE_WINDOWS_CERT_SHA1 = $savedCertificate
57 Remove-Item Env:CAGE_ESIGNER_PASSWORD, Env:CAGE_ESIGNER_TOTP_SECRET -ErrorAction SilentlyContinue
58 if (Test-Path -LiteralPath $stage) { Remove-Item -LiteralPath $stage -Recurse -Force }
59 New-Item -ItemType Directory -Path $reportDirectory -Force | Out-Null
60 $report | ConvertTo-Json | Set-Content -LiteralPath (Join-Path $reportDirectory 'result.json') -Encoding utf8
61}