Add signed package integrity verification

This commit is contained in:
biss committed 2026-11-15 18:56:06 +08:00
1 parent 8b944cad89
commit 8b51081a59
5 files changed
+130

No files matched your search

+13
View File
@@ -84,7 +84,19 @@ jobs:
- name: Build framework-dependent platform packages
shell: bash
env:
PACKAGE_SIGNING_PRIVATE_KEY_BASE64: ${{ secrets.PACKAGE_SIGNING_PRIVATE_KEY_BASE64 }}
run: |
set -euo pipefail
signing_key="$RUNNER_TEMP/jiaowu-package-signing-key.pem"
trap 'rm -f "$signing_key"' EXIT
if [[ -z "${PACKAGE_SIGNING_PRIVATE_KEY_BASE64:-}" ]]; then
echo "Configure the PACKAGE_SIGNING_PRIVATE_KEY_BASE64 Gitea secret before publishing packages." >&2
exit 2
fi
printf '%s' "$PACKAGE_SIGNING_PRIVATE_KEY_BASE64" | base64 --decode > "$signing_key"
chmod 600 "$signing_key"
export JIAOWU_PACKAGE_SIGNING_KEY="$signing_key"
bash ./scripts/publish-platform-packages.sh \
"${{ steps.package.outputs.version }}" \
"artifacts/packages" \
@@ -164,6 +176,7 @@ jobs:
- Windows x64:`.zip`
- Linux x64 / ARM64:`.tar.gz`
- `SHA256SUMS`:发布包校验值
- `SHA256SUMS.sig`:发布者 RSA-SHA256 签名;下载后用独立可信公钥验证签名,再校验压缩包哈希
- 二进制程序包不包含 .NET 或 ASP.NET Core Runtime;请先安装匹配版本的 ASP.NET Core Runtime
Windows ARM64 与 macOS Intel / Apple Silicon 包可通过手动运行工作流并启用扩展平台生成。
+19
View File
@@ -655,6 +655,25 @@ SQLite 开发环境直接使用在线备份 API。MySQL 环境需要在服务器
- Windows x64:`.zip`
- Linux x64、Linux ARM64:`.tar.gz`
- `SHA256SUMS`:所有压缩包的 SHA-256 校验值
- `SHA256SUMS.sig`:对校验清单的 RSA-SHA256 数字签名,可验证清单由发布密钥签发
发布工作流要求在 Gitea 配置 `PACKAGE_SIGNING_PRIVATE_KEY_BASE64` Secret(将 PEM 私钥
Base64 编码后存入)。私钥应离线保管或仅供受控发布环境使用,不能提交到仓库。公钥必须
通过独立可信渠道分发并固定保存;不能直接信任与压缩包放在一起的公钥。下载后,在 Bash
环境或 Windows PowerShell 中运行(两个验证脚本都随发布产物提供):
```powershell
.\Verify-PlatformPackages.ps1 -PackageDirectory <下载目录> -TrustedPublicKey <可信发布公钥.pem>
```
Linux/macOS 的 Bash 环境运行:
```bash
bash <下载目录>/verify-platform-packages.sh <下载目录> <可信发布公钥.pem>
```
脚本先验证 `SHA256SUMS.sig`,通过后再校验清单内所有压缩包的 SHA-256。任一步失败都应
停止安装或部署。公钥应由管理员通过已认证渠道发给用户,或预先安装在受信任设备上。
手动运行时启用 `include_extended_platforms`,还会生成 Windows ARM64、macOS x64
和 macOS ARM64。Windows 使用 `Jiaowu.Api.exe` 启动,Linux/macOS 使用
+62
View File
@@ -0,0 +1,62 @@
param(
[Parameter(Mandatory = $true)]
[string] $PackageDirectory,
[Parameter(Mandatory = $true)]
[string] $TrustedPublicKey
)
$ErrorActionPreference = 'Stop'
$packageRoot = [IO.Path]::GetFullPath($PackageDirectory)
$publicKeyPath = [IO.Path]::GetFullPath($TrustedPublicKey)
$manifestPath = Join-Path $packageRoot 'SHA256SUMS'
$signaturePath = Join-Path $packageRoot 'SHA256SUMS.sig'
foreach ($path in @($packageRoot, $publicKeyPath, $manifestPath, $signaturePath)) {
if (-not (Test-Path -LiteralPath $path -PathType Leaf)) {
if ($path -eq $packageRoot -and (Test-Path -LiteralPath $path -PathType Container)) { continue }
throw "Required verification file does not exist: $path"
}
}
$rsa = [Security.Cryptography.RSA]::Create()
try {
$rsa.ImportFromPem([IO.File]::ReadAllText($publicKeyPath))
$manifest = [IO.File]::ReadAllBytes($manifestPath)
$signature = [IO.File]::ReadAllBytes($signaturePath)
if (-not $rsa.VerifyData(
$manifest,
$signature,
[Security.Cryptography.HashAlgorithmName]::SHA256,
[Security.Cryptography.RSASignaturePadding]::Pkcs1
)) {
throw 'Release signature is invalid. Do not install these packages.'
}
}
finally {
$rsa.Dispose()
}
$entries = [IO.File]::ReadAllLines($manifestPath)
if ($entries.Count -eq 0) { throw 'SHA256SUMS is empty.' }
foreach ($entry in $entries) {
if ($entry -notmatch '^([A-Fa-f0-9]{64}) [ *](.+)$') {
throw "Invalid SHA256SUMS entry: $entry"
}
$expectedHash = $Matches[1].ToLowerInvariant()
$relativePath = $Matches[2].Replace('\', '/')
if ($relativePath.StartsWith('/') -or $relativePath -match '(^|/)\.\.(/|$)') {
throw "Unsafe package path in SHA256SUMS: $relativePath"
}
$filePath = [IO.Path]::GetFullPath((Join-Path $packageRoot $relativePath))
if (-not $filePath.StartsWith($packageRoot.TrimEnd([IO.Path]::DirectorySeparatorChar) + [IO.Path]::DirectorySeparatorChar, [StringComparison]::OrdinalIgnoreCase) -or
-not (Test-Path -LiteralPath $filePath -PathType Leaf)) {
throw "Package file is missing or outside the download directory: $relativePath"
}
$actualHash = (Get-FileHash -LiteralPath $filePath -Algorithm SHA256).Hash.ToLowerInvariant()
if ($actualHash -ne $expectedHash) {
throw "SHA-256 mismatch for $relativePath. Do not install these packages."
}
Write-Output "Verified $relativePath"
}
Write-Output 'Release signature and all package hashes are valid.'
Loaded 3 of 5 files, more files were not shown because too many files have changed in this diff. Show more