test-apt-update-weak-hashes 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #!/bin/sh
  2. set -e
  3. TESTDIR="$(readlink -f "$(dirname "$0")")"
  4. . "$TESTDIR/framework"
  5. setupenvironment
  6. configarchitecture 'i386'
  7. confighashes 'MD5'
  8. export APT_DONT_SIGN=''
  9. insertpackage 'unstable' 'foo' 'i386' '1.0'
  10. insertsource 'unstable' 'foo' 'any' '1.0'
  11. setupaptarchive --no-update
  12. APTARCHIVE="$(readlink -f ./aptarchive)"
  13. testnopkg() {
  14. testnopackage "$@"
  15. testnosrcpackage "$@"
  16. }
  17. testbadpkg() {
  18. testempty find rootdir/var/lib/apt/lists -maxdepth 1 -name '*InRelease' -o -name '*Release.gpg'
  19. testnotempty find rootdir/var/lib/apt/lists -maxdepth 1 -name '*Release'
  20. testnotempty apt show "$@"
  21. testnotempty apt showsrc "$@"
  22. testfailureequal "WARNING: The following packages cannot be authenticated!
  23. $*
  24. E: There were unauthenticated packages and -y was used without --allow-unauthenticated" aptget install -qq -y "$@"
  25. testfailureequal "WARNING: The following packages cannot be authenticated!
  26. $*
  27. E: Some packages could not be authenticated" aptget source -qq "$@"
  28. }
  29. testrun() {
  30. local TYPE="$1"
  31. local FILENAME="$2"
  32. shift 2
  33. local MANGLED="$(readlink -f ./rootdir)/var/lib/apt/lists/partial/$(echo "$FILENAME" | sed 's#/#_#g')"
  34. msgmsg "$TYPE contains only weak hashes"
  35. confighashes 'MD5'
  36. generatereleasefiles
  37. signreleasefiles
  38. preparetest
  39. if [ -z "$1" ]; then
  40. listcurrentlistsdirectory > lists.before
  41. testfailuremsg "W: No Hash entry in Release file ${MANGLED} which is considered strong enough for security purposes
  42. E: The repository 'file:${APTARCHIVE} unstable $(basename "$FILENAME")' provides only weak security information.
  43. N: Updating from such a repository can't be done securely, and is therefore disabled by default.
  44. N: See apt-secure(8) manpage for repository creation and user configuration details." apt update
  45. testfileequal lists.before "$(listcurrentlistsdirectory)"
  46. testnopkg 'foo'
  47. else
  48. testwarningmsg "W: No Hash entry in Release file ${MANGLED} which is considered strong enough for security purposes
  49. W: The repository 'file:${APTARCHIVE} unstable $(basename "$FILENAME")' provides only weak security information.
  50. N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
  51. N: See apt-secure(8) manpage for repository creation and user configuration details." apt update "$@"
  52. testbadpkg 'foo'
  53. fi
  54. msgmsg "$TYPE contains no hashes"
  55. generatereleasefiles
  56. sed -i -e '/^ / d' -e '/^MD5Sum:/ d' "$APTARCHIVE/dists/unstable/Release"
  57. signreleasefiles
  58. preparetest
  59. if [ -z "$1" ]; then
  60. listcurrentlistsdirectory > lists.before
  61. testfailuremsg "W: No Hash entry in Release file ${MANGLED}
  62. E: The repository 'file:${APTARCHIVE} unstable $(basename "$FILENAME")' provides only weak security information.
  63. N: Updating from such a repository can't be done securely, and is therefore disabled by default.
  64. N: See apt-secure(8) manpage for repository creation and user configuration details." apt update
  65. testfileequal lists.before "$(listcurrentlistsdirectory)"
  66. testnopkg 'foo'
  67. else
  68. testwarningmsg "W: No Hash entry in Release file ${MANGLED}
  69. W: The repository 'file:${APTARCHIVE} unstable $(basename "$FILENAME")' provides only weak security information.
  70. N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
  71. N: See apt-secure(8) manpage for repository creation and user configuration details." apt update "$@"
  72. testbadpkg 'foo'
  73. fi
  74. msgmsg "$TYPE contains only weak hashes for some files"
  75. confighashes 'MD5' 'SHA256'
  76. generatereleasefiles
  77. sed -i '/^ [0-9a-fA-Z]\{64\} .*Sources$/d' "$APTARCHIVE/dists/unstable/Release"
  78. signreleasefiles
  79. preparetest
  80. # trust is a repository property, so individual files can't be insecure
  81. testwarningmsg "W: Skipping acquire of configured file 'main/source/Sources' as repository 'file:${APTARCHIVE} unstable InRelease' provides only weak security information for it" apt update "$@"
  82. testsuccess apt show foo
  83. testnosrcpackage foo
  84. }
  85. genericprepare() {
  86. rm -rf rootdir/var/lib/apt/lists
  87. mkdir -p rootdir/var/lib/apt/lists/partial
  88. touch rootdir/var/lib/apt/lists/lock
  89. local RELEASEGPG="$(readlink -f ./rootdir)/var/lib/apt/lists/partial/$(echo "${APTARCHIVE}/dists/unstable/Release.gpg" | sed 's#/#_#g')"
  90. touch "$RELEASEGPG"
  91. chmod 644 "$RELEASEGPG"
  92. local INRELEASE="$(readlink -f ./rootdir)/var/lib/apt/lists/partial/$(echo "${APTARCHIVE}/dists/unstable/InRelease" | sed 's#/#_#g')"
  93. touch "$INRELEASE"
  94. chmod 644 "$INRELEASE"
  95. }
  96. preparetest() {
  97. rm -f "${APTARCHIVE}/dists/unstable/Release" "${APTARCHIVE}/dists/unstable/Release.gpg"
  98. genericprepare
  99. }
  100. testrun 'InRelease' "${APTARCHIVE}/dists/unstable/InRelease"
  101. testrun 'InRelease' "${APTARCHIVE}/dists/unstable/InRelease" --allow-insecure-repositories -o APT::Get::List-Cleanup=0
  102. preparetest() {
  103. rm -f "${APTARCHIVE}/dists/unstable/InRelease"
  104. genericprepare
  105. }
  106. testrun 'Release+Release.gpg' "${APTARCHIVE}/dists/unstable/Release"
  107. testrun 'Release+Release.gpg' "${APTARCHIVE}/dists/unstable/Release" --allow-insecure-repositories -o APT::Get::List-Cleanup=0
  108. preparetest() {
  109. rm -f "${APTARCHIVE}/dists/unstable/InRelease" "${APTARCHIVE}/dists/unstable/Release.gpg"
  110. genericprepare
  111. }
  112. msgmsg 'Moving between Release files with good and bad hashes'
  113. rm -rf rootdir/var/lib/apt/lists
  114. confighashes 'MD5'
  115. generatereleasefiles 'now - 1 day'
  116. signreleasefiles
  117. testfailure apt update
  118. testnopkg 'foo'
  119. testwarning apt update --allow-insecure-repositories
  120. testbadpkg 'foo'
  121. confighashes 'MD5' 'SHA256'
  122. rm -rf aptarchive/dists
  123. insertpackage 'unstable' 'foo2' 'i386' '1.0'
  124. insertsource 'unstable' 'foo2' 'any' '1.0'
  125. setupaptarchive --no-update 'now - 12 hours'
  126. testsuccess apt update
  127. testnopkg foo
  128. testnotempty find rootdir/var/lib/apt/lists -maxdepth 1 -name '*InRelease' -o -name '*Release.gpg'
  129. testnotempty apt show foo2
  130. testnotempty apt showsrc foo2
  131. confighashes 'MD5'
  132. rm -rf aptarchive/dists
  133. insertpackage 'unstable' 'foo3' 'i386' '1.0'
  134. insertsource 'unstable' 'foo3' 'any' '1.0'
  135. setupaptarchive --no-update
  136. testfailure apt update
  137. testnopkg foo
  138. testnopkg foo3
  139. testnotempty find rootdir/var/lib/apt/lists -maxdepth 1 -name '*InRelease' -o -name '*Release.gpg'
  140. testnotempty apt show foo2
  141. testnotempty apt showsrc foo2
  142. testwarning apt update --allow-insecure-repositories
  143. testnopkg foo2
  144. testbadpkg foo3