<# .SYNOPSIS Checks that downloaded MCZ release files are the ones the author published. .DESCRIPTION Download MCZ--SHA256SUMS.txt, its .sig, mcz-release-public.pem and the files you want from the release page into one folder, then run this script there (or pass -Folder). It recomputes each file's SHA-256 and compares it with the list, and, when openssl is available (Git for Windows ships it), verifies the author's signature over the list. On Linux the equivalent is: sha256sum -c MCZ--SHA256SUMS.txt openssl dgst -sha256 -verify mcz-release-public.pem -signature MCZ--SHA256SUMS.txt.sig MCZ--SHA256SUMS.txt #> [CmdletBinding()] param( [string] $Folder = (Get-Location).Path ) $ErrorActionPreference = 'Stop' $sums = Get-ChildItem $Folder -Filter 'MCZ-*-SHA256SUMS.txt' | Select-Object -First 1 if (-not $sums) { throw "no MCZ--SHA256SUMS.txt in $Folder" } $bad = 0; $checked = 0 foreach ($line in Get-Content $sums.FullName) { if ($line -notmatch '^([0-9a-f]{64})\s+(.+)$') { continue } $expected = $Matches[1]; $name = $Matches[2].Trim() $path = Join-Path $Folder $name if (-not (Test-Path $path)) { Write-Host " skipped $name (not downloaded)"; continue } $actual = (Get-FileHash $path -Algorithm SHA256).Hash.ToLowerInvariant() $checked++ if ($actual -eq $expected) { Write-Host " OK $name" } else { Write-Host " MISMATCH $name (do not install it)"; $bad++ } } $openssl = @((Get-Command openssl.exe -ErrorAction SilentlyContinue).Source, 'C:\Program Files\Git\mingw64\bin\openssl.exe') | Where-Object { $_ -and (Test-Path $_) } | Select-Object -First 1 $pub = Join-Path $Folder 'mcz-release-public.pem' $sig = "$($sums.FullName).sig" if ($openssl -and (Test-Path $pub) -and (Test-Path $sig)) { $ErrorActionPreference = 'Continue' # openssl writes to stderr even on success & $openssl dgst -sha256 -verify $pub -signature $sig $sums.FullName 2>&1 | Out-Null $ErrorActionPreference = 'Stop' if ($LASTEXITCODE -eq 0) { Write-Host " OK signature over the checksum list (author's key)" } else { Write-Host " BAD signature over the checksum list: the list itself was altered"; $bad++ } } else { Write-Host " (signature not checked: needs openssl, mcz-release-public.pem and the .sig file in $Folder)" } if ($bad) { Write-Host "`n$bad problem(s): the download does not match the published release."; exit 1 } Write-Host "`n$checked file(s) match the published release."