test-apt-key 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. #!/bin/sh
  2. set -e
  3. # apt-key is a shell script, so relatively prune to be effected by 'crazy' things:
  4. # confuses config parser as there exists no way of escaping " currently.
  5. #TMPDIR="$(mktemp -d)/This is \"fü\$\$ing cràzy\", \$(man man | head -n1 | cut -d' ' -f 1)\$!"
  6. # gpg doesn't like | in path names – documented e.g. in the man gpg2 --agent-program
  7. #TMPDIR="$(mktemp -d)/This is fü\$\$ing cràzy, \$(man man | head -n1 | cut -d' ' -f 1)\$!"
  8. TMPDIR_ADD="This is fü\$\$ing cràzy, \$(apt -v)\$!"
  9. TESTDIR="$(readlink -f "$(dirname "$0")")"
  10. . "$TESTDIR/framework"
  11. setupenvironment
  12. configarchitecture 'amd64'
  13. # start from a clean plate again
  14. cleanplate() {
  15. rm -rf "${ROOTDIR}/etc/apt/trusted.gpg.d/" "${ROOTDIR}/etc/apt/trusted.gpg"
  16. mkdir "${ROOTDIR}/etc/apt/trusted.gpg.d/"
  17. }
  18. testmultigpg() {
  19. testfailure --nomsg aptkey --quiet --readonly "$@"
  20. testsuccess grep "^gpgv: Can't check signature" "${ROOTDIR}/tmp/testfailure.output"
  21. testsuccess grep '^gpgv: Good signature from' "${ROOTDIR}/tmp/testfailure.output"
  22. }
  23. testaptkeyskeyring() {
  24. local KEYRING="$1"
  25. shift
  26. local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/aptkeylistkeyring.output"
  27. if ! aptkey --keyring "$KEYRING" list --with-colon | grep '^pub' | cut -d':' -f 5 > "$OUTPUT"; then
  28. echo -n > "$OUTPUT"
  29. fi
  30. testfileequal "$OUTPUT" "$(mapkeynametokeyid "$@")"
  31. }
  32. testrun() {
  33. local EXT="${1:-gpg}"
  34. echo "APT::Key::ArchiveKeyring \"${KEYDIR}/joesixpack.pub.gpg\";
  35. APT::Key::RemovedKeys \"${KEYDIR}/rexexpired.pub.gpg\";" > "${ROOTDIR}/etc/apt/apt.conf.d/aptkey.conf"
  36. cleanplate
  37. ln -sf "$(readlink -f "${KEYDIR}/joesixpack.pub.${EXT}")" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  38. testaptkeys 'Joe Sixpack'
  39. testsuccess aptkey list
  40. msgtest 'Check that paths in list output are not' 'double-slashed'
  41. testfailure --nomsg grep '//' "${ROOTDIR}/tmp/testsuccess.output"
  42. testsuccess aptkey finger
  43. msgtest 'Check that paths in finger output are not' 'double-slashed'
  44. testfailure --nomsg grep '//' "${ROOTDIR}/tmp/testsuccess.output"
  45. cp -a "${KEYDIR}/joesixpack.pub.${EXT}" "${KEYDIR}/joesixpack.pub.${EXT}.bak"
  46. testequalor2 'gpg: key DBAC8DAE: "Joe Sixpack (APT Testcases Dummy) <joe@example.org>" not changed
  47. gpg: Total number processed: 1
  48. gpg: unchanged: 1' 'gpg: key 5A90D141DBAC8DAE: "Joe Sixpack (APT Testcases Dummy) <joe@example.org>" not changed
  49. gpg: Total number processed: 1
  50. gpg: unchanged: 1' aptkey --fakeroot update
  51. testsuccess test -L "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  52. testsuccess cmp "${KEYDIR}/joesixpack.pub.${EXT}" "${KEYDIR}/joesixpack.pub.${EXT}.bak"
  53. testaptkeys 'Joe Sixpack'
  54. testfailure test -e "${ROOTDIR}/etc/apt/trusted.gpg"
  55. testsuccess aptkey --fakeroot add "${KEYDIR}/rexexpired.pub.${EXT}"
  56. testfilestats "${ROOTDIR}/etc/apt/trusted.gpg" '%a' '=' '644'
  57. testaptkeys 'Rex Expired' 'Joe Sixpack'
  58. msgtest 'Check that Sixpack key can be' 'exported'
  59. aptkey export 'Sixpack' > "${TMPWORKINGDIRECTORY}/aptkey.export"
  60. aptkey --keyring "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}" exportall > "${TMPWORKINGDIRECTORY}/aptkey.exportall"
  61. testsuccess --nomsg cmp "${TMPWORKINGDIRECTORY}/aptkey.export" "${TMPWORKINGDIRECTORY}/aptkey.exportall"
  62. testsuccess test -s "${TMPWORKINGDIRECTORY}/aptkey.export"
  63. testsuccess test -s "${TMPWORKINGDIRECTORY}/aptkey.exportall"
  64. msgtest 'Execute update again to trigger removal of' 'Rex Expired key'
  65. testsuccess --nomsg aptkey --fakeroot update
  66. testaptkeys 'Joe Sixpack'
  67. msgtest "Try to remove a key which exists, but isn't in the" 'forced keyring'
  68. testsuccess --nomsg aptkey --fakeroot --keyring "${ROOTDIR}/etc/apt/trusted.gpg" del DBAC8DAE
  69. testaptkeys 'Joe Sixpack'
  70. testsuccess aptkey --fakeroot del DBAC8DAE
  71. testempty aptkey list
  72. ln -sf "$(readlink -f "${KEYDIR}/joesixpack.pub.${EXT}")" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  73. testaptkeys 'Joe Sixpack'
  74. msgtest "Remove a key from" 'forced keyring in trusted.d.gpg'
  75. testsuccess --nomsg aptkey --fakeroot --keyring "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}" del DBAC8DAE
  76. testsuccess cmp -s "$(readlink -f "${KEYDIR}/joesixpack.pub.${EXT}")" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}~"
  77. testempty aptkey list
  78. cp -a "${KEYDIR}/marvinparanoid.pub.asc" "${ROOTDIR}/etc/foobar.pub"
  79. testsuccess aptkey --fakeroot --keyring "${ROOTDIR}/etc/foobar.pub" add "${KEYDIR}/rexexpired.pub.asc" "${KEYDIR}/joesixpack.pub.gpg"
  80. testfilestats "${ROOTDIR}/etc/foobar.pub" '%a' '=' '644'
  81. testaptkeyskeyring "${ROOTDIR}/etc/foobar.pub" 'Marvin Paranoid' 'Rex Expired' 'Joe Sixpack'
  82. testempty aptkey list
  83. msgtest 'Test key removal with' 'lowercase key ID' #keylength somewhere between 8byte and short
  84. cleanplate
  85. cp -a "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  86. testsuccess --nomsg aptkey --fakeroot del d141dbac8dae
  87. testempty aptkey list
  88. if [ "$(id -u)" != '0' ]; then
  89. msgtest 'Test key removal with' 'unreadable key'
  90. cleanplate
  91. cp -a "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  92. echo 'foobar' > "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.${EXT}"
  93. chmod 000 "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.${EXT}"
  94. testwarning --nomsg aptkey --fakeroot del d141dbac8dae
  95. testwarning aptkey list
  96. chmod 644 "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.${EXT}"
  97. rm -f "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.${EXT}"
  98. grep -v '^W: ' "${ROOTDIR}/tmp/testwarning.output" > "${ROOTDIR}/aptkeylist.output" || true
  99. testempty cat "${ROOTDIR}/aptkeylist.output"
  100. fi
  101. msgtest 'Test key removal with' 'single key in real file'
  102. cleanplate
  103. cp -a "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  104. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  105. testempty aptkey list
  106. testfailure test -e "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  107. testsuccess cmp "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}~"
  108. msgtest 'Test key removal with' 'different key specs'
  109. cleanplate
  110. cp -a "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  111. cp -a "${KEYDIR}/marvinparanoid.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/marvinparanoid.${EXT}"
  112. testsuccess --nomsg aptkey --fakeroot del 0xDBAC8DAE 528144E2
  113. testempty aptkey list
  114. testfailure test -e "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  115. testsuccess cmp "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}~"
  116. testfailure test -e "${ROOTDIR}/etc/apt/trusted.gpg.d/marvinparanoid.${EXT}"
  117. testsuccess cmp "${KEYDIR}/marvinparanoid.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/marvinparanoid.${EXT}~"
  118. msgtest 'Test key removal with' 'long key ID'
  119. cleanplate
  120. cp -a "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  121. testsuccess --nomsg aptkey --fakeroot del 5A90D141DBAC8DAE
  122. testempty aptkey list
  123. testfailure test -e "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  124. testsuccess cmp "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}~"
  125. msgtest 'Test key removal with' 'fingerprint'
  126. cleanplate
  127. cp -a "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  128. testsuccess --nomsg aptkey --fakeroot del 34A8E9D18DB320F367E8EAA05A90D141DBAC8DAE
  129. testempty aptkey list
  130. testfailure test -e "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  131. testsuccess cmp "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}~"
  132. msgtest 'Test key removal with' 'spaced fingerprint'
  133. cleanplate
  134. cp -a "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  135. testsuccess --nomsg aptkey --fakeroot del '34A8 E9D1 8DB3 20F3 67E8 EAA0 5A90 D141 DBAC 8DAE'
  136. testempty aptkey list
  137. testfailure test -e "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  138. testsuccess cmp "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}~"
  139. msgtest 'Test key removal with' 'single key in softlink'
  140. cleanplate
  141. ln -sf "$(readlink -f "${KEYDIR}/joesixpack.pub.${EXT}")" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  142. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  143. testempty aptkey list
  144. testfailure test -e "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  145. testsuccess test -L "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}~"
  146. cleanplate
  147. testsuccess aptkey --fakeroot add "${KEYDIR}/joesixpack.pub.${EXT}"
  148. ln -sf "$(readlink -f "${KEYDIR}/marvinparanoid.pub.${EXT}")" "${KEYDIR}/marvin paránöid.pub.${EXT}"
  149. testsuccess aptkey --fakeroot add "${KEYDIR}/marvin paránöid.pub.${EXT}"
  150. testaptkeys 'Joe Sixpack' 'Marvin Paranoid'
  151. cp -a "${ROOTDIR}/etc/apt/trusted.gpg" "${KEYDIR}/testcase-multikey.pub.gpg" # store for reuse
  152. gpg --no-default-keyring --keyring "${KEYDIR}/testcase-multikey.pub.gpg" --armor --export > "${KEYDIR}/testcase-multikey.pub.asc"
  153. msgtest 'Test key removal with' 'multi key in real file'
  154. cleanplate
  155. cp -a "${KEYDIR}/testcase-multikey.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/multikey.${EXT}"
  156. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  157. testaptkeys 'Marvin Paranoid'
  158. testsuccess cmp "${KEYDIR}/testcase-multikey.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/multikey.${EXT}~"
  159. msgtest 'Test key removal with' 'multi key in softlink'
  160. cleanplate
  161. ln -s "$(readlink -f "${KEYDIR}/testcase-multikey.pub.${EXT}")" "${ROOTDIR}/etc/apt/trusted.gpg.d/multikey.${EXT}"
  162. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  163. testaptkeys 'Marvin Paranoid'
  164. testsuccess cmp "${KEYDIR}/testcase-multikey.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/multikey.${EXT}~"
  165. testfailure test -L "${ROOTDIR}/etc/apt/trusted.gpg.d/multikey.${EXT}"
  166. testsuccess test -L "${ROOTDIR}/etc/apt/trusted.gpg.d/multikey.${EXT}~"
  167. msgtest 'Test key removal with' 'multiple files including key'
  168. cleanplate
  169. cp -a "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  170. cp -a "${KEYDIR}/testcase-multikey.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/multikey.${EXT}"
  171. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  172. testaptkeys 'Marvin Paranoid'
  173. testfailure test -e "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  174. testsuccess cmp "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}~"
  175. testsuccess cmp "${KEYDIR}/testcase-multikey.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/multikey.${EXT}~"
  176. cleanplate
  177. cp -a "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  178. cp -a "${KEYDIR}/testcase-multikey.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/multikey.${EXT}"
  179. testaptkeys 'Joe Sixpack' 'Joe Sixpack' 'Marvin Paranoid'
  180. msgtest 'Test merge-back of' 'added keys'
  181. testsuccess --nomsg aptkey adv --batch --yes --import "${KEYDIR}/rexexpired.pub.${EXT}"
  182. testaptkeys 'Rex Expired' 'Joe Sixpack' 'Joe Sixpack' 'Marvin Paranoid'
  183. msgtest 'Test merge-back of' 'removed keys'
  184. testsuccess --nomsg aptkey adv --batch --yes --delete-keys 27CE74F9
  185. testaptkeys 'Joe Sixpack' 'Joe Sixpack' 'Marvin Paranoid'
  186. msgtest 'Test merge-back of' 'removed duplicate keys'
  187. testsuccess --nomsg aptkey adv --batch --yes --delete-keys DBAC8DAE
  188. testaptkeys 'Marvin Paranoid'
  189. cleanplate
  190. cp -a "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
  191. cp -a "${KEYDIR}/testcase-multikey.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/multikey.${EXT}"
  192. local SIGNATURE="${TMPWORKINGDIRECTORY}/signature"
  193. msgtest 'Test signing a file' 'with a key'
  194. echo 'Verify me. This is my signature.' > "$SIGNATURE"
  195. echo 'lalalalala' > "${SIGNATURE}2"
  196. testsuccess --nomsg aptkey --quiet --keyring "${KEYDIR}/marvinparanoid.pub.gpg" --secret-keyring "${KEYDIR}/marvinparanoid.sec" --readonly \
  197. adv --batch --yes --default-key 'Marvin' --armor --detach-sign --sign --output "${SIGNATURE}.gpg" "${SIGNATURE}"
  198. testsuccess test -s "${SIGNATURE}.gpg" -a -s "${SIGNATURE}"
  199. msgtest 'Test verify a file' 'with no sig'
  200. testfailure --nomsg aptkey --quiet --readonly --keyring "${KEYDIR}/testcase-multikey.pub.${EXT}" verify "${SIGNATURE}" "${SIGNATURE}2"
  201. for GPGV in '' 'gpgv' 'gpgv1' 'gpgv2'; do
  202. echo "APT::Key::GPGVCommand \"$GPGV\";" > "${ROOTDIR}/etc/apt/apt.conf.d/00gpgvcmd"
  203. if [ -n "$GPGV" ] && ! command dpkg -l gnupg1 2>&1 | grep -q '^ii'; then continue; fi
  204. msgtest 'Test verify a file' 'with all keys'
  205. testsuccess --nomsg aptkey --quiet --readonly verify "${SIGNATURE}.gpg" "${SIGNATURE}"
  206. if [ "$(id -u)" != '0' ]; then
  207. msgtest 'Test verify a file' 'with unreadable key'
  208. echo 'foobar' > "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.${EXT}"
  209. chmod 000 "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.${EXT}"
  210. testwarning --nomsg aptkey --quiet --readonly verify "${SIGNATURE}.gpg" "${SIGNATURE}"
  211. testwarning aptkey list
  212. chmod 644 "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.${EXT}"
  213. rm -f "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.${EXT}"
  214. fi
  215. msgtest 'Test verify a file' 'with good keyring'
  216. testsuccess --nomsg aptkey --quiet --readonly --keyring "${KEYDIR}/testcase-multikey.pub.${EXT}" verify "${SIGNATURE}.gpg" "${SIGNATURE}"
  217. msgtest 'Test fail verify a file' 'with bad keyring'
  218. testfailure --nomsg aptkey --quiet --readonly --keyring "${KEYDIR}/joesixpack.pub.${EXT}" verify "${SIGNATURE}.gpg" "${SIGNATURE}"
  219. msgtest 'Test fail verify a file' 'with non-existing keyring'
  220. testfailure --nomsg aptkey --quiet --readonly --keyring "${KEYDIR}/does-not-exist.pub.${EXT}" verify "${SIGNATURE}.gpg" "${SIGNATURE}"
  221. testfailure test -e "${KEYDIR}/does-not-exist.pub.${EXT}"
  222. # note: this isn't how apts gpgv method implements keyid for verify
  223. msgtest 'Test verify a file' 'with good keyid'
  224. testsuccess --nomsg aptkey --quiet --readonly --keyid 'Paranoid' verify "${SIGNATURE}.gpg" "${SIGNATURE}"
  225. msgtest 'Test fail verify a file' 'with bad keyid'
  226. testfailure --nomsg aptkey --quiet --readonly --keyid 'Sixpack' verify "${SIGNATURE}.gpg" "${SIGNATURE}"
  227. msgtest 'Test fail verify a file' 'with non-existing keyid'
  228. testfailure --nomsg aptkey --quiet --readonly --keyid 'Kalnischkies' verify "${SIGNATURE}.gpg" "${SIGNATURE}"
  229. msgtest 'Test verify fails on' 'bad file'
  230. testfailure --nomsg aptkey --quiet --readonly verify "${SIGNATURE}.gpg" "${SIGNATURE}2"
  231. done
  232. rm -f "${ROOTDIR}/etc/apt/apt.conf.d/00gpgvcmd"
  233. msgtest 'Test verify a file' 'with good keyring'
  234. testsuccess --nomsg aptkey --quiet --readonly --keyring "${KEYDIR}/testcase-multikey.pub.${EXT}" verify "${SIGNATURE}.gpg" "${SIGNATURE}"
  235. cleanplate
  236. cat "${KEYDIR}/joesixpack.pub.gpg" "${KEYDIR}/marvinparanoid.pub.gpg" > "${KEYDIR}/double.pub.gpg"
  237. cat "${KEYDIR}/joesixpack.pub.asc" "${KEYDIR}/marvinparanoid.pub.asc" > "${KEYDIR}/double.pub.asc"
  238. cat "${KEYDIR}/joesixpack.sec" "${KEYDIR}/marvinparanoid.sec" > "${KEYDIR}/double.sec"
  239. cp -a "${KEYDIR}/double.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/double.${EXT}"
  240. cp -a "${KEYDIR}/testcase-multikey.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/multikey.${EXT}"
  241. rm -f "${SIGNATURE}.gpg"
  242. testsuccess aptkey --quiet --keyring "${KEYDIR}/double.pub.gpg" --secret-keyring "${KEYDIR}/double.sec" --readonly \
  243. adv --batch --yes -u 'Marvin' -u 'Joe' --armor --detach-sign --sign --output "${SIGNATURE}.gpg" "${SIGNATURE}"
  244. testsuccess test -s "${SIGNATURE}.gpg" -a -s "${SIGNATURE}"
  245. for GPGV in '' 'gpgv' 'gpgv1' 'gpgv2'; do
  246. echo "APT::Key::GPGVCommand \"$GPGV\";" > "${ROOTDIR}/etc/apt/apt.conf.d/00gpgvcmd"
  247. if [ -n "$GPGV" ] && ! command dpkg -l gnupg1 2>&1 | grep -q '^ii'; then continue; fi
  248. msgtest 'Test verify a doublesigned file' 'with all keys'
  249. testsuccess --nomsg aptkey --quiet --readonly verify "${SIGNATURE}.gpg" "${SIGNATURE}"
  250. msgtest 'Test verify a doublesigned file' 'with good keyring joe'
  251. testmultigpg --keyring "${KEYDIR}/joesixpack.pub.${EXT}" verify "${SIGNATURE}.gpg" "${SIGNATURE}"
  252. msgtest 'Test verify a doublesigned file' 'with good keyring marvin'
  253. testmultigpg --keyring "${KEYDIR}/marvinparanoid.pub.${EXT}" verify "${SIGNATURE}.gpg" "${SIGNATURE}"
  254. msgtest 'Test fail verify a doublesigned file' 'with bad keyring'
  255. testfailure --nomsg aptkey --quiet --readonly --keyring "${KEYDIR}/rexexpired.pub.${EXT}" verify "${SIGNATURE}.gpg" "${SIGNATURE}"
  256. msgtest 'Test fail verify a doublesigned file' 'with non-existing keyring'
  257. testfailure --nomsg aptkey --quiet --readonly --keyring "${KEYDIR}/does-not-exist.pub.${EXT}" verify "${SIGNATURE}.gpg" "${SIGNATURE}"
  258. testfailure test -e "${KEYDIR}/does-not-exist.pub.${EXT}"
  259. # note: this isn't how apts gpgv method implements keyid for verify
  260. msgtest 'Test verify a doublesigned file' 'with good keyid'
  261. testmultigpg --keyid 'Paranoid' verify "${SIGNATURE}.gpg" "${SIGNATURE}"
  262. msgtest 'Test fail verify a doublesigned file' 'with bad keyid'
  263. testfailure --nomsg aptkey --quiet --readonly --keyid 'Rex' verify "${SIGNATURE}.gpg" "${SIGNATURE}"
  264. msgtest 'Test fail verify a doublesigned file' 'with non-existing keyid'
  265. testfailure --nomsg aptkey --quiet --readonly --keyid 'Kalnischkies' verify "${SIGNATURE}.gpg" "${SIGNATURE}"
  266. msgtest 'Test verify fails on' 'bad doublesigned file'
  267. testfailure --nomsg aptkey --quiet --readonly verify "${SIGNATURE}.gpg" "${SIGNATURE}2"
  268. done
  269. rm -f "${ROOTDIR}/etc/apt/apt.conf.d/00gpgvcmd"
  270. }
  271. setupgpgcommand() {
  272. local GPGEXE;
  273. if command dpkg -l gnupg1 2>&1 | grep -q '^ii'; then
  274. if [ "$1" = '1' ]; then
  275. GPGEXE='gpg1'
  276. else
  277. GPGEXE='gpg'
  278. fi
  279. else
  280. if [ "$1" = '1' ]; then
  281. GPGEXE='gpg'
  282. else
  283. GPGEXE='gpg2'
  284. fi
  285. fi
  286. msgmsg 'Force tests to be run with' "$GPGEXE"
  287. echo "APT::Key::GPGCommand \"$GPGEXE\";" > "${ROOTDIR}/etc/apt/apt.conf.d/00gpgcmd"
  288. testsuccess aptkey --readonly adv --version
  289. cp "${ROOTDIR}/tmp/testsuccess.output" "${TMPWORKINGDIRECTORY}/aptkey.version"
  290. testsuccess grep "^gpg (GnuPG) $1\." "${TMPWORKINGDIRECTORY}/aptkey.version"
  291. }
  292. (cd /; find "${TMPWORKINGDIRECTORY}/keys" -name '*.pub' -type f) | while read trusted; do
  293. testsuccess aptkey --keyring "$trusted" adv --armor --export --output "${trusted}.asc"
  294. cp -a "$trusted" "${trusted}.gpg"
  295. done
  296. # run with default (whatever this is) in current CWD with relative paths
  297. ROOTDIR="./rootdir"
  298. KEYDIR="./keys"
  299. testrun
  300. # run with … and up the game with a strange CWD & absolute paths
  301. ROOTDIR="${TMPWORKINGDIRECTORY}/rootdir"
  302. KEYDIR="${TMPWORKINGDIRECTORY}/keys"
  303. mkdir inaccessible
  304. cd inaccessible
  305. chmod 600 ../inaccessible
  306. testfilestats "${TMPWORKINGDIRECTORY}/inaccessible" '%a' '=' '600'
  307. setupgpgcommand '1'
  308. testrun
  309. setupgpgcommand '2'
  310. testrun
  311. msgmsg 'Tests to be run with' 'asc files'
  312. rm -f "${ROOTDIR}/etc/apt/apt.conf.d/00gpgcmd"
  313. testrun 'asc'