]> git.saurik.com Git - apt.git/blame - test/integration/test-apt-update-nofallback
Merge branch 'debian/sid' into debian/experimental
[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
42 testsuccess "" aptget install -y -s foo
43 testfailure "" aptget install -y evil
44
45 LISTDIR=rootdir/var/lib/apt/lists
46 if ! ( ls $LISTDIR/*InRelease >/dev/null 2>&1 ||
47 ls $LISTDIR/*Release.gpg >/dev/null 2>&1 ); then
48 echo "Can not find InRelease/Release.gpg in $(ls $LISTDIR)"
49 msgfail
50 fi
51}
52
53setupaptarchive_with_lists_clean()
54{
55 setupaptarchive --no-update
56 rm -f rootdir/var/lib/apt/lists/_*
57 #rm -rf rootdir/var/lib/apt/lists
58}
59
60test_from_inrelease_to_unsigned()
61{
62 # setup archive with InRelease file
63 setupaptarchive_with_lists_clean
64 testsuccess aptget update
65
66 simulate_mitm_and_inject_evil_package
67 assert_update_is_refused_and_last_good_state_used
68}
69
70test_from_release_gpg_to_unsigned()
71{
72 # setup archive with Release/Release.gpg (but no InRelease)
73 setupaptarchive_with_lists_clean
74 rm $APTARCHIVE/dists/unstable/InRelease
75 testsuccess aptget update
76
77 simulate_mitm_and_inject_evil_package
78 assert_update_is_refused_and_last_good_state_used
79}
80
c99fe2e1
MV
81test_from_inrelease_to_unsigned_with_override()
82{
83 # setup archive with InRelease file
84 setupaptarchive_with_lists_clean
85 testsuccess aptget update
86
87 # simulate moving to a unsigned but otherwise valid repo
88 simulate_mitm_and_inject_evil_package
89 generatereleasefiles
90
91 # and ensure we can update to it (with enough force)
92 testsuccess aptget update --allow-insecure-repositories \
93 -o Acquire::AllowDowngradeToInsecureRepositories=1
94 # but that the individual packages are still considered untrusted
95 testequal "WARNING: The following packages cannot be authenticated!
96 evil
97E: There are problems and -y was used without --force-yes" aptget install -qq -y evil
98}
99
631a7dc7
MV
100test_cve_2012_0214()
101{
102 # see https://bugs.launchpad.net/ubuntu/+source/apt/+bug/947108
103 #
104 # it was possible to MITM the download so that InRelease/Release.gpg
105 # are not delivered (404) and a altered Release file was send
106 #
107 # apt left the old InRelease file in /var/lib/apt/lists and downloaded
108 # the unauthenticated Release file too giving the false impression that
109 # Release was authenticated
110 #
111 # Note that this is pretty much impossible nowdays because:
112 # a) InRelease is left as is, not split to InRelease/Release as it was
113 # in the old days
114 # b) we refuse to go from signed->unsigned
115 #
116 # Still worth having a regression test the simulates the condition
117
118 # setup archive with InRelease
119 setupaptarchive_with_lists_clean
120 testsuccess aptget update
121
122 # do what CVE-2012-0214 did
123 rm $APTARCHIVE/dists/unstable/InRelease
124 rm $APTARCHIVE/dists/unstable/Release.gpg
125 inject_evil_package
126 # build valid Release file
127 aptftparchive -qq release ./aptarchive > aptarchive/dists/unstable/Release
128
129 assert_update_is_refused_and_last_good_state_used
130
131 # ensure there is no _Release file downloaded
132 testfailure ls rootdir/var/lib/apt/lists/*_Release
133}
134
135test_subvert_inrelease()
136{
137 # setup archive with InRelease
138 setupaptarchive_with_lists_clean
139 testsuccess aptget update
140
141 # replace InRelease with something else
142 mv $APTARCHIVE/dists/unstable/Release $APTARCHIVE/dists/unstable/InRelease
143
144 testequal "W: Failed to fetch file:${APTARCHIVE}/dists/unstable/InRelease Does not start with a cleartext signature
145
146E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
147
148 # ensure we keep the repo
149 assert_repo_is_intact
150}
151
152test_inrelease_to_invalid_inrelease()
153{
154 # setup archive with InRelease
155 setupaptarchive_with_lists_clean
156 testsuccess aptget update
157
158 # now remove InRelease and subvert Release do no longer verify
159 sed -i 's/Codename.*/Codename: evil!'/ $APTARCHIVE/dists/unstable/InRelease
160 inject_evil_package
161
162 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>
163
4dbfe436 164W: 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
165
166W: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
167
168 # ensure we keep the repo
169 assert_repo_is_intact
170 testfailure grep "evil" rootdir/var/lib/apt/lists/*InRelease
171}
172
173test_release_gpg_to_invalid_release_release_gpg()
174{
175 # setup archive with InRelease
176 setupaptarchive_with_lists_clean
177 rm $APTARCHIVE/dists/unstable/InRelease
178 testsuccess aptget update
179
180 # now subvert Release do no longer verify
181 echo "Some evil data" >> $APTARCHIVE/dists/unstable/Release
182 inject_evil_package
183
8beef749
MV
184 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>
185
186W: Failed to fetch file:${APTARCHIVE}/dists/unstable/Release.gpg
187
188W: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
631a7dc7
MV
189
190 assert_repo_is_intact
191 testfailure grep "evil" rootdir/var/lib/apt/lists/*Release
192}
193
194
195TESTDIR=$(readlink -f $(dirname $0))
196. $TESTDIR/framework
197
198setupenvironment
199configarchitecture "i386"
200
201# a "normal" package with source and binary
202buildsimplenativepackage 'foo' 'all' '2.0'
203
204# setup the archive and ensure we have a single package that installs fine
205setupaptarchive
206APTARCHIVE=$(readlink -f ./aptarchive)
207assert_repo_is_intact
208
209# test the various cases where a repo may go from signed->unsigned
210msgmsg "test_from_inrelease_to_unsigned"
211test_from_inrelease_to_unsigned
212
213msgmsg "test_from_release_gpg_to_unsigned"
214test_from_release_gpg_to_unsigned
215
216# ensure we do not regress on CVE-2012-0214
217msgmsg "test_cve_2012_0214"
218test_cve_2012_0214
219
220# ensure InRelase can not be subverted
221msgmsg "test_subvert_inrelease"
222test_subvert_inrelease
223
224# ensure we revert to last good state if InRelease does not verify
225msgmsg "test_inrelease_to_invalid_inrelease"
226test_inrelease_to_invalid_inrelease
227
228# ensure we revert to last good state if Release/Release.gpg does not verify
229msgmsg "test_release_gpg_to_invalid_release_release_gpg"
230test_release_gpg_to_invalid_release_release_gpg
c99fe2e1
MV
231
232# ensure we can ovveride the downgrade error
233msgmsg "test_from_inrelease_to_unsigned"
234test_from_inrelease_to_unsigned_with_override