feat(client): 锁定终局结果并接入 Windows 签名构建
- fix(match): 首次归零结束对局并撤销双方扣血许可,裁判结果同步后不再改判 - fix(hud): 蓝方低血量始终保留队伍颜色 - build(windows): 校验代码签名身份和时间戳,明确标注未签名测试包 - docs(version): 说明发布标签基线与语义版本迭代
This commit is contained in:
26 files changed
+823
-229
No files matched your search
@@ -0,0 +1,104 @@
|
||||
# Build with Tauri's native Authenticode signing support. No private keys or
|
||||
# personal signing identities are stored in the shared Tauri configuration.
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$CertificateThumbprint = $env:RMIC_WINDOWS_CERT_THUMBPRINT,
|
||||
[string]$TimestampUrl = 'http://timestamp.digicert.com',
|
||||
[switch]$AllowUnsigned,
|
||||
[switch]$PreflightOnly,
|
||||
[string]$OutputDirectory
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version Latest
|
||||
$clientRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
|
||||
$repoRoot = Split-Path -Parent $clientRoot
|
||||
$thumbprint = ($CertificateThumbprint -replace '\s', '').ToUpperInvariant()
|
||||
$signed = $thumbprint.Length -gt 0
|
||||
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
|
||||
if (-not $certificate) { throw 'Code-signing certificate was not found in CurrentUser/My.' }
|
||||
$now = Get-Date
|
||||
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.' }
|
||||
$usageOids = @($certificate.Extensions |
|
||||
Where-Object { $_ -is [Security.Cryptography.X509Certificates.X509EnhancedKeyUsageExtension] } |
|
||||
ForEach-Object { $_.EnhancedKeyUsages } | ForEach-Object { $_.Value })
|
||||
if ('1.3.6.1.5.5.7.3.3' -notin $usageOids) {
|
||||
throw 'The certificate is not authorized for code signing.'
|
||||
}
|
||||
} elseif (-not $AllowUnsigned) {
|
||||
throw 'A code-signing certificate is required. Set RMIC_WINDOWS_CERT_THUMBPRINT or explicitly use -AllowUnsigned for a test package.'
|
||||
}
|
||||
$timestamp = $null
|
||||
if (-not [Uri]::TryCreate($TimestampUrl, [UriKind]::Absolute, [ref]$timestamp) -or
|
||||
$timestamp.Scheme -notin @('http', 'https') -or -not $timestamp.Host -or $timestamp.UserInfo) {
|
||||
throw 'Timestamp URL must be an HTTP(S) server without credentials.'
|
||||
}
|
||||
if ($PreflightOnly) {
|
||||
[pscustomobject]@{ signing = $signed; unsignedExplicitlyAllowed = [bool]$AllowUnsigned; digestAlgorithm = 'sha256'; tsp = $true }
|
||||
return
|
||||
}
|
||||
|
||||
& (Join-Path $PSScriptRoot 'prepare-windows-bundle.ps1') -CheckProcessOnly
|
||||
& node (Join-Path $repoRoot 'scripts/version.mjs') --check
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Regenerate versions before packaging.' }
|
||||
$version = Get-Content -LiteralPath (Join-Path $repoRoot 'version.json') -Raw | ConvertFrom-Json
|
||||
$label = "v$($version.version)+$($version.build)"
|
||||
if (-not $OutputDirectory) { $OutputDirectory = Join-Path $repoRoot "target/releases/$label" }
|
||||
$OutputDirectory = [IO.Path]::GetFullPath($OutputDirectory)
|
||||
New-Item -ItemType Directory -Force -Path $OutputDirectory | Out-Null
|
||||
$temporaryConfig = Join-Path $OutputDirectory 'windows-signing.local.json'
|
||||
$windows = if ($signed) {
|
||||
@{ certificateThumbprint = $thumbprint; digestAlgorithm = 'sha256'; timestampUrl = $TimestampUrl; tsp = $true }
|
||||
} else {
|
||||
@{ certificateThumbprint = $null; digestAlgorithm = $null; timestampUrl = $null; tsp = $false; signCommand = $null }
|
||||
}
|
||||
$utf8 = New-Object Text.UTF8Encoding($false)
|
||||
[IO.File]::WriteAllText($temporaryConfig, (@{ bundle = @{ windows = $windows } } | ConvertTo-Json -Depth 6), $utf8)
|
||||
$previousTarget = $env:CARGO_TARGET_DIR
|
||||
$previousToolchain = $env:RUSTUP_TOOLCHAIN
|
||||
try {
|
||||
Remove-Item Env:CARGO_TARGET_DIR -ErrorAction SilentlyContinue
|
||||
$env:RUSTUP_TOOLCHAIN = 'stable'
|
||||
Push-Location $clientRoot
|
||||
try {
|
||||
& pnpm tauri build --target x86_64-pc-windows-msvc --bundles nsis --ci --config $temporaryConfig -- --locked --config 'unstable.build-std=[]'
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Windows build or signing failed; no verified installer was delivered.' }
|
||||
& (Join-Path $PSScriptRoot 'prepare-windows-bundle.ps1') -CheckOnly
|
||||
$metadata = (& cargo +stable metadata --no-deps --format-version 1 --manifest-path src-tauri/Cargo.toml | ConvertFrom-Json)
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Cannot resolve Cargo output path.' }
|
||||
} finally { Pop-Location }
|
||||
$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"
|
||||
$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 (-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' }
|
||||
$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)
|
||||
$report = @{ version = $label; installer = $delivery; sha256 = $hash; signed = $signed;
|
||||
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
|
||||
} finally {
|
||||
# This config contains a personal public certificate identity, and is local only.
|
||||
Remove-Item -LiteralPath $temporaryConfig -ErrorAction SilentlyContinue
|
||||
if ($null -eq $previousTarget) { Remove-Item Env:CARGO_TARGET_DIR -ErrorAction SilentlyContinue } else { $env:CARGO_TARGET_DIR = $previousTarget }
|
||||
if ($null -eq $previousToolchain) { Remove-Item Env:RUSTUP_TOOLCHAIN -ErrorAction SilentlyContinue } else { $env:RUSTUP_TOOLCHAIN = $previousToolchain }
|
||||
}
|
||||
Reference in new issue
Block a user