列出公钥时出现“gpg:未找到密钥 XXX:未找到”

列出公钥时出现“gpg:未找到密钥 XXX:未找到”

最近,当我gpg --list-keys <email>对自己的个人电子邮件进行检查时,我注意到 GnuPG 在继续正常输出之前开始给我一些错误:

$ gpg --list-keys [email protected]
gpg: key "09F4605E1379E1909AAC87B10874248396A58CF5" not found: Not found
gpg: key "1141EF4806D03A7AFFF4B48AE31AF27D2BF9FD6F" not found: Not found
gpg: key "14EF360E24BC1C67B2DD718E985504164F3E0D3B" not found: Not found
gpg: key "6879E2F83421AC49A1368507AE906D1F50408E4E" not found: Not found
gpg: key "86790DCBF818ACA719CD3DD57032FFA24FFFA472" not found: Not found
gpg: key "893386E8012237AB6828522B6B8A2EF65CD744E2" not found: Not found
gpg: key "BDCE5CA5E5BDECA71DFC9B23C679EF7A1D64DDC1" not found: Not found
gpg: key "D3A913798447EE9C289715DE4270CFE164C5E325" not found: Not found
gpg: key "DC309E6872FC6DF6C61D1C3FC1F1504ACCD1403B" not found: Not found
pub   rsa4096/0x281015BE2CAC2CBC 2015-12-19 [C]
      Key fingerprint = 31EF DDC9 8A18 FA61 0D38  9A3D 2810 15BE 2CAC 2CBC
uid                   [ultimate] Ivan Shapovalov <[email protected]>
uid                   [ultimate] Ivan Shapovalov <[email protected]>
sub   rsa4096/0x7BDE17C8E4E30E9D 2015-12-19 [S]
      Key fingerprint = E4DF 27BC 899C C769 C994  519C 7BDE 17C8 E4E3 0E9D
sub   rsa4096/0x619341A697B609C7 2015-12-19 [E]
      Key fingerprint = 9F1E 297F 99D0 8C54 518C  6E8D 6193 41A6 97B6 09C7

<... rest of my keys ...>

针对任何其他 UID执行操作gpg --list-keys都不会导致问题。我不记得有任何带有这些指纹的密钥,并且尝试使用显示的指纹导出、删除或编辑这些密钥均未成功。

我不太清楚 GnuPG 试图用所有这些“未找到”键来告诉我什么:不知何故它同时“知道”这些 ID 和“不知道”它们。我如何让 GnuPG 忘记它们?

答案1

对于使用基于豆腐的信任模型的用户,此警告可能是由于现有密钥与不存在密钥的指纹冲突而导致的。可以通过在豆腐数据库内容中查找“未找到”的指纹来查看这种情况:

sqlite3 ~/.gnupg/tofu.db .dump

例如,在导入两个具有相同用户 ID 的密钥并删除其中一个密钥后,可能会发生这种情况:

temp_home() {
    GNUPGHOME=$(mktemp -d)/gnupg
    mkdir -- "$GNUPGHOME"
    chmod 700 -- "$GNUPGHOME"
    printf 'trust-model tofu\ntofu-default-policy unknown\n' >"$GNUPGHOME/gpg.conf"
    export GNUPGHOME
    printf 'Using GnuPG home: %s\n' "$GNUPGHOME"
}

uid='Alice Smith <[email protected]>'

temp_home
gpg --yes --batch --passphrase '' --quick-generate-key "$uid"
gpg --yes --batch --passphrase '' --quick-generate-key "$uid"
fpr1=$(gpg --with-colons -k "$uid" | awk -F : '$1 == "fpr" { print $10; exit }')
old_home=$GNUPGHOME

temp_home
gpg --homedir "$old_home" --export | gpg --import
gpg --list-public-keys  # Creates tofu.db
gpg --batch --delete-keys "$fpr1"

# We now get the warning
gpg --list-public-keys
# Notice the old fingerprint is still in the conflict column
sqlite3 -- "$GNUPGHOME/tofu.db" "SELECT * FROM bindings WHERE conflict != ''"

但是,我不确定建议采取什么措施来解决这个问题。当这种情况发生在我身上时,我从未将删除的密钥用于任何事情,所以我只需要从 tofu 数据库表中删除旧密钥和冲突bindings

DELETE FROM bindings WHERE fingerprint = '<old fingerprint>';
UPDATE bindings SET conflict = '' WHERE fingerprint = '<new fingerprint>';

如果密钥已使用但已被删除,数据库中的其他表可能会引用绑定记录,在这种情况下,其他记录可能也必须被删除。同样,我不知道如何自行解决这个问题gpg

相关内容