ci: 接入桌面安装包自签名流程

读取并使用 Windows PFX 证书签名三个桌面二进制文件。

在 Inno Setup 生成安装器后继续签名最终安装器,并将已签名二进制打入归档。

导入 macOS P12 到临时钥匙串,建立代码签名信任,并按由内到外顺序签名 App 及其内部组件。

对 macOS App 执行深度签名校验,签名失败时终止构建。

保持 Linux 安装包与现有 Docker 部署流程不变。
This commit is contained in:
Christ committed 2026-08-11 20:53:47 +08:00
1 parent bac5aa0c4f
commit 430fbc0767
3 files changed
+131

No files matched your search

+62
View File
@@ -98,6 +98,28 @@ jobs:
go build -trimpath -ldflags "-s -w" -o dist/windows/browser-install.exe ./cmd/browser-install
go build -trimpath -ldflags "-s -w -H=windowsgui" -o dist/windows/xianyu-tray.exe ./cmd/tray
- name: 导入 Windows 签名证书
shell: pwsh
env:
WINDOWS_SIGNING_PFX_BASE64: ${{ secrets.WINDOWS_SIGNING_PFX_BASE64 }}
WINDOWS_SIGNING_PFX_PASSWORD: ${{ secrets.WINDOWS_SIGNING_PFX_PASSWORD }}
WINDOWS_SIGNING_IDENTITY: ${{ secrets.WINDOWS_SIGNING_IDENTITY }}
run: |
$pfxPath = Join-Path $env:RUNNER_TEMP 'ydisks-windows-signing.pfx'
[IO.File]::WriteAllBytes($pfxPath, [Convert]::FromBase64String($env:WINDOWS_SIGNING_PFX_BASE64))
if (-not (Test-Path -LiteralPath $pfxPath -PathType Leaf)) { throw 'Windows PFX 文件写入失败' }
"WINDOWS_SIGNING_PFX_PATH=$pfxPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: 签名 Windows 桌面程序
shell: pwsh
env:
WINDOWS_SIGNING_PFX_PASSWORD: ${{ secrets.WINDOWS_SIGNING_PFX_PASSWORD }}
WINDOWS_SIGNING_IDENTITY: ${{ secrets.WINDOWS_SIGNING_IDENTITY }}
run: |
& packaging/windows/sign.ps1 `
-PfxPath $env:WINDOWS_SIGNING_PFX_PATH `
-Files 'dist/windows/xianyu-server.exe','dist/windows/browser-install.exe','dist/windows/xianyu-tray.exe'
- name: 安装 Inno Setup
shell: pwsh
run: choco install innosetup --no-progress --yes
@@ -112,6 +134,22 @@ jobs:
if ($null -eq $installer) { throw 'Inno Setup 未生成安装器' }
$target = Join-Path (Resolve-Path dist/windows) 'Ydisks-Xianyu-Helper-Setup.exe'
if ($installer.FullName -ne $target) { Copy-Item $installer.FullName $target -Force }
- name: 签名 Windows 安装器
shell: pwsh
env:
WINDOWS_SIGNING_PFX_PASSWORD: ${{ secrets.WINDOWS_SIGNING_PFX_PASSWORD }}
WINDOWS_SIGNING_IDENTITY: ${{ secrets.WINDOWS_SIGNING_IDENTITY }}
run: |
& packaging/windows/sign.ps1 `
-PfxPath $env:WINDOWS_SIGNING_PFX_PATH `
-Files 'dist/windows/Ydisks-Xianyu-Helper-Setup.exe'
- name: 打包 Windows 二进制归档
shell: pwsh
env:
APP_VERSION: ${{ env.APP_VERSION }}
run: |
Compress-Archive -Path dist/windows/xianyu-server.exe,dist/windows/browser-install.exe,dist/windows/xianyu-tray.exe -DestinationPath "dist/windows/Ydisks-Xianyu-Helper-${env:APP_VERSION}-binaries.zip"
- name: 上传 Windows 安装包
@@ -159,7 +197,31 @@ jobs:
lipo -create dist/macos/arm64/browser-install dist/macos/amd64/browser-install -output dist/macos/browser-install
lipo -create dist/macos/arm64/xianyu-tray dist/macos/amd64/xianyu-tray -output dist/macos/xianyu-tray
- name: 导入 macOS 签名证书
env:
MACOS_SIGNING_P12_BASE64: ${{ secrets.MACOS_SIGNING_P12_BASE64 }}
MACOS_SIGNING_P12_PASSWORD: ${{ secrets.MACOS_SIGNING_P12_PASSWORD }}
MACOS_SIGNING_IDENTITY: ${{ secrets.MACOS_SIGNING_IDENTITY }}
run: |
set -Eeuo pipefail
keychain_path="$RUNNER_TEMP/ydisks-signing.keychain-db"
keychain_password="$(uuidgen)"
p12_path="$RUNNER_TEMP/ydisks-signing.p12"
cert_path="$RUNNER_TEMP/ydisks-signing.pem"
printf '%s' "$MACOS_SIGNING_P12_BASE64" | base64 --decode > "$p12_path"
security create-keychain -p "$keychain_password" "$keychain_path"
security unlock-keychain -p "$keychain_password" "$keychain_path"
security import "$p12_path" -k "$keychain_path" -P "$MACOS_SIGNING_P12_PASSWORD" -T /usr/bin/codesign
security find-certificate -c "$MACOS_SIGNING_IDENTITY" -p "$keychain_path" > "$cert_path"
security add-trusted-cert -d -r trustRoot -p codeSign -k "$keychain_path" "$cert_path"
security set-key-partition-list -S apple-tool:,apple: -s -k "$keychain_password" "$keychain_path"
security list-keychains -d user -s "$keychain_path"
security unlock-keychain -p "$keychain_password" "$keychain_path"
echo "MACOS_SIGNING_KEYCHAIN=$keychain_path" >> "$GITHUB_ENV"
- name: 构建 macOS pkg
env:
MACOS_SIGNING_IDENTITY: ${{ secrets.MACOS_SIGNING_IDENTITY }}
run: |
chmod +x packaging/macos/build-pkg.sh
packaging/macos/build-pkg.sh "$APP_VERSION" "$PWD/dist/macos"
+20
View File
@@ -16,6 +16,26 @@ cp "$(dirname "$0")/com.christ.ydisks-xianyu-helper.tray.plist.template" "$APP/C
sed "s/__VERSION__/$VERSION/g" "$(dirname "$0")/Info.plist" > "$APP/Contents/Info.plist"
chmod 0755 "$APP/Contents/MacOS/xianyu-tray" "$APP/Contents/Helpers/xianyu-server" "$APP/Contents/Helpers/browser-install"
if [ -n "${MACOS_SIGNING_IDENTITY:-}" ]; then
sign_code() {
target="$1"
if [ -n "${MACOS_SIGNING_KEYCHAIN:-}" ]; then
codesign --force --sign "$MACOS_SIGNING_IDENTITY" \
--keychain "$MACOS_SIGNING_KEYCHAIN" --timestamp=none "$target"
else
codesign --force --sign "$MACOS_SIGNING_IDENTITY" \
--timestamp=none "$target"
fi
}
# macOS 代码签名必须从内部组件开始,最后再签名 App 包本身。
sign_code "$APP/Contents/Helpers/xianyu-server"
sign_code "$APP/Contents/Helpers/browser-install"
sign_code "$APP/Contents/MacOS/xianyu-tray"
sign_code "$APP"
codesign --verify --deep --strict --verbose=2 "$APP"
fi
pkgbuild \
--root "$ROOT_DIR" \
--scripts "$(dirname "$0")/scripts" \
+49
View File
@@ -0,0 +1,49 @@
param(
[Parameter(Mandatory = $true)]
[string]$PfxPath,
[Parameter(Mandatory = $true)]
[string[]]$Files
)
$ErrorActionPreference = 'Stop'
$pfxPassword = $env:WINDOWS_SIGNING_PFX_PASSWORD
$description = $env:WINDOWS_SIGNING_IDENTITY
if ([string]::IsNullOrWhiteSpace($pfxPassword)) {
throw 'WINDOWS_SIGNING_PFX_PASSWORD 未设置'
}
if ([string]::IsNullOrWhiteSpace($description)) {
throw 'WINDOWS_SIGNING_IDENTITY 未设置'
}
$signtool = Get-ChildItem -Path "${env:ProgramFiles(x86)}\Windows Kits\10\bin" -Filter 'signtool.exe' -Recurse |
Where-Object { $_.FullName -match '\\x64\\signtool\.exe$' } |
Sort-Object FullName |
Select-Object -Last 1
if ($null -eq $signtool) {
throw 'Windows SDK 中未找到 x64 signtool.exe'
}
foreach ($file in $Files) {
if (-not (Test-Path -LiteralPath $file -PathType Leaf)) {
throw "待签名文件不存在: $file"
}
& $signtool.FullName sign `
/f $PfxPath `
/p $pfxPassword `
/fd SHA256 `
/tr 'http://timestamp.acs.microsoft.com' `
/td SHA256 `
/d $description `
$file
if ($LASTEXITCODE -ne 0) {
throw "signtool 签名失败: $file"
}
$signature = Get-AuthenticodeSignature -FilePath $file
if ($null -eq $signature.SignerCertificate) {
throw "未找到 Authenticode 签名: $file"
}
}