|  | 
| 7 | 7 | $arch = 'INTEL' | 
| 8 | 8 | $bits = '64' | 
| 9 | 9 | $light = $false | 
| 10 |  | -$installer = "exe" | 
|  | 10 | +$installerType = "exe" | 
| 11 | 11 | $version = "3.3.2" | 
| 12 |  | -$installDir = "$Env:ProgramFiles\OpenSSL" | 
|  | 12 | +$installDir = "$env:ProgramFiles\OpenSSL" | 
| 13 | 13 | 
 | 
| 14 | 14 | # Fetch available installers list | 
| 15 | 15 | $jsonUrl = 'https://raw.githubusercontent.com/slproweb/opensslhashes/master/win32_openssl_hashes.json' | 
| 16 | 16 | 
 | 
| 17 | 17 | $installersAvailable = (Invoke-RestMethod $jsonUrl).files | 
|  | 18 | +$installerNames = $installersAvailable | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name | 
| 18 | 19 | 
 | 
| 19 |  | -$distributor_file_hash = $null | 
| 20 | 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 |  | -  } | 
|  | 21 | +$installerHash = $null | 
|  | 22 | + | 
|  | 23 | +foreach ($key in $installerNames) { | 
|  | 24 | +    $installer = $installersAvailable.$key | 
|  | 25 | +    if (($installer.light -eq $light) -and ($installer.arch -eq $arch) -and ($installer.bits -eq $bits) -and ($installer.installer -eq $installerType) -and ($installer.basever -eq $version)) { | 
|  | 26 | +        $installerUrl = $installer.url | 
|  | 27 | +        $installerHash = $installer.sha512 | 
|  | 28 | +    } | 
| 30 | 29 | } | 
| 31 | 30 | 
 | 
| 32 |  | -# Invoke installation | 
| 33 |  | - | 
| 34 |  | -$installerArgs = '/silent', '/sp-', '/suppressmsgboxes', "/DIR=`"$installDir`"" | 
| 35 |  | -Install-Binary -Url "$installerUrl" -Name "$installerName" -ArgumentList $installerArgs | 
| 36 |  | - | 
| 37 |  | -#region Supply chain security | 
| 38 |  | -Write-Verbose "Performing checksum verification" | 
| 39 |  | -$local_file_hash = (Get-FileHash -Path (Join-Path ${env:TEMP} $installerName) -Algorithm SHA512).Hash | 
| 40 |  | - | 
| 41 |  | -if ($local_file_hash -ne $distributor_file_hash) { | 
| 42 |  | -        Write-Host "hash must be equal to: ${distributor_file_hash}" | 
| 43 |  | -        Write-Host "actual hash is: ${local_file_hash}" | 
| 44 |  | -        throw 'Checksum verification failed, please rerun install' | 
|  | 31 | +if ($null -eq $installerUrl) { | 
|  | 32 | +    throw "Installer not found for version $version" | 
| 45 | 33 | } | 
| 46 |  | -#endregion | 
|  | 34 | + | 
|  | 35 | +Install-Binary ` | 
|  | 36 | +    -Url $installerUrl ` | 
|  | 37 | +    -InstallArgs @('/silent', '/sp-', '/suppressmsgboxes', "/DIR=`"$installDir`"") ` | 
|  | 38 | +    -ExpectedSHA512Sum $installerHash | 
| 47 | 39 | 
 | 
| 48 | 40 | # Update PATH | 
| 49 | 41 | Add-MachinePathItem "$installDir\bin" | 
| 50 |  | -$env:Path = Get-MachinePath | 
|  | 42 | +Update-Environment | 
| 51 | 43 | 
 | 
| 52 | 44 | Invoke-PesterTests -TestFile "Tools" -TestName "OpenSSL" | 
0 commit comments