X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/03aa08472dcd689572a46ce6efdb1dccf6136334..68151307d42ed64cd6258f94a0d748abe9efb8e0:/test/integration/test-apt-update-nofallback diff --git a/test/integration/test-apt-update-nofallback b/test/integration/test-apt-update-nofallback index e82a976a6..60f329a4a 100755 --- a/test/integration/test-apt-update-nofallback +++ b/test/integration/test-apt-update-nofallback @@ -8,14 +8,14 @@ set -e simulate_mitm_and_inject_evil_package() { - rm -f $APTARCHIVE/dists/unstable/InRelease - rm -f $APTARCHIVE/dists/unstable/Release.gpg + redatereleasefiles '+1 hour' + rm -f "$APTARCHIVE/dists/unstable/InRelease" "$APTARCHIVE/dists/unstable/Release.gpg" inject_evil_package } inject_evil_package() { - cat > $APTARCHIVE/dists/unstable/main/binary-i386/Packages < "$APTARCHIVE/dists/unstable/main/binary-i386/Packages" < @@ -27,28 +27,27 @@ Description: an autogenerated evil package EOF # avoid ims hit touch -d '+1hour' aptarchive/dists/unstable/main/binary-i386/Packages + compressfile aptarchive/dists/unstable/main/binary-i386/Packages } assert_update_is_refused_and_last_good_state_used() { - testequal "E: The repository 'file: unstable Release.gpg' is no longer signed." aptget update -qq + testfailuremsg "E: The repository 'file:${APTARCHIVE} unstable Release' is no longer signed. +N: Updating from such a repository can't be done securely, and is therefore disabled by default. +N: See apt-secure(8) manpage for repository creation and user configuration details." aptget update assert_repo_is_intact } assert_repo_is_intact() { - testequal "foo/unstable 2.0 all" apt list -q + testsuccessequal "foo/unstable 2.0 all" apt list -qq testsuccess aptget install -y -s foo testfailure aptget install -y evil testsuccess aptget source foo --print-uris LISTDIR=rootdir/var/lib/apt/lists - if ! ( ls $LISTDIR/*InRelease >/dev/null 2>&1 || - ls $LISTDIR/*Release.gpg >/dev/null 2>&1 ); then - echo "Can not find InRelease/Release.gpg in $(ls $LISTDIR)" - msgfail - fi + testempty find "$LISTDIR" -name 'InRelease' -o -name 'Release.gpg' } setupaptarchive_with_lists_clean() @@ -59,7 +58,7 @@ setupaptarchive_with_lists_clean() test_from_inrelease_to_unsigned() { - # setup archive with InRelease file + export APT_DONT_SIGN='Release.gpg' setupaptarchive_with_lists_clean testsuccess aptget update listcurrentlistsdirectory > lists.before @@ -71,9 +70,8 @@ test_from_inrelease_to_unsigned() test_from_release_gpg_to_unsigned() { - # setup archive with Release/Release.gpg (but no InRelease) + export APT_DONT_SIGN='InRelease' setupaptarchive_with_lists_clean - rm $APTARCHIVE/dists/unstable/InRelease testsuccess aptget update listcurrentlistsdirectory > lists.before @@ -83,23 +81,54 @@ test_from_release_gpg_to_unsigned() } test_from_inrelease_to_unsigned_with_override() +{ + export APT_DONT_SIGN='Release.gpg' + # setup archive with InRelease file + setupaptarchive_with_lists_clean + testsuccess aptget update + + # simulate moving to a unsigned but otherwise valid repo + simulate_mitm_and_inject_evil_package + generatereleasefiles '+2 hours' + find "$APTARCHIVE" -name '*Packages*' -exec touch -d '+2 hours' {} \; + + # and ensure we can update to it (with enough force) + testfailure apt update + testfailure aptget update + testfailure aptget update --allow-insecure-repositories + testfailure aptget update --no-allow-insecure-repositories + sed -i 's#^deb\(-src\)\? #deb\1 [allow-downgrade-to-insecure=yes] #' rootdir/etc/apt/sources.list.d/* + testfailure aptget update --no-allow-insecure-repositories + testfailure apt update + testwarning apt update --allow-insecure-repositories \ + -o Debug::pkgAcquire::Worker=1 -o Debug::pkgAcquire::Auth=1 + sed -i 's#^deb\(-src\)\? \[allow-downgrade-to-insecure=yes\] #deb\1 #' rootdir/etc/apt/sources.list.d/* + # but that the individual packages are still considered untrusted + testfailureequal "WARNING: The following packages cannot be authenticated! + evil +E: There were unauthenticated packages and -y was used without --allow-unauthenticated" aptget install -qq -y evil +} + +test_from_inrelease_to_norelease_with_override() { # setup archive with InRelease file setupaptarchive_with_lists_clean - # FIXME: is not what the server reported 4104 4106 - testsuccess aptget update #-o Debug::pkgAcquire::Worker=1 + testsuccess aptget update # simulate moving to a unsigned but otherwise valid repo simulate_mitm_and_inject_evil_package - generatereleasefiles + find "$APTARCHIVE" -name '*Release*' -delete + find "$APTARCHIVE" -name '*Packages*' -exec touch -d '+2 hours' {} \; # and ensure we can update to it (with enough force) + testfailure aptget update + testfailure aptget update --allow-insecure-repositories testwarning aptget update --allow-insecure-repositories \ - -o Acquire::AllowDowngradeToInsecureRepositories=1 + -o Acquire::AllowDowngradeToInsecureRepositories=1 -o Debug::pkgAcquire::Worker=1 -o Debug::pkgAcquire::Auth=1 # but that the individual packages are still considered untrusted - testequal "WARNING: The following packages cannot be authenticated! + testfailureequal "WARNING: The following packages cannot be authenticated! evil -E: There are problems and -y was used without --force-yes" aptget install -qq -y evil +E: There were unauthenticated packages and -y was used without --allow-unauthenticated" aptget install -qq -y evil } test_cve_2012_0214() @@ -113,24 +142,23 @@ test_cve_2012_0214() # the unauthenticated Release file too giving the false impression that # Release was authenticated # - # Note that this is pretty much impossible nowdays because: + # Note that this is pretty much impossible nowadays because: # a) InRelease is left as is, not split to InRelease/Release as it was # in the old days # b) we refuse to go from signed->unsigned # # Still worth having a regression test the simulates the condition - # setup archive with InRelease + export APT_DONT_SIGN='Release.gpg' setupaptarchive_with_lists_clean testsuccess aptget update listcurrentlistsdirectory > lists.before # do what CVE-2012-0214 did - rm $APTARCHIVE/dists/unstable/InRelease - rm $APTARCHIVE/dists/unstable/Release.gpg + rm -f "$APTARCHIVE/dists/unstable/InRelease" "$APTARCHIVE/dists/unstable/Release.gpg" inject_evil_package # build valid Release file - aptftparchive -qq release ./aptarchive > aptarchive/dists/unstable/Release + aptftparchive -qq release ./aptarchive > aptarchive/dists/unstable/Release assert_update_is_refused_and_last_good_state_used testfileequal lists.before "$(listcurrentlistsdirectory)" @@ -141,17 +169,16 @@ test_cve_2012_0214() test_subvert_inrelease() { - # setup archive with InRelease + export APT_DONT_SIGN='Release.gpg' setupaptarchive_with_lists_clean testsuccess aptget update listcurrentlistsdirectory > lists.before # replace InRelease with something else - mv $APTARCHIVE/dists/unstable/Release $APTARCHIVE/dists/unstable/InRelease + mv "$APTARCHIVE/dists/unstable/Release" "$APTARCHIVE/dists/unstable/InRelease" - testequal "W: Failed to fetch file:${APTARCHIVE}/dists/unstable/InRelease Does not start with a cleartext signature - -E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq + testfailuremsg "E: Failed to fetch file:${APTARCHIVE}/dists/unstable/InRelease Clearsigned file isn't valid, got 'NOSPLIT' (does the network require authentication?) +E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update # ensure we keep the repo testfileequal lists.before "$(listcurrentlistsdirectory)" @@ -160,19 +187,17 @@ E: Some index files failed to download. They have been ignored, or old ones used test_inrelease_to_invalid_inrelease() { - # setup archive with InRelease + export APT_DONT_SIGN='Release.gpg' setupaptarchive_with_lists_clean testsuccess aptget update listcurrentlistsdirectory > lists.before # now remove InRelease and subvert Release do no longer verify - sed -i 's/Codename.*/Codename: evil!'/ $APTARCHIVE/dists/unstable/InRelease + sed -i 's/^Codename:.*/Codename: evil!/' "$APTARCHIVE/dists/unstable/InRelease" inject_evil_package - testequal "W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: file: unstable InRelease: The following signatures were invalid: BADSIG 5A90D141DBAC8DAE Joe Sixpack (APT Testcases Dummy) - + testwarningequal "W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: file:${APTARCHIVE} unstable InRelease: The following signatures were invalid: BADSIG 5A90D141DBAC8DAE Joe Sixpack (APT Testcases Dummy) W: Failed to fetch file:${APTARCHIVE}/dists/unstable/InRelease The following signatures were invalid: BADSIG 5A90D141DBAC8DAE Joe Sixpack (APT Testcases Dummy) - W: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq # ensure we keep the repo @@ -183,20 +208,17 @@ W: Some index files failed to download. They have been ignored, or old ones used test_release_gpg_to_invalid_release_release_gpg() { - # setup archive with InRelease + export APT_DONT_SIGN='InRelease' setupaptarchive_with_lists_clean - rm $APTARCHIVE/dists/unstable/InRelease testsuccess aptget update listcurrentlistsdirectory > lists.before # now subvert Release do no longer verify - echo "Some evil data" >> $APTARCHIVE/dists/unstable/Release + echo "Some evil data" >> "$APTARCHIVE/dists/unstable/Release" inject_evil_package - testequal "W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: file: unstable Release.gpg: The following signatures were invalid: BADSIG 5A90D141DBAC8DAE Joe Sixpack (APT Testcases Dummy) - + testwarningequal "W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: file:${APTARCHIVE} unstable Release: The following signatures were invalid: BADSIG 5A90D141DBAC8DAE Joe Sixpack (APT Testcases Dummy) W: Failed to fetch file:${APTARCHIVE}/dists/unstable/Release.gpg The following signatures were invalid: BADSIG 5A90D141DBAC8DAE Joe Sixpack (APT Testcases Dummy) - W: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq testfailure grep 'evil' rootdir/var/lib/apt/lists/*Release @@ -205,8 +227,8 @@ W: Some index files failed to download. They have been ignored, or old ones used } -TESTDIR=$(readlink -f $(dirname $0)) -. $TESTDIR/framework +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "$TESTDIR/framework" setupenvironment configarchitecture "i386" @@ -216,7 +238,7 @@ buildsimplenativepackage 'foo' 'all' '2.0' # setup the archive and ensure we have a single package that installs fine setupaptarchive -APTARCHIVE=$(readlink -f ./aptarchive) +APTARCHIVE="$(readlink -f ./aptarchive)" assert_repo_is_intact # test the various cases where a repo may go from signed->unsigned @@ -230,7 +252,7 @@ test_from_release_gpg_to_unsigned msgmsg "test_cve_2012_0214" test_cve_2012_0214 -# ensure InRelase can not be subverted +# ensure InRelease can not be subverted msgmsg "test_subvert_inrelease" test_subvert_inrelease @@ -245,3 +267,5 @@ test_release_gpg_to_invalid_release_release_gpg # ensure we can override the downgrade error msgmsg "test_from_inrelease_to_unsigned_with_override" test_from_inrelease_to_unsigned_with_override +msgmsg "test_from_inrelease_to_norelease_with_override" +test_from_inrelease_to_norelease_with_override