diff options
author | David Kalnischkies <david@kalnischkies.de> | 2014-10-23 16:54:00 +0200 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2014-10-24 23:54:59 +0200 |
commit | 23397c9d7d4d455461176600bb45c81185493504 (patch) | |
tree | d31bba61b1c04aa66f9a17dca19127dd94d8f65d /test | |
parent | 10e100e59a96ea7b6834a139beab5d9d70180633 (diff) |
promote filesize to a hashstring
It is a very simple hashstring, which is why it isn't contributing to
the usability of a list of them, but it is also trivial to check and
calculate, so it doesn't hurt checking it either as it can combined even
with the simplest other hashes greatly complicate attacks on them as you
suddenly need a same-size hash collision, which is usually a lot harder
to achieve.
Diffstat (limited to 'test')
-rwxr-xr-x | test/integration/test-apt-update-filesize-mismatch | 55 | ||||
-rwxr-xr-x | test/integration/test-apt-update-hashsum-mismatch | 49 | ||||
-rwxr-xr-x | test/integration/test-apt-update-ims | 2 | ||||
-rw-r--r-- | test/interactive-helper/aptwebserver.cc | 4 | ||||
-rw-r--r-- | test/libapt/hashsums_test.cc | 25 |
5 files changed, 127 insertions, 8 deletions
diff --git a/test/integration/test-apt-update-filesize-mismatch b/test/integration/test-apt-update-filesize-mismatch new file mode 100755 index 000000000..8c73c059e --- /dev/null +++ b/test/integration/test-apt-update-filesize-mismatch @@ -0,0 +1,55 @@ +#!/bin/sh +set -e + +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework +setupenvironment +configarchitecture 'i386' +configcompression 'gz' + +insertpackage 'testing' 'foo' 'all' '1' +insertpackage 'testing' 'foo2' 'all' '1' +insertsource 'testing' 'foo' 'all' '1' +insertsource 'testing' 'foo2' 'all' '1' + +setupaptarchive --no-update +changetowebserver + +find aptarchive \( -name 'Packages' -o -name 'Sources' -o -name 'Translation-en' \) -delete +for release in $(find aptarchive -name 'Release'); do + cp "$release" "${release}.backup" +done + +testsuccess aptget update +testsuccess aptcache show foo +testsuccess aptget install foo -s + +for get in $(sed -n 's#^GET /\([^ ]\+\.gz\) HTTP.\+$#\1#p' aptarchive/webserver.log); do + for ext in '' '.gz'; do + COMPRESSFILE="$get" + get="${get}${ext}" + FILE="$(basename -s '.gz' "$get")" + msgmsg 'Test filesize mismatch with file' "$FILE" + rm -rf rootdir/var/lib/apt/lists + + for release in $(find aptarchive -name 'Release'); do + SIZE="$(awk "/$FILE\$/ { print \$2; exit }" "${release}.backup")" + sed "s# $SIZE # $(($SIZE + 111)) #" "${release}.backup" > "$release" + done + signreleasefiles + + TEST='testfailure' + if expr match "$COMPRESSFILE" '^.*Translation-.*$' >/dev/null; then + TEST='testsuccess' + unset COMPRESSFILE + fi + $TEST aptget update -o Debug::pkgAcquire::Worker=1 + cp rootdir/tmp/${TEST}.output rootdir/tmp/update.output + testsuccess grep -E "$(basename -s '.gz' "$COMPRESSFILE").*Hash Sum mismatch" rootdir/tmp/update.output + $TEST aptcache show foo + $TEST aptget install foo -s + + testfailure aptcache show bar + testfailure aptget install bar -s + done +done diff --git a/test/integration/test-apt-update-hashsum-mismatch b/test/integration/test-apt-update-hashsum-mismatch new file mode 100755 index 000000000..747418c53 --- /dev/null +++ b/test/integration/test-apt-update-hashsum-mismatch @@ -0,0 +1,49 @@ +#!/bin/sh +set -e + +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework +setupenvironment +configarchitecture 'i386' +configcompression 'gz' + +insertpackage 'testing' 'foo' 'all' '1' +insertpackage 'testing' 'foo2' 'all' '1' +insertsource 'testing' 'foo' 'all' '1' +insertsource 'testing' 'foo2' 'all' '1' + +setupaptarchive --no-update +changetowebserver + +echo 'Package: bar +Maintainer: Doctor Evil <evil@example.com> +Description: come to the dark side +' > aptarchive/DoctorEvil +compressfile aptarchive/DoctorEvil + +find aptarchive \( -name 'Packages' -o -name 'Sources' -o -name 'Translation-en' \) -delete + +testsuccess aptget update +testsuccess aptcache show foo +testsuccess aptget install foo -s + +for get in $(sed -n 's#^GET /\([^ ]\+\.gz\) HTTP.\+$#\1#p' aptarchive/webserver.log); do + msgmsg 'Test hashsum mismatch with file' "$get" + rm -rf rootdir/var/lib/apt/lists + webserverconfig 'aptwebserver::overwrite' '' + webserverconfig "aptwebserver::overwrite::$(printf '%s' "${get}" | sed 's#/#%2F#g' )::filename" '%2FDoctorEvil.gz' + + TEST='testfailure' + if expr match "$get" '^.*Translation-.*$' >/dev/null; then + TEST='testsuccess' + unset get + fi + $TEST aptget update + cp rootdir/tmp/${TEST}.output rootdir/tmp/update.output + testsuccess grep -E "$(basename -s '.gz' "$get").*Hash Sum mismatch" rootdir/tmp/update.output + $TEST aptcache show foo + $TEST aptget install foo -s + + testfailure aptcache show bar + testfailure aptget install bar -s +done diff --git a/test/integration/test-apt-update-ims b/test/integration/test-apt-update-ims index afae99563..5394a9f30 100755 --- a/test/integration/test-apt-update-ims +++ b/test/integration/test-apt-update-ims @@ -30,7 +30,7 @@ runtest() { # ensure that we still do a hash check on ims hit msgtest 'Test I-M-S' 'reverify' - aptget update -o Debug::pkgAcquire::Auth=1 2>&1 | grep -A1 'RecivedHash:' | grep -q -- '- SHA' && msgpass || msgfail + aptget update -o Debug::pkgAcquire::Auth=1 2>&1 | grep -A2 'RecivedHash:' | grep -q -- '- SHA' && msgpass || msgfail # ensure no leftovers in partial testfailure ls "rootdir/var/lib/apt/lists/partial/*" diff --git a/test/interactive-helper/aptwebserver.cc b/test/interactive-helper/aptwebserver.cc index 7474cf148..00004a524 100644 --- a/test/interactive-helper/aptwebserver.cc +++ b/test/interactive-helper/aptwebserver.cc @@ -499,9 +499,11 @@ static bool parseFirstLine(int const client, std::string const &request,/*{{{*/ return true; } /*}}}*/ -static bool handleOnTheFlyReconfiguration(int const client, std::string const &request, std::vector<std::string> const &parts)/*{{{*/ +static bool handleOnTheFlyReconfiguration(int const client, std::string const &request, std::vector<std::string> parts)/*{{{*/ { size_t const pcount = parts.size(); + for (size_t i = 0; i < pcount; ++i) + parts[i] = DeQuoteString(parts[i]); if (pcount == 4 && parts[1] == "set") { _config->Set(parts[2], parts[3]); diff --git a/test/libapt/hashsums_test.cc b/test/libapt/hashsums_test.cc index 2159996ff..a19a0befd 100644 --- a/test/libapt/hashsums_test.cc +++ b/test/libapt/hashsums_test.cc @@ -163,30 +163,34 @@ TEST(HashSumsTest, FileBased) FileFd fd(__FILE__, FileFd::ReadOnly); EXPECT_TRUE(fd.IsOpen()); + std::string FileSize; + strprintf(FileSize, "%llu", fd.FileSize()); { Hashes hashes; hashes.AddFD(fd.Fd()); HashStringList list = hashes.GetHashStringList(); EXPECT_FALSE(list.empty()); - EXPECT_EQ(4, list.size()); + EXPECT_EQ(5, list.size()); EXPECT_EQ(md5.Value(), list.find("MD5Sum")->HashValue()); EXPECT_EQ(sha1.Value(), list.find("SHA1")->HashValue()); EXPECT_EQ(sha256.Value(), list.find("SHA256")->HashValue()); EXPECT_EQ(sha512.Value(), list.find("SHA512")->HashValue()); + EXPECT_EQ(FileSize, list.find("Checksum-FileSize")->HashValue()); } - unsigned long sz = fd.FileSize(); + unsigned long long sz = fd.FileSize(); fd.Seek(0); { Hashes hashes; hashes.AddFD(fd.Fd(), sz); HashStringList list = hashes.GetHashStringList(); EXPECT_FALSE(list.empty()); - EXPECT_EQ(4, list.size()); + EXPECT_EQ(5, list.size()); EXPECT_EQ(md5.Value(), list.find("MD5Sum")->HashValue()); EXPECT_EQ(sha1.Value(), list.find("SHA1")->HashValue()); EXPECT_EQ(sha256.Value(), list.find("SHA256")->HashValue()); EXPECT_EQ(sha512.Value(), list.find("SHA512")->HashValue()); + EXPECT_EQ(FileSize, list.find("Checksum-FileSize")->HashValue()); } fd.Seek(0); { @@ -279,37 +283,46 @@ TEST(HashSumsTest, HashStringList) EXPECT_EQ(NULL, list.find("")); EXPECT_EQ(NULL, list.find("MD5Sum")); + // empty lists aren't equal HashStringList list2; EXPECT_FALSE(list == list2); EXPECT_TRUE(list != list2); + // some hashes don't really contribute to usability + list.push_back(HashString("Checksum-FileSize", "29")); + EXPECT_FALSE(list.empty()); + EXPECT_FALSE(list.usable()); + Hashes hashes; hashes.Add("The quick brown fox jumps over the lazy dog"); list = hashes.GetHashStringList(); EXPECT_FALSE(list.empty()); EXPECT_TRUE(list.usable()); - EXPECT_EQ(4, list.size()); + EXPECT_EQ(5, list.size()); EXPECT_TRUE(NULL != list.find(NULL)); EXPECT_TRUE(NULL != list.find("")); EXPECT_TRUE(NULL != list.find("MD5Sum")); + EXPECT_TRUE(NULL != list.find("Checksum-FileSize")); EXPECT_TRUE(NULL == list.find("ROT26")); _config->Set("Acquire::ForceHash", "MD5Sum"); EXPECT_FALSE(list.empty()); EXPECT_TRUE(list.usable()); - EXPECT_EQ(4, list.size()); + EXPECT_EQ(5, list.size()); EXPECT_TRUE(NULL != list.find(NULL)); EXPECT_TRUE(NULL != list.find("")); EXPECT_TRUE(NULL != list.find("MD5Sum")); + EXPECT_TRUE(NULL != list.find("Checksum-FileSize")); EXPECT_TRUE(NULL == list.find("ROT26")); _config->Set("Acquire::ForceHash", "ROT26"); EXPECT_FALSE(list.empty()); EXPECT_FALSE(list.usable()); - EXPECT_EQ(4, list.size()); + EXPECT_EQ(5, list.size()); EXPECT_TRUE(NULL == list.find(NULL)); EXPECT_TRUE(NULL == list.find("")); EXPECT_TRUE(NULL != list.find("MD5Sum")); + EXPECT_TRUE(NULL != list.find("Checksum-FileSize")); EXPECT_TRUE(NULL == list.find("ROT26")); _config->Clear("Acquire::ForceHash"); |