test-releasefile-verification 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. #!/bin/sh
  2. set -e
  3. TESTDIR=$(readlink -f $(dirname $0))
  4. . $TESTDIR/framework
  5. setupenvironment
  6. configarchitecture "i386"
  7. buildaptarchive
  8. setupflataptarchive
  9. changetowebserver
  10. webserverconfig 'aptwebserver::support::range' 'false'
  11. prepare() {
  12. local DATE="${2:-now}"
  13. if [ "$DATE" = 'now' ]; then
  14. if [ "$1" = "${PKGFILE}-new" ]; then
  15. DATE='now - 1 day'
  16. else
  17. DATE='now - 7 day'
  18. fi
  19. fi
  20. for release in $(find rootdir/var/lib/apt/lists 2> /dev/null); do
  21. touch -d 'now - 1 year' $release
  22. done
  23. aptget clean
  24. cp $1 aptarchive/Packages
  25. find aptarchive -name 'Release' -delete
  26. compressfile 'aptarchive/Packages' "$DATE"
  27. generatereleasefiles "$DATE"
  28. }
  29. installaptold() {
  30. testsuccessequal 'Reading package lists...
  31. Building dependency tree...
  32. Suggested packages:
  33. aptitude synaptic wajig dpkg-dev apt-doc bzip2 lzma python-apt
  34. The following NEW packages will be installed:
  35. apt
  36. 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
  37. After this operation, 5370 kB of additional disk space will be used.
  38. Get:1 http://localhost:8080/ apt 0.7.25.3
  39. Download complete and in download only mode' aptget install apt -dy
  40. }
  41. installaptnew() {
  42. testsuccessequal 'Reading package lists...
  43. Building dependency tree...
  44. Suggested packages:
  45. aptitude synaptic wajig dpkg-dev apt-doc bzip2 lzma python-apt
  46. The following NEW packages will be installed:
  47. apt
  48. 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
  49. After this operation, 5808 kB of additional disk space will be used.
  50. Get:1 http://localhost:8080/ apt 0.8.0~pre1
  51. Download complete and in download only mode' aptget install apt -dy
  52. }
  53. failaptold() {
  54. testfailureequal 'Reading package lists...
  55. Building dependency tree...
  56. Suggested packages:
  57. aptitude synaptic wajig dpkg-dev apt-doc bzip2 lzma python-apt
  58. The following NEW packages will be installed:
  59. apt
  60. 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
  61. After this operation, 5370 kB of additional disk space will be used.
  62. WARNING: The following packages cannot be authenticated!
  63. apt
  64. E: There are problems and -y was used without --force-yes' aptget install apt -dy
  65. }
  66. failaptnew() {
  67. testfailureequal 'Reading package lists...
  68. Building dependency tree...
  69. Suggested packages:
  70. aptitude synaptic wajig dpkg-dev apt-doc bzip2 lzma python-apt
  71. The following NEW packages will be installed:
  72. apt
  73. 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
  74. After this operation, 5808 kB of additional disk space will be used.
  75. WARNING: The following packages cannot be authenticated!
  76. apt
  77. E: There are problems and -y was used without --force-yes' aptget install apt -dy
  78. }
  79. # fake our downloadable file
  80. touch aptarchive/apt.deb
  81. PKGFILE="${TESTDIR}/$(echo "$(basename $0)" | sed 's#^test-#Packages-#')"
  82. updatewithwarnings() {
  83. testwarning aptget update
  84. testsuccess grep -E "$1" rootdir/tmp/testwarning.output
  85. }
  86. runtest() {
  87. prepare ${PKGFILE}
  88. rm -rf rootdir/var/lib/apt/lists
  89. signreleasefiles 'Joe Sixpack'
  90. find aptarchive/ -name "$DELETEFILE" -delete
  91. msgmsg 'Cold archive signed by' 'Joe Sixpack'
  92. testsuccess aptget update
  93. testsuccessequal "$(cat ${PKGFILE})
  94. " aptcache show apt
  95. installaptold
  96. prepare ${PKGFILE}-new
  97. signreleasefiles 'Joe Sixpack'
  98. find aptarchive/ -name "$DELETEFILE" -delete
  99. msgmsg 'Good warm archive signed by' 'Joe Sixpack'
  100. testsuccess aptget update
  101. testsuccessequal "$(cat ${PKGFILE}-new)
  102. " aptcache show apt
  103. installaptnew
  104. prepare ${PKGFILE}
  105. rm -rf rootdir/var/lib/apt/lists
  106. cp keys/rexexpired.pub rootdir/etc/apt/trusted.gpg.d/rexexpired.gpg
  107. signreleasefiles 'Rex Expired'
  108. find aptarchive/ -name "$DELETEFILE" -delete
  109. msgmsg 'Cold archive signed by' 'Rex Expired'
  110. updatewithwarnings '^W: .* KEYEXPIRED'
  111. testsuccessequal "$(cat ${PKGFILE})
  112. " aptcache show apt
  113. failaptold
  114. rm rootdir/etc/apt/trusted.gpg.d/rexexpired.gpg
  115. prepare ${PKGFILE}
  116. rm -rf rootdir/var/lib/apt/lists
  117. signreleasefiles 'Marvin Paranoid'
  118. find aptarchive/ -name "$DELETEFILE" -delete
  119. msgmsg 'Cold archive signed by' 'Marvin Paranoid'
  120. updatewithwarnings '^W: .* NO_PUBKEY'
  121. testsuccessequal "$(cat ${PKGFILE})
  122. " aptcache show apt
  123. failaptold
  124. prepare ${PKGFILE}-new
  125. # weborf doesn't support If-Range
  126. for release in $(find rootdir/var/lib/apt/lists/partial/ -name '*Release'); do
  127. rm $release
  128. touch $release
  129. done
  130. signreleasefiles 'Joe Sixpack'
  131. find aptarchive/ -name "$DELETEFILE" -delete
  132. msgmsg 'Bad warm archive signed by' 'Joe Sixpack'
  133. testsuccess aptget update
  134. testsuccessequal "$(cat ${PKGFILE}-new)
  135. " aptcache show apt
  136. installaptnew
  137. prepare ${PKGFILE}
  138. rm -rf rootdir/var/lib/apt/lists
  139. signreleasefiles 'Joe Sixpack'
  140. find aptarchive/ -name "$DELETEFILE" -delete
  141. msgmsg 'Cold archive signed by' 'Joe Sixpack'
  142. testsuccess aptget update
  143. testsuccessequal "$(cat ${PKGFILE})
  144. " aptcache show apt
  145. installaptold
  146. prepare ${PKGFILE}-new
  147. signreleasefiles 'Marvin Paranoid'
  148. find aptarchive/ -name "$DELETEFILE" -delete
  149. msgmsg 'Good warm archive signed by' 'Marvin Paranoid'
  150. updatewithwarnings '^W: .* NO_PUBKEY'
  151. testsuccessequal "$(cat ${PKGFILE})
  152. " aptcache show apt
  153. installaptold
  154. prepare ${PKGFILE}-new
  155. cp keys/rexexpired.pub rootdir/etc/apt/trusted.gpg.d/rexexpired.gpg
  156. signreleasefiles 'Rex Expired'
  157. find aptarchive/ -name "$DELETEFILE" -delete
  158. msgmsg 'Good warm archive signed by' 'Rex Expired'
  159. updatewithwarnings '^W: .* KEYEXPIRED'
  160. testsuccessequal "$(cat ${PKGFILE})
  161. " aptcache show apt
  162. installaptold
  163. rm rootdir/etc/apt/trusted.gpg.d/rexexpired.gpg
  164. prepare ${PKGFILE}-new
  165. signreleasefiles
  166. find aptarchive/ -name "$DELETEFILE" -delete
  167. msgmsg 'Good warm archive signed by' 'Joe Sixpack'
  168. testsuccess aptget update
  169. testsuccessequal "$(cat ${PKGFILE}-new)
  170. " aptcache show apt
  171. installaptnew
  172. }
  173. runtest2() {
  174. prepare ${PKGFILE}
  175. rm -rf rootdir/var/lib/apt/lists
  176. signreleasefiles 'Joe Sixpack'
  177. msgmsg 'Cold archive signed by' 'Joe Sixpack'
  178. testsuccess aptget update
  179. # New .deb but now an unsigned archive. For example MITM to circumvent
  180. # package verification.
  181. prepare ${PKGFILE}-new
  182. find aptarchive/ -name InRelease -delete
  183. find aptarchive/ -name Release.gpg -delete
  184. msgmsg 'Warm archive signed by' 'nobody'
  185. updatewithwarnings 'W: .* no longer signed.'
  186. testsuccessequal "$(cat ${PKGFILE}-new)
  187. " aptcache show apt
  188. failaptnew
  189. # Unsigned archive from the beginning must also be detected.
  190. rm -rf rootdir/var/lib/apt/lists
  191. msgmsg 'Cold archive signed by' 'nobody'
  192. updatewithwarnings 'W: .* is not signed.'
  193. testsuccessequal "$(cat ${PKGFILE}-new)
  194. " aptcache show apt
  195. failaptnew
  196. }
  197. # diable some protection by default and ensure we still do the verification
  198. # correctly
  199. cat > rootdir/etc/apt/apt.conf.d/weaken-security <<EOF
  200. Acquire::AllowInsecureRepositories "1";
  201. Acquire::AllowDowngradeToInsecureRepositories "1";
  202. EOF
  203. msgmsg "Runing base test"
  204. runtest2
  205. DELETEFILE="InRelease"
  206. msgmsg "Running test with deletion of $DELETEFILE"
  207. runtest
  208. DELETEFILE="Release.gpg"
  209. msgmsg "Running test with deletion of $DELETEFILE"
  210. runtest