test-apt-update-stale 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/sh
  2. #
  3. # Ensure that a MITM can not stale the Packages/Sources without
  4. # raising a error message. Note that the Release file is protected
  5. # via the "Valid-Until" header
  6. #
  7. set -e
  8. TESTDIR="$(readlink -f "$(dirname "$0")")"
  9. . "$TESTDIR/framework"
  10. setupenvironment
  11. configarchitecture "i386"
  12. insertpackage 'unstable' 'foo' 'i386' '1.0'
  13. setupaptarchive --no-update
  14. changetowebserver
  15. echo "Acquire::Languages \"none\";" > rootdir/etc/apt/apt.conf.d/00nolanguages
  16. testsuccess aptget update -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::http=1
  17. listcurrentlistsdirectory > lists.before
  18. # insert new version
  19. mkdir aptarchive/dists/unstable/main/binary-i386/saved
  20. cp -p aptarchive/dists/unstable/main/binary-i386/Packages* \
  21. aptarchive/dists/unstable/main/binary-i386/saved
  22. insertpackage 'unstable' 'foo' 'i386' '2.0'
  23. touch -d '+1 hour' aptarchive/dists/unstable/main/binary-i386/Packages
  24. compressfile aptarchive/dists/unstable/main/binary-i386/Packages
  25. # ensure that we do not get a I-M-S hit for the Release file
  26. generatereleasefiles '+1hour'
  27. signreleasefiles
  28. # but now only deliver the previous Packages file instead of the new one
  29. # (simulating a stale attack)
  30. cp -p aptarchive/dists/unstable/main/binary-i386/saved/Packages* \
  31. aptarchive/dists/unstable/main/binary-i386/
  32. # ensure this raises an error
  33. testfailuremsg "E: Failed to fetch http://localhost:${APTHTTPPORT}/dists/unstable/main/binary-i386/Packages.gz Hash Sum mismatch
  34. E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::http=1
  35. testfileequal lists.before "$(listcurrentlistsdirectory)"