检查加密文件是否有空内容
我正在使用 gpg 来解密供应商发送给我的文件。当加密文件的内容为空时,一切正常(供应商告诉我相关文件中没有内容)。
如果我尝试解密这些文件之一,我会得到:
gpg:无法处理这种模棱两可的情况 签名数据
有什么方法可以检查文件是否没有标题接受的内容,以便我可以将其设置为更优雅地失败?
I'm using gpg to decrypt files sent to me by a vendor. Everything works fine accept for when the content of the encrypted file is empty (the vendor has told me that there is no content in the files in question).
If I try and decrypt one of these files I get:
gpg: can't handle this ambiguous
signature data
Is there any way to check that the file has no content accept for the header, so that I can set it up to fail more elegantly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据此邮件列表帖子,官方 PGP工具有一个错误,有时会导致它生成格式错误的消息。您可以通过运行 gpg --list-packets path/to/encrypted/file.pgp 并查看输出来验证您的特定文件是否属于这种情况。如果您看到
:onepass_sig packet:
紧接着是:signature packet:
那么这可能就是发生的情况。根据我(有限的)经验,如果发件人尝试加密空文件,就会发生这种情况。不幸的是,由于加密的设计目的是让人们很难看到里面的内容,因此在尝试解密之前很难判断情况是否确实如此。 gpg 的
--list-packets
输出将为您提供一些信息,但我注意到:literal data packet:
输出通常会显示“原始数据:0 字节”即使消息包含非空文件。您可以使用
--skip-verify
选项让 gpg 忽略加密文件中的所有签名数据,但是您当然无法判断正在解密的文件是否来自可信来源。According to this mailing-list post, the official PGP tool has a bug that sometimes causes it to produce malformed messages. You can verify whether this is the case for your particular file by running
gpg --list-packets path/to/encrypted/file.pgp
and looking at the output. If you see a:onepass_sig packet:
followed immediately by a:signature packet:
then that's probably what's going on.In my (limited) experience, this occurs if the sender has tried to encrypt an empty file. Unfortunately, since encryption is designed to make it difficult to see what's inside, it's hard to tell if that's actually the case before you try to decrypt it. gpg's
--list-packets
output will give you some information, but I've noticed that the:literal data packet:
output will usually say "raw data: 0 bytes" even if the message contains a non-empty file.You can make gpg ignore all signature data in the encrypted file with the
--skip-verify
option, but then of course you can't tell whether the file you're decrypting comes from a trusted source.假设您使用的是 unix shell 脚本,您可以在尝试 GPG 解密之前先执行“[ -s /the/file ]”。
Assuming you are using a unix shell script, you could first do a '[ -s /the/file ]' before attempting the GPG decrypt.