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"
13 ARCHIVE_KEYRING_URI
=""
14 #MASTER_KEYRING=/usr/share/keyrings/debian-master-keyring.gpg
15 #ARCHIVE_KEYRING_URI=http://ftp.debian.org/debian/debian-archive-keyring.gpg
17 ARCHIVE_KEYRING
=/usr
/share
/keyrings
/debian
-archive-keyring.gpg
18 REMOVED_KEYS
=/usr
/share
/keyrings
/debian
-archive-removed-keys.gpg
20 add_keys_with_verify_against_master_keyring
() {
24 if [ ! -f "$ADD_KEYRING" ]; then
25 echo "ERROR: '$ADD_KEYRING' not found"
28 if [ ! -f "$MASTER" ]; then
29 echo "ERROR: '$MASTER' not found"
33 # when adding new keys, make sure that the archive-master-keyring
35 # all keys that are exported must have a valid signature
36 # from a key in the $distro-master-keyring
37 add_keys
=`$GPG_CMD --keyring $ADD_KEYRING --with-colons --list-keys | grep ^pub | cut -d: -f5`
38 master_keys
=`$GPG_CMD --keyring $MASTER --with-colons --list-keys | grep ^pub | cut -d: -f5`
39 for add_key
in $add_keys; do
41 for master_key
in $master_keys; do
42 if $GPG_CMD --keyring $ADD_KEYRING --list-sigs --with-colons $add_key | grep ^sig
| cut
-d: -f5 | grep -q $master_key; then
43 $GPG_CMD --quiet --batch --keyring $ADD_KEYRING --export $add_key | $GPG --import
47 if [ $ADDED = 0 ]; then
48 echo >&2 "Key '$add_key' not added. It is not signed with a master key"
53 # update the current archive signing keyring from a network URI
54 # the archive-keyring keys needs to be signed with the master key
55 # (otherwise it does not make sense from a security POV)
57 if [ -z "$ARCHIVE_KEYRING_URI" ]; then
58 echo "ERROR: no location for the archive-keyring given"
60 if [ ! -d /var
/lib
/apt
/keyrings
]; then
61 mkdir -p /var
/lib
/apt
/keyrings
63 keyring
=/var
/lib
/apt
/keyrings
/$(basename $ARCHIVE_KEYRING)
65 if [ -e $keyring ]; then
66 old_mtime
=$(stat -c %Y $keyring)
68 (cd /var
/lib
/apt
/keyrings
; wget
-q -N $ARCHIVE_KEYRING_URI)
69 if [ ! -e $keyring ]; then
72 new_mtime
=$(stat -c %Y $keyring)
73 if [ $new_mtime -ne $old_mtime ]; then
74 echo "Checking for new archive signing keys now"
75 add_keys_with_verify_against_master_keyring
$keyring $MASTER_KEYRING
80 if [ ! -f $ARCHIVE_KEYRING ]; then
81 echo >&2 "ERROR: Can't find the archive-keyring"
82 echo >&2 "Is the debian-archive-keyring package installed?"
86 # add new keys from the package;
88 # we do not use add_keys_with_verify_against_master_keyring here,
89 # because "update" is run on regular package updates. A
90 # attacker might as well replace the master-archive-keyring file
91 # in the package and add his own keys. so this check wouldn't
92 # add any security. we *need* this check on net-update though
93 $GPG_CMD --quiet --batch --keyring $ARCHIVE_KEYRING --export | $GPG --import
95 # remove no-longer supported/used keys
96 keys
=`$GPG_CMD --keyring $REMOVED_KEYS --with-colons --list-keys | grep ^pub | cut -d: -f5`
98 if $GPG --list-keys --with-colons | grep ^pub
| cut
-d: -f5 | grep -q $key; then
99 $GPG --quiet --batch --delete-key --yes ${key}
106 echo "Usage: apt-key [command] [arguments]"
108 echo "Manage apt's list of trusted keys"
110 echo " apt-key add <file> - add the key contained in <file> ('-' for stdin)"
111 echo " apt-key del <keyid> - remove the key <keyid>"
112 echo " apt-key export <keyid> - output the key <keyid>"
113 echo " apt-key exportall - output all trusted keys"
114 echo " apt-key update - update keys using the keyring package"
115 echo " apt-key net-update - update keys using the network"
116 echo " apt-key list - list keys"
117 echo " apt-key finger - list fingerprints"
118 echo " apt-key adv - pass advanced options to gpg (download key)"
123 if [ -z "$command" ]; then
129 if [ "$command" != "help" ] && ! which gpg
>/dev
/null
2>&1; then
130 echo >&2 "Warning: gnupg does not seem to be installed."
131 echo >&2 "Warning: apt-key requires gnupg for most operations."
137 $GPG --quiet --batch --import "$1"
141 $GPG --quiet --batch --delete-key --yes "$1"
151 $GPG --batch --list-keys
154 $GPG --batch --fingerprint
157 $GPG --armor --export "$1"
160 $GPG --armor --export
163 echo "Executing: $GPG $*"