使用gpg验证.asc文件而不导入KEYS文件。

16

我想创建一个脚本,用于在我的Docker镜像中下载和GPG验证文件。从Apache文档中可以看到,为了进行验证,我需要执行以下操作:

gpg --import KEYS
gpg --verify downloaded_file.tgz.asc downloaded_file.tgz

我希望跳过第一步,因为它会更改“某些文件的位置”。原因是我想尽可能保持docker映像的原始状态。我更喜欢简单地调用类似于:gpg --using-keys KEYS --verify file.tgz.asc file.tgz。这可行吗?
我尝试使用--no-default-keyring --keyring KEYS,如此处所述,但我无法正确解释输出(它打印Can't check signature: public key not found)。当我删除--no-default-keyring时,输出似乎很好,但我之前已导入了KEYS文件,不知道如何取消导入以查看清晰的结果。
KEYS、.tgz和.tgz.asc文件来自Apache Kafka

1
钥匙必须被导入到密钥链中才能被使用(文章提到了私钥,但同样适用于公钥)https://lists.gnupg.org/pipermail/gnupg-users/2016-February/055351.html - 根据 GnuPG 团队的说法,在数据库或变量中存储密钥是不可想象的用例。 - Ashley
gpg --no-default-keyring --keyring KEYS --list-keys 的输出是什么? - Jens Erat
看起来是 https://superuser.com/questions/639853/gpg-verifying-signatures-without-creating-trust-chain 的重复。 - undefined
1个回答

9

我是一个gpg的新手,所以请对我的翻译保留些许怀疑。但以下方法在我这里已经足够好用了,已在Debian上和使用GnuPG 2.1.18版本进行了测试:

test.asc是一个公钥,我们不想导入它,test.tar.bz2.asc是一个文件签名,由上述公钥签名,test.tar.bz2是一个需要验证签名的文件。首先我解密密钥,然后使用它们来验证文件签名:

gpg --dearmor ./test.asc
gpg --dearmor ./test.tar.bz2.asc
gpg --dry-run --no-default-keyring --keyring ./test.asc.gpg --homedir ./ --verify ./test.tar.bz2.asc.gpg ./test.tar.bz2

当然,GPG会抱怨签名不受信任,并在当前文件夹中创建信任数据库。
gpg: WARNING: unsafe permissions on homedir '/tmp/./'
gpg: Signature made Mi 24 Apr 2019 21:52:46 CEST
gpg:                using RSA key xxxxxxxxxxxxxxxx
gpg: /tmp/.//trustdb.gpg: trustdb created
gpg: Good signature from "example security <security@example.com>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: xxxx xxxx xxxx xxxx xxxx  xxxx xxxx xxxx xxxx xxxx

但是这之后将会失败:
gpg --dry-run  --homedir ./ --verify ./test.tar.bz2.asc.gpg ./test.tar.bz2
gpg --dry-run  --verify ./test.tar.bz2.asc.gpg ./test.tar.bz2
gpg --verify ./test.tar.bz2.asc.gpg ./test.tar.bz2

所以我认为该密钥并没有被导入到通常的密钥数据库中。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接