mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-22 21:23:02 +01:00
* windows: sign the setup engine so smart app control can run setup
Setup extracts a copy of its engine to %TEMP% at launch and writes the
installed uninstaller from the same bytes. Signing only the outer
hex-setup-*.exe left both unsigned, and Windows 11 Smart App Control
blocked the extracted copy ("Unable to execute file in the temporary
directory", error 4551).
SignedUninstaller embeds the engine's signature, but the signature has to
exist before the compile that uses it, and the compile job holds no
credentials. So the release signs it in two passes: the new
windows-setup-engine.yml compiles once with SignedUninstaller=yes and keeps
the unsigned uninst-*.e32 ISCC asks to be signed (ISCC leaves it and aborts
as a compile failure, exit 2); sign-windows-engine signs and verifies it in
the release environment; windows-installers.yml then compiles with the
signed engine and asserts the installed uninstaller's signature.
Test builds and runs without the Azure values keep the unsigned single
compile. Inno Setup is pinned to 6.7.1, read from the compiler's own banner
(ISCC.exe's version resource is 0.0.0), so both passes use one compiler.
* windows: harden the setup engine passes
Review fixes for the signed setup engine:
- sign-windows-engine requires sign-windows to have succeeded, and its
steps are unguarded like sign-windows-installers, so it can never upload
an empty digest.
- setup-engine runs only when Windows is signed (it waits for
sign-windows), so unsigned runs really do a single compile with no
engine pass at all.
- the Inno re-pin uses choco upgrade --allow-downgrade, because choco
install --version treats a preinstalled package as already installed.
- Invoke-Iscc collects native stderr safely under Windows PowerShell 5.1
and pwsh with $PSNativeCommandUseErrorActionPreference on, and echoes
the compiler's lines so build logs stay readable.
- the version probe compiles a minimal script from standard input into a
throwaway OutputDir, so it never touches the caller's -OutDir.
- only .e32 exists for the engine; drop the unused .e64 handling.
- the uninstaller signature test also checks the release publisher, and
the test-builds doc warns that Smart App Control cannot be turned back
on without resetting Windows.
* windows: correct the setup engine comments
171 lines
10 KiB
PowerShell
171 lines
10 KiB
PowerShell
# Silently installs, reinstalls, installs over another version with, and
|
|
# uninstalls a hex-setup-*.exe on a disposable Windows machine (CI), checking
|
|
# the managed layout that src/updater/windows.rs expects at every step. It
|
|
# uses the real %APPDATA%, so never run it on a machine with Hex installed.
|
|
#
|
|
# scripts/test-windows-installer.ps1 -Installer dist\hex-setup-2.4.0-windows-x64.exe `
|
|
# -Executable dist\hex-2.4.0-windows-x64.exe -Console dist\hex-2.4.0-windows-x64.com -Version 2.4.0
|
|
#
|
|
# -Console (hex.com) is left out only for a release published before it.
|
|
# -SignedEngine checks the installed uninstaller's Authenticode signature, its
|
|
# timestamp, and that the release publisher signed it (Release signs the setup
|
|
# engine; Test builds do not sign it).
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory)] [string]$Installer,
|
|
[Parameter(Mandatory)] [string]$Executable,
|
|
[string]$Console,
|
|
[Parameter(Mandatory)] [string]$Version,
|
|
[switch]$SignedEngine
|
|
)
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
$support = Join-Path $env:APPDATA 'hex'
|
|
$installed = Join-Path $support "versions\$Version\hex.exe"
|
|
$installedConsole = Join-Path $support "versions\$Version\hex.com"
|
|
$bin = Join-Path $support 'bin'
|
|
$pointer = Join-Path $support 'current-version'
|
|
$receipt = Join-Path $support 'install.json'
|
|
$shortcut = Join-Path $env:APPDATA 'Microsoft\Windows\Start Menu\Programs\Hex.lnk'
|
|
$uninstallKey = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\{6ED48C92-5177-41F4-B8D6-37B7B02CFDF4}_is1'
|
|
$runKey = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Run'
|
|
$logs = Join-Path $env:RUNNER_TEMP 'hex-installer-logs'
|
|
New-Item -ItemType Directory -Force $logs | Out-Null
|
|
|
|
function Check([bool]$condition, [string]$message) {
|
|
if (-not $condition) { throw "FAIL: $message" }
|
|
Write-Output "ok - $message"
|
|
}
|
|
|
|
function Run-Setup([string]$name) {
|
|
$process = Start-Process $Installer -Wait -PassThru -ArgumentList @(
|
|
'/VERYSILENT', '/SUPPRESSMSGBOXES', '/NORESTART', "/LOG=$logs\$name.log"
|
|
)
|
|
$process.ExitCode
|
|
}
|
|
|
|
if (Test-Path $support) { throw "$support already exists; run this only on a clean machine." }
|
|
$expected = (Get-FileHash -Algorithm SHA256 $Executable).Hash
|
|
|
|
Check ((Run-Setup 'install') -eq 0) 'silent install exits 0'
|
|
Check (Test-Path $installed) "hex.exe is at versions\$Version"
|
|
Check ((Get-FileHash -Algorithm SHA256 $installed).Hash -eq $expected) 'installed hex.exe matches the release bytes'
|
|
Check ((Get-Content $pointer -Raw).Trim() -eq $Version) "current-version names $Version"
|
|
$installReceipt = Get-Content $receipt -Raw | ConvertFrom-Json
|
|
Check ($installReceipt.app -eq 'hex' -and $installReceipt.artifact -eq 'desktop' -and $installReceipt.channel -eq 'stable' -and $installReceipt.method -eq 'direct') 'install.json marks a direct install of hex desktop stable'
|
|
Check ($installReceipt.root -eq $support) 'install.json names the install root'
|
|
# Hex reads the receipt as UTF-8; Setup once wrote the ANSI code page (#1352).
|
|
$receiptBytes = [IO.File]::ReadAllBytes($receipt)
|
|
Check (-not ($receiptBytes.Length -ge 3 -and $receiptBytes[0] -eq 0xEF -and $receiptBytes[1] -eq 0xBB -and $receiptBytes[2] -eq 0xBF)) 'install.json has no byte order mark'
|
|
$strict = New-Object System.Text.UTF8Encoding($false, $true)
|
|
Check ($null -ne $strict.GetString($receiptBytes)) 'install.json is valid UTF-8'
|
|
$link = (New-Object -ComObject WScript.Shell).CreateShortcut($shortcut)
|
|
Check ($link.TargetPath -eq $installed) 'Start Menu shortcut targets the managed executable'
|
|
Check ($link.Arguments -eq 'app') 'Start Menu shortcut launches the app'
|
|
Check ($link.Description -eq 'Hex managed install') 'Start Menu shortcut carries the managed mark the updater repoints'
|
|
$entry = Get-ItemProperty $uninstallKey
|
|
Check ($entry.DisplayName -eq 'Hex') 'Apps & Features lists Hex'
|
|
Check ($entry.DisplayVersion -eq $Version) "Apps & Features shows $Version"
|
|
$uninstaller = ($entry.UninstallString -replace '"', '')
|
|
Check ($uninstaller -like "$support\uninstall\*") 'the uninstaller lives outside versions\, which updates prune'
|
|
Check (Test-Path $uninstaller) 'the uninstaller exists'
|
|
# The uninstaller is the setup engine, and the copy Setup extracts to %TEMP%
|
|
# at launch is the same bytes: Smart App Control blocks an unsigned copy
|
|
# (error 4551), so Release embeds a signed engine.
|
|
if ($SignedEngine) {
|
|
$signature = Get-AuthenticodeSignature -LiteralPath $uninstaller
|
|
Check ($signature.Status -eq 'Valid') "the uninstaller has a valid Authenticode signature ($($signature.Status))"
|
|
Check ($null -ne $signature.TimeStamperCertificate) 'the uninstaller signature has an RFC 3161 timestamp'
|
|
Check ($signature.SignerCertificate.Subject -match 'Anomaly Innovations') "the uninstaller is signed by the release publisher ($($signature.SignerCertificate.Subject))"
|
|
}
|
|
function Run-Value { (Get-ItemProperty -Path $runKey -Name 'Hex' -ErrorAction SilentlyContinue).Hex }
|
|
Check ($null -eq (Run-Value)) 'installing leaves Launch at login off'
|
|
|
|
function User-Path { [Environment]::GetEnvironmentVariable('Path', 'User') }
|
|
function Path-Has([string]$folder) {
|
|
@((User-Path) -split ';' | Where-Object { $_.TrimEnd('\') -eq $folder }).Count -gt 0
|
|
}
|
|
|
|
# Starts without a Vulkan loader too (#1240), which some runners lack.
|
|
if ($Console) {
|
|
$expectedConsole = (Get-FileHash -Algorithm SHA256 $Console).Hash
|
|
Check (Test-Path $installedConsole) "hex.com is beside hex.exe at versions\$Version"
|
|
Check ((Get-FileHash -Algorithm SHA256 $installedConsole).Hash -eq $expectedConsole) 'installed hex.com matches the release bytes'
|
|
Check ((Get-FileHash -Algorithm SHA256 (Join-Path $bin 'hex.com')).Hash -eq $expectedConsole) 'bin\hex.com matches the release bytes'
|
|
Check (Path-Has $bin) 'bin is on the user''s PATH'
|
|
# hex.com is a console program, so PowerShell waits for it, prints or
|
|
# captures its output, and sets $LASTEXITCODE, as for any other command.
|
|
$reported = (& $installedConsole --version) -split '\s+' | Select-Object -Last 1
|
|
Check ($reported -eq $Version) "installed hex.com runs hex.exe, which reports $Version"
|
|
# A new terminal: the user's PATH, where `hex` resolves to bin\hex.com.
|
|
$env:Path = "$(User-Path);$([Environment]::GetEnvironmentVariable('Path', 'Machine'))"
|
|
$command = Get-Command hex -CommandType Application | Select-Object -First 1
|
|
Check ($command.Source -eq (Join-Path $bin 'hex.com')) "``hex`` resolves to bin\hex.com ($($command.Source))"
|
|
$started = Get-Date
|
|
$status = hex status --json
|
|
$code = $LASTEXITCODE
|
|
Check ($code -eq 3) "``hex status --json`` waits and exits 3, Hex isn't running ($code)"
|
|
Check (($status | Out-String) -match 'not-running') "``hex status --json`` printed its reply: $status"
|
|
Check ($null -ne (($status | Out-String) | ConvertFrom-Json)) '``hex status --json`` printed JSON'
|
|
Write-Output " (hex status --json took $([int]((Get-Date) - $started).TotalMilliseconds) ms)"
|
|
} else {
|
|
# A release before hex.com: its hex.exe was a console program.
|
|
$out = Join-Path $logs 'version.txt'
|
|
Start-Process $installed -ArgumentList '--version' -Wait -NoNewWindow -RedirectStandardOutput $out
|
|
$reported = (Get-Content $out -Raw).Trim() -split '\s+' | Select-Object -Last 1
|
|
Check ($reported -eq $Version) "installed hex.exe reports $Version"
|
|
}
|
|
|
|
# A Launch at login value outside the managed layout is the user's.
|
|
if (-not (Test-Path $runKey)) { New-Item -Path $runKey | Out-Null }
|
|
$foreign = '"C:\Tools\hex.exe" app --hidden'
|
|
Set-ItemProperty -Path $runKey -Name 'Hex' -Value $foreign
|
|
Check ((Run-Setup 'reinstall') -eq 0) 'reinstalling the same version exits 0'
|
|
Check ((Get-FileHash -Algorithm SHA256 $installed).Hash -eq $expected) 'reinstall keeps the release bytes'
|
|
Check ((Run-Value) -eq $foreign) 'Setup leaves a Launch at login value outside versions\ alone'
|
|
if ($Console) {
|
|
Check (@((User-Path) -split ';' | Where-Object { $_.TrimEnd('\') -eq $bin }).Count -eq 1) 'reinstalling adds bin to PATH once'
|
|
}
|
|
|
|
# Versions are never compared: the installer installs its own over any other.
|
|
Set-Content -Path $pointer -Value '99.0.0' -NoNewline
|
|
# Launch at login as the version this replaces registered it.
|
|
Set-ItemProperty -Path $runKey -Name 'Hex' -Value "`"$support\versions\99.0.0\hex.exe`" app --hidden"
|
|
Check ((Run-Setup 'over-another') -eq 0) 'installing over another version exits 0'
|
|
Check ((Get-Content $pointer -Raw).Trim() -eq $Version) 'current-version names this installer''s version'
|
|
Check ((Run-Value) -eq "`"$installed`" app --hidden") "Launch at login now starts versions\$Version ($(Run-Value))"
|
|
|
|
# Simulate what a self-update and Launch at login leave behind.
|
|
$updated = Join-Path $support 'versions\99.0.0\hex.exe'
|
|
New-Item -ItemType Directory -Force (Split-Path $updated) | Out-Null
|
|
Copy-Item $installed $updated
|
|
if ($Console) {
|
|
Copy-Item $installedConsole (Join-Path (Split-Path $updated) 'hex.com')
|
|
Copy-Item (Join-Path $bin 'hex.com') (Join-Path $bin 'hex.com.old')
|
|
}
|
|
New-Item -ItemType Directory -Force (Join-Path $support 'updates') | Out-Null
|
|
if (-not (Test-Path $runKey)) { New-Item -Path $runKey | Out-Null }
|
|
Set-ItemProperty -Path $runKey -Name 'Hex' -Value "`"$updated`" app --hidden"
|
|
Set-Content -Path (Join-Path $support 'settings.json') -Value '{}'
|
|
|
|
$process = Start-Process $uninstaller -Wait -PassThru -ArgumentList '/VERYSILENT', '/SUPPRESSMSGBOXES', '/NORESTART', "/LOG=$logs\uninstall.log"
|
|
Check ($process.ExitCode -eq 0) 'silent uninstall exits 0'
|
|
# The uninstaller finishes from a temporary copy of itself.
|
|
$deadline = (Get-Date).AddSeconds(60)
|
|
while ((Test-Path $uninstallKey) -and (Get-Date) -lt $deadline) { Start-Sleep -Milliseconds 500 }
|
|
Check (-not (Test-Path $uninstallKey)) 'Apps & Features entry is removed'
|
|
Check (-not (Test-Path (Join-Path $support 'versions'))) 'every version, including self-updated ones, is removed'
|
|
Check (-not (Test-Path (Join-Path $support 'updates'))) 'staged updates are removed'
|
|
Check (-not (Test-Path $pointer)) 'current-version is removed'
|
|
Check (-not (Test-Path $receipt)) 'install.json is removed'
|
|
Check (-not (Test-Path $shortcut)) 'Start Menu shortcut is removed'
|
|
Check ($null -eq (Get-ItemProperty -Path $runKey -Name 'Hex' -ErrorAction SilentlyContinue)) 'Launch at login is removed'
|
|
Check (Test-Path (Join-Path $support 'settings.json')) 'settings are kept'
|
|
if ($Console) {
|
|
Check (-not (Test-Path $bin)) 'bin is removed'
|
|
Check (-not (Path-Has $bin)) 'bin is off the user''s PATH'
|
|
}
|
|
Remove-Item $support -Recurse -Force
|
|
Write-Output "Installer $([IO.Path]::GetFileName($Installer)) passed."
|
|
# `hex status` left $LASTEXITCODE at 3, which would become this script's code.
|
|
exit 0
|