]>
Commit | Line | Data |
---|---|---|
fe0f7911 DK |
1 | #!/bin/sh |
2 | set -e | |
3 | ||
3abb6a6a DK |
4 | TESTDIR="$(readlink -f "$(dirname "$0")")" |
5 | . "$TESTDIR/framework" | |
fe0f7911 DK |
6 | |
7 | setupenvironment | |
8 | configarchitecture "i386" | |
9 | ||
10 | buildaptarchive | |
11 | setupflataptarchive | |
12 | changetowebserver | |
13 | ||
f2c0ec8b | 14 | webserverconfig 'aptwebserver::support::range' 'false' |
331e8396 | 15 | |
fe0f7911 DK |
16 | prepare() { |
17 | local DATE="${2:-now}" | |
331e8396 DK |
18 | if [ "$DATE" = 'now' ]; then |
19 | if [ "$1" = "${PKGFILE}-new" ]; then | |
20 | DATE='now - 1 day' | |
21 | else | |
22 | DATE='now - 7 day' | |
23 | fi | |
fe0f7911 DK |
24 | fi |
25 | for release in $(find rootdir/var/lib/apt/lists 2> /dev/null); do | |
63c71412 | 26 | touch -d 'now - 1 year' "$release" |
fe0f7911 | 27 | done |
8de79b68 | 28 | aptget clean |
63c71412 | 29 | cp "$1" aptarchive/Packages |
fe0f7911 | 30 | find aptarchive -name 'Release' -delete |
331e8396 | 31 | compressfile 'aptarchive/Packages' "$DATE" |
fe0f7911 DK |
32 | generatereleasefiles "$DATE" |
33 | } | |
34 | ||
35 | installaptold() { | |
6c0765c0 | 36 | testsuccessequal "Reading package lists... |
fe0f7911 DK |
37 | Building dependency tree... |
38 | Suggested packages: | |
9112f777 | 39 | aptitude | synaptic | wajig dpkg-dev apt-doc bzip2 lzma python-apt |
fe0f7911 DK |
40 | The following NEW packages will be installed: |
41 | apt | |
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. | |
6c0765c0 DK |
44 | Get:1 http://localhost:${APTHTTPPORT} apt 0.7.25.3 |
45 | Download complete and in download only mode" aptget install apt -dy | |
fe0f7911 DK |
46 | } |
47 | ||
48 | installaptnew() { | |
6c0765c0 | 49 | testsuccessequal "Reading package lists... |
fe0f7911 DK |
50 | Building dependency tree... |
51 | Suggested packages: | |
9112f777 | 52 | aptitude | synaptic | wajig dpkg-dev apt-doc bzip2 lzma python-apt |
fe0f7911 DK |
53 | The following NEW packages will be installed: |
54 | apt | |
55 | 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. | |
56 | After this operation, 5808 kB of additional disk space will be used. | |
6c0765c0 DK |
57 | Get:1 http://localhost:${APTHTTPPORT} apt 0.8.0~pre1 |
58 | Download complete and in download only mode" aptget install apt -dy | |
fe0f7911 DK |
59 | } |
60 | ||
61 | failaptold() { | |
25b86db1 | 62 | testfailureequal 'Reading package lists... |
fe0f7911 DK |
63 | Building dependency tree... |
64 | Suggested packages: | |
9112f777 | 65 | aptitude | synaptic | wajig dpkg-dev apt-doc bzip2 lzma python-apt |
fe0f7911 DK |
66 | The following NEW packages will be installed: |
67 | apt | |
68 | 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. | |
69 | After this operation, 5370 kB of additional disk space will be used. | |
70 | WARNING: The following packages cannot be authenticated! | |
71 | apt | |
b381a482 | 72 | E: There were unauthenticated packages and -y was used without --allow-unauthenticated' aptget install apt -dy |
fe0f7911 DK |
73 | } |
74 | ||
75 | failaptnew() { | |
25b86db1 | 76 | testfailureequal 'Reading package lists... |
fe0f7911 DK |
77 | Building dependency tree... |
78 | Suggested packages: | |
9112f777 | 79 | aptitude | synaptic | wajig dpkg-dev apt-doc bzip2 lzma python-apt |
fe0f7911 DK |
80 | The following NEW packages will be installed: |
81 | apt | |
82 | 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. | |
83 | After this operation, 5808 kB of additional disk space will be used. | |
84 | WARNING: The following packages cannot be authenticated! | |
85 | apt | |
b381a482 | 86 | E: There were unauthenticated packages and -y was used without --allow-unauthenticated' aptget install apt -dy |
fe0f7911 DK |
87 | } |
88 | ||
89 | # fake our downloadable file | |
90 | touch aptarchive/apt.deb | |
91 | ||
63c71412 | 92 | PKGFILE="${TESTDIR}/$(echo "$(basename "$0")" | sed 's#^test-#Packages-#')" |
fe0f7911 | 93 | |
6bf93605 | 94 | updatewithwarnings() { |
4e03c47d | 95 | testwarning aptget update -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::gpgv=1 |
6bf93605 | 96 | testsuccess grep -E "$1" rootdir/tmp/testwarning.output |
331e8396 DK |
97 | } |
98 | ||
fe0f7911 | 99 | runtest() { |
08b7761a | 100 | local DELETEFILE="$1" |
8fa99570 | 101 | msgmsg 'Cold archive signed by' 'Joe Sixpack' |
63c71412 | 102 | prepare "${PKGFILE}" |
fe0f7911 DK |
103 | rm -rf rootdir/var/lib/apt/lists |
104 | signreleasefiles 'Joe Sixpack' | |
105 | find aptarchive/ -name "$DELETEFILE" -delete | |
8fa99570 | 106 | successfulaptgetupdate |
63c71412 | 107 | testsuccessequal "$(cat "${PKGFILE}") |
fe0f7911 DK |
108 | " aptcache show apt |
109 | installaptold | |
110 | ||
8fa99570 | 111 | msgmsg 'Good warm archive signed by' 'Joe Sixpack' |
63c71412 | 112 | prepare "${PKGFILE}-new" |
fe0f7911 DK |
113 | signreleasefiles 'Joe Sixpack' |
114 | find aptarchive/ -name "$DELETEFILE" -delete | |
8fa99570 | 115 | successfulaptgetupdate |
63c71412 | 116 | testsuccessequal "$(cat "${PKGFILE}-new") |
fe0f7911 DK |
117 | " aptcache show apt |
118 | installaptnew | |
119 | ||
8fa99570 | 120 | msgmsg 'Cold archive signed by' 'Rex Expired' |
63c71412 | 121 | prepare "${PKGFILE}" |
29a59c46 DK |
122 | rm -rf rootdir/var/lib/apt/lists |
123 | cp keys/rexexpired.pub rootdir/etc/apt/trusted.gpg.d/rexexpired.gpg | |
124 | signreleasefiles 'Rex Expired' | |
125 | find aptarchive/ -name "$DELETEFILE" -delete | |
f13b413a | 126 | updatewithwarnings '^W: .* EXPKEYSIG' |
63c71412 | 127 | testsuccessequal "$(cat "${PKGFILE}") |
29a59c46 DK |
128 | " aptcache show apt |
129 | failaptold | |
130 | rm rootdir/etc/apt/trusted.gpg.d/rexexpired.gpg | |
fe0f7911 | 131 | |
1af227c2 DK |
132 | msgmsg 'Cold archive expired signed by' 'Joe Sixpack' |
133 | if dpkg --compare-versions "$(aptkey adv --version | head -n 2 | tail -n 1 | cut -d' ' -f 3)" '>=' '2.1' >/dev/null 2>&1; then | |
134 | touch rootdir/etc/apt/apt.conf.d/99gnupg2 | |
135 | elif gpg2 --version >/dev/null 2>&1; then | |
136 | echo 'Apt::Key::gpgcommand "gpg2";' > rootdir/etc/apt/apt.conf.d/99gnupg2 | |
137 | if ! dpkg --compare-versions "$(aptkey adv --version | head -n 2 | tail -n 1 | cut -d' ' -f 3)" '>=' '2.1' >/dev/null 2>&1; then | |
138 | rm rootdir/etc/apt/apt.conf.d/99gnupg2 | |
139 | fi | |
140 | fi | |
141 | if [ -e rootdir/etc/apt/apt.conf.d/99gnupg2 ]; then | |
142 | prepare "${PKGFILE}" | |
143 | rm -rf rootdir/var/lib/apt/lists | |
144 | signreleasefiles 'Joe Sixpack' 'aptarchive' --faked-system-time "20070924T154812" --default-sig-expire 2016-04-01 | |
145 | find aptarchive/ -name "$DELETEFILE" -delete | |
146 | updatewithwarnings '^W: .* EXPSIG' | |
147 | testsuccessequal "$(cat "${PKGFILE}") | |
148 | " aptcache show apt | |
149 | failaptold | |
150 | rm -f rootdir/etc/apt/apt.conf.d/99gnupg2 | |
151 | else | |
152 | msgskip 'Not a new enough gpg available providing --fake-system-time' | |
153 | fi | |
154 | ||
8fa99570 | 155 | msgmsg 'Cold archive signed by' 'Marvin Paranoid' |
63c71412 | 156 | prepare "${PKGFILE}" |
fe0f7911 DK |
157 | rm -rf rootdir/var/lib/apt/lists |
158 | signreleasefiles 'Marvin Paranoid' | |
159 | find aptarchive/ -name "$DELETEFILE" -delete | |
6bf93605 | 160 | updatewithwarnings '^W: .* NO_PUBKEY' |
63c71412 | 161 | testsuccessequal "$(cat "${PKGFILE}") |
fe0f7911 DK |
162 | " aptcache show apt |
163 | failaptold | |
164 | ||
8fa99570 | 165 | msgmsg 'Bad warm archive signed by' 'Joe Sixpack' |
63c71412 | 166 | prepare "${PKGFILE}-new" |
fe0f7911 DK |
167 | signreleasefiles 'Joe Sixpack' |
168 | find aptarchive/ -name "$DELETEFILE" -delete | |
8fa99570 | 169 | successfulaptgetupdate |
63c71412 | 170 | testsuccessequal "$(cat "${PKGFILE}-new") |
fe0f7911 DK |
171 | " aptcache show apt |
172 | installaptnew | |
173 | ||
8fa99570 | 174 | msgmsg 'Cold archive signed by' 'Joe Sixpack' |
63c71412 | 175 | prepare "${PKGFILE}" |
fe0f7911 DK |
176 | rm -rf rootdir/var/lib/apt/lists |
177 | signreleasefiles 'Joe Sixpack' | |
178 | find aptarchive/ -name "$DELETEFILE" -delete | |
8fa99570 | 179 | successfulaptgetupdate |
63c71412 | 180 | testsuccessequal "$(cat "${PKGFILE}") |
fe0f7911 DK |
181 | " aptcache show apt |
182 | installaptold | |
183 | ||
8fa99570 | 184 | msgmsg 'Good warm archive signed by' 'Marvin Paranoid' |
63c71412 | 185 | prepare "${PKGFILE}-new" |
fe0f7911 DK |
186 | signreleasefiles 'Marvin Paranoid' |
187 | find aptarchive/ -name "$DELETEFILE" -delete | |
6bf93605 | 188 | updatewithwarnings '^W: .* NO_PUBKEY' |
63c71412 | 189 | testsuccessequal "$(cat "${PKGFILE}") |
29a59c46 DK |
190 | " aptcache show apt |
191 | installaptold | |
192 | ||
8fa99570 | 193 | msgmsg 'Good warm archive signed by' 'Rex Expired' |
63c71412 | 194 | prepare "${PKGFILE}-new" |
29a59c46 DK |
195 | cp keys/rexexpired.pub rootdir/etc/apt/trusted.gpg.d/rexexpired.gpg |
196 | signreleasefiles 'Rex Expired' | |
197 | find aptarchive/ -name "$DELETEFILE" -delete | |
f13b413a | 198 | updatewithwarnings '^W: .* EXPKEYSIG' |
63c71412 | 199 | testsuccessequal "$(cat "${PKGFILE}") |
fe0f7911 DK |
200 | " aptcache show apt |
201 | installaptold | |
29a59c46 DK |
202 | rm rootdir/etc/apt/trusted.gpg.d/rexexpired.gpg |
203 | ||
8fa99570 | 204 | msgmsg 'Good warm archive signed by' 'Joe Sixpack' |
63c71412 | 205 | prepare "${PKGFILE}-new" |
29a59c46 DK |
206 | signreleasefiles |
207 | find aptarchive/ -name "$DELETEFILE" -delete | |
8fa99570 | 208 | successfulaptgetupdate |
63c71412 | 209 | testsuccessequal "$(cat "${PKGFILE}-new") |
29a59c46 DK |
210 | " aptcache show apt |
211 | installaptnew | |
b0d40854 | 212 | |
8fa99570 | 213 | msgmsg 'Cold archive signed by good keyring' 'Marvin Paranoid' |
63c71412 | 214 | prepare "${PKGFILE}" |
b0d40854 DK |
215 | rm -rf rootdir/var/lib/apt/lists |
216 | signreleasefiles 'Marvin Paranoid' | |
217 | find aptarchive/ -name "$DELETEFILE" -delete | |
b0d40854 DK |
218 | local MARVIN="$(readlink -f keys/marvinparanoid.pub)" |
219 | sed -i "s#^\(deb\(-src\)\?\) #\1 [signed-by=$MARVIN] #" rootdir/etc/apt/sources.list.d/* | |
8fa99570 | 220 | successfulaptgetupdate |
63c71412 | 221 | testsuccessequal "$(cat "${PKGFILE}") |
b0d40854 DK |
222 | " aptcache show apt |
223 | installaptold | |
224 | ||
8fa99570 | 225 | msgmsg 'Cold archive signed by bad keyring' 'Joe Sixpack' |
b0d40854 DK |
226 | rm -rf rootdir/var/lib/apt/lists |
227 | signreleasefiles 'Joe Sixpack' | |
228 | find aptarchive/ -name "$DELETEFILE" -delete | |
b0d40854 DK |
229 | updatewithwarnings '^W: .* NO_PUBKEY' |
230 | ||
231 | sed -i "s#^\(deb\(-src\)\?\) \[signed-by=$MARVIN\] #\1 #" rootdir/etc/apt/sources.list.d/* | |
232 | local MARVIN="$(aptkey --keyring $MARVIN finger | grep 'Key fingerprint' | cut -d'=' -f 2 | tr -d ' ')" | |
233 | ||
8fa99570 | 234 | msgmsg 'Cold archive signed by good keyid' 'Marvin Paranoid' |
63c71412 | 235 | prepare "${PKGFILE}" |
b0d40854 DK |
236 | rm -rf rootdir/var/lib/apt/lists |
237 | signreleasefiles 'Marvin Paranoid' | |
238 | find aptarchive/ -name "$DELETEFILE" -delete | |
b0d40854 DK |
239 | sed -i "s#^\(deb\(-src\)\?\) #\1 [signed-by=$MARVIN] #" rootdir/etc/apt/sources.list.d/* |
240 | cp keys/marvinparanoid.pub rootdir/etc/apt/trusted.gpg.d/marvinparanoid.gpg | |
8fa99570 | 241 | successfulaptgetupdate |
63c71412 | 242 | testsuccessequal "$(cat "${PKGFILE}") |
b0d40854 DK |
243 | " aptcache show apt |
244 | installaptold | |
245 | rm -f rootdir/etc/apt/trusted.gpg.d/marvinparanoid.gpg | |
246 | ||
8fa99570 | 247 | msgmsg 'Cold archive signed by bad keyid' 'Joe Sixpack' |
b0d40854 DK |
248 | rm -rf rootdir/var/lib/apt/lists |
249 | signreleasefiles 'Joe Sixpack' | |
250 | find aptarchive/ -name "$DELETEFILE" -delete | |
4e03c47d | 251 | updatewithwarnings '^W: .* be verified because the public key is not available: .*' |
b0d40854 DK |
252 | |
253 | sed -i "s#^\(deb\(-src\)\?\) \[signed-by=$MARVIN\] #\1 #" rootdir/etc/apt/sources.list.d/* | |
fe0f7911 DK |
254 | } |
255 | ||
43c1ca5d | 256 | runtest2() { |
8fa99570 | 257 | msgmsg 'Cold archive signed by' 'Joe Sixpack' |
63c71412 | 258 | prepare "${PKGFILE}" |
43c1ca5d SR |
259 | rm -rf rootdir/var/lib/apt/lists |
260 | signreleasefiles 'Joe Sixpack' | |
8fa99570 | 261 | successfulaptgetupdate |
43c1ca5d SR |
262 | |
263 | # New .deb but now an unsigned archive. For example MITM to circumvent | |
264 | # package verification. | |
8fa99570 | 265 | msgmsg 'Warm archive signed by' 'nobody' |
63c71412 | 266 | prepare "${PKGFILE}-new" |
43c1ca5d SR |
267 | find aptarchive/ -name InRelease -delete |
268 | find aptarchive/ -name Release.gpg -delete | |
6bf93605 | 269 | updatewithwarnings 'W: .* no longer signed.' |
63c71412 | 270 | testsuccessequal "$(cat "${PKGFILE}-new") |
43c1ca5d SR |
271 | " aptcache show apt |
272 | failaptnew | |
273 | ||
274 | # Unsigned archive from the beginning must also be detected. | |
6bf93605 | 275 | msgmsg 'Cold archive signed by' 'nobody' |
8fa99570 | 276 | rm -rf rootdir/var/lib/apt/lists |
6bf93605 | 277 | updatewithwarnings 'W: .* is not signed.' |
63c71412 | 278 | testsuccessequal "$(cat "${PKGFILE}-new") |
43c1ca5d SR |
279 | " aptcache show apt |
280 | failaptnew | |
281 | } | |
43c1ca5d | 282 | |
8fa99570 | 283 | runtest3() { |
6a4958d3 | 284 | echo "APT::Hashes::$APT_TESTS_DIGEST_ALGO::$1 \"yes\";" > rootdir/etc/apt/apt.conf.d/truststate |
08b7761a | 285 | msgmsg "Running base test with $1 digest" |
8fa99570 DK |
286 | runtest2 |
287 | ||
08b7761a DK |
288 | for DELETEFILE in 'InRelease' 'Release.gpg'; do |
289 | msgmsg "Running test with deletion of $DELETEFILE and $1 digest" | |
290 | runtest "$DELETEFILE" | |
291 | done | |
8fa99570 DK |
292 | } |
293 | ||
e8b1db38 MV |
294 | # diable some protection by default and ensure we still do the verification |
295 | # correctly | |
296 | cat > rootdir/etc/apt/apt.conf.d/weaken-security <<EOF | |
297 | Acquire::AllowInsecureRepositories "1"; | |
298 | Acquire::AllowDowngradeToInsecureRepositories "1"; | |
299 | EOF | |
08b7761a DK |
300 | # the hash marked as configureable in our gpgv method |
301 | export APT_TESTS_DIGEST_ALGO='SHA224' | |
e8b1db38 | 302 | |
8fa99570 DK |
303 | successfulaptgetupdate() { |
304 | testsuccess aptget update -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::gpgv=1 | |
305 | } | |
6a4958d3 | 306 | runtest3 'Trusted' |
e8b1db38 | 307 | |
8fa99570 DK |
308 | successfulaptgetupdate() { |
309 | testwarning aptget update -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::gpgv=1 | |
310 | testsuccess grep 'uses weak digest algorithm' rootdir/tmp/testwarning.output | |
311 | } | |
6a4958d3 | 312 | runtest3 'Weak' |
08b7761a DK |
313 | |
314 | msgmsg "Running test with apt-untrusted digest" | |
6a4958d3 | 315 | echo "APT::Hashes::$APT_TESTS_DIGEST_ALGO::Untrusted \"yes\";" > rootdir/etc/apt/apt.conf.d/truststate |
08b7761a DK |
316 | runfailure() { |
317 | for DELETEFILE in 'InRelease' 'Release.gpg'; do | |
318 | msgmsg 'Cold archive signed by' 'Joe Sixpack' | |
319 | prepare "${PKGFILE}" | |
320 | rm -rf rootdir/var/lib/apt/lists | |
321 | signreleasefiles 'Joe Sixpack' | |
322 | find aptarchive/ -name "$DELETEFILE" -delete | |
323 | testfailure aptget update --no-allow-insecure-repositories -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::gpgv=1 | |
324 | testsuccess grep 'The following signatures were invalid' rootdir/tmp/testfailure.output | |
325 | testnopackage 'apt' | |
326 | testwarning aptget update --allow-insecure-repositories -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::gpgv=1 | |
327 | failaptold | |
328 | ||
329 | msgmsg 'Cold archive signed by' 'Marvin Paranoid' | |
330 | prepare "${PKGFILE}" | |
331 | rm -rf rootdir/var/lib/apt/lists | |
332 | signreleasefiles 'Marvin Paranoid' | |
333 | find aptarchive/ -name "$DELETEFILE" -delete | |
334 | testfailure aptget update --no-allow-insecure-repositories -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::gpgv=1 | |
335 | testnopackage 'apt' | |
336 | updatewithwarnings '^W: .* NO_PUBKEY' | |
337 | testsuccessequal "$(cat "${PKGFILE}") | |
338 | " aptcache show apt | |
339 | failaptold | |
340 | done | |
341 | } | |
342 | runfailure | |
343 | ||
344 | msgmsg "Running test with gpgv-untrusted digest" | |
345 | export APT_TESTS_DIGEST_ALGO='MD5' | |
346 | runfailure |