icinga-powershell-framework/lib/core/framework/Test-IcingaZipBinaryChecksum.psm1

47 lines
1.2 KiB
PowerShell
Raw Normal View History

2020-05-22 03:52:48 -04:00
<#
.SYNOPSIS
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
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
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
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
#>
function Test-IcingaZipBinaryChecksum()
{
param(
$Path
);
$SHA256Path = [string]::Format('{0}.sha256', $Path);
if ((Test-Path $SHA256Path) -eq $FALSE) {
return $FALSE;
}
[string]$SHA256Checksum = Get-Content $SHA256Path;
$SHA256Checksum = ($SHA256Checksum.Split(' ')[0]).ToLower();
$FileHash = ((Get-IcingaFileHash $Path -Algorithm SHA256).Hash).ToLower();
if ($SHA256Checksum -ne $FileHash) {
return $FALSE;
}
return $TRUE;
}