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