]> git.saurik.com Git - apt.git/blame - test/integration/test-apt-update-nofallback
chown finished partial files earlier
[apt.git] / test / integration / test-apt-update-nofallback
CommitLineData
631a7dc7
MV
1#!/bin/sh
2#
3# ensure we never fallback from a signed to a unsigned repo
4#
5# hash checks are done in
6#
7set -e
8
9simulate_mitm_and_inject_evil_package()
10{
11 rm -f $APTARCHIVE/dists/unstable/InRelease
12 rm -f $APTARCHIVE/dists/unstable/Release.gpg
13 inject_evil_package
14}
15
16inject_evil_package()
17{
18 cat > $APTARCHIVE/dists/unstable/main/binary-i386/Packages <<EOF
19Package: evil
20Installed-Size: 29
21Maintainer: Joe Sixpack <joe@example.org>
22Architecture: all
23Version: 1.0
24Filename: pool/evil_1.0_all.deb
25Size: 1270
26Description: an autogenerated evil package
27EOF
28 # avoid ims hit
29 touch -d '+1hour' aptarchive/dists/unstable/main/binary-i386/Packages
30}
31
32assert_update_is_refused_and_last_good_state_used()
33{
34 testequal "E: The repository 'file: unstable Release.gpg' is no longer signed." aptget update -qq
35
36 assert_repo_is_intact
37}
38
39assert_repo_is_intact()
40{
41 testequal "foo/unstable 2.0 all" apt list -q
846bc058
DK
42 testsuccess aptget install -y -s foo
43 testfailure aptget install -y evil
44 testsuccess aptget source foo --print-uris
631a7dc7
MV
45
46 LISTDIR=rootdir/var/lib/apt/lists
47 if ! ( ls $LISTDIR/*InRelease >/dev/null 2>&1 ||
48 ls $LISTDIR/*Release.gpg >/dev/null 2>&1 ); then
49 echo "Can not find InRelease/Release.gpg in $(ls $LISTDIR)"
50 msgfail
51 fi
52}
53
54setupaptarchive_with_lists_clean()
55{
56 setupaptarchive --no-update
4fa34122 57 rm -rf rootdir/var/lib/apt/lists
631a7dc7
MV
58}
59
60test_from_inrelease_to_unsigned()
61{
62 # setup archive with InRelease file
63 setupaptarchive_with_lists_clean
64 testsuccess aptget update
846bc058 65 listcurrentlistsdirectory > lists.before
631a7dc7
MV
66
67 simulate_mitm_and_inject_evil_package
68 assert_update_is_refused_and_last_good_state_used
846bc058 69 testfileequal lists.before "$(listcurrentlistsdirectory)"
631a7dc7
MV
70}
71
72test_from_release_gpg_to_unsigned()
73{
74 # setup archive with Release/Release.gpg (but no InRelease)
75 setupaptarchive_with_lists_clean
76 rm $APTARCHIVE/dists/unstable/InRelease
77 testsuccess aptget update
846bc058 78 listcurrentlistsdirectory > lists.before
631a7dc7
MV
79
80 simulate_mitm_and_inject_evil_package
81 assert_update_is_refused_and_last_good_state_used
846bc058 82 testfileequal lists.before "$(listcurrentlistsdirectory)"
631a7dc7
MV
83}
84
c99fe2e1
MV
85test_from_inrelease_to_unsigned_with_override()
86{
87 # setup archive with InRelease file
88 setupaptarchive_with_lists_clean
4fa34122
DK
89 # FIXME: is not what the server reported 4104 4106
90 testsuccess aptget update #-o Debug::pkgAcquire::Worker=1
c99fe2e1
MV
91
92 # simulate moving to a unsigned but otherwise valid repo
93 simulate_mitm_and_inject_evil_package
94 generatereleasefiles
95
96 # and ensure we can update to it (with enough force)
4fa34122 97 testwarning aptget update --allow-insecure-repositories \
c99fe2e1
MV
98 -o Acquire::AllowDowngradeToInsecureRepositories=1
99 # but that the individual packages are still considered untrusted
100 testequal "WARNING: The following packages cannot be authenticated!
101 evil
102E: There are problems and -y was used without --force-yes" aptget install -qq -y evil
103}
104
631a7dc7
MV
105test_cve_2012_0214()
106{
107 # see https://bugs.launchpad.net/ubuntu/+source/apt/+bug/947108
108 #
109 # it was possible to MITM the download so that InRelease/Release.gpg
110 # are not delivered (404) and a altered Release file was send
111 #
112 # apt left the old InRelease file in /var/lib/apt/lists and downloaded
113 # the unauthenticated Release file too giving the false impression that
114 # Release was authenticated
115 #
116 # Note that this is pretty much impossible nowdays because:
117 # a) InRelease is left as is, not split to InRelease/Release as it was
118 # in the old days
119 # b) we refuse to go from signed->unsigned
120 #
121 # Still worth having a regression test the simulates the condition
122
123 # setup archive with InRelease
124 setupaptarchive_with_lists_clean
125 testsuccess aptget update
846bc058 126 listcurrentlistsdirectory > lists.before
631a7dc7
MV
127
128 # do what CVE-2012-0214 did
129 rm $APTARCHIVE/dists/unstable/InRelease
130 rm $APTARCHIVE/dists/unstable/Release.gpg
131 inject_evil_package
132 # build valid Release file
133 aptftparchive -qq release ./aptarchive > aptarchive/dists/unstable/Release
134
135 assert_update_is_refused_and_last_good_state_used
846bc058 136 testfileequal lists.before "$(listcurrentlistsdirectory)"
631a7dc7
MV
137
138 # ensure there is no _Release file downloaded
139 testfailure ls rootdir/var/lib/apt/lists/*_Release
140}
141
142test_subvert_inrelease()
143{
144 # setup archive with InRelease
145 setupaptarchive_with_lists_clean
146 testsuccess aptget update
846bc058 147 listcurrentlistsdirectory > lists.before
631a7dc7
MV
148
149 # replace InRelease with something else
150 mv $APTARCHIVE/dists/unstable/Release $APTARCHIVE/dists/unstable/InRelease
151
152 testequal "W: Failed to fetch file:${APTARCHIVE}/dists/unstable/InRelease Does not start with a cleartext signature
153
154E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
155
156 # ensure we keep the repo
846bc058 157 testfileequal lists.before "$(listcurrentlistsdirectory)"
631a7dc7
MV
158 assert_repo_is_intact
159}
160
161test_inrelease_to_invalid_inrelease()
162{
163 # setup archive with InRelease
164 setupaptarchive_with_lists_clean
165 testsuccess aptget update
846bc058 166 listcurrentlistsdirectory > lists.before
631a7dc7
MV
167
168 # now remove InRelease and subvert Release do no longer verify
169 sed -i 's/Codename.*/Codename: evil!'/ $APTARCHIVE/dists/unstable/InRelease
170 inject_evil_package
171
172 testequal "W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: file: unstable InRelease: The following signatures were invalid: BADSIG 5A90D141DBAC8DAE Joe Sixpack (APT Testcases Dummy) <joe@example.org>
173
4dbfe436 174W: Failed to fetch file:${APTARCHIVE}/dists/unstable/InRelease The following signatures were invalid: BADSIG 5A90D141DBAC8DAE Joe Sixpack (APT Testcases Dummy) <joe@example.org>
631a7dc7
MV
175
176W: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
177
178 # ensure we keep the repo
846bc058
DK
179 testfailure grep 'evil' rootdir/var/lib/apt/lists/*InRelease
180 testfileequal lists.before "$(listcurrentlistsdirectory)"
631a7dc7 181 assert_repo_is_intact
631a7dc7
MV
182}
183
184test_release_gpg_to_invalid_release_release_gpg()
185{
186 # setup archive with InRelease
187 setupaptarchive_with_lists_clean
188 rm $APTARCHIVE/dists/unstable/InRelease
189 testsuccess aptget update
846bc058 190 listcurrentlistsdirectory > lists.before
631a7dc7
MV
191
192 # now subvert Release do no longer verify
193 echo "Some evil data" >> $APTARCHIVE/dists/unstable/Release
194 inject_evil_package
195
8beef749
MV
196 testequal "W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: file: unstable Release.gpg: The following signatures were invalid: BADSIG 5A90D141DBAC8DAE Joe Sixpack (APT Testcases Dummy) <joe@example.org>
197
03aa0847 198W: Failed to fetch file:${APTARCHIVE}/dists/unstable/Release.gpg The following signatures were invalid: BADSIG 5A90D141DBAC8DAE Joe Sixpack (APT Testcases Dummy) <joe@example.org>
8beef749
MV
199
200W: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
631a7dc7 201
846bc058
DK
202 testfailure grep 'evil' rootdir/var/lib/apt/lists/*Release
203 testfileequal lists.before "$(listcurrentlistsdirectory)"
631a7dc7 204 assert_repo_is_intact
631a7dc7
MV
205}
206
207
208TESTDIR=$(readlink -f $(dirname $0))
209. $TESTDIR/framework
210
211setupenvironment
212configarchitecture "i386"
213
214# a "normal" package with source and binary
215buildsimplenativepackage 'foo' 'all' '2.0'
216
217# setup the archive and ensure we have a single package that installs fine
218setupaptarchive
219APTARCHIVE=$(readlink -f ./aptarchive)
220assert_repo_is_intact
221
222# test the various cases where a repo may go from signed->unsigned
223msgmsg "test_from_inrelease_to_unsigned"
224test_from_inrelease_to_unsigned
225
226msgmsg "test_from_release_gpg_to_unsigned"
227test_from_release_gpg_to_unsigned
228
229# ensure we do not regress on CVE-2012-0214
230msgmsg "test_cve_2012_0214"
231test_cve_2012_0214
232
233# ensure InRelase can not be subverted
234msgmsg "test_subvert_inrelease"
235test_subvert_inrelease
236
237# ensure we revert to last good state if InRelease does not verify
238msgmsg "test_inrelease_to_invalid_inrelease"
239test_inrelease_to_invalid_inrelease
240
241# ensure we revert to last good state if Release/Release.gpg does not verify
242msgmsg "test_release_gpg_to_invalid_release_release_gpg"
243test_release_gpg_to_invalid_release_release_gpg
c99fe2e1 244
846bc058
DK
245# ensure we can override the downgrade error
246msgmsg "test_from_inrelease_to_unsigned_with_override"
c99fe2e1 247test_from_inrelease_to_unsigned_with_override