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