|
1 | 1 | ################################################################################ |
2 | 2 | ## File: Install-OpenSSL.ps1 |
3 | 3 | ## Desc: Install win64-openssl. |
| 4 | +## Supply chain security: checksum validation |
4 | 5 | ################################################################################ |
5 | 6 |
|
6 | | -$arch = "INTEL" |
7 | | -$bits = "64" |
8 | | -$light = $false |
| 7 | +$arch = 'INTEL' |
| 8 | +$bits = '64' |
| 9 | +$light = 'false' |
9 | 10 | $installer = "exe" |
10 | 11 | $version = (Get-ToolsetContent).openssl.version |
11 | 12 | $installDir = "$Env:ProgramFiles\OpenSSL" |
12 | 13 |
|
13 | 14 | # Fetch available installers list |
14 | 15 | $jsonUrl = 'https://raw.githubusercontent.com/slproweb/opensslhashes/master/win32_openssl_hashes.json' |
15 | | -$installersAvailable = @() |
16 | | -(Invoke-RestMethod $jsonUrl).files.PSObject.Properties | |
17 | | -Where-Object MemberType -Eq NoteProperty | |
18 | | -ForEach-Object { $installersAvailable += $_.Value } |
19 | | - |
20 | | -# Select appropriate installers |
21 | | -$installersMatching = $installersAvailable | Where-Object { |
22 | | - ($_.basever -Eq $version -Or $_.basever -Like "$version.*") -And $_.arch -Eq $arch -And $_.bits -Eq $bits -And $_.light -Eq $light -And $_.installer -Eq $installer |
23 | | -} |
24 | 16 |
|
25 | | -# Get installer of the latest version |
26 | | -$latestInstaller = $installersMatching | |
27 | | -Sort-Object { [version]$_.basever }, subver | |
28 | | -Select-Object -Last 1 |
| 17 | +$installersAvailable = (Invoke-RestMethod $jsonUrl).files |
| 18 | + |
| 19 | +$distributor_file_hash = $null |
| 20 | +$installerUrl = $null |
| 21 | +$installerName = $null |
| 22 | + |
| 23 | +$installersAvailable | Get-Member -MemberType NoteProperty | ForEach-Object { |
| 24 | + $key = $_.Name |
| 25 | + if(($installersAvailable.$key.light -eq $light) -and ($installersAvailable.$key.arch -eq $arch) -and ($installersAvailable.$key.bits -eq $bits) -and ($installersAvailable.$key.installer -eq $installer) -and ($installersAvailable.$key.basever -eq $version)) { |
| 26 | + $installerUrl = $installersAvailable.$key.url |
| 27 | + $installerName = $key |
| 28 | + $distributor_file_hash = $installersAvailable.$key.sha512 |
| 29 | + Break; |
| 30 | + } |
| 31 | +} |
29 | 32 |
|
30 | 33 | # Invoke installation |
31 | | -$installerUrl = $latestInstaller.url |
32 | | -$installerName = "openssl-$($latestInstaller.basever)$($latestInstaller.subver)-setup.$($latestInstaller.installer)" |
| 34 | + |
33 | 35 | $installerArgs = '/silent', '/sp-', '/suppressmsgboxes', "/DIR=`"$installDir`"" |
34 | 36 | Install-Binary -Url "$installerUrl" -Name "$installerName" -ArgumentList $installerArgs |
35 | 37 |
|
| 38 | +#region Supply chain security |
| 39 | +Write-Verbose "Performing checksum verification" |
| 40 | +$local_file_hash = (Get-FileHash -Path (Join-Path ${env:TEMP} $installerName) -Algorithm SHA512).Hash |
| 41 | + |
| 42 | +if ($local_file_hash -ne $distributor_file_hash) { |
| 43 | + Write-Host "hash must be equal to: ${distributor_file_hash}" |
| 44 | + Write-Host "actual hash is: ${local_file_hash}" |
| 45 | + throw 'Checksum verification failed, please rerun install' |
| 46 | +} |
| 47 | +#endregion |
| 48 | + |
36 | 49 | # Update PATH |
37 | 50 | Add-MachinePathItem "$installDir\bin" |
38 | 51 | $env:Path = Get-MachinePath |
|
0 commit comments