3 # ensure we never fallback from a signed to a unsigned repo
5 # hash checks are done in
9 simulate_mitm_and_inject_evil_package
()
11 redatereleasefiles
'+1 hour'
12 rm -f $APTARCHIVE/dists
/unstable
/InRelease
13 rm -f $APTARCHIVE/dists
/unstable
/Release.gpg
19 cat > $APTARCHIVE/dists
/unstable
/main
/binary
-i386/Packages
<<EOF
22 Maintainer: Joe Sixpack <joe@example.org>
25 Filename: pool/evil_1.0_all.deb
27 Description: an autogenerated evil package
30 touch -d '+1hour' aptarchive
/dists
/unstable
/main
/binary
-i386/Packages
31 compressfile aptarchive
/dists
/unstable
/main
/binary
-i386/Packages
34 assert_update_is_refused_and_last_good_state_used
()
36 testfailuremsg
"E: The repository 'file: unstable Release' is no longer signed." aptget update
41 assert_repo_is_intact
()
43 testsuccessequal
"foo/unstable 2.0 all" apt list
-q
44 testsuccess aptget
install -y -s foo
45 testfailure aptget
install -y evil
46 testsuccess aptget
source foo
--print-uris
48 LISTDIR
=rootdir
/var
/lib
/apt
/lists
49 if ! ( ls $LISTDIR/*InRelease
>/dev
/null
2>&1 ||
50 ls $LISTDIR/*Release.gpg
>/dev
/null
2>&1 ); then
51 echo "Can not find InRelease/Release.gpg in $(ls $LISTDIR)"
56 setupaptarchive_with_lists_clean
()
58 setupaptarchive
--no-update
59 rm -rf rootdir
/var
/lib
/apt
/lists
62 test_from_inrelease_to_unsigned
()
64 # setup archive with InRelease file
65 setupaptarchive_with_lists_clean
66 testsuccess aptget update
67 listcurrentlistsdirectory
> lists.before
69 simulate_mitm_and_inject_evil_package
70 assert_update_is_refused_and_last_good_state_used
71 testfileequal lists.before
"$(listcurrentlistsdirectory)"
74 test_from_release_gpg_to_unsigned
()
76 # setup archive with Release/Release.gpg (but no InRelease)
77 setupaptarchive_with_lists_clean
78 rm $APTARCHIVE/dists
/unstable
/InRelease
79 testsuccess aptget update
80 listcurrentlistsdirectory
> lists.before
82 simulate_mitm_and_inject_evil_package
83 assert_update_is_refused_and_last_good_state_used
84 testfileequal lists.before
"$(listcurrentlistsdirectory)"
87 test_from_inrelease_to_unsigned_with_override
()
89 # setup archive with InRelease file
90 setupaptarchive_with_lists_clean
91 testsuccess aptget update
93 # simulate moving to a unsigned but otherwise valid repo
94 simulate_mitm_and_inject_evil_package
95 generatereleasefiles
'+2 hours'
96 find $APTARCHIVE -name '*Packages*' -exec touch -d '+2 hours' {} \
;
98 # and ensure we can update to it (with enough force)
99 testwarning aptget update
--allow-insecure-repositories \
100 -o Acquire
::AllowDowngradeToInsecureRepositories
=1 -o Debug
::pkgAcquire
::Worker
=1 -o Debug
::pkgAcquire
::Auth
=1
101 # but that the individual packages are still considered untrusted
102 testfailureequal
"WARNING: The following packages cannot be authenticated!
104 E: There are problems and -y was used without --force-yes" aptget
install -qq -y evil
109 # see https://bugs.launchpad.net/ubuntu/+source/apt/+bug/947108
111 # it was possible to MITM the download so that InRelease/Release.gpg
112 # are not delivered (404) and a altered Release file was send
114 # apt left the old InRelease file in /var/lib/apt/lists and downloaded
115 # the unauthenticated Release file too giving the false impression that
116 # Release was authenticated
118 # Note that this is pretty much impossible nowdays because:
119 # a) InRelease is left as is, not split to InRelease/Release as it was
121 # b) we refuse to go from signed->unsigned
123 # Still worth having a regression test the simulates the condition
125 # setup archive with InRelease
126 setupaptarchive_with_lists_clean
127 testsuccess aptget update
128 listcurrentlistsdirectory
> lists.before
130 # do what CVE-2012-0214 did
131 rm $APTARCHIVE/dists
/unstable
/InRelease
132 rm $APTARCHIVE/dists
/unstable
/Release.gpg
134 # build valid Release file
135 aptftparchive
-qq release .
/aptarchive
> aptarchive
/dists
/unstable
/Release
137 assert_update_is_refused_and_last_good_state_used
138 testfileequal lists.before
"$(listcurrentlistsdirectory)"
140 # ensure there is no _Release file downloaded
141 testfailure
ls rootdir
/var
/lib
/apt
/lists
/*_Release
144 test_subvert_inrelease
()
146 # setup archive with InRelease
147 setupaptarchive_with_lists_clean
148 testsuccess aptget update
149 listcurrentlistsdirectory
> lists.before
151 # replace InRelease with something else
152 mv $APTARCHIVE/dists
/unstable
/Release
$APTARCHIVE/dists
/unstable
/InRelease
154 testfailureequal
"W: Failed to fetch file:${APTARCHIVE}/dists/unstable/InRelease Does not start with a cleartext signature
156 E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update
-qq
158 # ensure we keep the repo
159 testfileequal lists.before
"$(listcurrentlistsdirectory)"
160 assert_repo_is_intact
163 test_inrelease_to_invalid_inrelease
()
165 # setup archive with InRelease
166 setupaptarchive_with_lists_clean
167 testsuccess aptget update
168 listcurrentlistsdirectory
> lists.before
170 # now remove InRelease and subvert Release do no longer verify
171 sed -i 's/^Codename:.*/Codename: evil!/' $APTARCHIVE/dists
/unstable
/InRelease
174 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: unstable InRelease: The following signatures were invalid: BADSIG 5A90D141DBAC8DAE Joe Sixpack (APT Testcases Dummy) <joe@example.org>
176 W: Failed to fetch file:${APTARCHIVE}/dists/unstable/InRelease The following signatures were invalid: BADSIG 5A90D141DBAC8DAE Joe Sixpack (APT Testcases Dummy) <joe@example.org>
178 W: Some index files failed to download. They have been ignored, or old ones used instead." aptget update
-qq
180 # ensure we keep the repo
181 testfailure
grep 'evil' rootdir
/var
/lib
/apt
/lists
/*InRelease
182 testfileequal lists.before
"$(listcurrentlistsdirectory)"
183 assert_repo_is_intact
186 test_release_gpg_to_invalid_release_release_gpg
()
188 # setup archive with InRelease
189 setupaptarchive_with_lists_clean
190 rm $APTARCHIVE/dists
/unstable
/InRelease
191 testsuccess aptget update
192 listcurrentlistsdirectory
> lists.before
194 # now subvert Release do no longer verify
195 echo "Some evil data" >> $APTARCHIVE/dists
/unstable
/Release
198 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: unstable Release: The following signatures were invalid: BADSIG 5A90D141DBAC8DAE Joe Sixpack (APT Testcases Dummy) <joe@example.org>
200 W: Failed to fetch file:${APTARCHIVE}/dists/unstable/Release.gpg The following signatures were invalid: BADSIG 5A90D141DBAC8DAE Joe Sixpack (APT Testcases Dummy) <joe@example.org>
202 W: Some index files failed to download. They have been ignored, or old ones used instead." aptget update
-qq
204 testfailure
grep 'evil' rootdir
/var
/lib
/apt
/lists
/*Release
205 testfileequal lists.before
"$(listcurrentlistsdirectory)"
206 assert_repo_is_intact
210 TESTDIR
=$(readlink -f $(dirname $0))
214 configarchitecture
"i386"
216 # a "normal" package with source and binary
217 buildsimplenativepackage
'foo' 'all' '2.0'
219 # setup the archive and ensure we have a single package that installs fine
221 APTARCHIVE
=$(readlink -f ./aptarchive)
222 assert_repo_is_intact
224 # test the various cases where a repo may go from signed->unsigned
225 msgmsg
"test_from_inrelease_to_unsigned"
226 test_from_inrelease_to_unsigned
228 msgmsg
"test_from_release_gpg_to_unsigned"
229 test_from_release_gpg_to_unsigned
231 # ensure we do not regress on CVE-2012-0214
232 msgmsg
"test_cve_2012_0214"
235 # ensure InRelase can not be subverted
236 msgmsg
"test_subvert_inrelease"
237 test_subvert_inrelease
239 # ensure we revert to last good state if InRelease does not verify
240 msgmsg
"test_inrelease_to_invalid_inrelease"
241 test_inrelease_to_invalid_inrelease
243 # ensure we revert to last good state if Release/Release.gpg does not verify
244 msgmsg
"test_release_gpg_to_invalid_release_release_gpg"
245 test_release_gpg_to_invalid_release_release_gpg
247 # ensure we can override the downgrade error
248 msgmsg
"test_from_inrelease_to_unsigned_with_override"
249 test_from_inrelease_to_unsigned_with_override