2020-05-22 03:52:48 -04:00
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
2025-12-30 10:26:53 -05:00
|
|
|
Compares a binary within a .zip file to a included .sha256 to ensure
|
2020-05-22 03:52:48 -04:00
|
|
|
the checksum is matching
|
|
|
|
|
.DESCRIPTION
|
2025-12-30 10:26:53 -05:00
|
|
|
Compares a possible included .sha256 checksum file with the provided binary
|
2020-05-22 03:52:48 -04:00
|
|
|
to ensure they are identical
|
|
|
|
|
.FUNCTIONALITY
|
2025-12-30 10:26:53 -05:00
|
|
|
Compares a binary within a .zip file to a included .sha256 to ensure
|
2020-05-22 03:52:48 -04:00
|
|
|
the checksum is matching.
|
|
|
|
|
.EXAMPLE
|
|
|
|
|
PS>Test-IcingaZipBinaryChecksum -Path 'C:\Program Files\icinga-service\icinga-service.exe';
|
|
|
|
|
.PARAMETER Path
|
2025-12-30 10:26:53 -05:00
|
|
|
Path to the binary to be checked for. A Corresponding .sha256 file with the
|
|
|
|
|
extension added on the file is required, like icinga-service.exe.sha256
|
2020-05-22 03:52:48 -04:00
|
|
|
.INPUTS
|
|
|
|
|
System.String
|
|
|
|
|
.OUTPUTS
|
|
|
|
|
Null
|
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/Icinga/icinga-powershell-framework
|
|
|
|
|
#>
|
|
|
|
|
|
2019-10-31 08:43:20 -04:00
|
|
|
function Test-IcingaZipBinaryChecksum()
|
|
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
$Path
|
|
|
|
|
);
|
|
|
|
|
|
2025-12-30 10:26:53 -05:00
|
|
|
$SHA256Path = [string]::Format('{0}.sha256', $Path);
|
2019-10-31 08:43:20 -04:00
|
|
|
|
2025-12-30 10:26:53 -05:00
|
|
|
if ((Test-Path $SHA256Path) -eq $FALSE) {
|
|
|
|
|
return $FALSE;
|
2019-10-31 08:43:20 -04:00
|
|
|
}
|
|
|
|
|
|
2025-12-30 10:26:53 -05:00
|
|
|
[string]$SHA256Checksum = Get-Content $SHA256Path;
|
|
|
|
|
$SHA256Checksum = ($SHA256Checksum.Split(' ')[0]).ToLower();
|
2019-10-31 08:43:20 -04:00
|
|
|
|
2025-12-30 10:26:53 -05:00
|
|
|
$FileHash = ((Get-IcingaFileHash $Path -Algorithm SHA256).Hash).ToLower();
|
2020-08-04 08:48:32 -04:00
|
|
|
|
2025-12-30 10:26:53 -05:00
|
|
|
if ($SHA256Checksum -ne $FileHash) {
|
2019-10-31 08:43:20 -04:00
|
|
|
return $FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $TRUE;
|
|
|
|
|
}
|