4 TESTDIR
="$(readlink -f "$(dirname "$0")")"
8 configarchitecture "i386
"
10 export APT_DONT_SIGN='Release.gpg'
16 local DATE="${2:-now}"
17 if [ "$DATE" = 'now' ]; then
18 if [ "$1" = "${PKGFILE}-new" ]; then
24 for release in $(find rootdir/var/lib/apt/lists 2> /dev/null); do
25 touch -d 'now - 1 year' "$release"
28 cp "$1" aptarchive/Packages
29 find aptarchive -name 'Release' -delete
30 compressfile 'aptarchive/Packages' "$DATE"
31 generatereleasefiles "$DATE" 'now + 1 month'
35 rm -rf rootdir/var/cache/apt/archives
36 testsuccessequal "Reading package lists...
37 Building dependency tree...
39 aptitude
| synaptic
| wajig dpkg
-dev apt
-doc bzip2 lzma python
-apt
40 The following NEW packages will be installed
:
42 0 upgraded
, 1 newly installed
, 0 to remove and
0 not upgraded.
43 After this operation
, 5370 kB of additional disk space will be used.
44 Get
:1 http
://localhost
:${APTHTTPPORT} apt
0.7.25.3
45 Download complete and
in download only mode
" aptget install apt -dy
49 rm -rf rootdir/var/cache/apt/archives
50 testsuccessequal "Reading package lists...
51 Building dependency tree...
53 aptitude
| synaptic
| wajig dpkg
-dev apt
-doc bzip2 lzma python
-apt
54 The following NEW packages will be installed
:
56 0 upgraded
, 1 newly installed
, 0 to remove and
0 not upgraded.
57 After this operation
, 5808 kB of additional disk space will be used.
58 Get
:1 http
://localhost
:${APTHTTPPORT} apt
0.8.0~pre1
59 Download complete and
in download only mode
" aptget install apt -dy
63 testfailureequal 'Reading package lists...
64 Building dependency tree...
66 aptitude | synaptic | wajig dpkg-dev apt-doc bzip2 lzma python-apt
67 The following NEW packages will be installed:
69 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
70 After this operation, 5370 kB of additional disk space will be used.
71 WARNING: The following packages cannot be authenticated!
73 E: There were unauthenticated packages and -y was used without --allow-unauthenticated' aptget install apt -dy
77 testfailureequal 'Reading package lists...
78 Building dependency tree...
80 aptitude | synaptic | wajig dpkg-dev apt-doc bzip2 lzma python-apt
81 The following NEW packages will be installed:
83 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
84 After this operation, 5808 kB of additional disk space will be used.
85 WARNING: The following packages cannot be authenticated!
87 E: There were unauthenticated packages and -y was used without --allow-unauthenticated' aptget install apt -dy
90 # fake our downloadable file
91 touch aptarchive/apt.deb
93 PKGFILE="${TESTDIR}/$(echo "$(basename "$0")" | sed 's#^test-#Packages-#')"
95 updatewithwarnings
() {
96 testwarning aptget update
-o Debug
::pkgAcquire
::Worker
=1 -o Debug
::Acquire
::gpgv
=1
97 testsuccess
grep -E "$1" rootdir
/tmp
/testwarning.output
101 msgmsg
'Cold archive signed by' 'Joe Sixpack'
103 rm -rf rootdir
/var
/lib
/apt
/lists
104 signreleasefiles
'Joe Sixpack'
105 successfulaptgetupdate
106 testsuccessequal
"$(cat "${PKGFILE}")
110 msgmsg
'Good warm archive signed by' 'Joe Sixpack'
111 prepare
"${PKGFILE}-new"
112 signreleasefiles
'Joe Sixpack'
113 successfulaptgetupdate
114 testsuccessequal
"$(cat "${PKGFILE}-new")
118 msgmsg
'Cold archive signed by' 'Rex Expired'
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 updatewithwarnings
'^W: .* EXPKEYSIG'
124 testsuccessequal
"$(cat "${PKGFILE}")
127 rm -f rootdir
/etc
/apt
/trusted.gpg.d
/rexexpired.gpg
129 msgmsg
'Cold archive expired signed by' 'Joe Sixpack'
130 if dpkg
--compare-versions "$(aptkey adv --version | head -n 2 | tail -n 1 | cut -d' ' -f 3)" '>=' '2.1' >/dev
/null
2>&1; then
131 touch rootdir
/etc
/apt
/apt.conf.d
/99gnupg2
132 elif gpg2
--version >/dev
/null
2>&1; then
133 echo 'Apt::Key::gpgcommand "gpg2";' > rootdir
/etc
/apt
/apt.conf.d
/99gnupg2
134 if ! dpkg
--compare-versions "$(aptkey adv --version | head -n 2 | tail -n 1 | cut -d' ' -f 3)" '>=' '2.1' >/dev
/null
2>&1; then
135 rm rootdir
/etc
/apt
/apt.conf.d
/99gnupg2
138 if [ -e rootdir
/etc
/apt
/apt.conf.d
/99gnupg2
]; then
140 rm -rf rootdir
/var
/lib
/apt
/lists
141 signreleasefiles
'Joe Sixpack' 'aptarchive' --faked-system-time "20070924T154812" --default-sig-expire 2016-04-01
142 updatewithwarnings
'^W: .* EXPSIG'
143 testsuccessequal
"$(cat "${PKGFILE}")
146 rm -f rootdir
/etc
/apt
/apt.conf.d
/99gnupg2
148 msgskip
'Not a new enough gpg available providing --fake-system-time'
151 msgmsg
'Cold archive signed by' 'Joe Sixpack,Marvin Paranoid'
153 rm -rf rootdir
/var
/lib
/apt
/lists
154 signreleasefiles
'Joe Sixpack,Marvin Paranoid'
155 successfulaptgetupdate
'NO_PUBKEY'
156 testsuccessequal
"$(cat "${PKGFILE}")
160 msgmsg
'Cold archive signed by' 'Joe Sixpack,Rex Expired'
162 rm -rf rootdir
/var
/lib
/apt
/lists
163 signreleasefiles
'Joe Sixpack,Rex Expired'
164 cp keys
/rexexpired.pub rootdir
/etc
/apt
/trusted.gpg.d
/rexexpired.gpg
165 successfulaptgetupdate
'EXPKEYSIG'
166 rm -f rootdir
/etc
/apt
/trusted.gpg.d
/rexexpired.gpg
167 testsuccessequal
"$(cat "${PKGFILE}")
171 msgmsg
'Cold archive signed by' 'Marvin Paranoid'
173 rm -rf rootdir
/var
/lib
/apt
/lists
174 signreleasefiles
'Marvin Paranoid'
175 updatewithwarnings
'^W: .* NO_PUBKEY'
176 testsuccessequal
"$(cat "${PKGFILE}")
180 msgmsg
'Bad warm archive signed by' 'Joe Sixpack'
181 prepare
"${PKGFILE}-new"
182 signreleasefiles
'Joe Sixpack'
183 successfulaptgetupdate
184 testsuccessequal
"$(cat "${PKGFILE}-new")
188 msgmsg
'Cold archive signed by' 'Joe Sixpack'
190 rm -rf rootdir
/var
/lib
/apt
/lists
191 signreleasefiles
'Joe Sixpack'
192 successfulaptgetupdate
193 testsuccessequal
"$(cat "${PKGFILE}")
197 msgmsg
'Good warm archive signed by' 'Marvin Paranoid'
198 prepare
"${PKGFILE}-new"
199 signreleasefiles
'Marvin Paranoid'
200 updatewithwarnings
'^W: .* NO_PUBKEY'
201 testsuccessequal
"$(cat "${PKGFILE}")
205 msgmsg
'Good warm archive signed by' 'Rex Expired'
206 prepare
"${PKGFILE}-new"
207 cp keys
/rexexpired.pub rootdir
/etc
/apt
/trusted.gpg.d
/rexexpired.gpg
208 signreleasefiles
'Rex Expired'
209 updatewithwarnings
'^W: .* EXPKEYSIG'
210 testsuccessequal
"$(cat "${PKGFILE}")
213 rm rootdir
/etc
/apt
/trusted.gpg.d
/rexexpired.gpg
215 msgmsg
'Good warm archive signed by' 'Joe Sixpack'
216 prepare
"${PKGFILE}-new"
218 successfulaptgetupdate
219 testsuccessequal
"$(cat "${PKGFILE}-new")
223 msgmsg
'Cold archive signed by good keyring' 'Marvin Paranoid'
225 rm -rf rootdir
/var
/lib
/apt
/lists
226 signreleasefiles
'Marvin Paranoid'
227 local MARVIN
="$(readlink -f keys/marvinparanoid.pub)"
228 sed -i "s#^\(deb\(-src\)\?\) #\1 [signed-by=$MARVIN] #" rootdir
/etc
/apt
/sources.list.d
/*
229 successfulaptgetupdate
230 testsuccessequal
"$(cat "${PKGFILE}")
234 msgmsg
'Cold archive signed by bad keyring' 'Joe Sixpack'
235 rm -rf rootdir
/var
/lib
/apt
/lists
236 signreleasefiles
'Joe Sixpack'
237 updatewithwarnings
'^W: .* NO_PUBKEY'
238 sed -i "s#^\(deb\(-src\)\?\) \[signed-by=$MARVIN\] #\1 #" rootdir
/etc
/apt
/sources.list.d
/*
240 local MARVIN
="$(aptkey --keyring $MARVIN finger --with-colons | grep '^fpr' | cut -d':' -f 10)"
241 msgmsg
'Cold archive signed by bad keyid' 'Joe Sixpack'
242 rm -rf rootdir
/var
/lib
/apt
/lists
243 signreleasefiles
'Joe Sixpack'
244 sed -i "s#^\(deb\(-src\)\?\) #\1 [signed-by=$MARVIN] #" rootdir
/etc
/apt
/sources.list.d
/*
245 updatewithwarnings
'^W: .* be verified because the public key is not available: .*'
247 msgmsg
'Cold archive signed by good keyid' 'Marvin Paranoid'
248 rm -rf rootdir
/var
/lib
/apt
/lists
249 signreleasefiles
'Marvin Paranoid'
250 cp keys
/marvinparanoid.pub rootdir
/etc
/apt
/trusted.gpg.d
/marvinparanoid.gpg
251 successfulaptgetupdate
252 testsuccessequal
"$(cat "${PKGFILE}")
256 msgmsg
'Cold archive signed by good keyid' 'Marvin Paranoid,Joe Sixpack'
257 rm -rf rootdir
/var
/lib
/apt
/lists
258 signreleasefiles
'Marvin Paranoid,Joe Sixpack'
259 successfulaptgetupdate
'NoPubKey: GOODSIG'
260 testsuccessequal
"$(cat "${PKGFILE}")
264 local SIXPACK
="$(aptkey --keyring keys/joesixpack.pub finger --with-colons | grep '^fpr' | cut -d':' -f 10)"
265 msgmsg
'Cold archive signed by good keyids' 'Joe Sixpack'
266 rm -rf rootdir
/var
/lib
/apt
/lists
267 signreleasefiles
'Joe Sixpack'
268 sed -i "s#^\(deb\(-src\)\?\) \[signed-by=$MARVIN\] #\1 [signed-by=${SIXPACK},${MARVIN}] #" rootdir
/etc
/apt
/sources.list.d
/*
269 successfulaptgetupdate
270 testsuccessequal
"$(cat "${PKGFILE}")
274 msgmsg
'Cold archive signed by good keyids' 'Joe Sixpack'
275 rm -rf rootdir
/var
/lib
/apt
/lists
276 sed -i "s#^\(deb\(-src\)\?\) \[signed-by=${SIXPACK},${MARVIN}\] #\1 [signed-by=${MARVIN},${SIXPACK}] #" rootdir
/etc
/apt
/sources.list.d
/*
277 successfulaptgetupdate
278 testsuccessequal
"$(cat "${PKGFILE}")
281 rm -f rootdir
/etc
/apt
/trusted.gpg.d
/marvinparanoid.gpg
282 sed -i "s#^\(deb\(-src\)\?\) \[signed-by=${MARVIN},${SIXPACK}\] #\1 #" rootdir
/etc
/apt
/sources.list.d
/*
284 rm -rf rootdir
/var
/lib
/apt
/lists
-bak
285 cp -a rootdir
/var
/lib
/apt
/lists rootdir
/var
/lib
/apt
/lists
-bak
286 prepare
"${PKGFILE}-new"
287 signreleasefiles
'Joe Sixpack'
289 msgmsg
'Warm archive with signed-by' 'Joe Sixpack'
290 sed -i "/^Valid-Until: / a\
291 Signed-By: ${SIXPACK}" rootdir
/var
/lib
/apt
/lists
/*Release
292 touch -d 'now - 1 year' rootdir
/var
/lib
/apt
/lists
/*Release
293 successfulaptgetupdate
294 testsuccessequal
"$(cat "${PKGFILE}-new")
298 msgmsg
'Warm archive with signed-by' 'Marvin Paranoid'
299 rm -rf rootdir
/var
/lib
/apt
/lists
300 cp -a rootdir
/var
/lib
/apt
/lists
-bak rootdir
/var
/lib
/apt
/lists
301 sed -i "/^Valid-Until: / a\
302 Signed-By: ${MARVIN}" rootdir
/var
/lib
/apt
/lists
/*Release
303 touch -d 'now - 1 year' rootdir
/var
/lib
/apt
/lists
/*Release
304 updatewithwarnings
'W: .* public key is not available: GOODSIG'
305 testsuccessequal
"$(cat "${PKGFILE}")
309 msgmsg
'Warm archive with outdated signed-by' 'Marvin Paranoid'
310 rm -rf rootdir
/var
/lib
/apt
/lists
311 cp -a rootdir
/var
/lib
/apt
/lists
-bak rootdir
/var
/lib
/apt
/lists
312 sed -i "/^Valid-Until: / a\
313 Valid-Until: $(date -u -d "now - 2min" '+%a, %d %b %Y %H:%M:%S %Z') \\
314 Signed-By: ${MARVIN}" rootdir
/var
/lib
/apt
/lists
/*Release
315 touch -d 'now - 1 year' rootdir
/var
/lib
/apt
/lists
/*Release
316 successfulaptgetupdate
317 testsuccessequal
"$(cat "${PKGFILE}-new")
321 msgmsg
'Warm archive with two signed-bys' 'Joe Sixpack'
322 rm -rf rootdir
/var
/lib
/apt
/lists
323 cp -a rootdir
/var
/lib
/apt
/lists
-bak rootdir
/var
/lib
/apt
/lists
324 sed -i "/^Valid-Until: / a\
325 Signed-By: ${MARVIN} ${MARVIN}, \\
326 ${SIXPACK}" rootdir
/var
/lib
/apt
/lists
/*Release
327 touch -d 'now - 1 year' rootdir
/var
/lib
/apt
/lists
/*Release
328 successfulaptgetupdate
329 testsuccessequal
"$(cat "${PKGFILE}-new")
335 msgmsg
'Cold archive signed by' 'Joe Sixpack'
337 rm -rf rootdir
/var
/lib
/apt
/lists
338 signreleasefiles
'Joe Sixpack'
339 successfulaptgetupdate
341 # New .deb but now an unsigned archive. For example MITM to circumvent
342 # package verification.
343 msgmsg
'Warm archive signed by' 'nobody'
344 prepare
"${PKGFILE}-new"
345 find aptarchive
/ \
( -name InRelease
-o -name Release.gpg \
) -delete
346 updatewithwarnings
'W: .* no longer signed.'
347 testsuccessequal
"$(cat "${PKGFILE}-new")
351 # Unsigned archive from the beginning must also be detected.
352 msgmsg
'Cold archive signed by' 'nobody'
353 rm -rf rootdir
/var
/lib
/apt
/lists
354 updatewithwarnings
'W: .* is not signed.'
355 testsuccessequal
"$(cat "${PKGFILE}-new")
361 echo "APT::Hashes::$APT_TESTS_DIGEST_ALGO::$1 \"yes\";" > rootdir
/etc
/apt
/apt.conf.d
/truststate
362 msgmsg
"Running base test with $1 digest"
365 for DELETEFILE
in 'InRelease' 'Release.gpg'; do
366 export APT_DONT_SIGN
="$DELETEFILE"
367 msgmsg
"Running test with deletion of $DELETEFILE and $1 digest"
369 export APT_DONT_SIGN
='Release.gpg'
373 # diable some protection by default and ensure we still do the verification
375 cat > rootdir
/etc
/apt
/apt.conf.d
/weaken
-security <<EOF
376 Acquire::AllowInsecureRepositories "1";
377 Acquire::AllowDowngradeToInsecureRepositories "1";
379 # the hash marked as configurable in our gpgv method
380 export APT_TESTS_DIGEST_ALGO
='SHA224'
382 successfulaptgetupdate
() {
383 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=1 -o Debug
::Acquire
::gpgv
=1
385 cp rootdir
/tmp
/testsuccess.output aptupdate.output
386 testsuccess
grep "$1" aptupdate.output
391 successfulaptgetupdate
() {
392 testwarning aptget update
-o Debug
::pkgAcquire
::Worker
=1 -o Debug
::Acquire
::gpgv
=1
394 testsuccess
grep "$1" rootdir
/tmp
/testwarning.output
396 testsuccess
grep 'uses weak digest algorithm' rootdir
/tmp
/testwarning.output
400 msgmsg
"Running test with apt-untrusted digest"
401 echo "APT::Hashes::$APT_TESTS_DIGEST_ALGO::Untrusted \"yes\";" > rootdir
/etc
/apt
/apt.conf.d
/truststate
403 for DELETEFILE
in 'InRelease' 'Release.gpg'; do
404 export APT_DONT_SIGN
="$DELETEFILE"
405 msgmsg
'Cold archive signed by' 'Joe Sixpack'
407 rm -rf rootdir
/var
/lib
/apt
/lists
408 signreleasefiles
'Joe Sixpack'
409 testfailure aptget update
--no-allow-insecure-repositories -o Debug
::pkgAcquire
::Worker
=1 -o Debug
::Acquire
::gpgv
=1
410 testsuccess
grep 'The following signatures were invalid' rootdir
/tmp
/testfailure.output
412 testwarning aptget update
--allow-insecure-repositories -o Debug
::pkgAcquire
::Worker
=1 -o Debug
::Acquire
::gpgv
=1
414 rm -rf rootdir
/var
/lib
/apt
/lists
415 sed -i 's#^deb\(-src\)\? #deb\1 [allow-insecure=yes] #' rootdir
/etc
/apt
/sources.list.d
/*
416 testwarning aptget update
--no-allow-insecure-repositories -o Debug
::pkgAcquire
::Worker
=1 -o Debug
::Acquire
::gpgv
=1
418 sed -i 's#^deb\(-src\)\? \[allow-insecure=yes\] #deb\1 #' rootdir
/etc
/apt
/sources.list.d
/*
420 msgmsg
'Cold archive signed by' 'Marvin Paranoid'
422 rm -rf rootdir
/var
/lib
/apt
/lists
423 signreleasefiles
'Marvin Paranoid'
424 testfailure aptget update
--no-allow-insecure-repositories -o Debug
::pkgAcquire
::Worker
=1 -o Debug
::Acquire
::gpgv
=1
426 updatewithwarnings
'^W: .* NO_PUBKEY'
427 testsuccessequal
"$(cat "${PKGFILE}")
430 export APT_DONT_SIGN
='Release.gpg'
435 msgmsg
"Running test with gpgv-untrusted digest"
436 export APT_TESTS_DIGEST_ALGO
='MD5'