5 # We don't use a secret keyring, of course, but gpg panics and
6 # 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"
9 GPG
="$GPG_CMD --keyring /etc/apt/trusted.gpg"
12 MASTER_KEYRING
=/usr
/share
/keyrings
/ubuntu
-master-keyring.gpg
13 ARCHIVE_KEYRING
=/usr
/share
/keyrings
/ubuntu
-archive-keyring.gpg
14 REMOVED_KEYS
=/usr
/share
/keyrings
/ubuntu
-archive-removed-keys.gpg
15 ARCHIVE_KEYRING_URI
=http
://archive.ubuntu.com
/ubuntu
/project
/ubuntu
-archive-keyring.gpg
17 add_keys_with_verify_against_master_keyring
() {
21 if [ ! -f "$ADD_KEYRING" ]; then
22 echo "ERROR: '$ADD_KEYRING' not found"
25 if [ ! -f "$MASTER" ]; then
26 echo "ERROR: '$MASTER' not found"
30 # when adding new keys, make sure that the archive-master-keyring
32 # all keys that are exported must have a valid signature
33 # from a key in the $distro-master-keyring
34 add_keys
=`$GPG_CMD --keyring $ADD_KEYRING --with-colons --list-keys | grep ^pub | cut -d: -f5`
35 master_keys
=`$GPG_CMD --keyring $MASTER --with-colons --list-keys | grep ^pub | cut -d: -f5`
36 for add_key
in $add_keys; do
38 for master_key
in $master_keys; do
39 if $GPG_CMD --keyring $ADD_KEYRING --list-sigs --with-colons $add_key | grep ^sig
| cut
-d: -f5 | grep -q $master_key; then
40 $GPG_CMD --quiet --batch --keyring $ADD_KEYRING --export $add_key | $GPG --import
44 if [ $ADDED = 0 ]; then
45 echo >&2 "Key '$add_key' not added. It is not signed with a master key"
50 # update the current archive signing keyring from a network URI
51 # the archive-keyring keys needs to be signed with the master key
52 # (otherwise it does not make sense from a security POV)
54 if [ -z "$ARCHIVE_KEYRING_URI" ]; then
55 echo "ERROR: no location for the archive-keyring given"
57 if [ ! -d /var
/lib
/apt
/keyrings
]; then
58 mkdir -p /var
/lib
/apt
/keyrings
60 keyring
=/var
/lib
/apt
/keyrings
/$(basename $ARCHIVE_KEYRING)
62 if [ -e $keyring ]; then
63 old_mtime
=$(stat -c %Y $keyring)
65 (cd /var
/lib
/apt
/keyrings
; wget
-q -N $ARCHIVE_KEYRING_URI)
66 if [ ! -e $keyring ]; then
69 new_mtime
=$(stat -c %Y $keyring)
70 if [ $new_mtime -ne $old_mtime ]; then
71 echo "Checking for new archive signing keys now"
72 add_keys_with_verify_against_master_keyring
$keyring $MASTER_KEYRING
77 if [ ! -f $ARCHIVE_KEYRING ]; then
78 echo >&2 "ERROR: Can't find the archive-keyring"
79 echo >&2 "Is the ubuntu-keyring package installed?"
83 # add new keys from the package;
85 # we do not use add_keys_with_verify_against_master_keyring here,
86 # because we "update" is run on regular package updates. A
87 # attacker might as well replace the master-archive-keyring file
88 # in the package and add his own keys. so this check wouldn't
89 # add any security. we *need* this check on net-update though
90 $GPG_CMD --quiet --batch --keyring $ARCHIVE_KEYRING --export | $GPG --import
92 # remove no-longer supported/used keys
93 keys
=`$GPG_CMD --keyring $REMOVED_KEYS --with-colons --list-keys | grep ^pub | cut -d: -f5`
95 if $GPG --list-keys --with-colons | grep ^pub
| cut
-d: -f5 | grep -q $key; then
96 $GPG --quiet --batch --delete-key --yes ${key}
103 echo "Usage: apt-key [command] [arguments]"
105 echo "Manage apt's list of trusted keys"
107 echo " apt-key add <file> - add the key contained in <file> ('-' for stdin)"
108 echo " apt-key del <keyid> - remove the key <keyid>"
109 echo " apt-key export <keyid> - output the key <keyid>"
110 echo " apt-key exportall - output all trusted keys"
111 echo " apt-key update - update keys using the keyring package"
112 echo " apt-key net-update - update keys using the network"
113 echo " apt-key list - list keys"
118 if [ -z "$command" ]; then
124 if [ "$command" != "help" ] && ! which gpg
>/dev
/null
2>&1; then
125 echo >&2 "Warning: gnupg does not seem to be installed."
126 echo >&2 "Warning: apt-key requires gnupg for most operations."
132 $GPG --quiet --batch --import "$1"
136 $GPG --quiet --batch --delete-key --yes "$1"
146 $GPG --batch --list-keys
149 $GPG --batch --fingerprint
152 $GPG --armor --export "$1"
155 $GPG --armor --export
158 echo "Executing: $GPG $*"