[Windows] Add checksum validation for Stack (#8403)

This commit is contained in:
Erik Bershel
2023-10-04 14:58:45 +02:00
committed by GitHub
parent 8b23f693e9
commit ae487529f3

View File

@@ -1,6 +1,7 @@
################################################################################
## File: Install-Stack.ps1
## Desc: Install Stack for Windows
## Supply chain security: Stack - checksum validation
################################################################################
Write-Host "Get the latest Stack version..."
@@ -14,6 +15,13 @@ $StackToolcachePath = Join-Path $Env:AGENT_TOOLSDIRECTORY "stack\$Version"
$DestinationPath = Join-Path $StackToolcachePath "x64"
$StackArchivePath = Start-DownloadWithRetry -Url $DownloadUrl
#region Supply chain security - Stack
$fileHash = (Get-FileHash -Path $StackArchivePath -Algorithm SHA256).Hash
$hashUrl = $StackReleasesJson.assets | Where-Object { $_.name.EndsWith("$DownloadFilePattern.sha256") } | Select-Object -ExpandProperty "browser_download_url" -First 1
$externalHash = (Invoke-RestMethod -Uri $hashURL).ToString().Split("`n").Where({ $_ -ilike "*$DownloadFilePattern*" }).Split(' ')[0]
Use-ChecksumComparison $fileHash $externalHash
#endregion
Write-Host "Expand stack archive"
Extract-7Zip -Path $StackArchivePath -DestinationPath $DestinationPath