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