summaryrefslogtreecommitdiff
path: root/Master/tlpkg/TeXLive/TLCrypto.pm
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2020-02-17 03:23:13 +0000
committerNorbert Preining <preining@logic.at>2020-02-17 03:23:13 +0000
commit4cd4f4003232c8e0e50766507fe129ec5cce8603 (patch)
tree0769905d5da28e5ca269dff42cdad2e2cdb6ae9b /Master/tlpkg/TeXLive/TLCrypto.pm
parent012d70bc65d961edc4646b4ce4c77f7344e0f57d (diff)
refactor verify_checksum return code handling into separate function
git-svn-id: svn://tug.org/texlive/trunk@53820 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/TeXLive/TLCrypto.pm')
-rw-r--r--Master/tlpkg/TeXLive/TLCrypto.pm61
1 files changed, 60 insertions, 1 deletions
diff --git a/Master/tlpkg/TeXLive/TLCrypto.pm b/Master/tlpkg/TeXLive/TLCrypto.pm
index 4db22b7f26d..6027885c1c9 100644
--- a/Master/tlpkg/TeXLive/TLCrypto.pm
+++ b/Master/tlpkg/TeXLive/TLCrypto.pm
@@ -1,6 +1,6 @@
# $Id$
# TeXLive::TLCrypto.pm - handle checksums and signatures.
-# Copyright 2016-2019 Norbert Preining
+# Copyright 2016-2020 Norbert Preining
# This file is licensed under the GNU General Public License version 2
# or any later version.
@@ -34,6 +34,7 @@ C<TeXLive::TLCrypto> -- checksums and cryptographic signatures
TeXLive::TLCrypto::tlchecksum($path);
TeXLive::TLCrypto::verify_checksum($file, $url);
+ TeXLive::TLCrypto::verify_checksum_and_check_return($file, $url);
=head2 Signatures
@@ -52,6 +53,7 @@ BEGIN {
&tlchecksum
&tl_short_digest
&verify_checksum
+ &verify_checksum_and_check_return
&setup_gpg
&verify_signature
%VerificationStatusDescription
@@ -226,6 +228,63 @@ sub tl_short_digest { return (Digest::MD5::md5_hex(shift)); }
# emacs-page
=pod
+=item C<< verify_checksum_and_check_return($file, $tlpdburl [, $is_main, $localcopymode ]) >>
+
+Calls C<<verify_checksum>> and checks the various return values
+for critical errors, and dies if necessary.
+
+If C<$is_main> is given and true, an unsigned tlpdb is considered
+fatal. If C<$localcopymode> is given and true, do not die for
+checksum and connection errors, thus allowing for re-downloading
+of a copy.
+
+=cut
+
+sub verify_checksum_and_check_return {
+ my ($file, $path, $is_main, $localcopymode) = @_;
+ my ($r, $m) = verify_checksum($file, "$path.$ChecksumExtension");
+ if ($r == $VS_CHECKSUM_ERROR) {
+ if (!$localcopymode) {
+ tldie("$0: checksum error when downloading $file from $path: $m\n");
+ }
+ } elsif ($r == $VS_SIGNATURE_ERROR) {
+ tldie("$0: signature verification error of $file from $path: $m\n");
+ } elsif ($r == $VS_CONNECTION_ERROR) {
+ if ($localcopymode) {
+ return(0, $r);
+ } else {
+ tldie("$0: cannot download: $m\n");
+ }
+ } elsif ($r == $VS_UNSIGNED) {
+ if ($is_main) {
+ tldie("$0: main database at $path is not signed: $m\n");
+ }
+ debug("$0: remote database checksum is not signed, continuing anyway: $m\n");
+ return(0, $r);
+ } elsif ($r == $VS_EXPKEYSIG) {
+ debug("$0: good signature bug gpg key expired, continuing anyway!\n");
+ return(0, $r);
+ } elsif ($r == $VS_REVKEYSIG) {
+ debug("$0: good signature but from revoked gpg key, continuing anyway!\n");
+ return(0, $r);
+ } elsif ($r == $VS_GPG_UNAVAILABLE) {
+ debug("$0: TLPDB: no gpg available, continuing anyway!\n");
+ return(0, $r);
+ } elsif ($r == $VS_PUBKEY_MISSING) {
+ debug("$0: TLPDB: pubkey missing, continuing anyway!\n");
+ return(0, $r);
+ } elsif ($r == $VS_VERIFIED) {
+ return(1, $r);
+ } else {
+ tldie("$0: unexpected return value from verify_checksum: $r\n");
+ }
+}
+
+
+
+# emacs-page
+=pod
+
=item C<< verify_checksum($file, $checksum_url) >>
Verifies that C<$file> has checksum C<$checksum_url>, and if gpg is