Skip to content

Commit

Permalink
Check hash of downloaded setup
Browse files Browse the repository at this point in the history
  • Loading branch information
mlocati authored and jon-turney committed Jan 5, 2025
1 parent b93253c commit b26c6b6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Parameters
| check-sig | true | Whether to check the setup.ini signature
| add-to-path | true | Whether to add Cygwin's `/bin` directory to the system `PATH`
| allow-test-packages | false | Consider package versions marked test for installation
| check-hash | true | Whether to check the hash of the downloaded Cygwin installer.

Line endings
------------
Expand Down
25 changes: 24 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ inputs:
description: Consider package versions marked test
required: false
default: false
check-hash:
description: Check the hash of the installer
required: false
default: 'true'

runs:
using: "composite"
steps:
- run: |
$ErrorActionPreference = 'Stop'
$platform = '${{ inputs.platform }}'
$platform = $platform -replace '^(x64|amd64)$', 'x86_64'
$platform = $platform -replace '^i686$', 'x86'
Expand All @@ -46,7 +51,25 @@ runs:
echo "unknown platform $platform"
exit 1
}
Invoke-WebRequest https://cygwin.com/setup-$platform.exe -OutFile C:\setup.exe
$setupFileName = "setup-$platform.exe"
Invoke-WebRequest "https://cygwin.com/$setupFileName" -OutFile C:\setup.exe
if ('${{ inputs.check-hash }}'.ToLower() -in @('','true', 'yes', '1', 'on')) {
$actualHash = $(Get-FileHash -LiteralPath C:\setup.exe -Algorithm SHA512).Hash
$expectedHashLines = $(Invoke-WebRequest -Uri https://cygwin.com/sha512.sum).ToString() -split "`n"
foreach ($expectedHashLine in $expectedHashLines) {
if ($expectedHashLine -match "^(\S+)\s+(\S+)$") {
$expectedHash = $matches[1]
$expectedFileName = $matches[2]
if ($expectedFileName -ieq $setupFileName) {
if ($expectedHash -ine $actualHash) {
throw "Invalid hash of the downloaded setup!`nExpected: $expectedHashLine`nActual : $actualHash $expectedFileName"
}
Write-Host "The downloaded file has the expected hash ($actualHash)"
}
}
}
}
$packages = '${{ inputs.packages }}'
$pkg_list = $packages.Split('', [System.StringSplitOptions]::RemoveEmptyEntries)
Expand Down

0 comments on commit b26c6b6

Please sign in to comment.