]> git.saurik.com Git - apt.git/blame - test/integration/test-releasefile-verification
treat older Release files than we already have as an IMSHit
[apt.git] / test / integration / test-releasefile-verification
CommitLineData
fe0f7911
DK
1#!/bin/sh
2set -e
3
4TESTDIR=$(readlink -f $(dirname $0))
5. $TESTDIR/framework
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
331e8396 26 touch -d 'now - 1 year' $release
fe0f7911 27 done
8de79b68 28 aptget clean
fe0f7911
DK
29 cp $1 aptarchive/Packages
30 find aptarchive -name 'Release' -delete
331e8396 31 compressfile 'aptarchive/Packages' "$DATE"
fe0f7911
DK
32 generatereleasefiles "$DATE"
33}
34
35installaptold() {
25b86db1 36 testsuccessequal 'Reading package lists...
fe0f7911
DK
37Building dependency tree...
38Suggested packages:
39 aptitude synaptic wajig dpkg-dev apt-doc bzip2 lzma python-apt
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.
5b63d2a9 44Get:1 http://localhost:8080/ apt 0.7.25.3
fe0f7911
DK
45Download complete and in download only mode' aptget install apt -dy
46}
47
48installaptnew() {
25b86db1 49 testsuccessequal 'Reading package lists...
fe0f7911
DK
50Building dependency tree...
51Suggested packages:
52 aptitude synaptic wajig dpkg-dev apt-doc bzip2 lzma python-apt
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.
5b63d2a9 57Get:1 http://localhost:8080/ apt 0.8.0~pre1
fe0f7911
DK
58Download complete and in download only mode' aptget install apt -dy
59}
60
61failaptold() {
25b86db1 62 testfailureequal 'Reading package lists...
fe0f7911
DK
63Building dependency tree...
64Suggested packages:
65 aptitude synaptic wajig dpkg-dev apt-doc bzip2 lzma python-apt
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
72E: There are problems and -y was used without --force-yes' aptget install apt -dy
73}
74
75failaptnew() {
25b86db1 76 testfailureequal 'Reading package lists...
fe0f7911
DK
77Building dependency tree...
78Suggested packages:
79 aptitude synaptic wajig dpkg-dev apt-doc bzip2 lzma python-apt
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
86E: There are problems and -y was used without --force-yes' aptget install apt -dy
87}
88
89# fake our downloadable file
90touch aptarchive/apt.deb
91
92PKGFILE="${TESTDIR}/$(echo "$(basename $0)" | sed 's#^test-#Packages-#')"
93
6bf93605
DK
94updatewithwarnings() {
95 testwarning aptget update
96 testsuccess grep -E "$1" rootdir/tmp/testwarning.output
331e8396
DK
97}
98
fe0f7911
DK
99runtest() {
100 prepare ${PKGFILE}
101 rm -rf rootdir/var/lib/apt/lists
102 signreleasefiles 'Joe Sixpack'
103 find aptarchive/ -name "$DELETEFILE" -delete
6bf93605
DK
104 msgmsg 'Cold archive signed by' 'Joe Sixpack'
105 testsuccess aptget update
25b86db1 106 testsuccessequal "$(cat ${PKGFILE})
fe0f7911
DK
107" aptcache show apt
108 installaptold
109
110 prepare ${PKGFILE}-new
111 signreleasefiles 'Joe Sixpack'
112 find aptarchive/ -name "$DELETEFILE" -delete
6bf93605
DK
113 msgmsg 'Good warm archive signed by' 'Joe Sixpack'
114 testsuccess aptget update
25b86db1 115 testsuccessequal "$(cat ${PKGFILE}-new)
fe0f7911
DK
116" aptcache show apt
117 installaptnew
118
29a59c46
DK
119 prepare ${PKGFILE}
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 find aptarchive/ -name "$DELETEFILE" -delete
6bf93605
DK
124 msgmsg 'Cold archive signed by' 'Rex Expired'
125 updatewithwarnings '^W: .* KEYEXPIRED'
25b86db1 126 testsuccessequal "$(cat ${PKGFILE})
29a59c46
DK
127" aptcache show apt
128 failaptold
129 rm rootdir/etc/apt/trusted.gpg.d/rexexpired.gpg
fe0f7911
DK
130
131 prepare ${PKGFILE}
132 rm -rf rootdir/var/lib/apt/lists
133 signreleasefiles 'Marvin Paranoid'
134 find aptarchive/ -name "$DELETEFILE" -delete
6bf93605
DK
135 msgmsg 'Cold archive signed by' 'Marvin Paranoid'
136 updatewithwarnings '^W: .* NO_PUBKEY'
25b86db1 137 testsuccessequal "$(cat ${PKGFILE})
fe0f7911
DK
138" aptcache show apt
139 failaptold
140
141 prepare ${PKGFILE}-new
142 # weborf doesn't support If-Range
143 for release in $(find rootdir/var/lib/apt/lists/partial/ -name '*Release'); do
144 rm $release
145 touch $release
146 done
147 signreleasefiles 'Joe Sixpack'
148 find aptarchive/ -name "$DELETEFILE" -delete
6bf93605
DK
149 msgmsg 'Bad warm archive signed by' 'Joe Sixpack'
150 testsuccess aptget update
25b86db1 151 testsuccessequal "$(cat ${PKGFILE}-new)
fe0f7911
DK
152" aptcache show apt
153 installaptnew
154
155
156 prepare ${PKGFILE}
157 rm -rf rootdir/var/lib/apt/lists
158 signreleasefiles 'Joe Sixpack'
159 find aptarchive/ -name "$DELETEFILE" -delete
6bf93605
DK
160 msgmsg 'Cold archive signed by' 'Joe Sixpack'
161 testsuccess aptget update
25b86db1 162 testsuccessequal "$(cat ${PKGFILE})
fe0f7911
DK
163" aptcache show apt
164 installaptold
165
166 prepare ${PKGFILE}-new
167 signreleasefiles 'Marvin Paranoid'
168 find aptarchive/ -name "$DELETEFILE" -delete
6bf93605
DK
169 msgmsg 'Good warm archive signed by' 'Marvin Paranoid'
170 updatewithwarnings '^W: .* NO_PUBKEY'
25b86db1 171 testsuccessequal "$(cat ${PKGFILE})
29a59c46
DK
172" aptcache show apt
173 installaptold
174
175 prepare ${PKGFILE}-new
176 cp keys/rexexpired.pub rootdir/etc/apt/trusted.gpg.d/rexexpired.gpg
177 signreleasefiles 'Rex Expired'
178 find aptarchive/ -name "$DELETEFILE" -delete
6bf93605
DK
179 msgmsg 'Good warm archive signed by' 'Rex Expired'
180 updatewithwarnings '^W: .* KEYEXPIRED'
25b86db1 181 testsuccessequal "$(cat ${PKGFILE})
fe0f7911
DK
182" aptcache show apt
183 installaptold
29a59c46
DK
184 rm rootdir/etc/apt/trusted.gpg.d/rexexpired.gpg
185
186 prepare ${PKGFILE}-new
187 signreleasefiles
188 find aptarchive/ -name "$DELETEFILE" -delete
6bf93605
DK
189 msgmsg 'Good warm archive signed by' 'Joe Sixpack'
190 testsuccess aptget update
25b86db1 191 testsuccessequal "$(cat ${PKGFILE}-new)
29a59c46
DK
192" aptcache show apt
193 installaptnew
fe0f7911
DK
194}
195
43c1ca5d
SR
196runtest2() {
197 prepare ${PKGFILE}
198 rm -rf rootdir/var/lib/apt/lists
199 signreleasefiles 'Joe Sixpack'
6bf93605
DK
200 msgmsg 'Cold archive signed by' 'Joe Sixpack'
201 testsuccess aptget update
43c1ca5d
SR
202
203 # New .deb but now an unsigned archive. For example MITM to circumvent
204 # package verification.
205 prepare ${PKGFILE}-new
206 find aptarchive/ -name InRelease -delete
207 find aptarchive/ -name Release.gpg -delete
6bf93605
DK
208 msgmsg 'Warm archive signed by' 'nobody'
209 updatewithwarnings 'W: .* no longer signed.'
25b86db1 210 testsuccessequal "$(cat ${PKGFILE}-new)
43c1ca5d
SR
211" aptcache show apt
212 failaptnew
213
214 # Unsigned archive from the beginning must also be detected.
215 rm -rf rootdir/var/lib/apt/lists
6bf93605
DK
216 msgmsg 'Cold archive signed by' 'nobody'
217 updatewithwarnings 'W: .* is not signed.'
25b86db1 218 testsuccessequal "$(cat ${PKGFILE}-new)
43c1ca5d
SR
219" aptcache show apt
220 failaptnew
221}
43c1ca5d 222
e8b1db38
MV
223# diable some protection by default and ensure we still do the verification
224# correctly
225cat > rootdir/etc/apt/apt.conf.d/weaken-security <<EOF
226Acquire::AllowInsecureRepositories "1";
227Acquire::AllowDowngradeToInsecureRepositories "1";
228EOF
229
230msgmsg "Runing base test"
231runtest2
43c1ca5d 232
fe0f7911 233DELETEFILE="InRelease"
e8b1db38 234msgmsg "Running test with deletion of $DELETEFILE"
fe0f7911 235runtest
e8b1db38 236
e3c62328 237DELETEFILE="Release.gpg"
e8b1db38 238msgmsg "Running test with deletion of $DELETEFILE"
e3c62328 239runtest