Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions eng/_util/go-install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,8 @@ function Get-AkaMSRedirectTarget([string] $akaMsLink) {
# https://github.com/PowerShell/PowerShell/issues/10875
function Get-OrNull($Target, $Property) {
if ($Target -and $Target.PSObject.Properties[$Property]) {
return $Target.PSObject.Properties[$Property].Value
# Preserve arrays so callers can distinguish them from scalar property values.
return ,$Target.PSObject.Properties[$Property].Value
}
return $null
}
Expand Down Expand Up @@ -887,6 +888,11 @@ if ($DryRun) {
return
}

$ExpectedSHA256 = Get-OrNull $Arch 'sha256'
if ($ExpectedSHA256 -isnot [string] -or $ExpectedSHA256 -notmatch '\A[0-9a-fA-F]{64}\z') {
throw "The asset manifest does not contain a valid SHA-256 digest for '$DownloadLink'."
}

Measure-Action "Installation directory preparation" { Prepare-Install-Directory }

Say-Verbose "Zip path: $ArchivePath"
Expand All @@ -896,6 +902,15 @@ Say-Verbose "Downloading link $DownloadLink"
try {
Measure-Action "Package download" { DownloadFile -Source $DownloadLink -OutPath $ArchivePath }
Say-Verbose "Download succeeded."

# This checks integrity, not authenticity: the manifest and archive are both remote.
# An attacker able to replace both can supply a matching digest. Authenticity requires
# verifying the signature at pgpSignatureUrl against a locally pinned Microsoft public key.
$ActualSHA256 = (Get-FileHash -LiteralPath $ArchivePath -Algorithm SHA256).Hash
if ($ActualSHA256 -ne $ExpectedSHA256) {
throw "SHA-256 mismatch for '$ArchivePath'. Expected: $ExpectedSHA256. Actual: $ActualSHA256."
}
Say-Verbose "SHA-256 verification succeeded."
}
catch {
$StatusCode = $null
Expand All @@ -915,7 +930,7 @@ catch {
Remove-FileSafely -Path $ArchivePath
}

throw "Downloading has failed with error:`nUri: $DownloadLink`nStatusCode: $StatusCode`nError: $ErrorMessage"
throw "Downloading or verifying the archive has failed with error:`nUri: $DownloadLink`nStatusCode: $StatusCode`nError: $ErrorMessage"
}

Say "Extracting the archive."
Expand Down
2 changes: 1 addition & 1 deletion eng/_util/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ go 1.26.0
require (
github.com/golang-jwt/jwt/v5 v5.3.1
github.com/microsoft/go-infra v0.0.21
github.com/microsoft/go-infra/goinstallscript v1.3.0
github.com/microsoft/go-infra/goinstallscript v1.3.1-0.20261113101331-48b97698e9cc
golang.org/x/net v0.62.0
)

Expand Down
2 changes: 2 additions & 0 deletions eng/_util/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ github.com/microsoft/go-infra v0.0.21 h1:1LS9pnSST73+9+XhY40svE7P/hT5qbsrjkAxKDQ
github.com/microsoft/go-infra v0.0.21/go.mod h1:jOetsM1g+txW4kK4CN+Hq+cJCNPVR5iXmy+ZzSMZMQA=
github.com/microsoft/go-infra/goinstallscript v1.3.0 h1:KhCeWh9JjCVnPEsL6pb9IzrFShypBKyhlDNjUunonlc=
github.com/microsoft/go-infra/goinstallscript v1.3.0/go.mod h1:SFsdKAEHdmGsGoh8FkksVaxoQ3rnnJ/TBqN09Ml/0Cw=
github.com/microsoft/go-infra/goinstallscript v1.3.1-0.20261113101331-48b97698e9cc h1:zrlmplsXtb+eK8TUqsZ9rum3bL5KlBwuD0wXAcilyXg=
github.com/microsoft/go-infra/goinstallscript v1.3.1-0.20261113101331-48b97698e9cc/go.mod h1:SFsdKAEHdmGsGoh8FkksVaxoQ3rnnJ/TBqN09Ml/0Cw=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
Expand Down
Loading