summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2018-07-03 22:24:07 +0000
committerNorbert Preining <preining@logic.at>2018-07-03 22:24:07 +0000
commitb6fe6b6d79b6718277703e8a821bf65cd637049a (patch)
tree1549e39dafe90a53f8c9196a5c27358de36de9a0
parent811efe80bf8a88d2f9649a5d20a83c41744339a6 (diff)
more detailed error checking during signature verification
git-svn-id: svn://tug.org/texlive/trunk@48130 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/tlpkg/TeXLive/TLCrypto.pm31
-rw-r--r--Master/tlpkg/TeXLive/TLPDB.pm2
-rw-r--r--Master/tlpkg/TeXLive/TLUtils.pm3
3 files changed, 34 insertions, 2 deletions
diff --git a/Master/tlpkg/TeXLive/TLCrypto.pm b/Master/tlpkg/TeXLive/TLCrypto.pm
index 07b67ad6654..66da491b5dc 100644
--- a/Master/tlpkg/TeXLive/TLCrypto.pm
+++ b/Master/tlpkg/TeXLive/TLCrypto.pm
@@ -252,6 +252,17 @@ sub verify_checksum {
debug("verify_checksum: download did not succeed for $checksum_url\n");
return($VS_CONNECTION_ERROR, "download did not succeed: $checksum_url");
}
+
+ # check that we have a non-trivial size for the checksum file
+ # the size should be at least 128 + 1 + length(filename) > 129
+ {
+ my $css = -s $checksum_file;
+ if ($css <= 128) {
+ debug("verify_checksum: size of checksum file suspicious: $css\n");
+ return($VS_CONNECTION_ERROR, "download corrupted: $checksum_url");
+ }
+ }
+
# check the signature
my ($ret, $msg) = verify_signature($checksum_file, $checksum_url);
@@ -418,6 +429,26 @@ sub verify_signature {
my $signature_file
= TeXLive::TLUtils::download_to_temp_or_file($signature_url);
if ($signature_file) {
+ {
+ # we expect a signature to be at least
+ # 30 header line + 30 footer line + 256 > 300
+ my $sigsize = -s $signature_file;
+ if ($sigsize < 300) {
+ debug("cryptographic signature seems to be corrupted (size $sigsize<300): $signature_url, $signature_file\n");
+ return($VS_UNSIGNED, "cryptographic signature download seems to be corrupted (size $sigsize<300)");
+ }
+ }
+ # check also the first line of the signature file for
+ # -----BEGIN PGP SIGNATURE-----
+ {
+ open my $file, '<', $signature_file;
+ chomp(my $firstLine = <$file>);
+ close $file;
+ if ($firstLine !~ m/^-----BEGIN PGP SIGNATURE-----/) {
+ debug("cryptographic signature seems to be corrupted (first line not signature): $signature_url, $signature_file, $firstLine\n");
+ return($VS_UNSIGNED, "cryptographic signature download seems to be corrupted (first line of $signature_url not signature: $firstLine)");
+ }
+ }
my ($ret, $out) = gpg_verify_signature($file, $signature_file);
if ($ret == 1) {
# no need to show the output
diff --git a/Master/tlpkg/TeXLive/TLPDB.pm b/Master/tlpkg/TeXLive/TLPDB.pm
index 07ad80c6169..25423f1a7b4 100644
--- a/Master/tlpkg/TeXLive/TLPDB.pm
+++ b/Master/tlpkg/TeXLive/TLPDB.pm
@@ -370,7 +370,7 @@ sub from_file {
} elsif ($r == $VS_CONNECTION_ERROR) {
tldie("$0: cannot download: $m\n");
} elsif ($r == $VS_UNSIGNED) {
- debug("$0: remote database checksum is not signed, continuing anyway!\n");
+ debug("$0: remote database checksum is not signed, continuing anyway: $m\n");
$self->verification_status($r);
} elsif ($r == $VS_GPG_UNAVAILABLE) {
debug("$0: TLPDB: no gpg available, continuing anyway!\n");
diff --git a/Master/tlpkg/TeXLive/TLUtils.pm b/Master/tlpkg/TeXLive/TLUtils.pm
index 48606687501..c4d21e26cb9 100644
--- a/Master/tlpkg/TeXLive/TLUtils.pm
+++ b/Master/tlpkg/TeXLive/TLUtils.pm
@@ -3908,7 +3908,8 @@ sub slurp_file {
=item C<< download_to_temp_or_file($url) >>
-If C<$url> tries to download the file into a temporary file.
+If C<$url> is a url, tries to download the file into a temporary file.
+Otherwise assume that C<$url> is a local file.
In both cases returns the local file.
Returns the local file name if succeeded, otherwise undef.