]> git.saurik.com Git - apt.git/blame - test/integration/test-apt-key-net-update
make apt-key net-update actually testable
[apt.git] / test / integration / test-apt-key-net-update
CommitLineData
f87338d2
DK
1#!/bin/sh
2set -e
3
4TESTDIR=$(readlink -f $(dirname $0))
5. $TESTDIR/framework
6
7setupenvironment
8configarchitecture "i386"
5acf154d
MV
9changetowebserver
10
11# setup env
12mkdir -p aptarchive/ubuntu/project var/lib/apt/keyrings
13echo 'APT::Key::ArchiveKeyringURI "http://localhost:8080/ubuntu/project/ubuntu-archive-keyring.gpg";' >> ./aptconfig.conf
14echo 'APT::Key::Net-Update-Enabled "1";' >> ./aptconfig.conf
15
16# signed thing
17echo "meep" > aptarchive/ubuntu/project/ubuntu-archive-keyring.gpg
18
19# test against the "real" webserver
20aptkey --fakeroot net-update
21
22exit 1
f87338d2
DK
23
24# mock
25requires_root() {
26 return 0
27}
28
29# extract net_update() and import it
30func=$( sed -n -e '/^add_keys_with_verify_against_master_keyring/,/^}/p' ${BUILDDIRECTORY}/apt-key )
31eval "$func"
32
33mkdir -p ./etc/apt
34TRUSTEDFILE=./etc/apt/trusted.gpg
35mkdir -p ./var/lib/apt/keyrings
36TMP_KEYRING=./var/lib/apt/keyrings/maybe-import-keyring.gpg
37GPG_CMD="gpg --ignore-time-conflict --no-options --no-default-keyring"
9b7c1050
MV
38
39# FIXME: instead of copying this use apt-key and the buildin apt webserver
40# to do a real test
f87338d2 41
fc85b0d8
MV
42# COPYIED from apt-key.in --------------
43
44# gpg needs a trustdb to function, but it can't be invalid (not even empty)
45# so we create a temporary directory to store our fresh readable trustdb in
46TRUSTDBDIR="$(mktemp -d)"
47CURRENTTRAP="${CURRENTTRAP} rm -rf '${TRUSTDBDIR}';"
48trap "${CURRENTTRAP}" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
49chmod 700 "$TRUSTDBDIR"
50# We also don't use a secret keyring, of course, but gpg panics and
51# implodes if there isn't one available - and writeable for imports
52SECRETKEYRING="${TRUSTDBDIR}/secring.gpg"
53touch $SECRETKEYRING
54GPG_CMD="$GPG_CMD --secret-keyring $SECRETKEYRING"
55GPG_CMD="$GPG_CMD --trustdb-name ${TRUSTDBDIR}/trustdb.gpg"
56#----------------------------------------- END COPY
f87338d2 57
9b7c1050
MV
58GPG="$GPG_CMD --keyring $TRUSTEDFILE"
59MASTER_KEYRING=/usr/share/keyrings/ubuntu-master-keyring.gpg
60
f87338d2
DK
61msgtest "add_keys_with_verify_against_master_keyring"
62if [ ! -e $MASTER_KEYRING ]; then
63 echo -n "No $MASTER_KEYRING found"
64 msgskip
65 exit 0
66fi
67
68# test bad keyring and ensure its not added (LP: #857472)
69ADD_KEYRING=./keys/exploid-keyring-with-dupe-keys.pub
70if add_keys_with_verify_against_master_keyring $ADD_KEYRING $MASTER_KEYRING; then
71 msgfail
72else
73 msgpass
74fi
75
76# ensure the keyring is still empty
77gpg_out=$($GPG --list-keys)
78msgtest "Test if keyring is empty"
79if [ -n "" ]; then
80 msgfail
81else
82 msgpass
83fi
84
85
86# test another possible attack vector using subkeys (LP: #1013128)
87msgtest "add_keys_with_verify_against_master_keyring with subkey attack"
88ADD_KEYRING=./keys/exploid-keyring-with-dupe-subkeys.pub
89if add_keys_with_verify_against_master_keyring $ADD_KEYRING $MASTER_KEYRING; then
90 msgfail
91else
92 msgpass
93fi
94
95# ensure the keyring is still empty
96gpg_out=$($GPG --list-keys)
97msgtest "Test if keyring is empty"
98if [ -n "" ]; then
99 msgfail
100else
101 msgpass
102fi
103
104
105# test good keyring and ensure we get no errors
106ADD_KEYRING=/usr/share/keyrings/ubuntu-archive-keyring.gpg
107if add_keys_with_verify_against_master_keyring $ADD_KEYRING $MASTER_KEYRING; then
108 msgpass
109else
110 msgfail
111fi
112
113testequal './etc/apt/trusted.gpg
114---------------------
115pub 1024D/437D05B5 2004-09-12
116uid Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com>
117sub 2048g/79164387 2004-09-12
118
119pub 1024D/FBB75451 2004-12-30
120uid Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>
121
122pub 4096R/C0B21F32 2012-05-11
123uid Ubuntu Archive Automatic Signing Key (2012) <ftpmaster@ubuntu.com>
124
125pub 4096R/EFE21092 2012-05-11
126uid Ubuntu CD Image Automatic Signing Key (2012) <cdimage@ubuntu.com>
127' $GPG --list-keys
128