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" "$APTARCHIVE/dists/unstable/Release.gpg"
18 cat > "$APTARCHIVE/dists/unstable/main/binary-i386/Packages" <<EOF
21 Maintainer: Joe Sixpack <joe@example.org>
24 Filename: pool/evil_1.0_all.deb
26 Description: an autogenerated evil package
29 touch -d '+1hour' aptarchive
/dists
/unstable
/main
/binary
-i386/Packages
30 compressfile aptarchive
/dists
/unstable
/main
/binary
-i386/Packages
33 assert_update_is_refused_and_last_good_state_used
()
35 testfailuremsg
"E: The repository 'file:${APTARCHIVE} unstable Release' is no longer signed.
36 N: Updating from such a repository can't be done securely, and is therefore disabled by default.
37 N: See apt-secure(8) manpage for repository creation and user configuration details." aptget update
42 assert_repo_is_intact
()
44 testsuccessequal
"foo/unstable 2.0 all" apt list
-qq
45 testsuccess aptget
install -y -s foo
46 testfailure aptget
install -y evil
47 testsuccess aptget
source foo
--print-uris
49 LISTDIR
=rootdir
/var
/lib
/apt
/lists
50 testempty
find "$LISTDIR" -name 'InRelease' -o -name 'Release.gpg'
53 setupaptarchive_with_lists_clean
()
55 setupaptarchive
--no-update
56 rm -rf rootdir
/var
/lib
/apt
/lists
59 test_from_inrelease_to_unsigned
()
61 export APT_DONT_SIGN
='Release.gpg'
62 setupaptarchive_with_lists_clean
63 testsuccess aptget update
64 listcurrentlistsdirectory
> lists.before
66 simulate_mitm_and_inject_evil_package
67 assert_update_is_refused_and_last_good_state_used
68 testfileequal lists.before
"$(listcurrentlistsdirectory)"
71 test_from_release_gpg_to_unsigned
()
73 export APT_DONT_SIGN
='InRelease'
74 setupaptarchive_with_lists_clean
75 testsuccess aptget update
76 listcurrentlistsdirectory
> lists.before
78 simulate_mitm_and_inject_evil_package
79 assert_update_is_refused_and_last_good_state_used
80 testfileequal lists.before
"$(listcurrentlistsdirectory)"
83 test_from_inrelease_to_unsigned_with_override
()
85 export APT_DONT_SIGN
='Release.gpg'
86 # setup archive with InRelease file
87 setupaptarchive_with_lists_clean
88 testsuccess aptget update
90 # simulate moving to a unsigned but otherwise valid repo
91 simulate_mitm_and_inject_evil_package
92 generatereleasefiles
'+2 hours'
93 find "$APTARCHIVE" -name '*Packages*' -exec touch -d '+2 hours' {} \
;
95 # and ensure we can update to it (with enough force)
96 testwarning aptget update
--allow-insecure-repositories \
97 -o Acquire
::AllowDowngradeToInsecureRepositories
=1 -o Debug
::pkgAcquire
::Worker
=1 -o Debug
::pkgAcquire
::Auth
=1
98 # but that the individual packages are still considered untrusted
99 testfailureequal
"WARNING: The following packages cannot be authenticated!
101 E: There were unauthenticated packages and -y was used without --allow-unauthenticated" aptget
install -qq -y evil
106 # see https://bugs.launchpad.net/ubuntu/+source/apt/+bug/947108
108 # it was possible to MITM the download so that InRelease/Release.gpg
109 # are not delivered (404) and a altered Release file was send
111 # apt left the old InRelease file in /var/lib/apt/lists and downloaded
112 # the unauthenticated Release file too giving the false impression that
113 # Release was authenticated
115 # Note that this is pretty much impossible nowadays because:
116 # a) InRelease is left as is, not split to InRelease/Release as it was
118 # b) we refuse to go from signed->unsigned
120 # Still worth having a regression test the simulates the condition
122 export APT_DONT_SIGN
='Release.gpg'
123 setupaptarchive_with_lists_clean
124 testsuccess aptget update
125 listcurrentlistsdirectory
> lists.before
127 # do what CVE-2012-0214 did
128 rm -f "$APTARCHIVE/dists/unstable/InRelease" "$APTARCHIVE/dists/unstable/Release.gpg"
130 # build valid Release file
131 aptftparchive
-qq release .
/aptarchive
> aptarchive
/dists
/unstable
/Release
133 assert_update_is_refused_and_last_good_state_used
134 testfileequal lists.before
"$(listcurrentlistsdirectory)"
136 # ensure there is no _Release file downloaded
137 testfailure
ls rootdir
/var
/lib
/apt
/lists
/*_Release
140 test_subvert_inrelease
()
142 export APT_DONT_SIGN
='Release.gpg'
143 setupaptarchive_with_lists_clean
144 testsuccess aptget update
145 listcurrentlistsdirectory
> lists.before
147 # replace InRelease with something else
148 mv "$APTARCHIVE/dists/unstable/Release" "$APTARCHIVE/dists/unstable/InRelease"
150 testfailuremsg
"E: Failed to fetch file:${APTARCHIVE}/dists/unstable/InRelease Clearsigned file isn't valid, got 'NOSPLIT' (does the network require authentication?)
151 E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update
153 # ensure we keep the repo
154 testfileequal lists.before
"$(listcurrentlistsdirectory)"
155 assert_repo_is_intact
158 test_inrelease_to_invalid_inrelease
()
160 export APT_DONT_SIGN
='Release.gpg'
161 setupaptarchive_with_lists_clean
162 testsuccess aptget update
163 listcurrentlistsdirectory
> lists.before
165 # now remove InRelease and subvert Release do no longer verify
166 sed -i 's/^Codename:.*/Codename: evil!/' "$APTARCHIVE/dists/unstable/InRelease"
169 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>
170 W: Failed to fetch file:${APTARCHIVE}/dists/unstable/InRelease The following signatures were invalid: BADSIG 5A90D141DBAC8DAE Joe Sixpack (APT Testcases Dummy) <joe@example.org>
171 W: Some index files failed to download. They have been ignored, or old ones used instead." aptget update
-qq
173 # ensure we keep the repo
174 testfailure
grep 'evil' rootdir
/var
/lib
/apt
/lists
/*InRelease
175 testfileequal lists.before
"$(listcurrentlistsdirectory)"
176 assert_repo_is_intact
179 test_release_gpg_to_invalid_release_release_gpg
()
181 export APT_DONT_SIGN
='InRelease'
182 setupaptarchive_with_lists_clean
183 testsuccess aptget update
184 listcurrentlistsdirectory
> lists.before
186 # now subvert Release do no longer verify
187 echo "Some evil data" >> "$APTARCHIVE/dists/unstable/Release"
190 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>
191 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>
192 W: Some index files failed to download. They have been ignored, or old ones used instead." aptget update
-qq
194 testfailure
grep 'evil' rootdir
/var
/lib
/apt
/lists
/*Release
195 testfileequal lists.before
"$(listcurrentlistsdirectory)"
196 assert_repo_is_intact
200 TESTDIR
="$(readlink -f "$(dirname "$0")")"
201 . "$TESTDIR/framework
"
204 configarchitecture "i386
"
206 # a "normal
" package with source and binary
207 buildsimplenativepackage 'foo' 'all' '2.0'
209 # setup the archive and ensure we have a single package that installs fine
211 APTARCHIVE="$(readlink -f ./aptarchive)"
212 assert_repo_is_intact
214 # test the various cases where a repo may go from signed->unsigned
215 msgmsg "test_from_inrelease_to_unsigned
"
216 test_from_inrelease_to_unsigned
218 msgmsg "test_from_release_gpg_to_unsigned
"
219 test_from_release_gpg_to_unsigned
221 # ensure we do not regress on CVE-2012-0214
222 msgmsg "test_cve_2012_0214
"
225 # ensure InRelease can not be subverted
226 msgmsg "test_subvert_inrelease
"
227 test_subvert_inrelease
229 # ensure we revert to last good state if InRelease does not verify
230 msgmsg "test_inrelease_to_invalid_inrelease
"
231 test_inrelease_to_invalid_inrelease
233 # ensure we revert to last good state if Release/Release.gpg does not verify
234 msgmsg "test_release_gpg_to_invalid_release_release_gpg
"
235 test_release_gpg_to_invalid_release_release_gpg
237 # ensure we can override the downgrade error
238 msgmsg "test_from_inrelease_to_unsigned_with_override
"
239 test_from_inrelease_to_unsigned_with_override