From dd4bdccfb5d96b72900478b3d07651d6b7382e6a Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Tue, 12 Apr 2016 06:07:40 +0000 Subject: replace sha256 with generic checksum We use tldigest($string) or tlchecksum($file) to generate checksum. The algorithm can be changed at any time provided that tldigest and tlchecksum (in TLUtils) and the setting TLConfig::ChecksumLength are kept in sync. git-svn-id: svn://tug.org/texlive/trunk@40429 c570f23f-e606-0410-a88d-b1316a301751 --- Master/tlpkg/TeXLive/TLConfig.pm | 5 +++++ Master/tlpkg/TeXLive/TLPOBJ.pm | 41 +++++++++++++++++++--------------------- Master/tlpkg/TeXLive/TLUtils.pm | 16 ++++++++++------ 3 files changed, 34 insertions(+), 28 deletions(-) (limited to 'Master/tlpkg/TeXLive') diff --git a/Master/tlpkg/TeXLive/TLConfig.pm b/Master/tlpkg/TeXLive/TLConfig.pm index 166451419a7..d2dba83146b 100644 --- a/Master/tlpkg/TeXLive/TLConfig.pm +++ b/Master/tlpkg/TeXLive/TLConfig.pm @@ -50,6 +50,7 @@ BEGIN { $NetworkTimeout $PartialEngineSupport $F_OK $F_WARNING $F_ERROR $F_NOPOSTACTION + $ChecksumLength ); @EXPORT = @EXPORT_OK; } @@ -213,6 +214,10 @@ our $F_ERROR = 2; # all fine, but no need to run post actions our $F_NOPOSTACTION = 4; +# The length of a checksum generated by tlchecksum and contained in +# texlive.tlpdb.checksum. Needs to be in agreement with the hash +# method used in TLUtils::tlchecksum and TLUtils::tldigest +$ChecksumLength = 128; 1; diff --git a/Master/tlpkg/TeXLive/TLPOBJ.pm b/Master/tlpkg/TeXLive/TLPOBJ.pm index 0da988c1aae..134d7cd8453 100644 --- a/Master/tlpkg/TeXLive/TLPOBJ.pm +++ b/Master/tlpkg/TeXLive/TLPOBJ.pm @@ -169,9 +169,9 @@ sub from_fh { || $cmd eq 'doccontainermd5') { $arg =~ /^[a-f0-9]{32}$/ or die "Illegal md5 value: $line!"; $self->{$cmd} = $arg; - } elsif ($cmd eq 'containersha256' || $cmd eq 'srccontainersha256' - || $cmd eq 'doccontainersha256') { - $arg =~ /^[a-f0-9]{64}$/ or die "Illegal sha256 value: $line!"; + } elsif ($cmd eq 'containerchecksum' || $cmd eq 'srccontainerchecksum' + || $cmd eq 'doccontainerchecksum') { + $arg =~ /^[a-f0-9]{$ChecksumLength}$/ or die "Illegal checksum value: $line!"; $self->{$cmd} = $arg; } elsif ($cmd eq 'name') { $arg =~ /^([-.\w]+)$/ or die("Invalid name: $line!"); @@ -312,8 +312,8 @@ sub writeout { if (defined($self->{'containermd5'})) { print $fd "containermd5 $self->{'containermd5'}\n"; } - if (defined($self->{'containersha256'})) { - print $fd "containersha256 $self->{'containersha256'}\n"; + if (defined($self->{'containerchecksum'})) { + print $fd "containerchecksum $self->{'containerchecksum'}\n"; } if (defined($self->{'doccontainersize'})) { print $fd "doccontainersize $self->{'doccontainersize'}\n"; @@ -321,8 +321,8 @@ sub writeout { if (defined($self->{'doccontainermd5'})) { print $fd "doccontainermd5 $self->{'doccontainermd5'}\n"; } - if (defined($self->{'doccontainersha256'})) { - print $fd "doccontainersha256 $self->{'doccontainersha256'}\n"; + if (defined($self->{'doccontainerchecksum'})) { + print $fd "doccontainerchecksum $self->{'doccontainerchecksum'}\n"; } if (defined($self->{'docfiles'}) && (@{$self->{'docfiles'}})) { print $fd "docfiles size=$self->{'docsize'}\n"; @@ -347,8 +347,8 @@ sub writeout { if (defined($self->{'srccontainermd5'})) { print $fd "srccontainermd5 $self->{'srccontainermd5'}\n"; } - if (defined($self->{'srccontainersha256'})) { - print $fd "srccontainersha256 $self->{'srccontainersha256'}\n"; + if (defined($self->{'srccontainerchecksum'})) { + print $fd "srccontainerchecksum $self->{'srccontainerchecksum'}\n"; } if (defined($self->{'srcfiles'}) && (@{$self->{'srcfiles'}})) { print $fd "srcfiles size=$self->{'srcsize'}\n"; @@ -687,7 +687,7 @@ sub make_container { return (0, 0, ""); } my $size = (stat "$destdir/$containername") [7]; - my $sha256 = TeXLive::TLUtils::tlsha256("$destdir/$containername"); + my $checksum = TeXLive::TLUtils::tlchecksum("$destdir/$containername"); # cleaning up unlink("$tlpobjdir/$self->{'name'}.tlpobj"); @@ -696,8 +696,8 @@ sub make_container { rmdir($InfraLocation) if $removetlpkgdir; xchdir($cwd); - debug(" done $containername, size $size, $sha256\n"); - return ($size, $sha256, "$destdir/$containername"); + debug(" done $containername, size $size, $checksum\n"); + return ($size, $checksum, "$destdir/$containername"); } @@ -1490,16 +1490,13 @@ there are 6 more possible keys: $tlpobj->containersize $tlpobj->doccontainersize $tlpobj->srccontainersize - $tlpobj->containermd5 - $tlpobj->doccontainermd5 - $tlpobj->srccontainermd5 - $tlpobj->containersha256 - $tlpobj->doccontainersha256 - $tlpobj->srccontainersha256 - -describing the respective sizes and md5sums/sha256sums in bytes and as hex string, resp. -The latter two are only present -if src/doc file container splitting is activated for that install medium. + $tlpobj->containerchecksum + $tlpobj->doccontainerchecksum + $tlpobj->srccontainerchecksum + +describing the respective sizes and checksums in bytes and as hex string, resp. +The latter two are only present if src/doc file container splitting is +activated for that install medium. =head1 OTHER FUNCTIONS diff --git a/Master/tlpkg/TeXLive/TLUtils.pm b/Master/tlpkg/TeXLive/TLUtils.pm index 0a9e527c516..6274e0b20aa 100644 --- a/Master/tlpkg/TeXLive/TLUtils.pm +++ b/Master/tlpkg/TeXLive/TLUtils.pm @@ -99,7 +99,7 @@ C -- utilities used in TeX Live infrastructure TeXLive::TLUtils::give_ctan_mirror(); TeXLive::TLUtils::give_ctan_mirror_base(); TeXLive::TLUtils::tlmd5($path); - TeXLive::TLUtils::tlsha256($path); + TeXLive::TLUtils::tlchecksum($path); TeXLive::TLUtils::compare_tlpobjs($tlpA, $tlpB); TeXLive::TLUtils::compare_tlpdbs($tlpdbA, $tlpdbB); TeXLive::TLUtils::report_tlpdb_differences(\%ret); @@ -174,7 +174,7 @@ BEGIN { &create_mirror_list &extract_mirror_entry &tlmd5 - &tlsha256 + &tlchecksum &wsystem &xsystem &run_cmd @@ -3582,16 +3582,20 @@ sub tlmd5 { } } -sub tlsha256 { +sub tldigest { + return (Digest::SHA::sha512_hex(shift)); +} + +sub tlchecksum { my ($file) = @_; if (-r $file) { open(FILE, $file) || die "open($file) failed: $!"; binmode(FILE); - my $sha256hash = Digest::SHA->new(256)->addfile(*FILE)->hexdigest; + my $cshash = Digest::SHA->new(512)->addfile(*FILE)->hexdigest; close(FILE); - return $sha256hash; + return $cshash; } else { - tlwarn("tlsha256, given file not readable: $file\n"); + tlwarn("tlchecksum: given file not readable: $file\n"); return ""; } } -- cgit v1.2.3