]>
Commit | Line | Data |
---|---|---|
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 | # | |
7 | set -e | |
8 | ||
9 | simulate_mitm_and_inject_evil_package() | |
10 | { | |
6bf93605 | 11 | redatereleasefiles '+1 hour' |
63c71412 DK |
12 | rm -f "$APTARCHIVE/dists/unstable/InRelease" |
13 | rm -f "$APTARCHIVE/dists/unstable/Release.gpg" | |
631a7dc7 MV |
14 | inject_evil_package |
15 | } | |
16 | ||
17 | inject_evil_package() | |
18 | { | |
63c71412 | 19 | cat > "$APTARCHIVE/dists/unstable/main/binary-i386/Packages" <<EOF |
631a7dc7 MV |
20 | Package: evil |
21 | Installed-Size: 29 | |
22 | Maintainer: Joe Sixpack <joe@example.org> | |
23 | Architecture: all | |
24 | Version: 1.0 | |
25 | Filename: pool/evil_1.0_all.deb | |
26 | Size: 1270 | |
27 | Description: an autogenerated evil package | |
28 | EOF | |
29 | # avoid ims hit | |
30 | touch -d '+1hour' aptarchive/dists/unstable/main/binary-i386/Packages | |
448c38bd | 31 | compressfile aptarchive/dists/unstable/main/binary-i386/Packages |
631a7dc7 MV |
32 | } |
33 | ||
34 | assert_update_is_refused_and_last_good_state_used() | |
35 | { | |
1da3b7b8 | 36 | testfailuremsg "E: The repository 'file:${APTARCHIVE} unstable Release' is no longer signed." aptget update |
631a7dc7 MV |
37 | |
38 | assert_repo_is_intact | |
39 | } | |
40 | ||
41 | assert_repo_is_intact() | |
42 | { | |
25b86db1 | 43 | testsuccessequal "foo/unstable 2.0 all" apt list -q |
846bc058 DK |
44 | testsuccess aptget install -y -s foo |
45 | testfailure aptget install -y evil | |
46 | testsuccess aptget source foo --print-uris | |
631a7dc7 MV |
47 | |
48 | LISTDIR=rootdir/var/lib/apt/lists | |
63c71412 | 49 | testempty find "$LISTDIR" -name 'InRelease' -o -name 'Release.gpg' |
631a7dc7 MV |
50 | } |
51 | ||
52 | setupaptarchive_with_lists_clean() | |
53 | { | |
54 | setupaptarchive --no-update | |
4fa34122 | 55 | rm -rf rootdir/var/lib/apt/lists |
631a7dc7 MV |
56 | } |
57 | ||
58 | test_from_inrelease_to_unsigned() | |
59 | { | |
60 | # setup archive with InRelease file | |
61 | setupaptarchive_with_lists_clean | |
62 | testsuccess aptget update | |
846bc058 | 63 | listcurrentlistsdirectory > lists.before |
631a7dc7 MV |
64 | |
65 | simulate_mitm_and_inject_evil_package | |
66 | assert_update_is_refused_and_last_good_state_used | |
846bc058 | 67 | testfileequal lists.before "$(listcurrentlistsdirectory)" |
631a7dc7 MV |
68 | } |
69 | ||
70 | test_from_release_gpg_to_unsigned() | |
71 | { | |
72 | # setup archive with Release/Release.gpg (but no InRelease) | |
73 | setupaptarchive_with_lists_clean | |
63c71412 | 74 | rm "$APTARCHIVE/dists/unstable/InRelease" |
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 |
83 | test_from_inrelease_to_unsigned_with_override() |
84 | { | |
85 | # setup archive with InRelease file | |
86 | setupaptarchive_with_lists_clean | |
448c38bd | 87 | testsuccess aptget update |
c99fe2e1 MV |
88 | |
89 | # simulate moving to a unsigned but otherwise valid repo | |
90 | simulate_mitm_and_inject_evil_package | |
448c38bd | 91 | generatereleasefiles '+2 hours' |
63c71412 | 92 | find "$APTARCHIVE" -name '*Packages*' -exec touch -d '+2 hours' {} \; |
c99fe2e1 MV |
93 | |
94 | # and ensure we can update to it (with enough force) | |
4fa34122 | 95 | testwarning aptget update --allow-insecure-repositories \ |
448c38bd | 96 | -o Acquire::AllowDowngradeToInsecureRepositories=1 -o Debug::pkgAcquire::Worker=1 -o Debug::pkgAcquire::Auth=1 |
c99fe2e1 | 97 | # but that the individual packages are still considered untrusted |
25b86db1 | 98 | testfailureequal "WARNING: The following packages cannot be authenticated! |
c99fe2e1 | 99 | evil |
b381a482 | 100 | E: There were unauthenticated packages and -y was used without --allow-unauthenticated" aptget install -qq -y evil |
c99fe2e1 MV |
101 | } |
102 | ||
631a7dc7 MV |
103 | test_cve_2012_0214() |
104 | { | |
105 | # see https://bugs.launchpad.net/ubuntu/+source/apt/+bug/947108 | |
106 | # | |
107 | # it was possible to MITM the download so that InRelease/Release.gpg | |
108 | # are not delivered (404) and a altered Release file was send | |
109 | # | |
110 | # apt left the old InRelease file in /var/lib/apt/lists and downloaded | |
111 | # the unauthenticated Release file too giving the false impression that | |
112 | # Release was authenticated | |
113 | # | |
3a8776a3 | 114 | # Note that this is pretty much impossible nowadays because: |
631a7dc7 MV |
115 | # a) InRelease is left as is, not split to InRelease/Release as it was |
116 | # in the old days | |
117 | # b) we refuse to go from signed->unsigned | |
118 | # | |
119 | # Still worth having a regression test the simulates the condition | |
120 | ||
121 | # setup archive with InRelease | |
122 | setupaptarchive_with_lists_clean | |
123 | testsuccess aptget update | |
846bc058 | 124 | listcurrentlistsdirectory > lists.before |
631a7dc7 MV |
125 | |
126 | # do what CVE-2012-0214 did | |
63c71412 DK |
127 | rm "$APTARCHIVE/dists/unstable/InRelease" |
128 | rm "$APTARCHIVE/dists/unstable/Release.gpg" | |
631a7dc7 MV |
129 | inject_evil_package |
130 | # build valid Release file | |
131 | aptftparchive -qq release ./aptarchive > aptarchive/dists/unstable/Release | |
132 | ||
133 | assert_update_is_refused_and_last_good_state_used | |
846bc058 | 134 | testfileequal lists.before "$(listcurrentlistsdirectory)" |
631a7dc7 MV |
135 | |
136 | # ensure there is no _Release file downloaded | |
137 | testfailure ls rootdir/var/lib/apt/lists/*_Release | |
138 | } | |
139 | ||
140 | test_subvert_inrelease() | |
141 | { | |
142 | # setup archive with InRelease | |
143 | setupaptarchive_with_lists_clean | |
144 | testsuccess aptget update | |
846bc058 | 145 | listcurrentlistsdirectory > lists.before |
631a7dc7 MV |
146 | |
147 | # replace InRelease with something else | |
63c71412 | 148 | mv "$APTARCHIVE/dists/unstable/Release" "$APTARCHIVE/dists/unstable/InRelease" |
631a7dc7 | 149 | |
dd676dc7 DK |
150 | testfailuremsg "W: 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 | |
631a7dc7 MV |
152 | |
153 | # ensure we keep the repo | |
846bc058 | 154 | testfileequal lists.before "$(listcurrentlistsdirectory)" |
631a7dc7 MV |
155 | assert_repo_is_intact |
156 | } | |
157 | ||
158 | test_inrelease_to_invalid_inrelease() | |
159 | { | |
160 | # setup archive with InRelease | |
161 | setupaptarchive_with_lists_clean | |
162 | testsuccess aptget update | |
846bc058 | 163 | listcurrentlistsdirectory > lists.before |
631a7dc7 MV |
164 | |
165 | # now remove InRelease and subvert Release do no longer verify | |
63c71412 | 166 | sed -i 's/^Codename:.*/Codename: evil!/' "$APTARCHIVE/dists/unstable/InRelease" |
631a7dc7 MV |
167 | inject_evil_package |
168 | ||
1da3b7b8 | 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> |
4dbfe436 | 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> |
631a7dc7 MV |
171 | W: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq |
172 | ||
173 | # ensure we keep the repo | |
846bc058 DK |
174 | testfailure grep 'evil' rootdir/var/lib/apt/lists/*InRelease |
175 | testfileequal lists.before "$(listcurrentlistsdirectory)" | |
631a7dc7 | 176 | assert_repo_is_intact |
631a7dc7 MV |
177 | } |
178 | ||
179 | test_release_gpg_to_invalid_release_release_gpg() | |
180 | { | |
181 | # setup archive with InRelease | |
182 | setupaptarchive_with_lists_clean | |
63c71412 | 183 | rm "$APTARCHIVE/dists/unstable/InRelease" |
631a7dc7 | 184 | testsuccess aptget update |
846bc058 | 185 | listcurrentlistsdirectory > lists.before |
631a7dc7 MV |
186 | |
187 | # now subvert Release do no longer verify | |
63c71412 | 188 | echo "Some evil data" >> "$APTARCHIVE/dists/unstable/Release" |
631a7dc7 MV |
189 | inject_evil_package |
190 | ||
1da3b7b8 | 191 | 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 | 192 | 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> |
8beef749 | 193 | W: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq |
631a7dc7 | 194 | |
846bc058 DK |
195 | testfailure grep 'evil' rootdir/var/lib/apt/lists/*Release |
196 | testfileequal lists.before "$(listcurrentlistsdirectory)" | |
631a7dc7 | 197 | assert_repo_is_intact |
631a7dc7 MV |
198 | } |
199 | ||
200 | ||
201 | TESTDIR=$(readlink -f $(dirname $0)) | |
202 | . $TESTDIR/framework | |
203 | ||
204 | setupenvironment | |
205 | configarchitecture "i386" | |
206 | ||
207 | # a "normal" package with source and binary | |
208 | buildsimplenativepackage 'foo' 'all' '2.0' | |
209 | ||
210 | # setup the archive and ensure we have a single package that installs fine | |
211 | setupaptarchive | |
63c71412 | 212 | APTARCHIVE="$(readlink -f ./aptarchive)" |
631a7dc7 MV |
213 | assert_repo_is_intact |
214 | ||
215 | # test the various cases where a repo may go from signed->unsigned | |
216 | msgmsg "test_from_inrelease_to_unsigned" | |
217 | test_from_inrelease_to_unsigned | |
218 | ||
219 | msgmsg "test_from_release_gpg_to_unsigned" | |
220 | test_from_release_gpg_to_unsigned | |
221 | ||
222 | # ensure we do not regress on CVE-2012-0214 | |
223 | msgmsg "test_cve_2012_0214" | |
224 | test_cve_2012_0214 | |
225 | ||
226 | # ensure InRelase can not be subverted | |
227 | msgmsg "test_subvert_inrelease" | |
228 | test_subvert_inrelease | |
229 | ||
230 | # ensure we revert to last good state if InRelease does not verify | |
231 | msgmsg "test_inrelease_to_invalid_inrelease" | |
232 | test_inrelease_to_invalid_inrelease | |
233 | ||
234 | # ensure we revert to last good state if Release/Release.gpg does not verify | |
235 | msgmsg "test_release_gpg_to_invalid_release_release_gpg" | |
236 | test_release_gpg_to_invalid_release_release_gpg | |
c99fe2e1 | 237 | |
846bc058 DK |
238 | # ensure we can override the downgrade error |
239 | msgmsg "test_from_inrelease_to_unsigned_with_override" | |
c99fe2e1 | 240 | test_from_inrelease_to_unsigned_with_override |