verify-binary.ps1 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <#
  2. .SYNOPSIS
  3. Re-verify SHA-256 of the committed process-compose.exe against recorded EXE_HASH.
  4. .DESCRIPTION
  5. Run periodically (e.g. monthly, or as a pre-commit hook). Fails loud on mismatch.
  6. .PARAMETER BinDir
  7. Path to the bin/ directory containing process-compose.exe and EXE_HASH.
  8. Defaults to ./bin or ../bin.
  9. .EXAMPLE
  10. .\verify-binary.ps1
  11. #>
  12. [CmdletBinding()]
  13. param(
  14. [string]$BinDir = $null
  15. )
  16. $ErrorActionPreference = 'Stop'
  17. # Auto-detect bin/
  18. if (-not $BinDir) {
  19. $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
  20. foreach ($candidate in @(
  21. (Join-Path $scriptDir '..\bin'),
  22. (Join-Path (Get-Location) 'bin')
  23. )) {
  24. if (Test-Path (Join-Path $candidate 'process-compose.exe')) {
  25. $BinDir = (Resolve-Path $candidate).Path
  26. break
  27. }
  28. }
  29. }
  30. if (-not $BinDir -or -not (Test-Path $BinDir)) {
  31. throw "bin/ directory not found - pass -BinDir explicitly"
  32. }
  33. $exePath = Join-Path $BinDir 'process-compose.exe'
  34. $hashFile = Join-Path $BinDir 'EXE_HASH'
  35. if (-not (Test-Path $exePath)) { throw "process-compose.exe not found in $BinDir" }
  36. if (-not (Test-Path $hashFile)) { throw "EXE_HASH not found in $BinDir (run install-process-compose.ps1 to create it)" }
  37. $expected = (Get-Content $hashFile -Raw).Trim().ToLower()
  38. $actual = (Get-FileHash $exePath -Algorithm SHA256).Hash.ToLower()
  39. Write-Host "Verifying: $exePath" -ForegroundColor Cyan
  40. Write-Host " Expected: $expected"
  41. Write-Host " Actual: $actual"
  42. if ($expected -ne $actual) {
  43. Write-Host " Status: MISMATCH" -ForegroundColor Red
  44. throw "BINARY VERIFICATION FAILED - do not trust this binary"
  45. }
  46. Write-Host " Status: OK" -ForegroundColor Green