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