6 # We don't use a secret keyring, of course, but gpg panics and
7 # implodes if there isn't one available
8 GPG_CMD
="gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /etc/apt/secring.gpg --trustdb-name /etc/apt/trustdb.gpg"
11 MASTER_KEYRING
=/usr
/share
/keyrings
/ubuntu
-master-keyring.gpg
12 ARCHIVE_KEYRING
=/usr
/share
/keyrings
/ubuntu
-archive-keyring.gpg
13 REMOVED_KEYS
=/usr
/share
/keyrings
/ubuntu
-archive-removed-keys.gpg
14 ARCHIVE_KEYRING_URI
=http
://archive.ubuntu.com
/ubuntu
/project
/ubuntu
-archive-keyring.gpg
16 add_keys_with_verify_against_master_keyring
() {
20 if [ ! -f "$ADD_KEYRING" ]; then
21 echo "ERROR: '$ADD_KEYRING' not found"
24 if [ ! -f "$MASTER" ]; then
25 echo "ERROR: '$MASTER' not found"
29 # when adding new keys, make sure that the archive-master-keyring
31 # all keys that are exported must have a valid signature
32 # from a key in the $distro-master-keyring
33 add_keys
=`$GPG_CMD --keyring $ADD_KEYRING --with-colons --list-keys | grep ^pub | cut -d: -f5`
34 master_keys
=`$GPG_CMD --keyring $MASTER --with-colons --list-keys | grep ^pub | cut -d: -f5`
35 for add_key
in $add_keys; do
37 for master_key
in $master_keys; do
38 if $GPG_CMD --keyring $ADD_KEYRING --list-sigs --with-colons $add_key | grep ^sig
| cut
-d: -f5 | grep -q $master_key; then
39 $GPG_CMD --quiet --batch --keyring $ADD_KEYRING --export $add_key | $GPG --import
43 if [ $ADDED = 0 ]; then
44 echo >&2 "Key '$add_key' not added. It is not signed with a master key"
49 # update the current archive signing keyring from a network URI
50 # the archive-keyring keys needs to be signed with the master key
51 # (otherwise it does not make sense from a security POV)
53 if [ -z "$ARCHIVE_KEYRING_URI" ]; then
54 echo "ERROR: no location for the archive-keyring given"
57 # in theory we would need to depend on wget for this, but this feature
58 # isn't useable in debian anyway as we have no keyring uri nor a master key
59 if ! which wget
>/dev
/null
2>&1; then
60 echo "ERROR: an installed wget is required for a network-based update"
63 if [ ! -d /var
/lib
/apt
/keyrings
]; then
64 mkdir -p /var
/lib
/apt
/keyrings
66 keyring
=/var
/lib
/apt
/keyrings
/$(basename $ARCHIVE_KEYRING)
68 if [ -e $keyring ]; then
69 old_mtime
=$(stat -c %Y $keyring)
71 (cd /var
/lib
/apt
/keyrings
; wget
-q -N $ARCHIVE_KEYRING_URI)
72 if [ ! -e $keyring ]; then
75 new_mtime
=$(stat -c %Y $keyring)
76 if [ $new_mtime -ne $old_mtime ]; then
77 echo "Checking for new archive signing keys now"
78 add_keys_with_verify_against_master_keyring
$keyring $MASTER_KEYRING
83 if [ ! -f $ARCHIVE_KEYRING ]; then
84 echo >&2 "ERROR: Can't find the archive-keyring"
85 echo >&2 "Is the ubuntu-keyring package installed?"
89 # add new keys from the package;
91 # we do not use add_keys_with_verify_against_master_keyring here,
92 # because we "update" is run on regular package updates. A
93 # attacker might as well replace the master-archive-keyring file
94 # in the package and add his own keys. so this check wouldn't
95 # add any security. we *need* this check on net-update though
96 $GPG_CMD --quiet --batch --keyring $ARCHIVE_KEYRING --export | $GPG --import
98 if [ -r "$REMOVED_KEYS" ]; then
99 # remove no-longer supported/used keys
100 keys
=`$GPG_CMD --keyring $REMOVED_KEYS --with-colons --list-keys | grep ^pub | cut -d: -f5`
102 if $GPG --list-keys --with-colons | grep ^pub
| cut
-d: -f5 | grep -q $key; then
103 $GPG --quiet --batch --delete-key --yes ${key}
107 echo "Warning: removed keys keyring $REMOVED_KEYS missing or not readable" >&2
113 echo "Usage: apt-key [--keyring file] [command] [arguments]"
115 echo "Manage apt's list of trusted keys"
117 echo " apt-key add <file> - add the key contained in <file> ('-' for stdin)"
118 echo " apt-key del <keyid> - remove the key <keyid>"
119 echo " apt-key export <keyid> - output the key <keyid>"
120 echo " apt-key exportall - output all trusted keys"
121 echo " apt-key update - update keys using the keyring package"
122 echo " apt-key net-update - update keys using the network"
123 echo " apt-key list - list keys"
124 echo " apt-key finger - list fingerprints"
125 echo " apt-key adv - pass advanced options to gpg (download key)"
127 echo "If no specific keyring file is given the command applies to all keyring files."
130 # Determine on which keyring we want to work
131 if [ "$1" = "--keyring" ]; then
132 #echo "keyfile given"
135 if [ -r "$TRUSTEDFILE" ]; then
136 GPG
="$GPG --keyring $TRUSTEDFILE --primary-keyring $TRUSTEDFILE"
138 echo >&2 "Error: The specified keyring »$TRUSTEDFILE« is missing or not readable"
142 # otherwise use the default
144 #echo "generate list"
145 TRUSTEDFILE
="/etc/apt/trusted.gpg"
146 if [ -r "$TRUSTEDFILE" ]; then
147 GPG
="$GPG --keyring $TRUSTEDFILE"
149 GPG
="$GPG --primary-keyring $TRUSTEDFILE"
150 TRUSTEDPARTS
="/etc/apt/trusted.gpg.d"
151 if [ -d "$TRUSTEDPARTS" ]; then
153 for trusted
in $(run-parts --list $TRUSTEDPARTS --regex '^.*\.gpg$'); do
154 #echo "part -> $trusted"
155 GPG
="$GPG --keyring $trusted"
159 #echo "COMMAND: $GPG"
162 if [ -z "$command" ]; then
168 if [ "$command" != "help" ] && ! which gpg
>/dev
/null
2>&1; then
169 echo >&2 "Warning: gnupg does not seem to be installed."
170 echo >&2 "Warning: apt-key requires gnupg for most operations."
176 $GPG --quiet --batch --import "$1"
180 $GPG --quiet --batch --delete-key --yes "$1"
190 $GPG --batch --list-keys
193 $GPG --batch --fingerprint
196 $GPG --armor --export "$1"
199 $GPG --armor --export
202 echo "Executing: $GPG $*"