]> git.saurik.com Git - apt.git/blame - test/integration/test-releasefile-verification
properly check for "all good sigs are weak"
[apt.git] / test / integration / test-releasefile-verification
CommitLineData
fe0f7911
DK
1#!/bin/sh
2set -e
3
3abb6a6a
DK
4TESTDIR="$(readlink -f "$(dirname "$0")")"
5. "$TESTDIR/framework"
fe0f7911
DK
6
7setupenvironment
8configarchitecture "i386"
9
10buildaptarchive
11setupflataptarchive
12changetowebserver
13
f2c0ec8b 14webserverconfig 'aptwebserver::support::range' 'false'
331e8396 15
fe0f7911
DK
16prepare() {
17 local DATE="${2:-now}"
331e8396
DK
18 if [ "$DATE" = 'now' ]; then
19 if [ "$1" = "${PKGFILE}-new" ]; then
20 DATE='now - 1 day'
21 else
22 DATE='now - 7 day'
23 fi
fe0f7911
DK
24 fi
25 for release in $(find rootdir/var/lib/apt/lists 2> /dev/null); do
63c71412 26 touch -d 'now - 1 year' "$release"
fe0f7911 27 done
8de79b68 28 aptget clean
63c71412 29 cp "$1" aptarchive/Packages
fe0f7911 30 find aptarchive -name 'Release' -delete
331e8396 31 compressfile 'aptarchive/Packages' "$DATE"
fe0f7911
DK
32 generatereleasefiles "$DATE"
33}
34
35installaptold() {
6c0765c0 36 testsuccessequal "Reading package lists...
fe0f7911
DK
37Building dependency tree...
38Suggested packages:
9112f777 39 aptitude | synaptic | wajig dpkg-dev apt-doc bzip2 lzma python-apt
fe0f7911
DK
40The following NEW packages will be installed:
41 apt
420 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
43After this operation, 5370 kB of additional disk space will be used.
6c0765c0
DK
44Get:1 http://localhost:${APTHTTPPORT} apt 0.7.25.3
45Download complete and in download only mode" aptget install apt -dy
fe0f7911
DK
46}
47
48installaptnew() {
6c0765c0 49 testsuccessequal "Reading package lists...
fe0f7911
DK
50Building dependency tree...
51Suggested packages:
9112f777 52 aptitude | synaptic | wajig dpkg-dev apt-doc bzip2 lzma python-apt
fe0f7911
DK
53The following NEW packages will be installed:
54 apt
550 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
56After this operation, 5808 kB of additional disk space will be used.
6c0765c0
DK
57Get:1 http://localhost:${APTHTTPPORT} apt 0.8.0~pre1
58Download complete and in download only mode" aptget install apt -dy
fe0f7911
DK
59}
60
61failaptold() {
25b86db1 62 testfailureequal 'Reading package lists...
fe0f7911
DK
63Building dependency tree...
64Suggested packages:
9112f777 65 aptitude | synaptic | wajig dpkg-dev apt-doc bzip2 lzma python-apt
fe0f7911
DK
66The following NEW packages will be installed:
67 apt
680 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
69After this operation, 5370 kB of additional disk space will be used.
70WARNING: The following packages cannot be authenticated!
71 apt
b381a482 72E: There were unauthenticated packages and -y was used without --allow-unauthenticated' aptget install apt -dy
fe0f7911
DK
73}
74
75failaptnew() {
25b86db1 76 testfailureequal 'Reading package lists...
fe0f7911
DK
77Building dependency tree...
78Suggested packages:
9112f777 79 aptitude | synaptic | wajig dpkg-dev apt-doc bzip2 lzma python-apt
fe0f7911
DK
80The following NEW packages will be installed:
81 apt
820 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
83After this operation, 5808 kB of additional disk space will be used.
84WARNING: The following packages cannot be authenticated!
85 apt
b381a482 86E: There were unauthenticated packages and -y was used without --allow-unauthenticated' aptget install apt -dy
fe0f7911
DK
87}
88
89# fake our downloadable file
90touch aptarchive/apt.deb
91
63c71412 92PKGFILE="${TESTDIR}/$(echo "$(basename "$0")" | sed 's#^test-#Packages-#')"
fe0f7911 93
6bf93605 94updatewithwarnings() {
4e03c47d 95 testwarning aptget update -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::gpgv=1
6bf93605 96 testsuccess grep -E "$1" rootdir/tmp/testwarning.output
331e8396
DK
97}
98
fe0f7911 99runtest() {
8fa99570 100 msgmsg 'Cold archive signed by' 'Joe Sixpack'
63c71412 101 prepare "${PKGFILE}"
fe0f7911
DK
102 rm -rf rootdir/var/lib/apt/lists
103 signreleasefiles 'Joe Sixpack'
104 find aptarchive/ -name "$DELETEFILE" -delete
8fa99570 105 successfulaptgetupdate
63c71412 106 testsuccessequal "$(cat "${PKGFILE}")
fe0f7911
DK
107" aptcache show apt
108 installaptold
109
8fa99570 110 msgmsg 'Good warm archive signed by' 'Joe Sixpack'
63c71412 111 prepare "${PKGFILE}-new"
fe0f7911
DK
112 signreleasefiles 'Joe Sixpack'
113 find aptarchive/ -name "$DELETEFILE" -delete
8fa99570 114 successfulaptgetupdate
63c71412 115 testsuccessequal "$(cat "${PKGFILE}-new")
fe0f7911
DK
116" aptcache show apt
117 installaptnew
118
8fa99570 119 msgmsg 'Cold archive signed by' 'Rex Expired'
63c71412 120 prepare "${PKGFILE}"
29a59c46
DK
121 rm -rf rootdir/var/lib/apt/lists
122 cp keys/rexexpired.pub rootdir/etc/apt/trusted.gpg.d/rexexpired.gpg
123 signreleasefiles 'Rex Expired'
124 find aptarchive/ -name "$DELETEFILE" -delete
6bf93605 125 updatewithwarnings '^W: .* KEYEXPIRED'
63c71412 126 testsuccessequal "$(cat "${PKGFILE}")
29a59c46
DK
127" aptcache show apt
128 failaptold
129 rm rootdir/etc/apt/trusted.gpg.d/rexexpired.gpg
fe0f7911 130
8fa99570 131 msgmsg 'Cold archive signed by' 'Marvin Paranoid'
63c71412 132 prepare "${PKGFILE}"
fe0f7911
DK
133 rm -rf rootdir/var/lib/apt/lists
134 signreleasefiles 'Marvin Paranoid'
135 find aptarchive/ -name "$DELETEFILE" -delete
6bf93605 136 updatewithwarnings '^W: .* NO_PUBKEY'
63c71412 137 testsuccessequal "$(cat "${PKGFILE}")
fe0f7911
DK
138" aptcache show apt
139 failaptold
140
8fa99570 141 msgmsg 'Bad warm archive signed by' 'Joe Sixpack'
63c71412 142 prepare "${PKGFILE}-new"
fe0f7911
DK
143 signreleasefiles 'Joe Sixpack'
144 find aptarchive/ -name "$DELETEFILE" -delete
8fa99570 145 successfulaptgetupdate
63c71412 146 testsuccessequal "$(cat "${PKGFILE}-new")
fe0f7911
DK
147" aptcache show apt
148 installaptnew
149
8fa99570 150 msgmsg 'Cold archive signed by' 'Joe Sixpack'
63c71412 151 prepare "${PKGFILE}"
fe0f7911
DK
152 rm -rf rootdir/var/lib/apt/lists
153 signreleasefiles 'Joe Sixpack'
154 find aptarchive/ -name "$DELETEFILE" -delete
8fa99570 155 successfulaptgetupdate
63c71412 156 testsuccessequal "$(cat "${PKGFILE}")
fe0f7911
DK
157" aptcache show apt
158 installaptold
159
8fa99570 160 msgmsg 'Good warm archive signed by' 'Marvin Paranoid'
63c71412 161 prepare "${PKGFILE}-new"
fe0f7911
DK
162 signreleasefiles 'Marvin Paranoid'
163 find aptarchive/ -name "$DELETEFILE" -delete
6bf93605 164 updatewithwarnings '^W: .* NO_PUBKEY'
63c71412 165 testsuccessequal "$(cat "${PKGFILE}")
29a59c46
DK
166" aptcache show apt
167 installaptold
168
8fa99570 169 msgmsg 'Good warm archive signed by' 'Rex Expired'
63c71412 170 prepare "${PKGFILE}-new"
29a59c46
DK
171 cp keys/rexexpired.pub rootdir/etc/apt/trusted.gpg.d/rexexpired.gpg
172 signreleasefiles 'Rex Expired'
173 find aptarchive/ -name "$DELETEFILE" -delete
6bf93605 174 updatewithwarnings '^W: .* KEYEXPIRED'
63c71412 175 testsuccessequal "$(cat "${PKGFILE}")
fe0f7911
DK
176" aptcache show apt
177 installaptold
29a59c46
DK
178 rm rootdir/etc/apt/trusted.gpg.d/rexexpired.gpg
179
8fa99570 180 msgmsg 'Good warm archive signed by' 'Joe Sixpack'
63c71412 181 prepare "${PKGFILE}-new"
29a59c46
DK
182 signreleasefiles
183 find aptarchive/ -name "$DELETEFILE" -delete
8fa99570 184 successfulaptgetupdate
63c71412 185 testsuccessequal "$(cat "${PKGFILE}-new")
29a59c46
DK
186" aptcache show apt
187 installaptnew
b0d40854 188
8fa99570 189 msgmsg 'Cold archive signed by good keyring' 'Marvin Paranoid'
63c71412 190 prepare "${PKGFILE}"
b0d40854
DK
191 rm -rf rootdir/var/lib/apt/lists
192 signreleasefiles 'Marvin Paranoid'
193 find aptarchive/ -name "$DELETEFILE" -delete
b0d40854
DK
194 local MARVIN="$(readlink -f keys/marvinparanoid.pub)"
195 sed -i "s#^\(deb\(-src\)\?\) #\1 [signed-by=$MARVIN] #" rootdir/etc/apt/sources.list.d/*
8fa99570 196 successfulaptgetupdate
63c71412 197 testsuccessequal "$(cat "${PKGFILE}")
b0d40854
DK
198" aptcache show apt
199 installaptold
200
8fa99570 201 msgmsg 'Cold archive signed by bad keyring' 'Joe Sixpack'
b0d40854
DK
202 rm -rf rootdir/var/lib/apt/lists
203 signreleasefiles 'Joe Sixpack'
204 find aptarchive/ -name "$DELETEFILE" -delete
b0d40854
DK
205 updatewithwarnings '^W: .* NO_PUBKEY'
206
207 sed -i "s#^\(deb\(-src\)\?\) \[signed-by=$MARVIN\] #\1 #" rootdir/etc/apt/sources.list.d/*
208 local MARVIN="$(aptkey --keyring $MARVIN finger | grep 'Key fingerprint' | cut -d'=' -f 2 | tr -d ' ')"
209
8fa99570 210 msgmsg 'Cold archive signed by good keyid' 'Marvin Paranoid'
63c71412 211 prepare "${PKGFILE}"
b0d40854
DK
212 rm -rf rootdir/var/lib/apt/lists
213 signreleasefiles 'Marvin Paranoid'
214 find aptarchive/ -name "$DELETEFILE" -delete
b0d40854
DK
215 sed -i "s#^\(deb\(-src\)\?\) #\1 [signed-by=$MARVIN] #" rootdir/etc/apt/sources.list.d/*
216 cp keys/marvinparanoid.pub rootdir/etc/apt/trusted.gpg.d/marvinparanoid.gpg
8fa99570 217 successfulaptgetupdate
63c71412 218 testsuccessequal "$(cat "${PKGFILE}")
b0d40854
DK
219" aptcache show apt
220 installaptold
221 rm -f rootdir/etc/apt/trusted.gpg.d/marvinparanoid.gpg
222
8fa99570 223 msgmsg 'Cold archive signed by bad keyid' 'Joe Sixpack'
b0d40854
DK
224 rm -rf rootdir/var/lib/apt/lists
225 signreleasefiles 'Joe Sixpack'
226 find aptarchive/ -name "$DELETEFILE" -delete
4e03c47d 227 updatewithwarnings '^W: .* be verified because the public key is not available: .*'
b0d40854
DK
228
229 sed -i "s#^\(deb\(-src\)\?\) \[signed-by=$MARVIN\] #\1 #" rootdir/etc/apt/sources.list.d/*
fe0f7911
DK
230}
231
43c1ca5d 232runtest2() {
8fa99570 233 msgmsg 'Cold archive signed by' 'Joe Sixpack'
63c71412 234 prepare "${PKGFILE}"
43c1ca5d
SR
235 rm -rf rootdir/var/lib/apt/lists
236 signreleasefiles 'Joe Sixpack'
8fa99570 237 successfulaptgetupdate
43c1ca5d
SR
238
239 # New .deb but now an unsigned archive. For example MITM to circumvent
240 # package verification.
8fa99570 241 msgmsg 'Warm archive signed by' 'nobody'
63c71412 242 prepare "${PKGFILE}-new"
43c1ca5d
SR
243 find aptarchive/ -name InRelease -delete
244 find aptarchive/ -name Release.gpg -delete
6bf93605 245 updatewithwarnings 'W: .* no longer signed.'
63c71412 246 testsuccessequal "$(cat "${PKGFILE}-new")
43c1ca5d
SR
247" aptcache show apt
248 failaptnew
249
250 # Unsigned archive from the beginning must also be detected.
6bf93605 251 msgmsg 'Cold archive signed by' 'nobody'
8fa99570 252 rm -rf rootdir/var/lib/apt/lists
6bf93605 253 updatewithwarnings 'W: .* is not signed.'
63c71412 254 testsuccessequal "$(cat "${PKGFILE}-new")
43c1ca5d
SR
255" aptcache show apt
256 failaptnew
257}
43c1ca5d 258
8fa99570
DK
259runtest3() {
260 export APT_TESTS_DIGEST_ALGO="$1"
261 msgmsg "Running base test with digest $1"
262 runtest2
263
264 DELETEFILE="InRelease"
265 msgmsg "Running test with deletion of $DELETEFILE and digest $1"
266 runtest
267
268 DELETEFILE="Release.gpg"
269 msgmsg "Running test with deletion of $DELETEFILE and digest $1"
270 runtest
271
272 unset APT_TESTS_DIGEST_ALGO
273}
274
e8b1db38
MV
275# diable some protection by default and ensure we still do the verification
276# correctly
277cat > rootdir/etc/apt/apt.conf.d/weaken-security <<EOF
278Acquire::AllowInsecureRepositories "1";
279Acquire::AllowDowngradeToInsecureRepositories "1";
280EOF
281
8fa99570
DK
282# an all-round good hash
283successfulaptgetupdate() {
284 testsuccess aptget update -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::gpgv=1
285}
286runtest3 'SHA512'
e8b1db38 287
8fa99570
DK
288# a hash we consider weak and therefore warn about
289rm -f rootdir/etc/apt/apt.conf.d/no-sha1
290successfulaptgetupdate() {
291 testwarning aptget update -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::gpgv=1
292 testsuccess grep 'uses weak digest algorithm' rootdir/tmp/testwarning.output
293}
294runtest3 'SHA1'