sslug-teknik team mailing list archive
-
sslug-teknik team
-
Mailing list archive
-
Message #75709
Re: Selv-validerende sumcheck
"Michael Schmidt" <m.schmidt@xxxxxxxx> writes:
> Hvordan kommer jeg ud af "paradokset" ?
Du gør så du let kan fjerne signaturen inden du tjekker filen. Noget
ala følgende:
add_hash.pl:
#!/usr/bin/perl
use Digest::SHA qw(sha1_hex);
# Slurp file
my $data;
{
local $/;
$data = <>;
}
# Remove everything that looks like our hash
$data =~ s/\$SHA: [^$]*\$/\$SHA: \$/g;
my $hash = sha1_hex($data);
$data =~ s/\$SHA: [^$]*\$/\$SHA: $data\$/g;
print $data;
__END__
check_hash.pl:
#!/usr/bin/perl
use Digest::SHA qw(sha1_hex);
# Slurp file
my $data;
{
local $/;
$data = <>;
}
$data =~ m/\$SHA: ([^$]+)\$/ or die "No shasum";
my $hash1 = $1;
# Remove everything that looks like our hash
$data =~ s/\$SHA: [^$]*\$/\$SHA: \$/g;
my $hash2 = sha1_hex($data);
if ($hash1 eq $hash2) {
print "OK\n";
} else {
print "Ikke ok\n"
}
__END__
Begge ovenstående læser fra stdin og skriver til stdout. Man burde nok
kunne læse et filnavn og indsætte hashen direkte i filen og man burde
nok også tjekke at der ikke er flere hash'er i filen som ikke er
ens. check_hash.pl bruger bare den første.
(Og det er absolut ikke afprøvet.)
--
Peter Makholm | Sit back and watch the messages. This is actually
peter@xxxxxxxxxxx | more important than one might think as there is a
http://hacking.dk | bug in GNU Mach whereby hitting a key during the
| boot process causes the kernel to panic
| -- GNU Hurd Installation Guide
Follow ups
References