From 1bf271f3d5249f93f9c8f9b911f0a0ee0221194f Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Thu, 21 Apr 2016 00:31:43 +0000 Subject: verification reporting reworked: be non-intrusive git-svn-id: svn://tug.org/texlive/trunk@40640 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/scripts/texlive/tlmgr.pl | 17 ++++++++++++---- Master/tlpkg/TeXLive/TLPDB.pm | 26 ++++++++++++++++++------ Master/tlpkg/TeXLive/TLUtils.pm | 32 ++++++++++++++++++++---------- 3 files changed, 54 insertions(+), 21 deletions(-) (limited to 'Master') diff --git a/Master/texmf-dist/scripts/texlive/tlmgr.pl b/Master/texmf-dist/scripts/texlive/tlmgr.pl index 8c419844a45..0576c5d7767 100755 --- a/Master/texmf-dist/scripts/texlive/tlmgr.pl +++ b/Master/texmf-dist/scripts/texlive/tlmgr.pl @@ -5819,7 +5819,8 @@ sub init_tlmedia { # this "location-url" line should not be changed since GUI programs # depend on it: print "location-url\t$locstr\n" if $::machinereadable; - info("$prg: package repositories:\n"); + info("$prg: package repositories" . + ($::gpg ? " (all verified)" : "") . ":\n"); info("\tmain = " . $repos{'main'} . "\n"); for my $t (@tags) { if ($t ne 'main') { @@ -5858,7 +5859,8 @@ sub _init_tlmedia { # this "location-url" line should not be changed since GUI programs # depend on it: print "location-url\t$location\n" if $::machinereadable; - info("$prg: package repository $location\n"); + info("$prg: package repository $location" . + ($::gpg ? " (verified)" : "") . "\n"); return 1; } @@ -5917,12 +5919,19 @@ END_NO_INTERNET $remotetlpdb = TeXLive::TLPDB->new(root => $location, tlpdbfile => $loc_copy_of_remote_tlpdb); $local_copy_tlpdb_used = 1; - } elsif ($ret > 0) { + } elsif ($ret == 1) { # no problem, checksum is wrong, we need to get new tlpdb - } else { + } elsif ($ret == 2) { + # umpf, signature error + # TODO should we die here? Probably yes because one of + # checksum file or signature file has changed! + tldie("$0: verification of checksum for $location failed: $msg\n"); + } elsif ($ret == 0) { $remotetlpdb = TeXLive::TLPDB->new(root => $location, tlpdbfile => $loc_copy_of_remote_tlpdb); $local_copy_tlpdb_used = 1; + } else { + tldie("$0: unexpected return value from verify_checksum: $ret\n"); } } } diff --git a/Master/tlpkg/TeXLive/TLPDB.pm b/Master/tlpkg/TeXLive/TLPDB.pm index a3c22358000..65999bfc9a5 100644 --- a/Master/tlpkg/TeXLive/TLPDB.pm +++ b/Master/tlpkg/TeXLive/TLPDB.pm @@ -368,18 +368,32 @@ sub from_file { # before we open and proceed, verify the downloaded file if ($params{'verify'} && $media ne 'local_uncompressed') { my ($r, $m) = TeXLive::TLUtils::verify_checksum($tlpdbfile, "$path.$TeXLive::TLConfig::ChecksumExtension"); - # TODO here we could check for -1 as return value - # which would indicate that the checksum could not be downloaded! - if ($r != 0) { - tldie("$0: verification of $tlpdbfile from $path failed ($r): $m\n"); + if ($r == 1) { + tldie("$0: checksum error when downloading $tlpdbfile from $path: $m\n"); + } elsif ($r == 2) { + tldie("$0: signature verification error of $tlpdbfile from $path: $m\n"); + } elsif ($r == -1) { + tldie("$0: connection problems, cannot download: $m\n"); + } elsif ($r == 0) { + # all is fine, do nothing + } else { + tldie("$0: unexpected return value from verify_checksum: $r\n"); } } open($retfh, "<$tlpdbfile") || die "$0: open($tlpdbfile) failed: $!"; } else { if ($params{'verify'} && $media ne 'local_uncompressed') { my ($r, $m) = TeXLive::TLUtils::verify_checksum($path, "$path.$TeXLive::TLConfig::ChecksumExtension"); - if ($r != 0) { - tldie("$0: verification of $path failed ($r): $m\n"); + if ($r == 1) { + tldie("$0: checksum error when downloading $tlpdbfile from $path: $m\n"); + } elsif ($r == 2) { + tldie("$0: signature verification error of $tlpdbfile from $path: $m\n"); + } elsif ($r == -1) { + tldie("$0: connection problems, cannot download: $m\n"); + } elsif ($r == 0) { + # all is fine, do nothing + } else { + tldie("$0: unexpected return value from verify_checksum: $r\n"); } } open(TMP, "<$path") || die "$0: open($path) failed: $!"; diff --git a/Master/tlpkg/TeXLive/TLUtils.pm b/Master/tlpkg/TeXLive/TLUtils.pm index 8de05ee9d75..dc3c909df08 100644 --- a/Master/tlpkg/TeXLive/TLUtils.pm +++ b/Master/tlpkg/TeXLive/TLUtils.pm @@ -3750,9 +3750,11 @@ sub slurp_file { =item C<< verify_checksum($file, $checksum_url) >> -Verifies that C<$file> has checksum C<$checksum_url>. +Verifies that C<$file> has checksum C<$checksum_url>, and if gpg is +available also verifies that the checksum is signed. -Returns 0 on success, -1 on connection error, 1 on checksum error. +Returns 0 on success, -1 on connection error, 1 on checksum, and +2 on signature errors. In case of errors returns an informal message as second argument. =cut @@ -3829,7 +3831,7 @@ sub download_to_temp_or_file { Verifies a download of C<$url> into C<$file> by cheking the gpg signature in C<$url.asc>. -Returns 0 on success, -1 on connection error, 1 on checksum error. +Returns 0 on success, -1 on connection error, 2 on signature error. In case of errors returns an informal message as second argument. =cut @@ -3842,23 +3844,32 @@ sub verify_signature { if ($::gpg) { my $signature_file = download_to_temp_or_file($signature_url); if ($signature_file) { - if (TeXLive::TLUtils::gpg_verify_signature($file, $signature_file)) { - info("cryptographic signature of $url verified\n"); + my ($ret, $out) = gpg_verify_signature($file, $signature_file); + if ($ret) { + # no need to show the output + debug("cryptographic signature of $url verified\n"); + return(0); } else { - return(1, <&1"); if ($ret == 0) { debug("verification succeeded, output:\n$out\n"); - return 1; + return (1, $out); } else { - tlwarn("verification failed, output:\n$out\n"); - return 0; + return (0, $out); } } -- cgit v1.2.3