]> git.saurik.com Git - apt.git/blame - cmdline/apt-key
cmdline/apt-key: fix in the trusted key import script
[apt.git] / cmdline / apt-key
CommitLineData
b3d44315
MV
1#!/bin/sh
2
3set -e
4
4a242c5b
MV
5# We don't use a secret keyring, of course, but gpg panics and
6# implodes if there isn't one available
7
9129f2af 8GPG_CMD="gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /etc/apt/secring.gpg --trustdb-name /etc/apt/trustdb.gpg"
4a242c5b
MV
9GPG="$GPG_CMD --keyring /etc/apt/trusted.gpg"
10
11
7fbe42c0
MV
12MASTER_KEYRING=""
13#MASTER_KEYRING=/usr/share/keyrings/debian-master-keyring.gpg
7ef96224
MV
14ARCHIVE_KEYRING=/usr/share/keyrings/debian-archive-keyring.gpg
15REMOVED_KEYS=/usr/share/keyrings/debian-archive-removed-keys.gpg
4a242c5b 16
7fbe42c0 17add_keys_with_verify_against_master_keyring() {
8c56b1e0
MV
18 ADD_KEYRING=$1
19 MASTER=$2
20
21 if [ ! -f "$ADD_KEYRING" ]; then
22 echo "ERROR: '$ADD_KEYRING' not found"
23 return
24 fi
25 if [ ! -f "$MASTER" ]; then
26 echo "ERROR: '$MASTER' not found"
27 return
28 fi
29
30 # when adding new keys, make sure that the archive-master-keyring
31 # is honored. so:
32 # all keys that are exported and have the name
33 # "Ubuntu Archive Automatic Signing Key" must have a valid signature
34 # from a key in the ubuntu-master-keyring
35 add_keys=`$GPG_CMD --keyring $ADD_KEYRING --with-colons --list-keys | grep ^pub | cut -d: -f5`
36 master_keys=`$GPG_CMD --keyring $MASTER --with-colons --list-keys | grep ^pub | cut -d: -f5`
37 for add_key in $add_keys; do
c9bb37c7 38 ADDED=0
8c56b1e0 39 for master_key in $master_keys; do
c9bb37c7 40 if $GPG_CMD --keyring $ADD_KEYRING --list-sigs --with-colons $add_key | grep ^sig | cut -d: -f5 | grep -q $master_key; then
8c56b1e0 41 $GPG_CMD --quiet --batch --keyring $ARCHIVE_KEYRING --export $add_key | $GPG --import
c9bb37c7 42 ADDED=1
8c56b1e0 43 fi
7fbe42c0 44 done
c9bb37c7
MV
45 if [ $ADDED = 0 ]; then
46 echo >&2 "Key '$add_key' not added. It is not signed with a master key"
47 fi
8c56b1e0 48 done
7fbe42c0 49}
4a242c5b
MV
50
51update() {
52 if [ ! -f $ARCHIVE_KEYRING ]; then
53 echo >&2 "ERROR: Can't find the archive-keyring"
5fdd72f2 54 echo >&2 "Is the debian-archive-keyring package installed?"
4a242c5b
MV
55 exit 1
56 fi
57
7fbe42c0
MV
58 # add new keys, if no MASTER_KEYRING is used, use the traditional
59 # way
60 if [ -z "$MASTER_KEYRING" ]; then
61 $GPG_CMD --quiet --batch --keyring $ARCHIVE_KEYRING --export | $GPG --import
62 else
8c56b1e0 63 add_keys_with_verify_against_master_keyring $ARCHIVE_KEYRING $MASTER_KEYRING
7fbe42c0 64 fi
4a242c5b 65
7fbe42c0 66 # remove no-longer supported/used keys
3036f1e4 67 keys=`$GPG_CMD --keyring $REMOVED_KEYS --with-colons --list-keys | grep ^pub | cut -d: -f5`
4a242c5b 68 for key in $keys; do
3036f1e4 69 if $GPG --list-keys --with-colons | grep ^pub | cut -d: -f5 | grep -q $key; then
32133629 70 $GPG --quiet --batch --delete-key --yes ${key}
4a242c5b
MV
71 fi
72 done
73}
74
7fbe42c0 75
b3d44315
MV
76usage() {
77 echo "Usage: apt-key [command] [arguments]"
78 echo
79 echo "Manage apt's list of trusted keys"
80 echo
81 echo " apt-key add <file> - add the key contained in <file> ('-' for stdin)"
82 echo " apt-key del <keyid> - remove the key <keyid>"
bf6d5b42
OS
83 echo " apt-key export <keyid> - output the key <keyid>"
84 echo " apt-key exportall - output all trusted keys"
4a242c5b 85 echo " apt-key update - update keys using the keyring package"
b3d44315
MV
86 echo " apt-key list - list keys"
87 echo
88}
89
90command="$1"
91if [ -z "$command" ]; then
92 usage
93 exit 1
94fi
95shift
96
97if [ "$command" != "help" ] && ! which gpg >/dev/null 2>&1; then
98 echo >&2 "Warning: gnupg does not seem to be installed."
99 echo >&2 "Warning: apt-key requires gnupg for most operations."
100 echo >&2
101fi
102
b3d44315
MV
103case "$command" in
104 add)
105 $GPG --quiet --batch --import "$1"
106 echo "OK"
107 ;;
108 del|rm|remove)
109 $GPG --quiet --batch --delete-key --yes "$1"
110 echo "OK"
111 ;;
4a242c5b
MV
112 update)
113 update
114 ;;
b3d44315
MV
115 list)
116 $GPG --batch --list-keys
117 ;;
118 finger*)
119 $GPG --batch --fingerprint
120 ;;
bf6d5b42
OS
121 export)
122 $GPG --armor --export "$1"
123 ;;
124 exportall)
125 $GPG --armor --export
126 ;;
b3d44315
MV
127 adv*)
128 echo "Executing: $GPG $*"
129 $GPG $*
130 ;;
131 help)
132 usage
133 ;;
134 *)
135 usage
136 exit 1
137 ;;
138esac