Skip to content

Commit 8de4497

Browse files
[windows] implement DotNETSDK checksum validation (#8355)
1 parent 620e2c2 commit 8de4497

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

images/win/scripts/Installers/Install-DotnetSDK.ps1

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
## File: Install-DotnetSDK.ps1
33
## Desc: Install all released versions of the dotnet sdk and populate package
44
## cache. Should run after VS and Node
5+
## Supply chain security: checksum validation
56
################################################################################
67

78
# Set environment variables
@@ -52,13 +53,22 @@ function Invoke-Warmup (
5253

5354
function InstallSDKVersion (
5455
$SdkVersion,
56+
$dotnetVersion,
5557
$Warmup
5658
)
5759
{
5860
if (!(Test-Path -Path "C:\Program Files\dotnet\sdk\$sdkVersion"))
5961
{
6062
Write-Host "Installing dotnet $sdkVersion"
61-
.\dotnet-install.ps1 -Version $sdkVersion -InstallDir $(Join-Path -Path $env:ProgramFiles -ChildPath 'dotnet')
63+
$ZipPath = [System.IO.Path]::combine([System.IO.Path]::GetTempPath(), [System.IO.Path]::GetRandomFileName())
64+
.\dotnet-install.ps1 -Version $sdkVersion -InstallDir $(Join-Path -Path $env:ProgramFiles -ChildPath 'dotnet') -ZipPath $ZipPath -KeepZip
65+
66+
#region Supply chain security
67+
$distributorFileHash = (Invoke-RestMethod -Uri "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/$dotnetVersion/releases.json").releases.sdks.Where({$_.version -eq $SdkVersion}).files.Where({ $_.name -eq 'dotnet-sdk-win-x64.zip'}).hash
68+
$localFileHash = (Get-FileHash -Path $ZipPath -Algorithm 'SHA512').Hash
69+
70+
Use-ChecksumComparison -LocalFileHash $localFileHash -DistributorFileHash $distributorFileHash
71+
#endregion
6272
}
6373
else
6474
{
@@ -89,7 +99,7 @@ function InstallAllValidSdks()
8999

90100
ForEach ($sdkVersion in $sdkVersionsToInstall)
91101
{
92-
InstallSDKVersion -SdkVersion $sdkVersion -Warmup $warmup
102+
InstallSDKVersion -SdkVersion $sdkVersion -DotnetVersion $dotnetVersion -Warmup $warmup
93103
}
94104
}
95105
}

0 commit comments

Comments
 (0)