Files
simba-rmic-2026/client/scripts/initialize-windows-signing.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

37 lines
2.4 KiB
PowerShell

#requires -Version 7.4
# Keep the non-exportable private key in CurrentUser/My. Never install a root.
[CmdletBinding()]
param([string]$ConfigPath = $env:RMIC_WINDOWS_SIGNING_CONFIG)
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
if (-not $ConfigPath) { $ConfigPath = Join-Path $env:LOCALAPPDATA 'RMIC-2026/signing/windows.json' }
if (Test-Path -LiteralPath $ConfigPath) {
$saved = Get-Content -LiteralPath $ConfigPath -Raw | ConvertFrom-Json
if ($saved.schema -ne 1 -or $saved.certificateThumbprint -notmatch '^[0-9A-F]{40}$') {
throw 'Invalid saved Windows signing identity. Restore the local signing configuration.'
}
$cert = Get-Item -LiteralPath "Cert:\CurrentUser\My\$($saved.certificateThumbprint)" -ErrorAction SilentlyContinue
if (-not $cert -or -not $cert.HasPrivateKey -or $cert.NotAfter -le (Get-Date)) {
throw 'Saved signing certificate/key is missing or expired. Restore the original identity or explicitly provision a replacement; it will not be silently rotated.'
}
$saved
return
}
$existing = @(Get-ChildItem Cert:\CurrentUser\My -CodeSigningCert | Where-Object FriendlyName -eq 'RMIC-2026 self-signed code signing')
if ($existing.Count -gt 1) { throw 'Multiple RMIC signing identities exist. Select one explicitly with RMIC_WINDOWS_CERT_THUMBPRINT.' }
if ($existing.Count -eq 1) {
$cert = $existing[0]
if (-not $cert.HasPrivateKey -or $cert.NotAfter -le (Get-Date)) { throw 'Existing RMIC signing identity is unusable; provision a replacement explicitly.' }
} else {
$cert = New-SelfSignedCertificate -Type CodeSigningCert -Subject 'CN=RMIC-2026 Self-signed Code Signing' `
-FriendlyName 'RMIC-2026 self-signed code signing' -KeyAlgorithm RSA -KeyLength 3072 `
-HashAlgorithm SHA256 -KeyUsage DigitalSignature -KeyExportPolicy NonExportable `
-Provider 'Microsoft Software Key Storage Provider' -CertStoreLocation 'Cert:\CurrentUser\My' `
-NotBefore (Get-Date).AddMinutes(-5) -NotAfter (Get-Date).AddYears(3)
}
$saved = [ordered]@{ schema = 1; certificateThumbprint = $cert.Thumbprint; kind = 'self-signed';
subject = $cert.Subject; expiresUtc = $cert.NotAfter.ToUniversalTime().ToString('o') }
New-Item -ItemType Directory -Force -Path (Split-Path -Parent ([IO.Path]::GetFullPath($ConfigPath))) | Out-Null
[IO.File]::WriteAllText([IO.Path]::GetFullPath($ConfigPath), ($saved | ConvertTo-Json), [Text.UTF8Encoding]::new($false))
[pscustomobject]$saved