test-cve-2013-1051-InRelease-parsing 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/sh
  2. set -e
  3. TESTDIR="$(readlink -f "$(dirname "$0")")"
  4. . "$TESTDIR/framework"
  5. setupenvironment
  6. configarchitecture 'i386'
  7. insertpackage 'stable' 'good-pkg' 'all' '1.0'
  8. setupaptarchive
  9. changetowebserver
  10. ARCHIVE="http://localhost:${APTHTTPPORT}"
  11. msgtest 'Initial apt-get update should work with' 'InRelease'
  12. testsuccess --nomsg aptget update
  13. # check that the setup is correct
  14. testsuccessequal "good-pkg:
  15. Installed: (none)
  16. Candidate: 1.0
  17. Version table:
  18. 1.0 500
  19. 500 ${ARCHIVE} stable/main all Packages" aptcache policy good-pkg
  20. # now exchange to the Packages file, note that this could be
  21. # done via MITM too
  22. insertpackage 'stable' 'bad-mitm' 'all' '1.0'
  23. # this builds compressed files and a new (unsigned) Release
  24. buildaptarchivefromfiles '+1hour'
  25. # add a space into the BEGIN PGP SIGNATURE PART/END PGP SIGNATURE part
  26. # to trick apt - this is still legal to gpg(v)
  27. sed -i '/^-----BEGIN PGP SIGNATURE-----/,/^-----END PGP SIGNATURE-----/ s/^$/ /g' aptarchive/dists/stable/InRelease
  28. # we append the (evil unsigned) Release file to the (good signed) InRelease
  29. cat aptarchive/dists/stable/Release >> aptarchive/dists/stable/InRelease
  30. touch -d '+1hour' aptarchive/dists/stable/InRelease
  31. # ensure the update doesn't load bad data as good data
  32. # Note that we will pick up the InRelease itself as we download no other
  33. # indexes which would trigger a hashsum mismatch, but we ignore the 'bad'
  34. # part of the InRelease
  35. listcurrentlistsdirectory | sed '/_InRelease/ d' > listsdir.lst
  36. msgtest 'apt-get update should ignore unsigned data in the' 'InRelease'
  37. testsuccessequal "Get:1 http://localhost:${APTHTTPPORT} stable InRelease [$(stat -c%s aptarchive/dists/stable/InRelease) B]
  38. Reading package lists..." --nomsg aptget update
  39. testfileequal './listsdir.lst' "$(listcurrentlistsdirectory | sed '/_InRelease/ d')"
  40. # ensure there is no package
  41. testfailureequal 'Reading package lists...
  42. Building dependency tree...
  43. E: Unable to locate package bad-mitm' aptget install bad-mitm -s
  44. # and verify that its not picked up
  45. testsuccessequal 'N: Unable to locate package bad-mitm' aptcache policy bad-mitm
  46. # and that the right one is used
  47. testsuccessequal "good-pkg:
  48. Installed: (none)
  49. Candidate: 1.0
  50. Version table:
  51. 1.0 500
  52. 500 ${ARCHIVE} stable/main all Packages" aptcache policy good-pkg