2011-06-30 11:07:54 -04:00
|
|
|
#!/bin/bash -e
|
2010-09-15 23:40:35 -04:00
|
|
|
#
|
|
|
|
# pacman-key - manages pacman's keyring
|
|
|
|
# Based on apt-key, from Debian
|
|
|
|
# @configure_input@
|
|
|
|
#
|
2011-06-04 10:18:33 -04:00
|
|
|
# Copyright (c) 2010-2011 Pacman Development Team <pacman-dev@archlinux.org>
|
2010-09-15 23:40:35 -04:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
# gettext initialization
|
2011-06-23 22:21:51 -04:00
|
|
|
export TEXTDOMAIN='pacman-scripts'
|
2010-09-15 23:40:35 -04:00
|
|
|
export TEXTDOMAINDIR='@localedir@'
|
|
|
|
|
|
|
|
myver="@PACKAGE_VERSION@"
|
|
|
|
|
2011-07-05 13:05:08 -04:00
|
|
|
# Options
|
|
|
|
ADD=0
|
|
|
|
DELETE=0
|
2011-07-08 07:14:53 -04:00
|
|
|
EDITKEY=0
|
2011-07-05 13:05:08 -04:00
|
|
|
EXPORT=0
|
|
|
|
FINGER=0
|
2011-07-19 08:52:07 -04:00
|
|
|
IMPORT=0
|
|
|
|
IMPORT_TRUSTDB=0
|
2011-07-09 03:26:17 -04:00
|
|
|
INIT=0
|
2011-09-01 16:20:53 -04:00
|
|
|
KEYSERVER=''
|
2011-07-29 22:24:46 -04:00
|
|
|
LISTKEYS=0
|
|
|
|
LISTSIGS=0
|
2011-08-29 13:52:51 -04:00
|
|
|
LSIGNKEY=0
|
2011-08-15 08:51:58 -04:00
|
|
|
POPULATE=0
|
2011-07-05 13:05:08 -04:00
|
|
|
RECEIVE=0
|
2011-09-01 16:29:25 -04:00
|
|
|
REFRESH=0
|
2011-07-05 13:05:08 -04:00
|
|
|
UPDATEDB=0
|
2011-07-08 21:41:04 -04:00
|
|
|
VERIFY=0
|
2011-07-05 13:05:08 -04:00
|
|
|
|
2011-09-01 16:20:53 -04:00
|
|
|
DEFAULT_KEYSERVER='hkp://keys.gnupg.net'
|
|
|
|
|
2011-06-09 06:43:25 -04:00
|
|
|
m4_include(library/output_format.sh)
|
2010-09-15 23:40:35 -04:00
|
|
|
|
2011-07-05 13:05:08 -04:00
|
|
|
m4_include(library/parse_options.sh)
|
|
|
|
|
2010-09-15 23:40:35 -04:00
|
|
|
usage() {
|
|
|
|
printf "pacman-key (pacman) %s\n" ${myver}
|
|
|
|
echo
|
2011-07-05 13:05:08 -04:00
|
|
|
printf "$(gettext "Usage: %s [options]")\n" $(basename $0)
|
2010-09-15 23:40:35 -04:00
|
|
|
echo
|
2011-07-05 14:01:14 -04:00
|
|
|
printf "$(gettext "Manage pacman\'s list of trusted keys")\n"
|
2010-09-15 23:40:35 -04:00
|
|
|
echo
|
2011-07-05 13:05:08 -04:00
|
|
|
echo "$(gettext "Options:")"
|
2011-09-01 16:04:28 -04:00
|
|
|
echo "$(gettext " -a, --add [file(s)] Add the specified keys (empty for stdin)")"
|
2011-07-05 13:34:04 -04:00
|
|
|
echo "$(gettext " -d, --delete <keyid(s)> Remove the specified keyids")"
|
2011-09-01 16:04:28 -04:00
|
|
|
echo "$(gettext " -e, --export [keyid(s)] Export the specified or all keyids")"
|
|
|
|
echo "$(gettext " -f, --finger [keyid(s)] List fingerprint for specified or all keyids")"
|
2011-04-21 09:59:05 -04:00
|
|
|
echo "$(gettext " -h, --help Show this help message and exit")"
|
2011-09-01 16:04:28 -04:00
|
|
|
echo "$(gettext " -l, --list-keys [keyid(s)] List the specified or all keys")"
|
2011-09-01 16:20:53 -04:00
|
|
|
echo "$(gettext " -r, --recv-keys <keyid(s)> Fetch the specified keyids")"
|
2011-03-23 02:24:28 -04:00
|
|
|
echo "$(gettext " -u, --updatedb Update the trustdb of pacman")"
|
2011-07-08 21:41:04 -04:00
|
|
|
echo "$(gettext " -v, --verify <signature> Verify the file specified by the signature")"
|
2011-03-23 02:24:28 -04:00
|
|
|
echo "$(gettext " -V, --version Show program version")"
|
2011-08-08 20:01:26 -04:00
|
|
|
printf "$(gettext " --config <file> Use an alternate config file (instead of\n\
|
|
|
|
'%s')")\n" "@sysconfdir@/pacman.conf"
|
2011-07-08 07:14:53 -04:00
|
|
|
echo "$(gettext " --edit-key <keyid(s)> Present a menu for key management task on keyids")"
|
2011-08-08 20:01:26 -04:00
|
|
|
printf "$(gettext " --gpgdir <dir> Set an alternate directory for GnuPG (instead\n\
|
|
|
|
of '%s')")\n" "@sysconfdir@/pacman.d/gnupg"
|
2011-07-19 08:52:07 -04:00
|
|
|
echo "$(gettext " --import <dir(s)> Imports pubring.gpg and trustdb.gpg from dir(s)")"
|
|
|
|
echo "$(gettext " --import-trustdb <dir(s)> Imports ownertrust values from trustdb.gpg in dir(s)")"
|
2011-07-10 00:23:47 -04:00
|
|
|
echo "$(gettext " --init Ensure the keyring is properly initialized")"
|
2011-09-01 16:20:53 -04:00
|
|
|
echo "$(gettext " --keyserver Specify a keyserver to use if necessary")"
|
2011-09-01 16:04:28 -04:00
|
|
|
echo "$(gettext " --list-sigs [keyid(s)] List keys and their signatures")"
|
2011-09-01 15:47:33 -04:00
|
|
|
echo "$(gettext " --lsign-key <keyid> Locally sign the specified keyid")"
|
2011-09-01 16:04:28 -04:00
|
|
|
printf "$(gettext " --populate [keyring(s)] Reload the default keys from the (given) keyrings\n\
|
2011-08-15 08:51:58 -04:00
|
|
|
in '%s'")\n" "@pkgdatadir@/keyrings"
|
2011-09-01 16:29:25 -04:00
|
|
|
echo "$(gettext " --refresh-keys [keyid(s)] Update specified or all keys from a keyserver")"
|
2010-09-15 23:40:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
version() {
|
|
|
|
printf "pacman-key (pacman) %s\n" "${myver}"
|
|
|
|
printf "$(gettext "\
|
2011-03-23 02:24:28 -04:00
|
|
|
Copyright (c) 2010-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\
|
2010-09-15 23:40:35 -04:00
|
|
|
This is free software; see the source for copying conditions.\n\
|
|
|
|
There is NO WARRANTY, to the extent permitted by law.\n")"
|
|
|
|
}
|
|
|
|
|
2011-07-08 22:40:25 -04:00
|
|
|
# read the config file "$1" which has key=value pairs, and return the key which
|
|
|
|
# matches "$2". the equals sign between pairs may be surrounded by any amount
|
|
|
|
# of whitespace.
|
2011-04-21 09:59:07 -04:00
|
|
|
get_from() {
|
2011-07-08 22:40:25 -04:00
|
|
|
while IFS='=' read -r key value; do
|
|
|
|
[[ -z $key || ${key:0:1} = '#' ]] && continue
|
|
|
|
|
|
|
|
if [[ ${key%% *} = "$2" && -n ${value##* } ]]; then
|
|
|
|
echo "${value##* }"
|
|
|
|
return 0
|
2011-06-08 02:48:56 -04:00
|
|
|
fi
|
|
|
|
done < "$1"
|
2011-07-08 22:40:25 -04:00
|
|
|
return 1
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
}
|
|
|
|
|
2011-08-25 19:39:11 -04:00
|
|
|
generate_master_key() {
|
|
|
|
# Generate the master key, which will be in both pubring and secring
|
|
|
|
"${GPG_PACMAN[@]}" --gen-key --batch <<EOF
|
|
|
|
%echo Generating pacman keychain master key...
|
|
|
|
Key-Type: RSA
|
|
|
|
Key-Length: 2048
|
|
|
|
Key-Usage: sign
|
|
|
|
Name-Real: Pacman Keychain Master Key
|
|
|
|
Name-Email: pacman@localhost
|
|
|
|
Expire-Date: 0
|
|
|
|
%commit
|
|
|
|
%echo Done
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
secret_keys_available() {
|
|
|
|
"${GPG_PACMAN[@]}" -K --with-colons | wc -l
|
|
|
|
}
|
|
|
|
|
2011-08-25 13:59:27 -04:00
|
|
|
# Adds the given gpg.conf option if it is not present in the file.
|
|
|
|
# Note that if we find it commented out, we won't add the option.
|
|
|
|
# args: $1 conffile, $2 option-name, $3 (optional) option-value
|
|
|
|
add_gpg_conf_option() {
|
|
|
|
local confline
|
|
|
|
# looking for the option 'bare', only leading spaces or # chars allowed,
|
|
|
|
# followed by at least one space and any other text or the end of line.
|
|
|
|
if ! grep -q "^[[:space:]#]*$2\([[:space:]].*\)*$" "$1" &>/dev/null; then
|
|
|
|
confline="$2"
|
|
|
|
[[ -n $3 ]] && confline="$2 $3"
|
|
|
|
echo "$confline" >> "$1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2011-07-09 03:26:17 -04:00
|
|
|
initialize() {
|
2011-09-01 16:20:53 -04:00
|
|
|
local conffile keyserv
|
2011-07-09 03:26:17 -04:00
|
|
|
# Check for simple existence rather than for a directory as someone
|
|
|
|
# may want to use a symlink here
|
|
|
|
[[ -e ${PACMAN_KEYRING_DIR} ]] || mkdir -p -m 755 "${PACMAN_KEYRING_DIR}"
|
|
|
|
|
|
|
|
# keyring files
|
|
|
|
[[ -f ${PACMAN_KEYRING_DIR}/pubring.gpg ]] || touch ${PACMAN_KEYRING_DIR}/pubring.gpg
|
|
|
|
[[ -f ${PACMAN_KEYRING_DIR}/secring.gpg ]] || touch ${PACMAN_KEYRING_DIR}/secring.gpg
|
2011-07-20 00:28:39 -04:00
|
|
|
[[ -f ${PACMAN_KEYRING_DIR}/trustdb.gpg ]] || "${GPG_PACMAN[@]}" --update-trustdb
|
2011-08-25 13:59:26 -04:00
|
|
|
chmod 644 ${PACMAN_KEYRING_DIR}/{pubring,trustdb}.gpg
|
|
|
|
chmod 600 ${PACMAN_KEYRING_DIR}/secring.gpg
|
2011-07-09 03:26:17 -04:00
|
|
|
|
|
|
|
# gpg.conf
|
2011-08-25 13:59:27 -04:00
|
|
|
conffile="${PACMAN_KEYRING_DIR}/gpg.conf"
|
|
|
|
[[ -f $conffile ]] || touch "$conffile"
|
|
|
|
chmod 644 "$conffile"
|
|
|
|
add_gpg_conf_option "$conffile" 'no-greeting'
|
|
|
|
add_gpg_conf_option "$conffile" 'no-permission-warning'
|
|
|
|
add_gpg_conf_option "$conffile" 'lock-never'
|
2011-09-01 16:20:53 -04:00
|
|
|
keyserv=${KEYSERVER:-$DEFAULT_KEYSERVER}
|
|
|
|
add_gpg_conf_option "$conffile" 'keyserver' "$keyserv"
|
2011-08-25 19:39:11 -04:00
|
|
|
|
|
|
|
# set up a private signing key (if none available)
|
|
|
|
if [[ $(secret_keys_available) -lt 1 ]]; then
|
|
|
|
generate_master_key
|
|
|
|
UPDATEDB=1
|
|
|
|
fi
|
2011-07-09 03:26:17 -04:00
|
|
|
}
|
|
|
|
|
2011-07-09 07:51:01 -04:00
|
|
|
check_keyring() {
|
|
|
|
if [[ ! -r ${PACMAN_KEYRING_DIR}/pubring.gpg || \
|
|
|
|
! -r ${PACMAN_KEYRING_DIR}/trustdb.gpg ]]; then
|
|
|
|
error "$(gettext "You do not have sufficient permissions to read the %s keyring...")" "pacman"
|
|
|
|
msg "$(gettext "Use '%s' to correct the keyring permissions.")" "pacman-key --init"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if (( (EXPORT || FINGER || LIST || VERIFY) && EUID != 0 )); then
|
2011-08-25 13:59:26 -04:00
|
|
|
if ! grep -q "^[[:space:]]*lock-never[[:space:]]*$" ${PACMAN_KEYRING_DIR}/gpg.conf &>/dev/null; then
|
2011-07-09 07:51:01 -04:00
|
|
|
error "$(gettext "You do not have sufficient permissions to run this command...")"
|
|
|
|
msg "$(gettext "Use '%s' to correct the keyring permissions.")" "pacman-key --init"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2011-08-29 13:52:51 -04:00
|
|
|
if (( LSIGNKEY )); then
|
|
|
|
if [[ $(secret_keys_available) -lt 1 ]]; then
|
|
|
|
error "$(gettext "There is no secret key available to sign with.")"
|
|
|
|
msg "$(gettext "Use '%s' to generate a default secret key.")" "pacman-key --init"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2011-07-09 07:51:01 -04:00
|
|
|
}
|
|
|
|
|
2011-07-08 21:16:12 -04:00
|
|
|
verify_keyring_input() {
|
|
|
|
local ret=0;
|
2011-08-15 08:51:58 -04:00
|
|
|
local KEYRING_IMPORT_DIR='@pkgdatadir@/keyrings'
|
2010-09-15 23:40:35 -04:00
|
|
|
|
2011-08-15 08:51:58 -04:00
|
|
|
# Verify signatures of keyring files and association revocation files if they exist
|
|
|
|
msg "$(gettext "Verifying keyring file signatures...")"
|
|
|
|
local keyring
|
2011-09-20 20:35:11 -04:00
|
|
|
for keyring in "${KEYRINGIDS[@]}"; do
|
2011-08-15 08:51:58 -04:00
|
|
|
if ! "${GPG_PACMAN[@]}" --verify "${KEYRING_IMPORT_DIR}/${keyring}.gpg.sig" &>/dev/null; then
|
2010-09-15 23:40:35 -04:00
|
|
|
error "$(gettext "The signature of file %s is not valid.")" "${ADDED_KEYS}"
|
2011-07-08 21:16:12 -04:00
|
|
|
ret=1
|
2010-09-15 23:40:35 -04:00
|
|
|
fi
|
|
|
|
|
2011-08-15 08:51:58 -04:00
|
|
|
if [[ -f "${KEYRING_IMPORT_DIR}/${keyring}-revoked" ]]; then
|
|
|
|
if ! "${GPG_PACMAN[@]}" --verify "${KEYRING_IMPORT_DIR}/${keyring}-revoked.sig" &>/dev/null; then
|
|
|
|
error "$(gettext "The signature of file %s is not valid.")" "${KEYRING_IMPORT_DIR}/${keyring}-revoked"
|
|
|
|
ret=1
|
|
|
|
fi
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
fi
|
2011-08-15 08:51:58 -04:00
|
|
|
done
|
2010-09-15 23:40:35 -04:00
|
|
|
|
2011-08-15 08:51:58 -04:00
|
|
|
return $ret
|
|
|
|
}
|
|
|
|
|
|
|
|
populate_keyring() {
|
|
|
|
local KEYRING_IMPORT_DIR='@pkgdatadir@/keyrings'
|
|
|
|
local GPG_NOKEYRING=(gpg --batch --quiet --ignore-time-conflict --no-options --no-default-keyring --homedir ${PACMAN_KEYRING_DIR} --no-permission-warning)
|
|
|
|
|
|
|
|
local keyring
|
|
|
|
local ret=0
|
|
|
|
if [[ -z ${KEYRINGIDS[@]} ]]; then
|
|
|
|
# get list of all available keyrings
|
|
|
|
shopt -s nullglob
|
|
|
|
KEYRINGIDS=("$KEYRING_IMPORT_DIR"/*.gpg)
|
|
|
|
shopt -u nullglob
|
|
|
|
KEYRINGIDS=("${KEYRINGIDS[@]##*/}")
|
|
|
|
KEYRINGIDS=("${KEYRINGIDS[@]%.gpg}")
|
|
|
|
if [[ -z ${KEYRINGIDS[@]} ]]; then
|
|
|
|
error "$(gettext "No keyring files exist in %s.")" "$KEYRING_IMPORT_DIR"
|
2011-07-08 21:16:12 -04:00
|
|
|
ret=1
|
2010-09-15 23:40:35 -04:00
|
|
|
fi
|
2011-08-15 08:51:58 -04:00
|
|
|
else
|
|
|
|
# verify listed keyrings exist
|
2011-09-20 20:35:11 -04:00
|
|
|
for keyring in "${KEYRINGIDS[@]}"; do
|
2011-08-15 08:51:58 -04:00
|
|
|
if [[ ! -f "$KEYRING_IMPORT_DIR/$keyring.gpg" ]]; then
|
|
|
|
error "$(gettext "The keyring file %s does not exist.")" "$KEYRING_IMPORT_DIR/$keyring.gpg"
|
|
|
|
ret=1
|
|
|
|
fi
|
|
|
|
done
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
fi
|
|
|
|
|
2011-08-15 08:51:58 -04:00
|
|
|
if (( ret )); then
|
|
|
|
exit 1
|
|
|
|
fi
|
2011-07-08 21:16:12 -04:00
|
|
|
|
2011-08-15 08:51:58 -04:00
|
|
|
verify_keyring_input || exit 1
|
2011-07-08 21:16:12 -04:00
|
|
|
|
|
|
|
# Variable used for iterating on keyrings
|
|
|
|
local key
|
|
|
|
local key_id
|
|
|
|
|
2011-08-23 01:00:19 -04:00
|
|
|
# Add keys from requested keyrings
|
2011-09-20 20:35:11 -04:00
|
|
|
for keyring in "${KEYRINGIDS[@]}"; do
|
2011-08-23 01:00:19 -04:00
|
|
|
msg "$(gettext "Appending keys from %s.gpg...")" "$keyring"
|
|
|
|
local add_keys="$("${GPG_NOKEYRING[@]}" --keyring "${KEYRING_IMPORT_DIR}/${keyring}.gpg" --with-colons --list-keys | grep ^pub | cut -d: -f5)"
|
|
|
|
for key_id in ${add_keys}; do
|
|
|
|
"${GPG_NOKEYRING[@]}" --keyring "${KEYRING_IMPORT_DIR}/${keyring}.gpg" --export "${key_id}" | "${GPG_PACMAN[@]}" --import
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
# Read the revoked key IDs to an array. The conversion from whatever is inside the file
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
# to key ids is important, because key ids are the only guarantee of identification
|
|
|
|
# for the keys.
|
|
|
|
local -A removed_ids
|
2011-09-20 20:35:11 -04:00
|
|
|
for keyring in "${KEYRINGIDS[@]}"; do
|
2011-08-15 08:51:58 -04:00
|
|
|
if [[ -f "${KEYRING_IMPORT_DIR}/${keyring}-revoked" ]]; then
|
|
|
|
while read key; do
|
|
|
|
local key_values name
|
|
|
|
# extract key ID (field 5) and the name of owner (field 10)
|
|
|
|
key_values="$("${GPG_PACMAN[@]}" --quiet --with-colons --list-key "${key}" 2>/dev/null | grep ^pub | cut -d: -f5,10 --output-delimiter=' ')"
|
|
|
|
if [[ -n $key_values ]]; then
|
|
|
|
# The first word is the key_id
|
|
|
|
key_id="${key_values%% *}"
|
|
|
|
# the rest is the name of the owner
|
|
|
|
name="${key_values#* }"
|
|
|
|
if [[ -n ${key_id} ]]; then
|
|
|
|
# Mark this key to be deleted
|
|
|
|
removed_ids[$key_id]="$name"
|
|
|
|
fi
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
fi
|
2011-08-15 08:51:58 -04:00
|
|
|
done < "${KEYRING_IMPORT_DIR}/${keyring}-revoked"
|
|
|
|
fi
|
|
|
|
done
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
|
2011-08-23 02:10:06 -04:00
|
|
|
# Read list of keys that must be kept installed and remove them from the list
|
|
|
|
# of keys to be removed
|
|
|
|
if [[ -f "${PACMAN_KEYRING_DIR}/holdkeys" ]]; then
|
|
|
|
while read key; do
|
2011-07-20 00:28:39 -04:00
|
|
|
key_id="$("${GPG_PACMAN[@]}" --quiet --with-colons --list-key "${key}" | grep ^pub | cut -d: -f5)"
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
if [[ -n "${removed_ids[$key_id]}" ]]; then
|
|
|
|
unset removed_ids[$key_id]
|
|
|
|
fi
|
2011-08-23 02:10:06 -04:00
|
|
|
done < "${PACMAN_KEYRING_DIR}/holdkeys"
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Remove the keys not marked to keep
|
|
|
|
if (( ${#removed_ids[@]} > 0 )); then
|
2011-08-15 08:51:58 -04:00
|
|
|
msg "$(gettext "Removing revoked keys from keyring...")"
|
pacman-key: remake of --reload command
The --reload command was refactored to allow a more flexible management.
There are two sets of keys that will be added, one that will be
removed and one that will be kept.
The set of keys to be kept are configured in pacman.conf, with the
option HoldKeys, with the same meaning of HoldPkgs. It can be repeated
and several values can be put in the same entry.
The new behavior allows a key to be marked for removal, but the user
can decide if that key must be kept. For example, if a developer has
a public repository, signed with his own key, that key must be added
to the HoldKeys option. If the key is marked for removal from pacman's
keyring, it will not be removed for the users that have configured
HoldKeys correctly.
There are other minor fixes, mainly in the handling of --add command
when there is no aditional parameter. In that case, pacman-key will
behave just like gpg, adding the contents of stdin into pacman's keyring.
Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
2010-10-07 20:13:13 -04:00
|
|
|
for key_id in "${!removed_ids[@]}"; do
|
|
|
|
echo " removing key $key_id - ${removed_ids[$key_id]}"
|
2011-07-20 00:28:39 -04:00
|
|
|
"${GPG_PACMAN[@]}" --quiet --batch --yes --delete-key "${key_id}"
|
2010-09-15 23:40:35 -04:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2011-07-08 21:07:29 -04:00
|
|
|
edit_keys() {
|
|
|
|
local errors=0;
|
2011-09-20 20:35:11 -04:00
|
|
|
for key in "${KEYIDS[@]}"; do
|
2011-07-08 21:07:29 -04:00
|
|
|
# Verify if the key exists in pacman's keyring
|
2011-07-20 00:28:39 -04:00
|
|
|
if ! "${GPG_PACMAN[@]}" --list-keys "$key" &>/dev/null; then
|
2011-07-08 21:07:29 -04:00
|
|
|
error "$(gettext "The key identified by %s does not exist")" "$key"
|
|
|
|
errors=1;
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
(( errors )) && exit 1;
|
|
|
|
|
2011-09-20 20:35:11 -04:00
|
|
|
for key in "${KEYIDS[@]}"; do
|
2011-07-20 00:28:39 -04:00
|
|
|
"${GPG_PACMAN[@]}" --edit-key "$key"
|
2011-07-08 21:07:29 -04:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2011-07-19 08:52:07 -04:00
|
|
|
import_trustdb() {
|
|
|
|
local importdir
|
|
|
|
local trustdb=$(mktemp)
|
|
|
|
"${GPG_PACMAN[@]}" --export-ownertrust > ${trustdb}
|
|
|
|
|
|
|
|
for importdir in "${IMPORT_DIRS[@]}"; do
|
|
|
|
if [[ -f "${importdir}/trustdb.gpg" ]]; then
|
|
|
|
gpg --homedir "${importdir}" --export-ownertrust >> ${trustdb}
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
"${GPG_PACMAN[@]}" --import-ownertrust ${trustdb}
|
|
|
|
rm -f ${trustdb}
|
|
|
|
}
|
|
|
|
|
|
|
|
import() {
|
|
|
|
local importdir
|
|
|
|
|
|
|
|
# Imports public keys, then import trustdbs
|
|
|
|
for importdir in "${IMPORT_DIRS[@]}"; do
|
|
|
|
if [[ -f "${importdir}/pubring.gpg" ]]; then
|
|
|
|
"${GPG_PACMAN[@]}" --quiet --batch --import "${importdir}/pubring.gpg"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
import_trustdb
|
|
|
|
}
|
|
|
|
|
2010-09-15 23:40:35 -04:00
|
|
|
# PROGRAM START
|
|
|
|
if ! type gettext &>/dev/null; then
|
|
|
|
gettext() {
|
|
|
|
echo "$@"
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
2011-07-29 22:24:46 -04:00
|
|
|
OPT_SHORT="a::d:e:f::hl::r:uv:V"
|
2011-07-08 07:14:53 -04:00
|
|
|
OPT_LONG="add::,config:,delete:,edit-key:,export::,finger::,gpgdir:"
|
2011-09-01 16:20:53 -04:00
|
|
|
OPT_LONG+=",help,import:,import-trustdb:,init,keyserver:,list-keys::,list-sigs::"
|
2011-09-01 16:29:25 -04:00
|
|
|
OPT_LONG+=",lsign-key:,populate::,recv-keys:,refresh-keys::,updatedb"
|
|
|
|
OPT_LONG+=",verify:,version"
|
2011-07-05 13:05:08 -04:00
|
|
|
if ! OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@")"; then
|
|
|
|
echo; usage; exit 1 # E_INVALID_OPTION;
|
|
|
|
fi
|
|
|
|
eval set -- "$OPT_TEMP"
|
|
|
|
unset OPT_SHORT OPT_LONG OPT_TEMP
|
|
|
|
|
|
|
|
if [[ $1 == "--" ]]; then
|
|
|
|
usage;
|
|
|
|
exit 0;
|
2010-09-15 23:40:35 -04:00
|
|
|
fi
|
|
|
|
|
2011-07-05 13:05:08 -04:00
|
|
|
while true; do
|
2010-09-15 23:40:35 -04:00
|
|
|
case "$1" in
|
2011-08-23 01:12:08 -04:00
|
|
|
-a|--add) ADD=1; [[ -n $2 && ${2:0:1} != "-" ]] && shift && KEYFILES=($1); UPDATEDB=1 ;;
|
2011-07-05 13:05:08 -04:00
|
|
|
--config) shift; CONFIG=$1 ;;
|
2011-08-23 01:12:08 -04:00
|
|
|
-d|--delete) DELETE=1; shift; KEYIDS=($1); UPDATEDB=1 ;;
|
|
|
|
--edit-key) EDITKEY=1; shift; KEYIDS=($1); UPDATEDB=1 ;;
|
2011-07-05 13:41:52 -04:00
|
|
|
-e|--export) EXPORT=1; [[ -n $2 && ${2:0:1} != "-" ]] && shift && KEYIDS=($1) ;;
|
2011-07-05 13:05:08 -04:00
|
|
|
-f|--finger) FINGER=1; [[ -n $2 && ${2:0:1} != "-" ]] && shift && KEYIDS=($1) ;;
|
|
|
|
--gpgdir) shift; PACMAN_KEYRING_DIR=$1 ;;
|
2011-08-23 01:12:08 -04:00
|
|
|
--import) IMPORT=1; shift; IMPORT_DIRS=($1); UPDATEDB=1 ;;
|
|
|
|
--import-trustdb) IMPORT_TRUSTDB=1; shift; IMPORT_DIRS=($1); UPDATEDB=1 ;;
|
2011-07-09 03:26:17 -04:00
|
|
|
--init) INIT=1 ;;
|
2011-09-01 16:20:53 -04:00
|
|
|
--keyserver) shift; KEYSERVER=$1 ;;
|
2011-07-29 22:24:46 -04:00
|
|
|
-l|--list-keys) LISTKEYS=1; [[ -n $2 && ${2:0:1} != "-" ]] && shift && KEYIDS=($1) ;;
|
|
|
|
--list-sigs) LISTSIGS=1; [[ -n $2 && ${2:0:1} != "-" ]] && shift && KEYIDS=($1) ;;
|
2011-08-29 13:52:51 -04:00
|
|
|
--lsign-key) LSIGNKEY=1; shift; KEYIDS=($1); UPDATEDB=1 ;;
|
2011-08-23 01:12:08 -04:00
|
|
|
--populate) POPULATE=1; [[ -n $2 && ${2:0:1} != "-" ]] && shift && KEYRINGIDS=($1); UPDATEDB=1 ;;
|
2011-09-01 16:20:53 -04:00
|
|
|
-r|--recv-keys) RECEIVE=1; shift; KEYIDS=($1); UPDATEDB=1 ;;
|
2011-09-01 16:29:25 -04:00
|
|
|
--refresh-keys) REFRESH=1; [[ -n $2 && ${2:0:1} != "-" ]] && shift && KEYIDS=($1) ;;
|
2011-07-05 13:05:08 -04:00
|
|
|
-u|--updatedb) UPDATEDB=1 ;;
|
2011-07-08 21:41:04 -04:00
|
|
|
-v|--verify) VERIFY=1; shift; SIGNATURE=$1 ;;
|
2011-07-05 13:05:08 -04:00
|
|
|
|
|
|
|
-h|--help) usage; exit 0 ;;
|
|
|
|
-V|--version) version; exit 0 ;;
|
|
|
|
|
|
|
|
--) OPT_IND=0; shift; break;;
|
|
|
|
*) usage; exit 1 ;;
|
2010-09-15 23:40:35 -04:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2011-07-05 13:05:08 -04:00
|
|
|
|
|
|
|
if ! type -p gpg >/dev/null; then
|
|
|
|
error "$(gettext "Cannot find the %s binary required for all %s operations.")" "gpg" "pacman-key"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-09-01 16:29:25 -04:00
|
|
|
if (( (ADD || DELETE || EDITKEY || IMPORT || IMPORT_TRUSTDB || INIT || LSIGNKEY || POPULATE || RECEIVE || REFRESH || UPDATEDB) && EUID != 0 )); then
|
2011-07-05 13:05:08 -04:00
|
|
|
error "$(gettext "%s needs to be run as root for this operation.")" "pacman-key"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
CONFIG=${CONFIG:-@sysconfdir@/pacman.conf}
|
2010-09-15 23:40:35 -04:00
|
|
|
if [[ ! -r "${CONFIG}" ]]; then
|
2011-08-08 20:01:26 -04:00
|
|
|
error "$(gettext "%s configuration file '%s' not found.")" "pacman" "$CONFIG"
|
2010-09-15 23:40:35 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-07-08 22:48:41 -04:00
|
|
|
# if PACMAN_KEYRING_DIR isn't assigned, try to get it from the config
|
|
|
|
# file, falling back on a hard default
|
|
|
|
PACMAN_KEYRING_DIR=${PACMAN_KEYRING_DIR:-$(get_from "$CONFIG" "GPGDir" || echo "@sysconfdir@/pacman.d/gnupg")}
|
2011-03-27 12:14:15 -04:00
|
|
|
|
2011-07-20 00:28:39 -04:00
|
|
|
GPG_PACMAN=(gpg --homedir ${PACMAN_KEYRING_DIR} --no-permission-warning)
|
2011-09-01 16:20:53 -04:00
|
|
|
if [[ -n ${KEYSERVER} ]]; then
|
|
|
|
GPG_PACMAN+=(--keyserver ${KEYSERVER})
|
|
|
|
fi
|
2011-07-05 13:05:08 -04:00
|
|
|
|
2011-07-08 21:28:57 -04:00
|
|
|
# check only a single operation has been given
|
2011-08-29 11:52:12 -04:00
|
|
|
# don't include UPDATEDB in here as other opts can induce it
|
2011-07-29 22:24:46 -04:00
|
|
|
numopt=$(( ADD + DELETE + EDITKEY + EXPORT + FINGER + IMPORT + IMPORT_TRUSTDB +
|
2011-09-01 16:29:25 -04:00
|
|
|
INIT + LISTKEYS + LISTSIGS + LSIGNKEY + POPULATE + RECEIVE + REFRESH + VERIFY ))
|
2011-07-08 21:28:57 -04:00
|
|
|
|
2011-07-20 13:26:44 -04:00
|
|
|
case $numopt in
|
|
|
|
0)
|
2011-08-29 11:52:12 -04:00
|
|
|
if (( ! UPDATEDB )); then
|
|
|
|
error "$(gettext "no operation specified (use -h for help)")"
|
|
|
|
exit 1
|
|
|
|
fi
|
2011-07-20 13:26:44 -04:00
|
|
|
;;
|
|
|
|
[!1])
|
|
|
|
error "$(gettext "Multiple operations specified")"
|
|
|
|
printf "$(gettext "Please run %s with each operation separately\n")" "pacman-key"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2011-07-08 21:28:57 -04:00
|
|
|
|
2011-07-09 07:51:01 -04:00
|
|
|
(( ! INIT )) && check_keyring
|
2011-07-05 13:05:08 -04:00
|
|
|
|
2011-07-20 00:28:39 -04:00
|
|
|
(( ADD )) && "${GPG_PACMAN[@]}" --quiet --batch --import "${KEYFILES[@]}"
|
|
|
|
(( DELETE )) && "${GPG_PACMAN[@]}" --quiet --batch --delete-key --yes "${KEYIDS[@]}"
|
2011-07-08 21:07:29 -04:00
|
|
|
(( EDITKEY )) && edit_keys
|
2011-07-20 00:28:39 -04:00
|
|
|
(( EXPORT )) && "${GPG_PACMAN[@]}" --armor --export "${KEYIDS[@]}"
|
|
|
|
(( FINGER )) && "${GPG_PACMAN[@]}" --batch --fingerprint "${KEYIDS[@]}"
|
2011-07-19 08:52:07 -04:00
|
|
|
(( IMPORT )) && import
|
|
|
|
(( IMPORT_TRUSTDB)) && import_trustdb
|
2011-07-09 03:26:17 -04:00
|
|
|
(( INIT )) && initialize
|
2011-07-29 22:24:46 -04:00
|
|
|
(( LISTKEYS )) && "${GPG_PACMAN[@]}" --batch --list-keys "${KEYIDS[@]}"
|
|
|
|
(( LISTSIGS )) && "${GPG_PACMAN[@]}" --batch --list-sigs "${KEYIDS[@]}"
|
2011-08-29 13:52:51 -04:00
|
|
|
# TODO: we can't do --batch on lsign until we figure out --command-fd
|
|
|
|
(( LSIGNKEY )) && "${GPG_PACMAN[@]}" --lsign-key "${KEYIDS[@]}"
|
2011-08-15 08:51:58 -04:00
|
|
|
(( POPULATE )) && populate_keyring
|
2011-09-01 16:20:53 -04:00
|
|
|
(( RECEIVE )) && "${GPG_PACMAN[@]}" --recv-keys "${KEYIDS[@]}"
|
2011-09-01 16:29:25 -04:00
|
|
|
(( REFRESH )) && "${GPG_PACMAN[@]}" --refresh-keys "${KEYIDS[@]}"
|
2011-07-20 00:28:39 -04:00
|
|
|
(( VERIFY )) && "${GPG_PACMAN[@]}" --verify $SIGNATURE
|
2011-07-05 13:05:08 -04:00
|
|
|
|
2011-08-29 11:52:12 -04:00
|
|
|
if (( UPDATEDB )); then
|
|
|
|
msg "$(gettext "Updating trust database...")"
|
|
|
|
"${GPG_PACMAN[@]}" --batch --check-trustdb
|
|
|
|
fi
|
2011-08-23 01:12:08 -04:00
|
|
|
|
2011-06-08 02:48:56 -04:00
|
|
|
# vim: set ts=2 sw=2 noet:
|