test-inrelease-verification-fail 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/sh
  2. set -e
  3. TESTDIR=$(readlink -f $(dirname $0))
  4. . $TESTDIR/framework
  5. setupenvironment
  6. configarchitecture "i386"
  7. buildsimplenativepackage 'good-pkg' 'all' '1.0' 'stable'
  8. setupaptarchive
  9. # now exchange to the Packages file, note that this could be
  10. # done via MITM too
  11. cat > aptarchive/dists/stable/main/binary-i386/Packages <<EOF
  12. Package: bad-mitm
  13. Installed-Size: 108
  14. Architecture: all
  15. Version: 0.5-3
  16. Filename: pool/bad-mitm.deb
  17. Size: 14348
  18. SHA256: e9b9a3859940c5882b35d56c0097667e552d87b662778c2c451fe6db657b0519
  19. Description: Evil package
  20. EOF
  21. for pair in "gzip:gz" "bzip2:bz2" "lzma:lzma" "xz:xz"; do
  22. compressor=$(echo $pair|cut -f1 -d:)
  23. extension=$(echo $pair|cut -f2 -d:)
  24. $compressor -c aptarchive/dists/stable/main/binary-i386/Packages > aptarchive/dists/stable/main/binary-i386/Packages.$extension
  25. done
  26. # add a space into the BEGIN PGP SIGNATURE PART/END PGP SIGNATURE part
  27. # to trick apt - this is still legal to gpg(v)
  28. sed -i '/^-----BEGIN PGP SIGNATURE-----/,/^-----END PGP SIGNATURE-----/ s/^$/ /g' aptarchive/dists/stable/InRelease
  29. # and append our own hashes for the modified Packages files
  30. cat >> aptarchive/dists/stable/InRelease <<EOF
  31. Origin: Ansgar
  32. Codename: evilevil
  33. Suite: stable
  34. Date: Sun, 03 Jun 2012 13:26:11 UTC
  35. Architectures: i386
  36. Components: main
  37. SHA512:
  38. EOF
  39. for comp in "" ".gz" ".bz2" ".xz" ".lzma"; do
  40. # Packages
  41. s="$(sha512sum aptarchive/dists/stable/main/binary-i386/Packages$comp | cut -f1 -d' ') $(stat -c %s aptarchive/dists/stable/main/binary-i386/Packages$comp) main/binary-i386/Packages$comp"
  42. echo " $s" >> aptarchive/dists/stable/InRelease
  43. # Sources
  44. s="$(sha512sum aptarchive/dists/stable/main/source/Sources$comp | cut -f1 -d' ') $(stat -c %s aptarchive/dists/stable/main/source/Sources$comp) main/source/Sources$comp"
  45. echo " $s" >> aptarchive/dists/stable/InRelease
  46. done;
  47. # deliver this
  48. changetowebserver
  49. # ensure the update fails
  50. # useful for debugging to add "-o Debug::pkgAcquire::auth=true"
  51. if aptget update -qq; then
  52. msgfail "apt-get update should NOT work for MITM"
  53. exit 1
  54. fi
  55. # ensure there is no package
  56. testequal 'Reading package lists...
  57. Building dependency tree...
  58. E: Unable to locate package bad-mitm' aptget install bad-mitm
  59. # and verify that its not picked up
  60. #testequal 'N: Unable to locate package bad-mitm' aptcache policy bad-mitm
  61. # and that the right one is used
  62. #testequal 'good-pkg:
  63. #+ Installed: (none)
  64. #+ Candidate: 1.0
  65. #+ Version table:
  66. #+ 1.0 0
  67. #+ 500 http://localhost/ stable/main i386 Packages' aptcache policy good-pkg