test-releasefile-verification 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. testequal '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. testequal '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. testequal '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. testequal '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. updatesuccess() {
  83. local LOG='update.log'
  84. if aptget update >$LOG 2>&1 || grep -q -E '^(W|E): ' $LOG; then
  85. msgpass
  86. else
  87. cat $LOG
  88. msgfail
  89. fi
  90. }
  91. updatefailure() {
  92. local LOG='update.log'
  93. aptget update >$LOG 2>&1 || true
  94. if grep -q -E "$1" $LOG; then
  95. msgpass
  96. else
  97. cat $LOG
  98. msgfail
  99. fi
  100. }
  101. runtest() {
  102. prepare ${PKGFILE}
  103. rm -rf rootdir/var/lib/apt/lists
  104. signreleasefiles 'Joe Sixpack'
  105. find aptarchive/ -name "$DELETEFILE" -delete
  106. msgtest 'Cold archive signed by' 'Joe Sixpack'
  107. updatesuccess
  108. testequal "$(cat ${PKGFILE})
  109. " aptcache show apt
  110. installaptold
  111. prepare ${PKGFILE}-new
  112. signreleasefiles 'Joe Sixpack'
  113. find aptarchive/ -name "$DELETEFILE" -delete
  114. msgtest 'Good warm archive signed by' 'Joe Sixpack'
  115. updatesuccess
  116. testequal "$(cat ${PKGFILE}-new)
  117. " aptcache show apt
  118. installaptnew
  119. prepare ${PKGFILE}
  120. rm -rf rootdir/var/lib/apt/lists
  121. cp keys/rexexpired.pub rootdir/etc/apt/trusted.gpg.d/rexexpired.gpg
  122. signreleasefiles 'Rex Expired'
  123. find aptarchive/ -name "$DELETEFILE" -delete
  124. msgtest 'Cold archive signed by' 'Rex Expired'
  125. updatefailure '^W: .* KEYEXPIRED'
  126. testequal "$(cat ${PKGFILE})
  127. " aptcache show apt
  128. failaptold
  129. rm rootdir/etc/apt/trusted.gpg.d/rexexpired.gpg
  130. prepare ${PKGFILE}
  131. rm -rf rootdir/var/lib/apt/lists
  132. signreleasefiles 'Marvin Paranoid'
  133. find aptarchive/ -name "$DELETEFILE" -delete
  134. msgtest 'Cold archive signed by' 'Marvin Paranoid'
  135. updatefailure '^W: .* NO_PUBKEY'
  136. testequal "$(cat ${PKGFILE})
  137. " aptcache show apt
  138. failaptold
  139. prepare ${PKGFILE}-new
  140. # weborf doesn't support If-Range
  141. for release in $(find rootdir/var/lib/apt/lists/partial/ -name '*Release'); do
  142. rm $release
  143. touch $release
  144. done
  145. signreleasefiles 'Joe Sixpack'
  146. find aptarchive/ -name "$DELETEFILE" -delete
  147. msgtest 'Bad warm archive signed by' 'Joe Sixpack'
  148. updatesuccess
  149. testequal "$(cat ${PKGFILE}-new)
  150. " aptcache show apt
  151. installaptnew
  152. prepare ${PKGFILE}
  153. rm -rf rootdir/var/lib/apt/lists
  154. signreleasefiles 'Joe Sixpack'
  155. find aptarchive/ -name "$DELETEFILE" -delete
  156. msgtest 'Cold archive signed by' 'Joe Sixpack'
  157. updatesuccess
  158. testequal "$(cat ${PKGFILE})
  159. " aptcache show apt
  160. installaptold
  161. prepare ${PKGFILE}-new
  162. signreleasefiles 'Marvin Paranoid'
  163. find aptarchive/ -name "$DELETEFILE" -delete
  164. msgtest 'Good warm archive signed by' 'Marvin Paranoid'
  165. updatefailure '^W: .* NO_PUBKEY'
  166. testequal "$(cat ${PKGFILE})
  167. " aptcache show apt
  168. installaptold
  169. prepare ${PKGFILE}-new
  170. cp keys/rexexpired.pub rootdir/etc/apt/trusted.gpg.d/rexexpired.gpg
  171. signreleasefiles 'Rex Expired'
  172. find aptarchive/ -name "$DELETEFILE" -delete
  173. msgtest 'Good warm archive signed by' 'Rex Expired'
  174. updatefailure '^W: .* KEYEXPIRED'
  175. testequal "$(cat ${PKGFILE})
  176. " aptcache show apt
  177. installaptold
  178. rm rootdir/etc/apt/trusted.gpg.d/rexexpired.gpg
  179. prepare ${PKGFILE}-new
  180. signreleasefiles
  181. find aptarchive/ -name "$DELETEFILE" -delete
  182. msgtest 'Good warm archive signed by' 'Joe Sixpack'
  183. updatesuccess
  184. testequal "$(cat ${PKGFILE}-new)
  185. " aptcache show apt
  186. installaptnew
  187. }
  188. runtest2() {
  189. prepare ${PKGFILE}
  190. rm -rf rootdir/var/lib/apt/lists
  191. signreleasefiles 'Joe Sixpack'
  192. msgtest 'Cold archive signed by' 'Joe Sixpack'
  193. updatesuccess
  194. # New .deb but now an unsigned archive. For example MITM to circumvent
  195. # package verification.
  196. prepare ${PKGFILE}-new
  197. find aptarchive/ -name InRelease -delete
  198. find aptarchive/ -name Release.gpg -delete
  199. msgtest 'Warm archive signed by' 'nobody'
  200. updatesuccess
  201. testequal "$(cat ${PKGFILE}-new)
  202. " aptcache show apt
  203. failaptnew
  204. # Unsigned archive from the beginning must also be detected.
  205. rm -rf rootdir/var/lib/apt/lists
  206. msgtest 'Cold archive signed by' 'nobody'
  207. updatesuccess
  208. testequal "$(cat ${PKGFILE}-new)
  209. " aptcache show apt
  210. failaptnew
  211. }
  212. runtest2
  213. DELETEFILE="InRelease"
  214. runtest
  215. DELETEFILE="Release.gpg"
  216. runtest