验证PDF文档中的数字签名 [英] Verifying digital signatures in PDF documents

查看:929
本文介绍了验证PDF文档中的数字签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试验证PDF的数字签名。

I'm trying to verify PDF's digital signatures.

我知道当签名PDF时,会定义一个字节范围,证书会嵌入,以及我已阅读,签名的邮件摘要和时间戳也存储在PDF中。

I know that when a PDF is signed, a byterange is defined, the certificates get embedded, and from what i've read, the signed message digest and the timestamp are also stored in the PDF.

我已经可以提取证书并验证它们。
现在我正在尝试验证pdf的完整性,我的问题是我不知道签名的邮件摘要位于何处。

I already can extract the certificates and validate them. Now I'm trying to validate the pdf's integrity and my problem is I don't know where the signed message digest is located.

在此示例中签名来自Adobe的pdf( http://blogs.adobe.com/security/SampleSignedPDFDocument.pdf ),我可以清楚地识别摘要,因为它低于嵌入证书:/ DigestMethod / MD5 / DigestValue /(第1520行)。

In this sample signed pdf from Adobe (http://blogs.adobe.com/security/SampleSignedPDFDocument.pdf), i can clearly identify the digest since it is down below the embedded certificates: /DigestMethod/MD5/DigestValue/ (line 1520).

但该PDF样本似乎从2009年起,我怀疑消息摘要现在以不同的方式存储,因为我使用Adobe Reader和iText签署了PDF,我找不到像上一个消息摘要字段。
有人可以判断摘要现在是否以不同的方式存储?它们位于何处?

But that PDF sample seems to be from 2009, and I suspect the message digest is stored in a different way now, because I signed a PDF with Adobe Reader and also with iText, and I can't find any message digest field like the previous one. Can someone tell if the digests are now stored in a different way? Where are they located?

无论如何,目前我正在使用Adobe的示例文档,并尝试验证其完整性。
我正在根据指定的字节范围获取文档的字节,并使用MD5算法消化它们,但我获得的摘要值与消息摘要字段中的摘要值不匹配...
我做错了吗?摘要是否也与签名者的私钥签名?

Anyway, for now I'm using that sample document from Adobe, and trying to verify its integrity. I'm getting the document's bytes to be signed acording to the specified byterange, and digesting them with MD5 algorithm, but the digest value I get doesn't match with the one from the message digest field... Am I doing something wrong? Is the digest also signed with the signer's private key?

我感谢任何帮助。

推荐答案

在计算集成PDF签名的哈希时,有很多细节要做,其中包括:

There are numerous details to get right when calculating the hash for integrated PDF signatures, among them:


  • 从PDF中提取正确的字节以进行哈希。 ByteRange 会准确地告诉您签名的字节范围。要在现代签名上下文中接受,范围必须涵盖整个PDF文件修订版,但内容的值除外。

  • Extract the correct bytes from the PDF to hash. The ByteRange tells you exactly which byte ranges are signed. To be accepted in modern signing contexts, the ranges must cover the whole PDF file revision with the exception of the value of Contents.

注意, 内容 的值包括前导'<'和尾随'>'括号。

Beware, the value of Contents includes the the leading '<' and the trailing '>' brackets.

不要使用常规文本编辑器或文本处理指令(如 readln writeln )来处理PDF。 PDF本质上是二元的,即使它们看起来是用肉眼观察的。使用此类文本相关操作复制PDF部件很可能会更改细节,最终会破坏签名哈希值。

Don't use a regular text editor or text processing instructions (like readln or writeln) to process PDFs. PDFs are binary in nature, even if they look textual to the naked eye. Copying PDF parts using such text related operations most likely changes them in details, definitively breaking the signature hash value.

有疑问,不要猜测,但阅读规范。 Adobe提供了ISO 32000-1的副本在这里,你需要了解很多关于开始处理它们的PDF格式,可以在那里和其他公共标准中找到。可以在这个答案和从那里引用的文件。

When in doubt, don't guess but read the specification. A copy of ISO 32000-1 has been made available by Adobe here, and much you need to know about the PDF format to start processing them can be found there and in other public standards referenced in there. A very short introduction to integrated PDF signatures can be found in this answer and documents referenced from there.

这篇关于验证PDF文档中的数字签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆