# search for a public key
if [ "${publine%%:*}" != 'pub' ]; then continue; fi
# search for the associated fingerprint (should be the very next line)
# search for a public key
if [ "${publine%%:*}" != 'pub' ]; then continue; fi
# search for the associated fingerprint (should be the very next line)
# all keys that are exported must have a valid signature
# from a key in the $distro-master-keyring
add_keys="$(get_fingerprints_of_keyring "$ADD_KEYRING")"
# all keys that are exported must have a valid signature
# from a key in the $distro-master-keyring
add_keys="$(get_fingerprints_of_keyring "$ADD_KEYRING")"
- all_add_keys=`$GPG_CMD --keyring $ADD_KEYRING --with-colons --list-keys | grep ^[ps]ub | cut -d: -f5`
- master_keys=`$GPG_CMD --keyring $MASTER --with-colons --list-keys | grep ^pub | cut -d: -f5`
+ all_add_keys=`aptkey_execute "$GPG_SH" --keyring "$ADD_KEYRING" --with-colons --list-keys | grep ^[ps]ub | cut -d: -f5`
+ master_keys=`aptkey_execute "$GPG_SH" --keyring "$MASTER" --with-colons --list-keys | grep ^pub | cut -d: -f5`
for add_key in $add_keys; do
# export the add keyring one-by-one
local TMP_KEYRING="${GPGHOMEDIR}/tmp-keyring.gpg"
for add_key in $add_keys; do
# export the add keyring one-by-one
local TMP_KEYRING="${GPGHOMEDIR}/tmp-keyring.gpg"
- $GPG_CMD --batch --yes --keyring "$ADD_KEYRING" --output "$TMP_KEYRING" --export "$add_key"
- if ! $GPG_CMD --batch --yes --keyring "$TMP_KEYRING" --import "$MASTER" > "${GPGHOMEDIR}/gpgoutput.log" 2>&1; then
+ aptkey_execute "$GPG_SH" --batch --yes --keyring "$ADD_KEYRING" --output "$TMP_KEYRING" --export "$add_key"
+ if ! aptkey_execute "$GPG_SH" --batch --yes --keyring "$TMP_KEYRING" --import "$MASTER" > "${GPGHOMEDIR}/gpgoutput.log" 2>&1; then
cat >&2 "${GPGHOMEDIR}/gpgoutput.log"
false
fi
# check if signed with the master key and only add in this case
ADDED=0
for master_key in $master_keys; do
cat >&2 "${GPGHOMEDIR}/gpgoutput.log"
false
fi
# check if signed with the master key and only add in this case
ADDED=0
for master_key in $master_keys; do
- if $GPG_CMD --keyring $TMP_KEYRING --check-sigs --with-colons $add_key | grep '^sig:!:' | cut -d: -f5 | grep -q $master_key; then
- $GPG_CMD --batch --yes --keyring "$ADD_KEYRING" --export "$add_key" | $GPG --batch --yes --import
+ if aptkey_execute "$GPG_SH" --keyring "$TMP_KEYRING" --check-sigs --with-colons "$add_key" \
+ | grep '^sig:!:' | cut -d: -f5 | grep -q "$master_key"; then
+ aptkey_execute "$GPG_SH" --batch --yes --keyring "$ADD_KEYRING" --export "$add_key" \
+ | aptkey_execute "$GPG" --batch --yes --import
- (cd ${APT_DIR}/var/lib/apt/keyrings; wget --timeout=90 -q -N $ARCHIVE_KEYRING_URI)
- if [ ! -e $keyring ]; then
+ (cd "${APT_DIR}/var/lib/apt/keyrings"; wget --timeout=90 -q -N "$ARCHIVE_KEYRING_URI")
+ if [ ! -e "$keyring" ]; then
echo >&2 "ERROR: Can't find the archive-keyring"
echo >&2 "Is the &keyring-package; package installed?"
exit 1
echo >&2 "ERROR: Can't find the archive-keyring"
echo >&2 "Is the &keyring-package; package installed?"
exit 1
for KEY in "$@"; do
local FINGERPRINTS="${GPGHOMEDIR}/keyringfile.keylst"
get_fingerprints_of_keyring "$KEYRINGFILE" > "$FINGERPRINTS"
for KEY in "$@"; do
local FINGERPRINTS="${GPGHOMEDIR}/keyringfile.keylst"
get_fingerprints_of_keyring "$KEYRINGFILE" > "$FINGERPRINTS"
if [ -n "$REALTARGET" ]; then
# the real backup is the old link, not the copy we made
mv -f "${KEYRINGFILE}.dpkg-tmp" "${KEYRINGFILE}~"
if [ -n "$REALTARGET" ]; then
# the real backup is the old link, not the copy we made
mv -f "${KEYRINGFILE}.dpkg-tmp" "${KEYRINGFILE}~"
shift 2
rm -f "${GPGHOMEDIR}/gpgoutput.log"
# the idea is simple: We take keys from one keyring and copy it to another
shift 2
rm -f "${GPGHOMEDIR}/gpgoutput.log"
# the idea is simple: We take keys from one keyring and copy it to another
# creation, so we know that the (potentially) created $TO keyring is a
# simple keyring rather than a keybox as gpg2 would create it which in turn
# can't be read by gpgv.
# creation, so we know that the (potentially) created $TO keyring is a
# simple keyring rather than a keybox as gpg2 would create it which in turn
# can't be read by gpgv.
eval $(apt-config shell TRUSTEDPARTS Dir::Etc::TrustedParts/d)
if [ -d "$TRUSTEDPARTS" ]; then
# ignore errors mostly for non-existing $TRUSTEDFILE
eval $(apt-config shell TRUSTEDPARTS Dir::Etc::TrustedParts/d)
if [ -d "$TRUSTEDPARTS" ]; then
# ignore errors mostly for non-existing $TRUSTEDFILE
- cat /dev/null "$TRUSTEDFILE" $(find -L "$TRUSTEDPARTS" -type f -name '*.gpg') > "$PUBRING" 2>/dev/null || true
+ {
+ cat "$TRUSTEDFILE" || true
+ for parts in $(find -L "$TRUSTEDPARTS" -type f -name '*.gpg'); do
+ cat "$parts" || true
+ done
+ } > "$PUBRING" 2>/dev/null
merge_all_trusted_keyrings_into_pubring
FORCED_KEYRING="${GPGHOMEDIR}/forcedkeyid.gpg"
TRUSTEDFILE="${FORCED_KEYRING}"
merge_all_trusted_keyrings_into_pubring
FORCED_KEYRING="${GPGHOMEDIR}/forcedkeyid.gpg"
TRUSTEDFILE="${FORCED_KEYRING}"
# ignore error as this "just" means we haven't found the forced keyid and the keyring will be empty
import_keyring_into_keyring '' "$TRUSTEDFILE" "$FORCED_KEYID" || true
elif [ -z "$FORCED_KEYRING" ]; then
# ignore error as this "just" means we haven't found the forced keyid and the keyring will be empty
import_keyring_into_keyring '' "$TRUSTEDFILE" "$FORCED_KEYID" || true
elif [ -z "$FORCED_KEYRING" ]; then
create_gpg_home
# We don't use a secret keyring, of course, but gpg panics and
# implodes if there isn't one available - and writeable for imports
SECRETKEYRING="${GPGHOMEDIR}/secring.gpg"
create_gpg_home
# We don't use a secret keyring, of course, but gpg panics and
# implodes if there isn't one available - and writeable for imports
SECRETKEYRING="${GPGHOMEDIR}/secring.gpg"
# create the trustdb with an (empty) dummy keyring
# older gpgs required it, newer gpgs even warn that it isn't needed,
# but require it nonetheless for some commands, so we just play safe
# here for the foreseeable future and create a dummy one
# create the trustdb with an (empty) dummy keyring
# older gpgs required it, newer gpgs even warn that it isn't needed,
# but require it nonetheless for some commands, so we just play safe
# here for the foreseeable future and create a dummy one
- $GPG_CMD --quiet --check-trustdb --keyring $SECRETKEYRING >/dev/null 2>&1
+ if ! "$GPG_EXE" --ignore-time-conflict --no-options --no-default-keyring \
+ --homedir "$GPGHOMEDIR" --quiet --check-trustdb --keyring "$SECRETKEYRING" >"${GPGHOMEDIR}/gpgoutput.log" 2>&1; then
+ cat >&2 "${GPGHOMEDIR}/gpgoutput.log"
+ false
+ fi
- GPG_CMD="$GPG_CMD --no-auto-check-trustdb --trust-model always"
- GPG="$GPG_CMD"
+ echo "#!/bin/sh
+exec \"${GPG_EXE}\" --ignore-time-conflict --no-options --no-default-keyring \\
+ --homedir \"${GPGHOMEDIR}\" --no-auto-check-trustdb --trust-model always \"\$@\"" > "${GPGHOMEDIR}/gpg.0.sh"
+ GPG_SH="${GPGHOMEDIR}/gpg.0.sh"
+ GPG="$GPG_SH"
# for advanced operations, we might really need a secret keyring after all
if [ -n "$FORCED_SECRET_KEYRING" ] && [ -r "$FORCED_SECRET_KEYRING" ]; then
# for advanced operations, we might really need a secret keyring after all
if [ -n "$FORCED_SECRET_KEYRING" ] && [ -r "$FORCED_SECRET_KEYRING" ]; then
# a hint to start a migration from earlier versions. The file is empty
# anyhow, so nothing actually happens, but its three lines of output
# nobody expects to see in apt-key context, so trigger it in silence
# a hint to start a migration from earlier versions. The file is empty
# anyhow, so nothing actually happens, but its three lines of output
# nobody expects to see in apt-key context, so trigger it in silence