]> git.saurik.com Git - apt.git/blame - test/integration/test-apt-key-net-update
clarify error message when apt-get source=ver fails, print a real error message inste...
[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"
24GPG="$GPG_CMD --keyring $TRUSTEDFILE"
25MASTER_KEYRING=/usr/share/keyrings/ubuntu-master-keyring.gpg
26
fc85b0d8
MV
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
31TRUSTDBDIR="$(mktemp -d)"
32CURRENTTRAP="${CURRENTTRAP} rm -rf '${TRUSTDBDIR}';"
33trap "${CURRENTTRAP}" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
34chmod 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
37SECRETKEYRING="${TRUSTDBDIR}/secring.gpg"
38touch $SECRETKEYRING
39GPG_CMD="$GPG_CMD --secret-keyring $SECRETKEYRING"
40GPG_CMD="$GPG_CMD --trustdb-name ${TRUSTDBDIR}/trustdb.gpg"
41#----------------------------------------- END COPY
f87338d2
DK
42
43msgtest "add_keys_with_verify_against_master_keyring"
44if [ ! -e $MASTER_KEYRING ]; then
45 echo -n "No $MASTER_KEYRING found"
46 msgskip
47 exit 0
48fi
49
50# test bad keyring and ensure its not added (LP: #857472)
51ADD_KEYRING=./keys/exploid-keyring-with-dupe-keys.pub
52if add_keys_with_verify_against_master_keyring $ADD_KEYRING $MASTER_KEYRING; then
53 msgfail
54else
55 msgpass
56fi
57
58# ensure the keyring is still empty
59gpg_out=$($GPG --list-keys)
60msgtest "Test if keyring is empty"
61if [ -n "" ]; then
62 msgfail
63else
64 msgpass
65fi
66
67
68# test another possible attack vector using subkeys (LP: #1013128)
69msgtest "add_keys_with_verify_against_master_keyring with subkey attack"
70ADD_KEYRING=./keys/exploid-keyring-with-dupe-subkeys.pub
71if add_keys_with_verify_against_master_keyring $ADD_KEYRING $MASTER_KEYRING; then
72 msgfail
73else
74 msgpass
75fi
76
77# ensure the keyring is still empty
78gpg_out=$($GPG --list-keys)
79msgtest "Test if keyring is empty"
80if [ -n "" ]; then
81 msgfail
82else
83 msgpass
84fi
85
86
87# test good keyring and ensure we get no errors
88ADD_KEYRING=/usr/share/keyrings/ubuntu-archive-keyring.gpg
89if add_keys_with_verify_against_master_keyring $ADD_KEYRING $MASTER_KEYRING; then
90 msgpass
91else
92 msgfail
93fi
94
95testequal './etc/apt/trusted.gpg
96---------------------
97pub 1024D/437D05B5 2004-09-12
98uid Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com>
99sub 2048g/79164387 2004-09-12
100
101pub 1024D/FBB75451 2004-12-30
102uid Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>
103
104pub 4096R/C0B21F32 2012-05-11
105uid Ubuntu Archive Automatic Signing Key (2012) <ftpmaster@ubuntu.com>
106
107pub 4096R/EFE21092 2012-05-11
108uid Ubuntu CD Image Automatic Signing Key (2012) <cdimage@ubuntu.com>
109' $GPG --list-keys
110