]> git.saurik.com Git - apt.git/blobdiff - cmdline/apt-key.in
use https instead of git for Vcs-Git
[apt.git] / cmdline / apt-key.in
index 4d1079a4bd15d427a7ad6d1c894f7f15da70db29..b309142cf8471f71b56f83d29f691ffe67889517 100644 (file)
@@ -191,6 +191,10 @@ remove_key_from_keyring() {
     for KEY in "$@"; do
        local FINGERPRINTS="${GPGHOMEDIR}/keyringfile.keylst"
        get_fingerprints_of_keyring "$KEYRINGFILE" > "$FINGERPRINTS"
+
+        # strip leading 0x, if present:
+        KEY="${KEY#0x}"
+
        # check if the key is in this keyring
        if ! grep -iq "^[0-9A-F]*${KEY}$" "$FINGERPRINTS"; then
            continue
@@ -489,8 +493,21 @@ create_gpg_home() {
 }
 
 prepare_gpg_home() {
+    # crude detection if we are called from a maintainerscript where the
+    # package depends on gnupg or not. We accept recommends here as
+    # well as the script hopefully uses apt-key optionally then like e.g.
+    # debian-archive-keyring for (upgrade) cleanup did
+    if [ -n "$DPKG_MAINTSCRIPT_PACKAGE" ]; then
+       if ! dpkg-query --show --showformat '${Pre-Depends}${Depends}${Recommends}\n' "$DPKG_MAINTSCRIPT_PACKAGE" 2>/dev/null | grep -q gnupg; then
+           cat >&2 <<EOF
+Warning: The $DPKG_MAINTSCRIPT_NAME maintainerscript of the package $DPKG_MAINTSCRIPT_PACKAGE
+Warning: seems to use apt-key (provided by apt) without depending on gnupg or gnupg2.
+Warning: This will BREAK in the future and should be fixed by the package maintainer(s).
+Note: Check first if apt-key functionality is needed at all - it probably isn't!
+EOF
+       fi
+    fi
     eval "$(apt-config shell GPG_EXE Apt::Key::gpgcommand)"
-
     if [ -n "$GPG_EXE" ] && command_available "$GPG_EXE"; then
        true
     elif command_available 'gpg'; then
@@ -506,38 +523,38 @@ prepare_gpg_home() {
 
     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"
-    touch "$SECRETKEYRING"
-
     # 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
+    touch "${GPGHOMEDIR}/empty.gpg"
     if ! "$GPG_EXE" --ignore-time-conflict --no-options --no-default-keyring \
-       --homedir "$GPGHOMEDIR" --quiet --check-trustdb --keyring "$SECRETKEYRING" >"${GPGHOMEDIR}/gpgoutput.log" 2>&1; then
+       --homedir "$GPGHOMEDIR" --quiet --check-trustdb --keyring "${GPGHOMEDIR}/empty.gpg" >"${GPGHOMEDIR}/gpgoutput.log" 2>&1; then
        cat >&2 "${GPGHOMEDIR}/gpgoutput.log"
        false
     fi
-    # tell gpg that it shouldn't try to maintain a trustdb file
+
+    # now tell gpg that it shouldn't try to maintain this trustdb file
     echo "#!/bin/sh
 exec '$(escape_shell "${GPG_EXE}")' --ignore-time-conflict --no-options --no-default-keyring \\
 --homedir '$(escape_shell "${GPGHOMEDIR}")' --no-auto-check-trustdb --trust-model always \"\$@\"" > "${GPGHOMEDIR}/gpg.0.sh"
     GPG_SH="${GPGHOMEDIR}/gpg.0.sh"
     GPG="$GPG_SH"
 
+    # We don't usually need a secret keyring, of course, but
     # for advanced operations, we might really need a secret keyring after all
     if [ -n "$FORCED_SECRET_KEYRING" ] && [ -r "$FORCED_SECRET_KEYRING" ]; then
-       rm -f "$SECRETKEYRING"
-       cp -a "$FORCED_SECRET_KEYRING" "$SECRETKEYRING"
+       if ! aptkey_execute "$GPG" -v --batch --import "$FORCED_SECRET_KEYRING" >"${GPGHOMEDIR}/gpgoutput.log" 2>&1; then
+           cat >&2 "${GPGHOMEDIR}/gpgoutput.log"
+           false
+       fi
+    else
+       # and then, there are older versions of gpg which panic and implode
+       # if there isn't one available - and writeable for imports
+       # and even if not output is littered with the creation of a secring,
+       # so lets call import once to have it create what it wants in silence
+       echo -n | aptkey_execute "$GPG" --batch --import >/dev/null 2>&1 || true
     fi
-
-    # older gpg versions need a secring file, but newer versions take it as
-    # 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
-    echo -n | aptkey_execute "$GPG" --batch --import >/dev/null 2>&1 || true
 }
 
 if [ "$command" != 'help' ] && [ "$command" != 'verify' ]; then