Skip to content

Commit 486298a

Browse files
authored
[Windows] Add checksum verification for Aliyun CLI (#8512)
1 parent b3b303d commit 486298a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
################################################################################
22
## File: Install-AliyunCli.ps1
33
## Desc: Install Alibaba Cloud CLI
4+
## Supply chain security: Alibaba Cloud CLI - checksum validation
45
################################################################################
56

67
Write-Host "Download Latest aliyun-cli archive"
7-
$ZipballUrl = 'https://aliyuncli.alicdn.com/aliyun-cli-windows-latest-amd64.zip'
8-
$aliyunArchivePath = Start-DownloadWithRetry -Url $ZipballUrl -Name "aliyun-cli.zip"
8+
$repoUrl = "https://api.github.com/repos/aliyun/aliyun-cli/releases/latest"
9+
$installerFileName = "aliyun-cli-windows"
10+
$assets = (Invoke-RestMethod -Uri $repoUrl).assets
11+
$downloadUrl = ($assets.browser_download_url -ilike "*aliyun-cli-windows-*-amd64.zip*") | Select-Object -First 1
12+
$packagePath = Start-DownloadWithRetry -Url $downloadUrl -Name "$installerFileName.zip"
13+
14+
#region Supply chain security - Alibaba Cloud CLI
15+
$fileHash = (Get-FileHash -Path $packagePath -Algorithm SHA256).Hash
16+
$hashUrl = ($assets.browser_download_url -ilike "*SHASUMS256.txt*") | Select-Object -First 1
17+
$externalHash = (Invoke-RestMethod -Uri $hashURL).ToString().Split("`n").Where({ $_ -ilike "*$installerFileName*" }).Split(' ')[0]
18+
Use-ChecksumComparison $fileHash $externalHash
19+
#endregion
920

1021
Write-Host "Expand aliyun-cli archive"
1122
$aliyunPath = "C:\aliyun-cli"
1223
New-Item -Path $aliyunPath -ItemType Directory -Force
13-
Extract-7Zip -Path $aliyunArchivePath -DestinationPath $aliyunPath
24+
Extract-7Zip -Path $packagePath -DestinationPath $aliyunPath
1425

1526
# Add aliyun-cli to path
1627
Add-MachinePathItem $aliyunPath
1728

18-
Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Aliyun CLI"
29+
Invoke-PesterTests -TestFile "CLI.Tools" -TestName "Aliyun CLI"

0 commit comments

Comments
 (0)