Files
simba-rmic-2026/client/scripts/verify-windows-signature.ps1
T
sloray aea1cf60ae
构建客户端 / 检查(类型 + 单元测试) (push) Canceled after 0s
构建客户端 / Linux x64(deb + AppImage) (push) Canceled after 0s
构建客户端 / Windows x64(NSIS 安装包) (push) Canceled after 0s
构建客户端 / macOS 通用(.app + .dmg) (push) Canceled after 0s
fix(build): 默认复用自签名证书签署 Windows 发布包
- fix(signing): 独立校验文件摘要、CMS 签名与 RFC 3161 时间戳,不修改系统信任库

- build(windows): 发布脚本和 CI 复用本机签名身份,交付公钥证书与真实信任状态
2026-10-31 13:22:25 +08:00

24 lines
1.4 KiB
PowerShell

#requires -Version 7.4
[CmdletBinding()]
param(
[Parameter(Mandatory)][string]$Path,
[Parameter(Mandatory)][string]$CertificateThumbprint,
[switch]$SelfSigned
)
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
$signature = Get-AuthenticodeSignature -LiteralPath $Path
if ($signature.Status -eq 'NotSigned') { throw "The file has no embedded signature: $Path" }
if (-not ('RmicWindowsSignature' -as [type])) {
$references = @((Get-ChildItem -LiteralPath (Join-Path $PSHOME 'ref') -Filter '*.dll').FullName) +
@([System.Security.Cryptography.Pkcs.SignedCms].Assembly.Location)
Add-Type -Path (Join-Path $PSScriptRoot 'windows-signature.cs') -ReferencedAssemblies $references
}
$timestamp = [RmicWindowsSignature]::Verify([IO.Path]::GetFullPath($Path), $CertificateThumbprint, [bool]$SelfSigned)
if (-not $SelfSigned -and $signature.Status -ne 'Valid') { throw "Windows does not trust the CA-signed output: $Path" }
[pscustomobject]@{ file = [IO.Path]::GetFileName($Path); status = [string]$signature.Status;
verificationStatus = $(if ($SelfSigned) { 'valid-pinned-self-signed' } else { 'valid-trusted-signature' });
windowsTrustMessage = $signature.StatusMessage;
integrityVerified = $true; timestamped = $true; timestampVerified = $true; timestampUtc = $timestamp.ToString('o');
certificateThumbprint = $CertificateThumbprint; selfSigned = [bool]$SelfSigned; windowsTrusted = $signature.Status -eq 'Valid' }