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