]> git.saurik.com Git - apt.git/blame - test/integration/test-apt-key
Don't download "optional" files not in Release :/.
[apt.git] / test / integration / test-apt-key
CommitLineData
80f3aeb0
DK
1#!/bin/sh
2set -e
3
bc8f83a5
DK
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)\$!"
9TMPDIR_ADD="This is fü\$\$ing cràzy, \$(apt -v)\$!"
10
3abb6a6a
DK
11TESTDIR="$(readlink -f "$(dirname "$0")")"
12. "$TESTDIR/framework"
80f3aeb0
DK
13
14setupenvironment
15configarchitecture 'amd64'
16
93d0d08c
DK
17# start from a clean plate again
18cleanplate() {
0cfec3ab
DK
19 rm -rf "${ROOTDIR}/etc/apt/trusted.gpg.d/" "${ROOTDIR}/etc/apt/trusted.gpg"
20 mkdir "${ROOTDIR}/etc/apt/trusted.gpg.d/"
93d0d08c 21}
fb7b11eb
DK
22testmultigpg() {
23 testfailure --nomsg aptkey --quiet --readonly "$@"
0cfec3ab
DK
24 testsuccess grep "^gpgv: Can't check signature" "${ROOTDIR}/tmp/testfailure.output"
25 testsuccess grep '^gpgv: Good signature from' "${ROOTDIR}/tmp/testfailure.output"
fb7b11eb 26}
2906182d
DK
27testaptkeyskeyring() {
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}
80f3aeb0 36
93d0d08c 37testrun() {
2906182d
DK
38 local EXT="${1:-gpg}"
39 echo "APT::Key::ArchiveKeyring \"${KEYDIR}/joesixpack.pub.gpg\";
40APT::Key::RemovedKeys \"${KEYDIR}/rexexpired.pub.gpg\";" > "${ROOTDIR}/etc/apt/apt.conf.d/aptkey.conf"
0cfec3ab 41
93d0d08c 42 cleanplate
2906182d 43 ln -sf "$(readlink -f "${KEYDIR}/joesixpack.pub.${EXT}")" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
0cfec3ab 44 testaptkeys 'Joe Sixpack'
80f3aeb0 45
0cfec3ab 46 testsuccess aptkey list
93d0d08c 47 msgtest 'Check that paths in list output are not' 'double-slashed'
0cfec3ab 48 testfailure --nomsg grep '//' "${ROOTDIR}/tmp/testsuccess.output"
80f3aeb0 49
0cfec3ab 50 testsuccess aptkey finger
93d0d08c 51 msgtest 'Check that paths in finger output are not' 'double-slashed'
0cfec3ab 52 testfailure --nomsg grep '//' "${ROOTDIR}/tmp/testsuccess.output"
80f3aeb0 53
2906182d 54 cp -a "${KEYDIR}/joesixpack.pub.${EXT}" "${KEYDIR}/joesixpack.pub.${EXT}.bak"
19fdf93d
DK
55 testequalor2 'gpg: key DBAC8DAE: "Joe Sixpack (APT Testcases Dummy) <joe@example.org>" not changed
56gpg: Total number processed: 1
57gpg: unchanged: 1' 'gpg: key 5A90D141DBAC8DAE: "Joe Sixpack (APT Testcases Dummy) <joe@example.org>" not changed
93d0d08c
DK
58gpg: Total number processed: 1
59gpg: unchanged: 1' aptkey --fakeroot update
2906182d
DK
60 testsuccess test -L "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
61 testsuccess cmp "${KEYDIR}/joesixpack.pub.${EXT}" "${KEYDIR}/joesixpack.pub.${EXT}.bak"
80f3aeb0 62
f14cde2c 63 testaptkeys 'Joe Sixpack'
0cfec3ab 64 testfailure test -e "${ROOTDIR}/etc/apt/trusted.gpg"
f14cde2c 65
2906182d 66 testsuccess aptkey --fakeroot add "${KEYDIR}/rexexpired.pub.${EXT}"
0cfec3ab 67 testfilestats "${ROOTDIR}/etc/apt/trusted.gpg" '%a' '=' '644'
04937adc 68
f14cde2c 69 testaptkeys 'Rex Expired' 'Joe Sixpack'
04937adc 70
38005d8b 71 msgtest 'Check that Sixpack key can be' 'exported'
0cfec3ab 72 aptkey export 'Sixpack' > "${TMPWORKINGDIRECTORY}/aptkey.export"
2906182d 73 aptkey --keyring "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}" exportall > "${TMPWORKINGDIRECTORY}/aptkey.exportall"
0cfec3ab
DK
74 testsuccess --nomsg cmp "${TMPWORKINGDIRECTORY}/aptkey.export" "${TMPWORKINGDIRECTORY}/aptkey.exportall"
75 testsuccess test -s "${TMPWORKINGDIRECTORY}/aptkey.export"
76 testsuccess test -s "${TMPWORKINGDIRECTORY}/aptkey.exportall"
38005d8b 77
93d0d08c
DK
78 msgtest 'Execute update again to trigger removal of' 'Rex Expired key'
79 testsuccess --nomsg aptkey --fakeroot update
80
f14cde2c 81 testaptkeys 'Joe Sixpack'
93d0d08c
DK
82
83 msgtest "Try to remove a key which exists, but isn't in the" 'forced keyring'
0cfec3ab 84 testsuccess --nomsg aptkey --fakeroot --keyring "${ROOTDIR}/etc/apt/trusted.gpg" del DBAC8DAE
93d0d08c 85
f14cde2c 86 testaptkeys 'Joe Sixpack'
93d0d08c
DK
87
88 testsuccess aptkey --fakeroot del DBAC8DAE
89 testempty aptkey list
90
2906182d
DK
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
b0d40854 104 msgtest 'Test key removal with' 'lowercase key ID' #keylength somewhere between 8byte and short
05f64ca2 105 cleanplate
2906182d 106 cp -a "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
05f64ca2
DK
107 testsuccess --nomsg aptkey --fakeroot del d141dbac8dae
108 testempty aptkey list
109
105503b4
DK
110 if [ "$(id -u)" != '0' ]; then
111 msgtest 'Test key removal with' 'unreadable key'
112 cleanplate
2906182d
DK
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}"
105503b4
DK
116 testwarning --nomsg aptkey --fakeroot del d141dbac8dae
117 testwarning aptkey list
2906182d
DK
118 chmod 644 "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.${EXT}"
119 rm -f "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.${EXT}"
105503b4
DK
120 grep -v '^W: ' "${ROOTDIR}/tmp/testwarning.output" > "${ROOTDIR}/aptkeylist.output" || true
121 testempty cat "${ROOTDIR}/aptkeylist.output"
122 fi
123
93d0d08c
DK
124 msgtest 'Test key removal with' 'single key in real file'
125 cleanplate
2906182d 126 cp -a "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
93d0d08c
DK
127 testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
128 testempty aptkey list
2906182d
DK
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}~"
93d0d08c 131
031a3f25
DK
132 msgtest 'Test key removal with' 'different key specs'
133 cleanplate
2906182d
DK
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}"
031a3f25
DK
136 testsuccess --nomsg aptkey --fakeroot del 0xDBAC8DAE 528144E2
137 testempty aptkey list
2906182d
DK
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}~"
031a3f25 142
29f1b977
JM
143 msgtest 'Test key removal with' 'long key ID'
144 cleanplate
2906182d 145 cp -a "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
29f1b977
JM
146 testsuccess --nomsg aptkey --fakeroot del 5A90D141DBAC8DAE
147 testempty aptkey list
2906182d
DK
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}~"
29f1b977 150
ba72845c
DK
151 msgtest 'Test key removal with' 'fingerprint'
152 cleanplate
2906182d 153 cp -a "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
ba72845c
DK
154 testsuccess --nomsg aptkey --fakeroot del 34A8E9D18DB320F367E8EAA05A90D141DBAC8DAE
155 testempty aptkey list
2906182d
DK
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}~"
ba72845c 158
e289907f
DK
159 msgtest 'Test key removal with' 'spaced fingerprint'
160 cleanplate
2906182d 161 cp -a "${KEYDIR}/joesixpack.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
e289907f
DK
162 testsuccess --nomsg aptkey --fakeroot del '34A8 E9D1 8DB3 20F3 67E8 EAA0 5A90 D141 DBAC 8DAE'
163 testempty aptkey list
2906182d
DK
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}~"
e289907f 166
93d0d08c
DK
167 msgtest 'Test key removal with' 'single key in softlink'
168 cleanplate
2906182d 169 ln -sf "$(readlink -f "${KEYDIR}/joesixpack.pub.${EXT}")" "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
93d0d08c
DK
170 testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
171 testempty aptkey list
2906182d
DK
172 testfailure test -e "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}"
173 testsuccess test -L "${ROOTDIR}/etc/apt/trusted.gpg.d/joesixpack.${EXT}~"
93d0d08c
DK
174
175 cleanplate
2906182d
DK
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}"
f14cde2c 179 testaptkeys 'Joe Sixpack' 'Marvin Paranoid'
2906182d
DK
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"
93d0d08c
DK
182
183 msgtest 'Test key removal with' 'multi key in real file'
184 cleanplate
2906182d 185 cp -a "${KEYDIR}/testcase-multikey.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/multikey.${EXT}"
93d0d08c 186 testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
f14cde2c 187 testaptkeys 'Marvin Paranoid'
2906182d 188 testsuccess cmp "${KEYDIR}/testcase-multikey.pub.${EXT}" "${ROOTDIR}/etc/apt/trusted.gpg.d/multikey.${EXT}~"
93d0d08c
DK
189
190 msgtest 'Test key removal with' 'multi key in softlink'
191 cleanplate
2906182d 192 ln -s "$(readlink -f "${KEYDIR}/testcase-multikey.pub.${EXT}")" "${ROOTDIR}/etc/apt/trusted.gpg.d/multikey.${EXT}"
93d0d08c 193 testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
f14cde2c 194 testaptkeys 'Marvin Paranoid'
2906182d
DK
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}~"
93d0d08c
DK
198
199 msgtest 'Test key removal with' 'multiple files including key'
200 cleanplate
2906182d
DK
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}"
93d0d08c 203 testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
f14cde2c 204 testaptkeys 'Marvin Paranoid'
2906182d
DK
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}~"
0dae96a2
DK
208
209 cleanplate
2906182d
DK
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}"
f14cde2c 212 testaptkeys 'Joe Sixpack' 'Joe Sixpack' 'Marvin Paranoid'
0dae96a2 213 msgtest 'Test merge-back of' 'added keys'
2906182d 214 testsuccess --nomsg aptkey adv --batch --yes --import "${KEYDIR}/rexexpired.pub.${EXT}"
f14cde2c 215 testaptkeys 'Rex Expired' 'Joe Sixpack' 'Joe Sixpack' 'Marvin Paranoid'
0dae96a2
DK
216
217 msgtest 'Test merge-back of' 'removed keys'
218 testsuccess --nomsg aptkey adv --batch --yes --delete-keys 27CE74F9
f14cde2c 219 testaptkeys 'Joe Sixpack' 'Joe Sixpack' 'Marvin Paranoid'
0dae96a2
DK
220
221 msgtest 'Test merge-back of' 'removed duplicate keys'
222 testsuccess --nomsg aptkey adv --batch --yes --delete-keys DBAC8DAE
f14cde2c 223 testaptkeys 'Marvin Paranoid'
b0d40854
DK
224
225 cleanplate
2906182d
DK
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}"
0cfec3ab 228 local SIGNATURE="${TMPWORKINGDIRECTORY}/signature"
b0d40854 229 msgtest 'Test signing a file' 'with a key'
0cfec3ab
DK
230 echo 'Verify me. This is my signature.' > "$SIGNATURE"
231 echo 'lalalalala' > "${SIGNATURE}2"
2906182d 232 testsuccess --nomsg aptkey --quiet --keyring "${KEYDIR}/marvinparanoid.pub.gpg" --secret-keyring "${KEYDIR}/marvinparanoid.sec" --readonly \
0cfec3ab
DK
233 adv --batch --yes --default-key 'Marvin' --armor --detach-sign --sign --output "${SIGNATURE}.gpg" "${SIGNATURE}"
234 testsuccess test -s "${SIGNATURE}.gpg" -a -s "${SIGNATURE}"
b0d40854 235
2fac0dd5 236 msgtest 'Test verify a file' 'with no sig'
2906182d 237 testfailure --nomsg aptkey --quiet --readonly --keyring "${KEYDIR}/testcase-multikey.pub.${EXT}" verify "${SIGNATURE}" "${SIGNATURE}2"
2fac0dd5 238
19fdf93d 239 for GPGV in '' 'gpgv' 'gpgv1' 'gpgv2'; do
0cfec3ab 240 echo "APT::Key::GPGVCommand \"$GPGV\";" > "${ROOTDIR}/etc/apt/apt.conf.d/00gpgvcmd"
19fdf93d 241 if [ -n "$GPGV" ] && ! command dpkg -l gnupg1 2>&1 | grep -q '^ii'; then continue; fi
f14cde2c
DK
242
243 msgtest 'Test verify a file' 'with all keys'
0cfec3ab 244 testsuccess --nomsg aptkey --quiet --readonly verify "${SIGNATURE}.gpg" "${SIGNATURE}"
b0d40854 245
105503b4
DK
246 if [ "$(id -u)" != '0' ]; then
247 msgtest 'Test verify a file' 'with unreadable key'
2906182d
DK
248 echo 'foobar' > "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.${EXT}"
249 chmod 000 "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.${EXT}"
105503b4
DK
250 testwarning --nomsg aptkey --quiet --readonly verify "${SIGNATURE}.gpg" "${SIGNATURE}"
251 testwarning aptkey list
2906182d
DK
252 chmod 644 "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.${EXT}"
253 rm -f "${ROOTDIR}/etc/apt/trusted.gpg.d/unreadablekey.${EXT}"
105503b4
DK
254 fi
255
f14cde2c 256 msgtest 'Test verify a file' 'with good keyring'
2906182d 257 testsuccess --nomsg aptkey --quiet --readonly --keyring "${KEYDIR}/testcase-multikey.pub.${EXT}" verify "${SIGNATURE}.gpg" "${SIGNATURE}"
b0d40854 258
f14cde2c 259 msgtest 'Test fail verify a file' 'with bad keyring'
2906182d 260 testfailure --nomsg aptkey --quiet --readonly --keyring "${KEYDIR}/joesixpack.pub.${EXT}" verify "${SIGNATURE}.gpg" "${SIGNATURE}"
b0d40854 261
f14cde2c 262 msgtest 'Test fail verify a file' 'with non-existing keyring'
2906182d
DK
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}"
b0d40854 265
4e03c47d 266 # note: this isn't how apts gpgv method implements keyid for verify
f14cde2c 267 msgtest 'Test verify a file' 'with good keyid'
0cfec3ab 268 testsuccess --nomsg aptkey --quiet --readonly --keyid 'Paranoid' verify "${SIGNATURE}.gpg" "${SIGNATURE}"
b0d40854 269
f14cde2c 270 msgtest 'Test fail verify a file' 'with bad keyid'
0cfec3ab 271 testfailure --nomsg aptkey --quiet --readonly --keyid 'Sixpack' verify "${SIGNATURE}.gpg" "${SIGNATURE}"
b0d40854 272
f14cde2c 273 msgtest 'Test fail verify a file' 'with non-existing keyid'
0cfec3ab 274 testfailure --nomsg aptkey --quiet --readonly --keyid 'Kalnischkies' verify "${SIGNATURE}.gpg" "${SIGNATURE}"
f14cde2c
DK
275
276 msgtest 'Test verify fails on' 'bad file'
0cfec3ab 277 testfailure --nomsg aptkey --quiet --readonly verify "${SIGNATURE}.gpg" "${SIGNATURE}2"
f14cde2c 278 done
0cfec3ab 279 rm -f "${ROOTDIR}/etc/apt/apt.conf.d/00gpgvcmd"
fb7b11eb
DK
280
281 msgtest 'Test verify a file' 'with good keyring'
2906182d 282 testsuccess --nomsg aptkey --quiet --readonly --keyring "${KEYDIR}/testcase-multikey.pub.${EXT}" verify "${SIGNATURE}.gpg" "${SIGNATURE}"
fb7b11eb
DK
283
284 cleanplate
2906182d
DK
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"
0cfec3ab 287 cat "${KEYDIR}/joesixpack.sec" "${KEYDIR}/marvinparanoid.sec" > "${KEYDIR}/double.sec"
2906182d
DK
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}"
0cfec3ab 290 rm -f "${SIGNATURE}.gpg"
2906182d 291 testsuccess aptkey --quiet --keyring "${KEYDIR}/double.pub.gpg" --secret-keyring "${KEYDIR}/double.sec" --readonly \
0cfec3ab
DK
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}"
fb7b11eb 294
19fdf93d 295 for GPGV in '' 'gpgv' 'gpgv1' 'gpgv2'; do
0cfec3ab 296 echo "APT::Key::GPGVCommand \"$GPGV\";" > "${ROOTDIR}/etc/apt/apt.conf.d/00gpgvcmd"
19fdf93d 297 if [ -n "$GPGV" ] && ! command dpkg -l gnupg1 2>&1 | grep -q '^ii'; then continue; fi
fb7b11eb
DK
298
299 msgtest 'Test verify a doublesigned file' 'with all keys'
0cfec3ab 300 testsuccess --nomsg aptkey --quiet --readonly verify "${SIGNATURE}.gpg" "${SIGNATURE}"
fb7b11eb
DK
301
302 msgtest 'Test verify a doublesigned file' 'with good keyring joe'
2906182d 303 testmultigpg --keyring "${KEYDIR}/joesixpack.pub.${EXT}" verify "${SIGNATURE}.gpg" "${SIGNATURE}"
fb7b11eb
DK
304
305 msgtest 'Test verify a doublesigned file' 'with good keyring marvin'
2906182d 306 testmultigpg --keyring "${KEYDIR}/marvinparanoid.pub.${EXT}" verify "${SIGNATURE}.gpg" "${SIGNATURE}"
fb7b11eb
DK
307
308 msgtest 'Test fail verify a doublesigned file' 'with bad keyring'
2906182d 309 testfailure --nomsg aptkey --quiet --readonly --keyring "${KEYDIR}/rexexpired.pub.${EXT}" verify "${SIGNATURE}.gpg" "${SIGNATURE}"
fb7b11eb
DK
310
311 msgtest 'Test fail verify a doublesigned file' 'with non-existing keyring'
2906182d
DK
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}"
fb7b11eb
DK
314
315 # note: this isn't how apts gpgv method implements keyid for verify
316 msgtest 'Test verify a doublesigned file' 'with good keyid'
0cfec3ab 317 testmultigpg --keyid 'Paranoid' verify "${SIGNATURE}.gpg" "${SIGNATURE}"
fb7b11eb
DK
318
319 msgtest 'Test fail verify a doublesigned file' 'with bad keyid'
0cfec3ab 320 testfailure --nomsg aptkey --quiet --readonly --keyid 'Rex' verify "${SIGNATURE}.gpg" "${SIGNATURE}"
fb7b11eb
DK
321
322 msgtest 'Test fail verify a doublesigned file' 'with non-existing keyid'
0cfec3ab 323 testfailure --nomsg aptkey --quiet --readonly --keyid 'Kalnischkies' verify "${SIGNATURE}.gpg" "${SIGNATURE}"
fb7b11eb
DK
324
325 msgtest 'Test verify fails on' 'bad doublesigned file'
0cfec3ab 326 testfailure --nomsg aptkey --quiet --readonly verify "${SIGNATURE}.gpg" "${SIGNATURE}2"
fb7b11eb 327 done
0cfec3ab 328 rm -f "${ROOTDIR}/etc/apt/apt.conf.d/00gpgvcmd"
93d0d08c 329}
04937adc 330
93d0d08c 331setupgpgcommand() {
19fdf93d
DK
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"
f14cde2c 348 testsuccess aptkey --readonly adv --version
0cfec3ab 349 cp "${ROOTDIR}/tmp/testsuccess.output" "${TMPWORKINGDIRECTORY}/aptkey.version"
19fdf93d 350 testsuccess grep "^gpg (GnuPG) $1\." "${TMPWORKINGDIRECTORY}/aptkey.version"
04937adc
DK
351}
352
2906182d
DK
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"
356done
357
0cfec3ab
DK
358# run with default (whatever this is) in current CWD with relative paths
359ROOTDIR="./rootdir"
360KEYDIR="./keys"
93d0d08c 361testrun
0cfec3ab
DK
362
363# run with … and up the game with a strange CWD & absolute paths
364ROOTDIR="${TMPWORKINGDIRECTORY}/rootdir"
365KEYDIR="${TMPWORKINGDIRECTORY}/keys"
366mkdir inaccessible
367cd inaccessible
368chmod 600 ../inaccessible
369testfilestats "${TMPWORKINGDIRECTORY}/inaccessible" '%a' '=' '600'
370
19fdf93d 371setupgpgcommand '1'
93d0d08c 372testrun
19fdf93d 373setupgpgcommand '2'
93d0d08c 374testrun
2906182d
DK
375
376msgmsg 'Tests to be run with' 'asc files'
377rm -f "${ROOTDIR}/etc/apt/apt.conf.d/00gpgcmd"
378testrun 'asc'