texlive[45286] Master: crypto: use symbolic constants, require

commits+preining at tug.org commits+preining at tug.org
Wed Sep 13 03:55:27 CEST 2017


Revision: 45286
          http://tug.org/svn/texlive?view=revision&revision=45286
Author:   preining
Date:     2017-09-13 03:55:27 +0200 (Wed, 13 Sep 2017)
Log Message:
-----------
crypto: use symbolic constants, require verification of main tlpdb

Modified Paths:
--------------
    trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl
    trunk/Master/tlpkg/TeXLive/TLCrypto.pm
    trunk/Master/tlpkg/TeXLive/TLPDB.pm

Modified: trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl
===================================================================
--- trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl	2017-09-13 00:21:32 UTC (rev 45285)
+++ trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl	2017-09-13 01:55:27 UTC (rev 45286)
@@ -6454,7 +6454,7 @@
   my $verstat = "";
   if (!$remotetlpdb->virtual_get_tlpdb('main')->is_verified) {
     $verstat = ": ";
-    $verstat .= $remotetlpdb->virtual_get_tlpdb('main')->verification_status;
+    $verstat .= $VerificationStatusDescription{$remotetlpdb->virtual_get_tlpdb('main')->verification_status};
   }
   info("\tmain = " . $repos{'main'} . " (" . 
     ($remotetlpdb->virtual_get_tlpdb('main')->is_verified ? "" : "not ") .
@@ -6464,7 +6464,7 @@
       $verstat = "";
       if (!$remotetlpdb->virtual_get_tlpdb($t)->is_verified) {
         $verstat = ": ";
-        $verstat .= $remotetlpdb->virtual_get_tlpdb($t)->verification_status;
+        $verstat .= $VerificationStatusDescription{$remotetlpdb->virtual_get_tlpdb($t)->verification_status};
       }
       info("\t$t = " . $repos{$t} . " (" .
         ($remotetlpdb->virtual_get_tlpdb($t)->is_verified ? "" : "not ") .
@@ -6511,7 +6511,7 @@
     my $verstat = "";
     if (!$remotetlpdb->is_verified) {
       $verstat = ": ";
-      $verstat .= $remotetlpdb->verification_status;
+      $verstat .= $VerificationStatusDescription{$remotetlpdb->verification_status};
     }
     info("$prg: package repository $location (" . 
       ($remotetlpdb->is_verified ? "" : "not ") . "verified$verstat)\n");
@@ -6561,7 +6561,7 @@
 
       my ($ret,$msg)
         = TeXLive::TLCrypto::verify_checksum($loc_copy_of_remote_tlpdb, $path);
-      if ($ret == -1) {
+      if ($ret == $VS_CONNECTION_ERROR) {
         info(<<END_NO_INTERNET);
 No connection to the internet.
 Unable to download the checksum of the remote TeX Live database,
@@ -6577,23 +6577,28 @@
         $remotetlpdb = TeXLive::TLPDB->new(root => $location,
           tlpdbfile => $loc_copy_of_remote_tlpdb);
         $local_copy_tlpdb_used = 1;
-      } elsif ($ret == -2) {
+      } elsif ($ret == $VS_UNSIGNED) {
+        # we require the main database to be signed, but allow for
+        # subsidiary to be unsigned
+        if ($is_main) {
+          tldie("$prg: main database at $location is not signed: $msg\n");
+        }
         # the remote database has not be signed, warn
         debug("$prg: remote database is not signed, continuing anyway!\n");
-      } elsif ($ret == -3) {
+      } elsif ($ret == $VS_GPG_UNAVAILABLE) {
         # no gpg available
         debug("$prg: no gpg available for verification, continuing anyway!\n");
-      } elsif ($ret == -4) {
+      } elsif ($ret == $VS_PUBKEY_MISSING) {
         # pubkey missing
         debug("$prg: $msg, continuing anyway!\n");
-      } elsif ($ret == 1) {
+      } elsif ($ret == $VS_CHECKSUM_ERROR) {
         # no problem, checksum is wrong, we need to get new tlpdb
-      } elsif ($ret == 2) {
+      } elsif ($ret == $VS_SIGNATURE_ERROR) {
         # umpf, signature error
         # TODO should we die here? Probably yes because one of 
         # checksum file or signature file has changed!
         tldie("$prg: verification of checksum for $location failed: $msg\n");
-      } elsif ($ret == 0) {
+      } elsif ($ret == $VS_VERIFIED) {
         $remotetlpdb = TeXLive::TLPDB->new(root => $location,
           tlpdbfile => $loc_copy_of_remote_tlpdb);
         $local_copy_tlpdb_used = 1;
@@ -6606,6 +6611,12 @@
   }
   if (!$local_copy_tlpdb_used) {
     $remotetlpdb = TeXLive::TLPDB->new(root => $location, verify => 1);
+    if ($is_main) {
+      if ($remotetlpdb->verification_status == $VS_UNSIGNED) {
+        # we don't allow unsigned main data bases!
+        tldie("$prg: main database at $location is not signed\n");
+      }
+    }
   }
   if (!defined($remotetlpdb)) {
     return(undef, $loadmediasrcerror . $location);

Modified: trunk/Master/tlpkg/TeXLive/TLCrypto.pm
===================================================================
--- trunk/Master/tlpkg/TeXLive/TLCrypto.pm	2017-09-13 00:21:32 UTC (rev 45285)
+++ trunk/Master/tlpkg/TeXLive/TLCrypto.pm	2017-09-13 01:55:27 UTC (rev 45286)
@@ -12,7 +12,7 @@
 use TeXLive::TLUtils qw(debug ddebug win32 which platform conv_to_w32_path tlwarn tldie);
 
 
-my $svnrev = '$Revision: 40650 $';
+my $svnrev = '$Revision$';
 my $_modulerevision = ($svnrev =~ m/: ([0-9]+) /) ? $1 : "unknown";
 sub module_revision { return $_modulerevision; }
 
@@ -54,7 +54,15 @@
     &verify_checksum
     &setup_gpg
     &verify_signature
+    %VerificationStatusDescription
+    $VS_VERIFIED $VS_CHECKSUM_ERROR $VS_SIGNATURE_ERROR $VS_CONNECTION_ERROR
+    $VS_UNSIGNED $VS_GPG_UNAVAILABLE $VS_PUBKEY_MISSING $VS_UNKNOWN
   );
+  @EXPORT = qw(
+    %VerificationStatusDescription
+    $VS_VERIFIED $VS_CHECKSUM_ERROR $VS_SIGNATURE_ERROR $VS_CONNECTION_ERROR
+    $VS_UNSIGNED $VS_GPG_UNAVAILABLE $VS_PUBKEY_MISSING $VS_UNKNOWN
+  );
 }
 
 =pod
@@ -216,9 +224,14 @@
 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, -2 on missing signature
-file, -3 if no gpg program is available, -4 if the pubkey is not
-available,  1 on checksum errors, and 2 on signature errors.
+Returns 
+C<$VS_VERIFIED> on success, 
+C<$VS_CONNECTION_ERROR> on connection error,
+C<$VS_UNSIGNED> on missing signature file, 
+C<$VS_GPG_UNAVAILABLE> if no gpg program is available,
+C<$VS_PUBKEY_MISSING> if the pubkey is not available, 
+C<$VS_CHECKSUM_ERROR> on checksum errors,and 
+C<$VS_SIGNATURE_ERROR> on signature errors.
 In case of errors returns an informal message as second argument.
 
 =cut
@@ -227,7 +240,7 @@
   my ($file, $checksum_url) = @_;
   # don't do anything if we cannot determine a checksum method
   # return -2 which is as much as missing signature
-  return(-2) if (!$::checksum_method);
+  return($VS_UNSIGNED) if (!$::checksum_method);
   my $checksum_file
     = TeXLive::TLUtils::download_to_temp_or_file($checksum_url);
 
@@ -234,7 +247,7 @@
   # next step is verification of tlpdb checksum with checksum file
   # existenc of checksum_file was checked above
   if (!$checksum_file) {
-    return(-1, "download did not succeed: $checksum_url");
+    return($VS_CONNECTION_ERROR, "download did not succeed: $checksum_url");
   }
   # check the signature
   my ($ret, $msg) = verify_signature($checksum_file, $checksum_url);
@@ -244,7 +257,7 @@
   open $cs_fh, "<$checksum_file" or die("cannot read file: $!");
   if (read ($cs_fh, $remote_digest, $ChecksumLength) != $ChecksumLength) {
     close($cs_fh);
-    return(1, "incomplete read from $checksum_file");
+    return($VS_CHECKSUM_ERROR, "incomplete read from $checksum_file");
   } else {
     close($cs_fh);
     ddebug("found remote digest: $remote_digest\n");
@@ -252,7 +265,7 @@
   $local_digest = tlchecksum($file);
   ddebug("local_digest = $local_digest\n");
   if ($local_digest ne $remote_digest) {
-    return(1, "digest disagree");
+    return($VS_CHECKSUM_ERROR, "digest disagree");
   }
 
   # we are still here, so checksum also succeeded
@@ -378,8 +391,12 @@
 Verifies a download of C<$url> into C<$file> by cheking the 
 gpg signature in C<$url.asc>.
 
-Returns 0 on success, -2 on missing signature file, 2 on signature error,
--3 if no gpg is available, and -4 if a pubkey is missing.
+Returns 
+$VS_VERIFIED on success, 
+$VS_UNSIGNED on missing signature file, 
+$VS_SIGNATURE_ERROR on signature error,
+$VS_GPG_UNAVAILABLE if no gpg is available, and 
+$VS_PUBKEY_MISSING if a pubkey is missing.
 In case of errors returns an informal message as second argument.
 
 =cut
@@ -397,11 +414,11 @@
       if ($ret == 1) {
         # no need to show the output
         debug("cryptographic signature of $url verified\n");
-        return(0);
+        return($VS_VERIFIED);
       } elsif ($ret == -1) {
-        return(-4, $out);
+        return($VS_PUBKEY_MISSING, $out);
       } else {
-        return(2, <<GPGERROR);
+        return($VS_SIGNATURE_ERROR, <<GPGERROR);
 cryptographic signature verification of
   $file
 against
@@ -413,15 +430,15 @@
       }
     } else {
       debug("no access to cryptographic signature $signature_url\n");
-      return(-2, "no access to cryptographic signature");
+      return($VS_UNSIGNED, "no access to cryptographic signature");
     }
   } else {
     debug("gpg prog not defined, no checking of signatures\n");
     # we return 0 (= success) if not gpg is available
-    return(-3, "no gpg available");
+    return($VS_GPG_UNAVAILABLE, "no gpg available");
   }
   # not reached
-  return (0);
+  return ($VS_UNKNOWN);
 }
 
 =pod
@@ -461,6 +478,34 @@
   }
 }
 
+=pod
+
+=item C<< %VerificationStatusDescription >>
+
+Provides a textual representation for the verification status values.
+
+=cut
+
+our $VS_VERIFIED = 0;
+our $VS_CHECKSUM_ERROR = 1;
+our $VS_SIGNATURE_ERROR = 2;
+our $VS_CONNECTION_ERROR = -1;
+our $VS_UNSIGNED = -2;
+our $VS_GPG_UNAVAILABLE = -3;
+our $VS_PUBKEY_MISSING = -4;
+our $VS_UNKNOWN = -100;
+
+our %VerificationStatusDescription = (
+  $VS_VERIFIED         => 'verified',
+  $VS_CHECKSUM_ERROR   => 'checksum error',
+  $VS_SIGNATURE_ERROR  => 'signature error',
+  $VS_CONNECTION_ERROR => 'connection error',
+  $VS_UNSIGNED         => 'unsigned',
+  $VS_GPG_UNAVAILABLE  => 'gpg unavailable',
+  $VS_PUBKEY_MISSING   => 'pubkey missing',
+  $VS_UNKNOWN          => 'unknown',
+);
+
 =back
 =cut
 

Modified: trunk/Master/tlpkg/TeXLive/TLPDB.pm
===================================================================
--- trunk/Master/tlpkg/TeXLive/TLPDB.pm	2017-09-13 00:21:32 UTC (rev 45285)
+++ trunk/Master/tlpkg/TeXLive/TLPDB.pm	2017-09-13 01:55:27 UTC (rev 45286)
@@ -271,7 +271,7 @@
   } else {
     $self->root($root_from_path);
   }
-  $self->verification_status("unknown");
+  $self->verification_status($VS_UNKNOWN);
   my $retfh;
   my $tlpdbfile;
   my $is_verified = 0;
@@ -367,24 +367,24 @@
     # before we open and proceed, verify the downloaded file
     if ($params{'verify'} && $media ne 'local_uncompressed') {
       my ($r, $m) = TeXLive::TLCrypto::verify_checksum($tlpdbfile, "$path.$TeXLive::TLConfig::ChecksumExtension");
-      if ($r == 1) {
+      if ($r == $VS_CHECKSUM_ERROR) {
         tldie("$0: checksum error when downloading $tlpdbfile from $path: $m\n");
-      } elsif ($r == 2) {
+      } elsif ($r == $VS_SIGNATURE_ERROR) {
         tldie("$0: signature verification error of $tlpdbfile from $path: $m\n");
-      } elsif ($r == -1) {
+      } elsif ($r == $VS_CONNECTION_ERROR) {
         tldie("$0: cannot download: $m\n");
-      } elsif ($r == -2) {
+      } elsif ($r == $VS_UNSIGNED) {
         debug("$0: remote database checksum is not signed, continuing anyway!\n");
-        $self->verification_status("not signed");
-      } elsif ($r == -3) {
+        $self->verification_status($r);
+      } elsif ($r == $VS_GPG_UNAVAILABLE) {
         debug("$0: TLPDB: no gpg available, continuing anyway!\n");
-        $self->verification_status("gnupg not available");
-      } elsif ($r == -4) {
+        $self->verification_status($r);
+      } elsif ($r == $VS_PUBKEY_MISSING) {
         debug("$0: TLPDB: pubkey missing, continuing anyway!\n");
-        $self->verification_status("pubkey missing");
-      } elsif ($r == 0) {
+        $self->verification_status($r);
+      } elsif ($r == $VS_VERIFIED) {
         $is_verified = 1;
-        $self->verification_status("verified");
+        $self->verification_status($r);
       } else {
         tldie("$0: unexpected return value from verify_checksum: $r\n");
       }
@@ -393,23 +393,24 @@
   } else {
     if ($params{'verify'} && $media ne 'local_uncompressed') {
       my ($r, $m) = TeXLive::TLCrypto::verify_checksum($path, "$path.$TeXLive::TLConfig::ChecksumExtension");
-      if ($r == 1) {
+      if ($r == $VS_CHECKSUM_ERROR) {
         tldie("$0: checksum error when downloading $path from $path: $m\n");
-      } elsif ($r == 2) {
+      } elsif ($r == $VS_SIGNATURE_ERROR) {
         tldie("$0: signature verification error of $path from $path: $m\n");
-      } elsif ($r == -1) {
+      } elsif ($r == $VS_CONNECTION_ERROR) {
         tldie("$0: cannot download: $m\n");
-      } elsif ($r == -2) {
+      } elsif ($r == $VS_UNSIGNED) {
         debug("$0: remote database checksum is not signed, continuing anyway!\n");
-        $self->verification_status("not signed");
-      } elsif ($r == -3) {
+        $self->verification_status($r);
+      } elsif ($r == $VS_GPG_UNAVAILABLE) {
         debug("$0: TLPDB: no gpg available, continuing anyway!\n");
-        $self->verification_status("gnupg not available");
-      } elsif ($r == -4) {
+        $self->verification_status($r);
+      } elsif ($r == $VS_PUBKEY_MISSING) {
         debug("$0: TLPDB: pubkey missing, continuing anyway!\n");
-        $self->verification_status("pubkey missing");
-      } elsif ($r == 0) {
+        $self->verification_status($r);
+      } elsif ($r == $VS_VERIFIED) {
         $is_verified = 1;
+        $self->verification_status($r);
       } else {
         tldie("$0: unexpected return value from verify_checksum: $r\n");
       }
@@ -1174,8 +1175,8 @@
 
 =item C<< $tlpdb->verification_status >>
 
-Returns a short textual explanation of the verification status. 
-In particular if the database is not verified, it returns the reason.
+Returns the id of the verification status. To obtain a textual representation
+us %TLCrypto::VerificationStatusDescription.
 
 =cut
 



More information about the tex-live-commits mailing list