See https://unix.stackexchange.com/a/391346/29483. Treating the keyfile as a keyring didn't work for me, but the accepted answer helped.
cat keyfile.key | gpg --with-colons --import-options import-show --dry-run --import
Tested on Debian 9 with gpg 2.1.18, and Fedora 26 with gpg2 2.2.0:
$ gpg2 --with-fingerprint --import-options import-show --dry-run --import < linux_signing_key.pub
pub dsa1024 2007-03-08 [SC]
4CCA 1EAF 950C EE4A B839 76DC A040 830F 7FAC 5991
uid Google, Inc. Linux Package Signing Key <linux-packages-keymaster@google.com>
sub elg2048 2007-03-08 [E]
pub rsa4096 2016-04-12 [SC]
EB4C 1BFD 4F04 2F6D DDCC EC91 7721 F63B D38B 4796
uid Google Inc. (Linux Packages Signing Authority) <linux-packages-keymaster@google.com>
sub rsa4096 2016-04-12 [S] [expires: 2019-04-12]
gpg: Total number processed: 2
It's also possible --with-fingerprint
is obsolescent. GPG2 seems to have been fixed to stop outputting the insecure short key ids.
$ gpg2 --import-options import-show --dry-run --import < linux_signing_key.pub pub dsa1024 2007-03-08 [SC]
4CCA1EAF950CEE4AB83976DCA040830F7FAC5991
4CCA1EAF950CEE4AB83976DCA040830F7FAC5991
uid Google, Inc. Linux Package Signing Key <linux-packages-keymaster@google.com>
sub elg2048 2007-03-08 [E]
pub rsa4096 2016-04-12 [SC]
EB4C1BFD4F042F6DDDCCEC917721F63BD38B4796
EB4C1BFD4F042F6DDDCCEC917721F63BD38B4796
uid Google Inc. (Linux Packages Signing Authority) <linux-packages-keymaster@google.com>
sub rsa4096 2016-04-12 [S] [expires: 2019-04-12]
gpg: Total number processed: 2
Unfortunately I wanted machine-readable output from --with-colons
, but there's something else going on there :-(.
$ gpg --with-colons --with-fingerprint --import-options import-show --dry-run --import < linux_signing_key.pub
gpg: lookup_hashtable failed: Unknown system error
gpg: trustdb: searching trust record failed: Unknown system error
gpg: Error: The trustdb is corrupted.
gpg: You may try to re-create the trustdb using the commands:
gpg: cd ~/.gnupg
gpg: gpg --export-ownertrust > otrust.tmp
gpg: rm trustdb.gpg
gpg: gpg --import-ownertrust < otrust.tmp
gpg: If that does not work, please consult the manual
I ended up using the following code
gpg_show_fingerprints() {
gpg2 --with-fingerprint --import-options import-show --dry-run --import < "$1" >/dev/null 2>&1
if [ "$?" == 2 ]; then
# Usage error. Try the old way.
gpg2 --with-fingerprint "$1"
else
gpg2 --with-fingerprint --import-options import-show --dry-run --import < "$1"
fi
}
gpg_show_fingerprints "$1" |
sed -E -n -e 's/.*(([0-9A-F]{4}[ ]*){10,}).*/\1/ p'