fix(build): 默认复用自签名证书签署 Windows 发布包
- fix(signing): 独立校验文件摘要、CMS 签名与 RFC 3161 时间戳,不修改系统信任库 - build(windows): 发布脚本和 CI 复用本机签名身份,交付公钥证书与真实信任状态
This commit is contained in:
14 files changed
+323
-39
No files matched your search
@@ -1,3 +1,4 @@
|
||||
#requires -Version 7.4
|
||||
# Build with Tauri's native Authenticode signing support. No private keys or
|
||||
# personal signing identities are stored in the shared Tauri configuration.
|
||||
[CmdletBinding()]
|
||||
@@ -6,6 +7,7 @@ param(
|
||||
[string]$TimestampUrl = 'http://timestamp.digicert.com',
|
||||
[switch]$AllowUnsigned,
|
||||
[switch]$PreflightOnly,
|
||||
[string]$SigningConfigPath = $env:RMIC_WINDOWS_SIGNING_CONFIG,
|
||||
[string]$OutputDirectory
|
||||
)
|
||||
|
||||
@@ -13,8 +15,17 @@ $ErrorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version Latest
|
||||
$clientRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
|
||||
$repoRoot = Split-Path -Parent $clientRoot
|
||||
if (-not $SigningConfigPath) { $SigningConfigPath = Join-Path $env:LOCALAPPDATA 'RMIC-2026/signing/windows.json' }
|
||||
if (-not $CertificateThumbprint -and -not $AllowUnsigned) {
|
||||
if ($PreflightOnly -and -not (Test-Path -LiteralPath $SigningConfigPath)) {
|
||||
throw 'A code-signing certificate is required. Initialize the local signing identity before a read-only preflight.'
|
||||
}
|
||||
$identity = & (Join-Path $PSScriptRoot 'initialize-windows-signing.ps1') -ConfigPath $SigningConfigPath
|
||||
$CertificateThumbprint = $identity.certificateThumbprint
|
||||
}
|
||||
$thumbprint = ($CertificateThumbprint -replace '\s', '').ToUpperInvariant()
|
||||
$signed = $thumbprint.Length -gt 0
|
||||
$selfSigned = $false
|
||||
if ($signed) {
|
||||
if ($thumbprint -notmatch '^[0-9A-F]{40}$') { throw 'Invalid code-signing certificate thumbprint.' }
|
||||
$certificate = Get-Item -LiteralPath "Cert:\CurrentUser\My\$thumbprint" -ErrorAction SilentlyContinue
|
||||
@@ -23,7 +34,7 @@ if ($signed) {
|
||||
if (-not $certificate.HasPrivateKey -or $certificate.NotBefore -gt $now -or $certificate.NotAfter -le $now) {
|
||||
throw 'The signing certificate needs an accessible private key and must be currently valid.'
|
||||
}
|
||||
if ($certificate.Subject -eq $certificate.Issuer) { throw 'A self-signed certificate cannot be used as a public release identity.' }
|
||||
$selfSigned = [Convert]::ToBase64String($certificate.SubjectName.RawData) -eq [Convert]::ToBase64String($certificate.IssuerName.RawData)
|
||||
$usageOids = @($certificate.Extensions |
|
||||
Where-Object { $_ -is [Security.Cryptography.X509Certificates.X509EnhancedKeyUsageExtension] } |
|
||||
ForEach-Object { $_.EnhancedKeyUsages } | ForEach-Object { $_.Value })
|
||||
@@ -39,7 +50,8 @@ if (-not [Uri]::TryCreate($TimestampUrl, [UriKind]::Absolute, [ref]$timestamp) -
|
||||
throw 'Timestamp URL must be an HTTP(S) server without credentials.'
|
||||
}
|
||||
if ($PreflightOnly) {
|
||||
[pscustomobject]@{ signing = $signed; unsignedExplicitlyAllowed = [bool]$AllowUnsigned; digestAlgorithm = 'sha256'; tsp = $true }
|
||||
[pscustomobject]@{ signing = $signed; selfSigned = $selfSigned; certificateThumbprint = $thumbprint;
|
||||
unsignedExplicitlyAllowed = [bool]$AllowUnsigned; digestAlgorithm = $(if ($signed) { 'sha256' } else { $null }); tsp = $signed }
|
||||
return
|
||||
}
|
||||
|
||||
@@ -75,24 +87,52 @@ try {
|
||||
$release = Join-Path $metadata.target_directory 'x86_64-pc-windows-msvc/release'
|
||||
$main = Join-Path $release 'cam-desktop.exe'
|
||||
$installer = Join-Path $release "bundle/nsis/RMIC-2026_$($version.version)_x64-setup.exe"
|
||||
if ($signed) {
|
||||
# Tauri signs the bundled copy, then can restore the original standalone
|
||||
# executable. Sign that final output too, using the same identity.
|
||||
$signTool = Get-Command signtool.exe -ErrorAction SilentlyContinue
|
||||
$signToolPath = if ($signTool) { $signTool.Source } else { $null }
|
||||
if (-not $signToolPath) {
|
||||
$sdkRoot = (Get-ItemProperty -LiteralPath 'HKLM:\SOFTWARE\Microsoft\Windows Kits\Installed Roots' -Name KitsRoot10).KitsRoot10
|
||||
$sdkVersions = Get-ChildItem -LiteralPath (Join-Path $sdkRoot 'bin') -Directory |
|
||||
Where-Object Name -Match '^\d+\.\d+\.\d+\.\d+$' | Sort-Object { [version]$_.Name } -Descending
|
||||
foreach ($sdk in $sdkVersions) {
|
||||
$candidate = Join-Path $sdk.FullName 'x64/signtool.exe'
|
||||
if (Test-Path -LiteralPath $candidate) { $signToolPath = $candidate; break }
|
||||
}
|
||||
}
|
||||
if (-not $signToolPath) { throw 'Windows SDK signtool.exe is required to sign the final standalone executable.' }
|
||||
& $signToolPath sign /sha1 $thumbprint /s My /fd SHA256 /tr $TimestampUrl /td SHA256 /d RMIC-2026 $main
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Signing the final standalone executable failed.' }
|
||||
}
|
||||
$signatures = @()
|
||||
foreach ($file in @($main, $installer)) {
|
||||
$signature = Get-AuthenticodeSignature -LiteralPath $file
|
||||
if ($signed -and ($signature.Status -ne 'Valid' -or -not $signature.TimeStamperCertificate -or
|
||||
$signature.SignerCertificate.Thumbprint -ne $thumbprint)) {
|
||||
throw "The signature, signer or timestamp could not be verified: $file"
|
||||
if ($signed) {
|
||||
$signatures += & (Join-Path $PSScriptRoot 'verify-windows-signature.ps1') -Path $file -CertificateThumbprint $thumbprint -SelfSigned:$selfSigned
|
||||
} else {
|
||||
if ($signature.Status -ne 'NotSigned') { throw "Unexpected signature on explicitly unsigned output: $file" }
|
||||
$signatures += @{ file = [IO.Path]::GetFileName($file); status = [string]$signature.Status; timestamped = $false }
|
||||
}
|
||||
if (-not $signed -and $signature.Status -ne 'NotSigned') { throw "Unexpected signature on explicitly unsigned output: $file" }
|
||||
$signatures += @{ file = [IO.Path]::GetFileName($file); status = [string]$signature.Status; timestamped = $null -ne $signature.TimeStamperCertificate }
|
||||
}
|
||||
$suffix = if ($signed) { '' } else { '-unsigned' }
|
||||
$suffix = if ($selfSigned) { '-self-signed' } elseif ($signed) { '' } else { '-unsigned' }
|
||||
$delivery = Join-Path $OutputDirectory "RMIC-2026_${label}_windows-x64${suffix}-setup.exe"
|
||||
Copy-Item -LiteralPath $installer -Destination $delivery
|
||||
& icacls.exe $delivery /setintegritylevel M | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Cannot set installer Medium integrity label.' }
|
||||
$hash = (Get-FileHash -LiteralPath $delivery -Algorithm SHA256).Hash.ToLowerInvariant()
|
||||
[IO.File]::WriteAllText("$delivery.sha256", "$hash $([IO.Path]::GetFileName($delivery))`n", $utf8)
|
||||
$publicCertificate = $null
|
||||
if ($signed) {
|
||||
$certPath = Join-Path $OutputDirectory 'RMIC-2026-codesign.cer'
|
||||
[IO.File]::WriteAllBytes($certPath, $certificate.Export([Security.Cryptography.X509Certificates.X509ContentType]::Cert))
|
||||
$publicCertificate = @{ file = 'RMIC-2026-codesign.cer'; subject = $certificate.Subject;
|
||||
expiresUtc = $certificate.NotAfter.ToUniversalTime().ToString('o');
|
||||
sha256 = (Get-FileHash -LiteralPath $certPath -Algorithm SHA256).Hash.ToLowerInvariant() }
|
||||
}
|
||||
$report = @{ version = $label; installer = $delivery; sha256 = $hash; signed = $signed;
|
||||
selfSigned = $selfSigned; certificateThumbprint = $thumbprint;
|
||||
publicCertificate = $publicCertificate;
|
||||
signatures = $signatures; smartScreenReputationVerified = $false }
|
||||
[IO.File]::WriteAllText((Join-Path $OutputDirectory 'windows-signature-verification.json'), ($report | ConvertTo-Json -Depth 6), $utf8)
|
||||
$report | ConvertTo-Json -Depth 6
|
||||
|
||||
Reference in new issue
Block a user