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 rm -f $APTARCHIVE/dists
/unstable
/InRelease
12 rm -f $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
32 assert_update_is_refused_and_last_good_state_used
()
34 testequal
"E: The repository 'file: unstable Release.gpg' is no longer signed." aptget update
-qq
39 assert_repo_is_intact
()
41 testequal
"foo/unstable 2.0 all" apt list
-q
42 testsuccess
"" aptget
install -y -s foo
43 testfailure
"" aptget
install -y evil
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)"
53 setupaptarchive_with_lists_clean
()
55 setupaptarchive
--no-update
56 rm -f rootdir
/var
/lib
/apt
/lists
/_
*
57 #rm -rf rootdir/var/lib/apt/lists
60 test_from_inrelease_to_unsigned
()
62 # setup archive with InRelease file
63 setupaptarchive_with_lists_clean
64 testsuccess aptget update
66 simulate_mitm_and_inject_evil_package
67 assert_update_is_refused_and_last_good_state_used
70 test_from_release_gpg_to_unsigned
()
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
77 simulate_mitm_and_inject_evil_package
78 assert_update_is_refused_and_last_good_state_used
83 # see https://bugs.launchpad.net/ubuntu/+source/apt/+bug/947108
85 # it was possible to MITM the download so that InRelease/Release.gpg
86 # are not delivered (404) and a altered Release file was send
88 # apt left the old InRelease file in /var/lib/apt/lists and downloaded
89 # the unauthenticated Release file too giving the false impression that
90 # Release was authenticated
92 # Note that this is pretty much impossible nowdays because:
93 # a) InRelease is left as is, not split to InRelease/Release as it was
95 # b) we refuse to go from signed->unsigned
97 # Still worth having a regression test the simulates the condition
99 # setup archive with InRelease
100 setupaptarchive_with_lists_clean
101 testsuccess aptget update
103 # do what CVE-2012-0214 did
104 rm $APTARCHIVE/dists
/unstable
/InRelease
105 rm $APTARCHIVE/dists
/unstable
/Release.gpg
107 # build valid Release file
108 aptftparchive
-qq release .
/aptarchive
> aptarchive
/dists
/unstable
/Release
110 assert_update_is_refused_and_last_good_state_used
112 # ensure there is no _Release file downloaded
113 testfailure
ls rootdir
/var
/lib
/apt
/lists
/*_Release
116 test_subvert_inrelease
()
118 # setup archive with InRelease
119 setupaptarchive_with_lists_clean
120 testsuccess aptget update
122 # replace InRelease with something else
123 mv $APTARCHIVE/dists
/unstable
/Release
$APTARCHIVE/dists
/unstable
/InRelease
125 testequal
"W: Failed to fetch file:${APTARCHIVE}/dists/unstable/InRelease Does not start with a cleartext signature
127 E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update
-qq
129 # ensure we keep the repo
130 assert_repo_is_intact
133 test_inrelease_to_invalid_inrelease
()
135 # setup archive with InRelease
136 setupaptarchive_with_lists_clean
137 testsuccess aptget update
139 # now remove InRelease and subvert Release do no longer verify
140 sed -i 's/Codename.*/Codename: evil!'/ $APTARCHIVE/dists
/unstable
/InRelease
143 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>
145 W: Failed to fetch file:${APTARCHIVE}/dists/unstable/InRelease
147 W: Some index files failed to download. They have been ignored, or old ones used instead." aptget update
-qq
149 # ensure we keep the repo
150 assert_repo_is_intact
151 testfailure
grep "evil" rootdir
/var
/lib
/apt
/lists
/*InRelease
154 test_release_gpg_to_invalid_release_release_gpg
()
156 # setup archive with InRelease
157 setupaptarchive_with_lists_clean
158 rm $APTARCHIVE/dists
/unstable
/InRelease
159 testsuccess aptget update
161 # now subvert Release do no longer verify
162 echo "Some evil data" >> $APTARCHIVE/dists
/unstable
/Release
165 testequal
"E: The repository 'file: unstable Release.gpg' is no longer signed." aptget update
-qq
167 assert_repo_is_intact
168 testfailure
grep "evil" rootdir
/var
/lib
/apt
/lists
/*Release
172 TESTDIR
=$(readlink -f $(dirname $0))
176 configarchitecture
"i386"
178 # a "normal" package with source and binary
179 buildsimplenativepackage
'foo' 'all' '2.0'
181 # setup the archive and ensure we have a single package that installs fine
183 APTARCHIVE
=$(readlink -f ./aptarchive)
184 assert_repo_is_intact
186 # test the various cases where a repo may go from signed->unsigned
187 msgmsg
"test_from_inrelease_to_unsigned"
188 test_from_inrelease_to_unsigned
190 msgmsg
"test_from_release_gpg_to_unsigned"
191 test_from_release_gpg_to_unsigned
193 # ensure we do not regress on CVE-2012-0214
194 msgmsg
"test_cve_2012_0214"
197 # ensure InRelase can not be subverted
198 msgmsg
"test_subvert_inrelease"
199 test_subvert_inrelease
201 # ensure we revert to last good state if InRelease does not verify
202 msgmsg
"test_inrelease_to_invalid_inrelease"
203 test_inrelease_to_invalid_inrelease
205 # ensure we revert to last good state if Release/Release.gpg does not verify
206 msgmsg
"test_release_gpg_to_invalid_release_release_gpg"
207 test_release_gpg_to_invalid_release_release_gpg