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