windows provisioning: automatically choose the right hash algorithm

...based on the length of the given hash.

Additionally use -ine for string comparison, which explicitly does
case-insensitive comparison. That is what the function needs, previously
it was done implicitly by -ne.

And remove MD5, it's not used anywhere.

Pick-to: 6.11 6.10 6.8 6.5
Change-Id: Ib4303737e5e1d743dd0be1a8f829be9a0db2bc04
Reviewed-by: Tero Heikkinen <tero.heikkinen@qt.io>
This commit is contained in:
Dimitrios Apostolou
2026-03-12 13:05:43 +01:00
parent 08892fc088
commit e5e813ef90
8 changed files with 15 additions and 11 deletions

View File

@@ -10,7 +10,7 @@ $sdkChecksumSha1 = "8fe98c00fde0f524760bb9021f438bd7d9304a69"
$package_path = "C:\Windows\Temp\$package"
Download $officialUrl $cachedUrl $package_path
Verify-Checksum $package_path $sdkChecksumSha1 sha1
Verify-Checksum $package_path $sdkChecksumSha1
Write-Host "Installing DirectX SDK"
Run-Executable $package_path "/u"

View File

@@ -2,16 +2,20 @@ function Verify-Checksum
{
Param (
[string]$File=$(throw("You must specify a filename to get the checksum of.")),
[string]$Expected=$(throw("Checksum required")),
[ValidateSet("sha256","sha1","md5")][string]$Algorithm="sha1"
[string]$Expected=$(throw("Checksum required"))
)
switch ($Expected.Length) {
40 { $Algorithm = "SHA1" }
64 { $Algorithm = "SHA256" }
default { throw "Unknown hash length for: $Expected" }
}
Write-Host "Verifying checksum of $File"
$fs = new-object System.IO.FileStream $File, "Open"
$algo = [type]"System.Security.Cryptography.$Algorithm"
$crypto = $algo::Create()
$hash = [BitConverter]::ToString($crypto.ComputeHash($fs)).Replace("-", "")
$fs.Close()
if ($hash -ne $Expected) {
if ($hash -ine $Expected) {
throw "Checksum verification failed, got: '$hash' expected: '$Expected'"
}
}

View File

@@ -33,7 +33,7 @@ $url_official = "https://go.dev/dl/go" + $version + ".windows-" + $arch + ".msi"
Write-Host "Fetching Go $version..."
Download $url_official $url_cache $goPackage
Verify-Checksum $goPackage $sha256 sha256
Verify-Checksum $goPackage $sha256
Write-Host "Installing Go $version..."
Run-Executable "msiexec" "/quiet /i $goPackage"
Write-Output "Go = $version" >> ~\versions.txt

View File

@@ -14,7 +14,7 @@ $script:package_path = "$packageRoot\\$nugetPackage"
New-Item -ItemType Directory -Path "$packageRoot"
Download $officialUrl $cachedUrl $package_path
Verify-Checksum $package_path $sdkChecksumSha1 sha1
Verify-Checksum $package_path $sdkChecksumSha1
Write-Host "Installing Nuget"
Set-EnvironmentVariable "NUGET_EXE_PATH" "$package_path"

View File

@@ -17,9 +17,9 @@ $install_location = "c:\Utils\$prog"
$tmp_location = "c:\users\qt\downloads"
Download $cached_url $cached_url "$tmp_location\$pkg"
Verify-Checksum "$tmp_location\$pkg" $sha1 sha1
Verify-Checksum "$tmp_location\$pkg" $sha1
Download $dep_cached_url $dep_cached_url "$tmp_location\$dep_pkg"
Verify-Checksum "$tmp_location\$dep_pkg" $dep_sha1 sha1
Verify-Checksum "$tmp_location\$dep_pkg" $dep_sha1
Extract-7Zip "$tmp_location\$pkg" $install_location
Extract-7Zip "$tmp_location\$dep_pkg" $install_location

View File

@@ -60,7 +60,7 @@ $vcpkgExeCacheUrl = "\\ci-files01-hki.ci.qt.io\provisioning\vcpkg\vcpkg-$nonDott
$vcpkgExe = "C:\Windows\Temp\vcpkg.exe"
Download "$vcpkgExeOfficialUrl" "$vcpkgExeCacheUrl" "$vcpkgExe"
Verify-Checksum $vcpkgExe $vcpkgExechecksum "sha256"
Verify-Checksum $vcpkgExe $vcpkgExechecksum
Move-Item "$vcpkgExe" -Destination "$vcpkgRoot" -Force
if(![System.IO.File]::Exists("$vcpkgRoot\vcpkg.exe")){

View File

@@ -43,7 +43,7 @@ $tempfile = "C:\Windows\Temp\" + $filename_zip
Write-Host "Fetching Telegraf $version..."
Download $url_official $url_cache $tempfile
Verify-Checksum $tempfile $sha256 sha256
Verify-Checksum $tempfile $sha256
Write-Host "Installing telegraf.exe under C:\Utils\telegraf"

View File

@@ -38,7 +38,7 @@ $internalUrl = "http://ci-files01-hki.ci.qt.io/input/windows/node-v$version-win-
Write-Host "Installing Node.js"
Download $externalUrl $internalUrl $package
Verify-Checksum $package $sha256 "sha256"
Verify-Checksum $package $sha256
Extract-7Zip $package $targetFolder
Add-Path $installFolder
Remove $package