]> git.saurik.com Git - apt.git/blame - test/integration/test-apt-update-nofallback
add [weak] tag to hash errors to indicate insufficiency
[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{
6bf93605 11 redatereleasefiles '+1 hour'
761a5ad2 12 rm -f "$APTARCHIVE/dists/unstable/InRelease" "$APTARCHIVE/dists/unstable/Release.gpg"
631a7dc7
MV
13 inject_evil_package
14}
15
16inject_evil_package()
17{
63c71412 18 cat > "$APTARCHIVE/dists/unstable/main/binary-i386/Packages" <<EOF
631a7dc7
MV
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
448c38bd 30 compressfile aptarchive/dists/unstable/main/binary-i386/Packages
631a7dc7
MV
31}
32
33assert_update_is_refused_and_last_good_state_used()
34{
002b1bc4 35 testfailuremsg "E: The repository 'file:${APTARCHIVE} unstable Release' is no longer signed.
83960341 36N: Updating from such a repository can't be done securely, and is therefore disabled by default.
87d6947d 37N: See apt-secure(8) manpage for repository creation and user configuration details." aptget update
631a7dc7
MV
38
39 assert_repo_is_intact
40}
41
42assert_repo_is_intact()
43{
2b0660b5 44 testsuccessequal "foo/unstable 2.0 all" apt list -qq
846bc058
DK
45 testsuccess aptget install -y -s foo
46 testfailure aptget install -y evil
47 testsuccess aptget source foo --print-uris
631a7dc7
MV
48
49 LISTDIR=rootdir/var/lib/apt/lists
63c71412 50 testempty find "$LISTDIR" -name 'InRelease' -o -name 'Release.gpg'
631a7dc7
MV
51}
52
53setupaptarchive_with_lists_clean()
54{
55 setupaptarchive --no-update
4fa34122 56 rm -rf rootdir/var/lib/apt/lists
631a7dc7
MV
57}
58
59test_from_inrelease_to_unsigned()
60{
5a23c56d 61 export APT_DONT_SIGN='Release.gpg'
631a7dc7
MV
62 setupaptarchive_with_lists_clean
63 testsuccess aptget update
846bc058 64 listcurrentlistsdirectory > lists.before
631a7dc7
MV
65
66 simulate_mitm_and_inject_evil_package
67 assert_update_is_refused_and_last_good_state_used
846bc058 68 testfileequal lists.before "$(listcurrentlistsdirectory)"
631a7dc7
MV
69}
70
71test_from_release_gpg_to_unsigned()
72{
5a23c56d 73 export APT_DONT_SIGN='InRelease'
631a7dc7 74 setupaptarchive_with_lists_clean
631a7dc7 75 testsuccess aptget update
846bc058 76 listcurrentlistsdirectory > lists.before
631a7dc7
MV
77
78 simulate_mitm_and_inject_evil_package
79 assert_update_is_refused_and_last_good_state_used
846bc058 80 testfileequal lists.before "$(listcurrentlistsdirectory)"
631a7dc7
MV
81}
82
c99fe2e1
MV
83test_from_inrelease_to_unsigned_with_override()
84{
5a23c56d 85 export APT_DONT_SIGN='Release.gpg'
c99fe2e1
MV
86 # setup archive with InRelease file
87 setupaptarchive_with_lists_clean
448c38bd 88 testsuccess aptget update
c99fe2e1
MV
89
90 # simulate moving to a unsigned but otherwise valid repo
91 simulate_mitm_and_inject_evil_package
448c38bd 92 generatereleasefiles '+2 hours'
63c71412 93 find "$APTARCHIVE" -name '*Packages*' -exec touch -d '+2 hours' {} \;
c99fe2e1
MV
94
95 # and ensure we can update to it (with enough force)
b1bdfe68
DK
96 testfailure aptget update
97 testfailure aptget update --allow-insecure-repositories
98 testwarning aptget update --allow-insecure-repositories \
99 -o Acquire::AllowDowngradeToInsecureRepositories=1 -o Debug::pkgAcquire::Worker=1 -o Debug::pkgAcquire::Auth=1
100 # but that the individual packages are still considered untrusted
101 testfailureequal "WARNING: The following packages cannot be authenticated!
102 evil
103E: There were unauthenticated packages and -y was used without --allow-unauthenticated" aptget install -qq -y evil
104}
105
106test_from_inrelease_to_norelease_with_override()
107{
108 # setup archive with InRelease file
109 setupaptarchive_with_lists_clean
110 testsuccess aptget update
111
112 # simulate moving to a unsigned but otherwise valid repo
113 simulate_mitm_and_inject_evil_package
114 find "$APTARCHIVE" -name '*Release*' -delete
115 find "$APTARCHIVE" -name '*Packages*' -exec touch -d '+2 hours' {} \;
116
117 # and ensure we can update to it (with enough force)
118 testfailure aptget update
119 testfailure aptget update --allow-insecure-repositories
4fa34122 120 testwarning aptget update --allow-insecure-repositories \
448c38bd 121 -o Acquire::AllowDowngradeToInsecureRepositories=1 -o Debug::pkgAcquire::Worker=1 -o Debug::pkgAcquire::Auth=1
c99fe2e1 122 # but that the individual packages are still considered untrusted
25b86db1 123 testfailureequal "WARNING: The following packages cannot be authenticated!
c99fe2e1 124 evil
b381a482 125E: There were unauthenticated packages and -y was used without --allow-unauthenticated" aptget install -qq -y evil
c99fe2e1
MV
126}
127
631a7dc7
MV
128test_cve_2012_0214()
129{
130 # see https://bugs.launchpad.net/ubuntu/+source/apt/+bug/947108
131 #
132 # it was possible to MITM the download so that InRelease/Release.gpg
133 # are not delivered (404) and a altered Release file was send
134 #
135 # apt left the old InRelease file in /var/lib/apt/lists and downloaded
136 # the unauthenticated Release file too giving the false impression that
137 # Release was authenticated
138 #
3a8776a3 139 # Note that this is pretty much impossible nowadays because:
631a7dc7
MV
140 # a) InRelease is left as is, not split to InRelease/Release as it was
141 # in the old days
142 # b) we refuse to go from signed->unsigned
143 #
144 # Still worth having a regression test the simulates the condition
145
5a23c56d 146 export APT_DONT_SIGN='Release.gpg'
631a7dc7
MV
147 setupaptarchive_with_lists_clean
148 testsuccess aptget update
846bc058 149 listcurrentlistsdirectory > lists.before
631a7dc7
MV
150
151 # do what CVE-2012-0214 did
5a23c56d 152 rm -f "$APTARCHIVE/dists/unstable/InRelease" "$APTARCHIVE/dists/unstable/Release.gpg"
631a7dc7
MV
153 inject_evil_package
154 # build valid Release file
761a5ad2 155 aptftparchive -qq release ./aptarchive > aptarchive/dists/unstable/Release
631a7dc7
MV
156
157 assert_update_is_refused_and_last_good_state_used
846bc058 158 testfileequal lists.before "$(listcurrentlistsdirectory)"
631a7dc7
MV
159
160 # ensure there is no _Release file downloaded
161 testfailure ls rootdir/var/lib/apt/lists/*_Release
162}
163
164test_subvert_inrelease()
165{
5a23c56d 166 export APT_DONT_SIGN='Release.gpg'
631a7dc7
MV
167 setupaptarchive_with_lists_clean
168 testsuccess aptget update
846bc058 169 listcurrentlistsdirectory > lists.before
631a7dc7
MV
170
171 # replace InRelease with something else
63c71412 172 mv "$APTARCHIVE/dists/unstable/Release" "$APTARCHIVE/dists/unstable/InRelease"
631a7dc7 173
f695e761 174 testfailuremsg "E: Failed to fetch file:${APTARCHIVE}/dists/unstable/InRelease Clearsigned file isn't valid, got 'NOSPLIT' (does the network require authentication?)
dd676dc7 175E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update
631a7dc7
MV
176
177 # ensure we keep the repo
846bc058 178 testfileequal lists.before "$(listcurrentlistsdirectory)"
631a7dc7
MV
179 assert_repo_is_intact
180}
181
182test_inrelease_to_invalid_inrelease()
183{
5a23c56d 184 export APT_DONT_SIGN='Release.gpg'
631a7dc7
MV
185 setupaptarchive_with_lists_clean
186 testsuccess aptget update
846bc058 187 listcurrentlistsdirectory > lists.before
631a7dc7
MV
188
189 # now remove InRelease and subvert Release do no longer verify
63c71412 190 sed -i 's/^Codename:.*/Codename: evil!/' "$APTARCHIVE/dists/unstable/InRelease"
631a7dc7
MV
191 inject_evil_package
192
1da3b7b8 193 testwarningequal "W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: file:${APTARCHIVE} unstable InRelease: The following signatures were invalid: BADSIG 5A90D141DBAC8DAE Joe Sixpack (APT Testcases Dummy) <joe@example.org>
4dbfe436 194W: 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
195W: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
196
197 # ensure we keep the repo
846bc058
DK
198 testfailure grep 'evil' rootdir/var/lib/apt/lists/*InRelease
199 testfileequal lists.before "$(listcurrentlistsdirectory)"
631a7dc7 200 assert_repo_is_intact
631a7dc7
MV
201}
202
203test_release_gpg_to_invalid_release_release_gpg()
204{
5a23c56d 205 export APT_DONT_SIGN='InRelease'
631a7dc7 206 setupaptarchive_with_lists_clean
631a7dc7 207 testsuccess aptget update
846bc058 208 listcurrentlistsdirectory > lists.before
631a7dc7
MV
209
210 # now subvert Release do no longer verify
63c71412 211 echo "Some evil data" >> "$APTARCHIVE/dists/unstable/Release"
631a7dc7
MV
212 inject_evil_package
213
1da3b7b8 214 testwarningequal "W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: file:${APTARCHIVE} unstable Release: The following signatures were invalid: BADSIG 5A90D141DBAC8DAE Joe Sixpack (APT Testcases Dummy) <joe@example.org>
03aa0847 215W: 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 216W: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
631a7dc7 217
846bc058
DK
218 testfailure grep 'evil' rootdir/var/lib/apt/lists/*Release
219 testfileequal lists.before "$(listcurrentlistsdirectory)"
631a7dc7 220 assert_repo_is_intact
631a7dc7
MV
221}
222
223
3abb6a6a
DK
224TESTDIR="$(readlink -f "$(dirname "$0")")"
225. "$TESTDIR/framework"
631a7dc7
MV
226
227setupenvironment
228configarchitecture "i386"
229
230# a "normal" package with source and binary
231buildsimplenativepackage 'foo' 'all' '2.0'
232
233# setup the archive and ensure we have a single package that installs fine
234setupaptarchive
63c71412 235APTARCHIVE="$(readlink -f ./aptarchive)"
631a7dc7
MV
236assert_repo_is_intact
237
238# test the various cases where a repo may go from signed->unsigned
239msgmsg "test_from_inrelease_to_unsigned"
240test_from_inrelease_to_unsigned
241
242msgmsg "test_from_release_gpg_to_unsigned"
243test_from_release_gpg_to_unsigned
244
245# ensure we do not regress on CVE-2012-0214
246msgmsg "test_cve_2012_0214"
247test_cve_2012_0214
248
8d89cda7 249# ensure InRelease can not be subverted
631a7dc7
MV
250msgmsg "test_subvert_inrelease"
251test_subvert_inrelease
252
253# ensure we revert to last good state if InRelease does not verify
254msgmsg "test_inrelease_to_invalid_inrelease"
255test_inrelease_to_invalid_inrelease
256
257# ensure we revert to last good state if Release/Release.gpg does not verify
258msgmsg "test_release_gpg_to_invalid_release_release_gpg"
259test_release_gpg_to_invalid_release_release_gpg
c99fe2e1 260
846bc058
DK
261# ensure we can override the downgrade error
262msgmsg "test_from_inrelease_to_unsigned_with_override"
c99fe2e1 263test_from_inrelease_to_unsigned_with_override
b1bdfe68
DK
264msgmsg "test_from_inrelease_to_norelease_with_override"
265test_from_inrelease_to_norelease_with_override