Skip to content

Commit

Permalink
fix: Fix file digest check to lower case provided value before compar…
Browse files Browse the repository at this point in the history
  • Loading branch information
g-bougard committed Dec 11, 2024
1 parent cfa605b commit 999066d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
7 changes: 7 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ deploy:
"return code is not" and "command output doesn't contain" checks which was always
failing.
* fix #804: Don't scan network and broadcast addresses when using P2P
* Fix sha512 file checks to also accep provided digest in upper case

collect:
* Fix sha512 file check to also accep provided digest in upper case
* Change 'checkSumSHA2' file check meaning to compute sha256
* Add 'checkSumSHA256' params support for file checking to replace 'checkSumSHA2' one
and it is mandatory over its alias 'checkSumSHA2'

esx:
* Support reporting of ESX virtualmachines ip and operating system. It requires
Expand Down
10 changes: 6 additions & 4 deletions lib/GLPI/Agent/Task/Collect.pm
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,16 @@ sub _findFile {
my $sha = Digest::SHA->new('512');
$sha->addfile( $File::Find::name, 'b' );
return
if $sha->hexdigest ne $params{filter}{checkSumSHA512};
if $sha->hexdigest ne lc($params{filter}{checkSumSHA512});
}

if ( $params{filter}{checkSumSHA2} ) {
my $sha = Digest::SHA->new('2');
# checkSumSHA2 is an historic feature and was indeed sha256 at the time of this code original writing
my $expectedSha256 = $params{filter}{checkSumSHA256} || $params{filter}{checkSumSHA2};
if (!empty($expectedSha256)) {
my $sha = Digest::SHA->new('256');
$sha->addfile( $File::Find::name, 'b' );
return
if $sha->hexdigest ne $params{filter}{checkSumSHA2};
if $sha->hexdigest ne lc($expectedSha256);
}

$params{logger}->debug2("Found file: ".$File::Find::name)
Expand Down
2 changes: 1 addition & 1 deletion lib/GLPI/Agent/Task/Deploy/CheckProcessor/FileSHA512.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ sub success {
return 0 unless (defined($sha512) && $sha512);

$self->on_failure($self->{path} . " has wrong sha512 file hash, found $sha512");
return ( $sha512 eq $expected );
return ( $sha512 eq lc($expected) );
}

1;
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ sub success {

$self->on_failure("got sha512 file hash match for $path");
$self->on_success("got sha512 file hash mismatch for $path, found $sha512");
return ( $sha512 ne $expected );
return ( $sha512 ne lc($expected) );
}

1;

0 comments on commit 999066d

Please sign in to comment.