简体   繁体   English

iText pdf完整性检查

[英]iText pdf integrity check

I have a pdf file, where: 我有一个pdf文件,其中:

  • Rev. 1 contains document timestamp 修订版1包含文档时间戳
  • after timestamping some text was added without creating the new revision 加上时间戳后,添加了一些文本,但未创建新修订版
  • in Rev. 2 document was signes 在修订版2中的文档是签名

Here is 这是 Adobe Acrobat屏幕 from Signatures panel 从“签名”面板

How validate pdf integrity with iText 5? 如何使用iText 5验证pdf完整性? I want to detect, that someone change document after timestamp (between Rev.1 and Rev.2, or after Rev. 2). 我想检测到有人在时间戳之后(在Rev.1和Rev.2之间或在Rev.2之后)更改了文档。

Is it possible with iText 5 detect document changes which way as Adobe Acrobat this evaluates, as shown in the screen: 屏幕显示:iText 5是否可以通过评估Adobe Acrobat的方式来检测文档更改:

  • 'Document has been altered or corrupted since it was signed.' 自签署以来,文件已被更改或损坏。
  • '2 Pages(s) Modified' “ 2页已修改”

Pseudo JAVA code below, always returns Integrity check OK? 下面的伪JAVA代码,总是返回完整性检查好吗? true for Rev.1 timestampField 对于Rev.1 timestampField为true

 PdfReader reader = new PdfReader("C:/tstEditSign.pdf");
 AcroFields acro = reader.getAcroFields();
 PdfPKCS7 pkcs7 = acro.verifySignature("timestampField");
 System.out.println("Integrity check OK? " + pkcs7.verify());

Thanks for any help or hint, how to resolve this issue. 感谢您的帮助或提示,如何解决此问题。

Please be aware that there two ways the integrity of an integrated PDF signature can be violated: 请注意,有两种方法可以破坏集成PDF签名的完整性:

  • The range of bytes in the PDF it signs is actually changed. 它所签名的PDF中的字节范围实际上已更改。
  • Additions in incremental updates after the range of bytes it signs introduce disallowed changes. 在其标志的字节范围之后的增量更新中添加了不允许的更改。

iText can recognize the first type of change (using code like your pseudocode) but it cannot out of the box differentiate allowed and disallowed changes in incremental updates. iText可以识别第一种类型的更改(使用伪代码之类的代码),但是它不能立即区分增量更新中允许和不允许的更改。

Backgrounds 背景

结构体

A PDF with multiple signatures has a structure like in this image: The signature in the original version, signature1, only signs the bytes of this original version. 具有多个签名的PDF具有如下图所示的结构:原始版本中的签名signature1仅签名此原始版本的字节。 signature2 then signs the original version plus the changes for version 2 etc. (For details read here and here .) 然后,signature2对原始版本以及版本2的更改等进行签名。 (有关详细信息,请在此处此处阅读。)

But according to the PDF specifications only a limited set of changes are allowed to be applied by the later versions, and this set of changes can depend on properties of the original signature. 但是,根据PDF规范,以后的版本只允许应用一组有限的更改,而这组更改可能取决于原始签名的属性。 (For details read here .) (有关详细信息,请点击此处 。)

Your code, in particular the pkcs7.verify() , only checks whether a signature still correctly signs the bytes it applies to. 您的代码(尤其是pkcs7.verify()仅检查签名是否仍正确签名了适用于其的字节。 It does not check, though, whether the kind of changes introduced by later additions are allowed by the first signature. 但是,它不会检查第一个签名是否允许以后添加的更改类型。

Actually I'm not aware of any non-Adobe software executing that check, and even Adobe's checks are not perfect: They are biased towards recognizing allowed changes only if they are applied in a way akin to how Adobe software would have applied it. 实际上,我不知道有任何非Adobe软件可以执行该检查,甚至Adobe的检查也不是完美的:只有在以类似于Adobe软件应用方式的方式应用允许的更改时,它们才会倾向于识别允许的更改。 This sometimes results in contradicting statements, eg both 有时这会导致矛盾的陈述,例如两者

  • Some of the changes that have been made to this document since this signature was applied are not permitted by the document author. 自从应用此签名以来,对该文档所做的某些更改是文档作者所不允许的。
  • There have been no changes made to this document since this signature was applied. 自应用此签名以来,此文档未做任何更改。

in

在此处输入链接说明

Implementing a check for (dis)allowed changes 实施检查(不允许)的更改

While iText does not offer this check out of the box, it does offer you a base framework upon which you can try and implement it yourself. 尽管iText不提供开箱即用的功能,但它确实为您提供了一个基础框架,您可以在该框架上尝试并实现它。 In particular you can retrieve each complete signed revision of the document and compare their structures on the level of simple PDF objects. 特别是,您可以检索文档的每个完整的签名修订版,并在简单PDF对象的级别上比较它们的结构。

Unfortunately the allowed and disallowed changes are described only in terms of how the document looks like in a viewer or which behaviors it has, not in terms of which exact low level object additions are allowed. 不幸的是,仅根据文档在查看器中的外观或其行为来描述允许和不允许的更改,而不是根据允许的确切低级对象添加来描述。 This will make the endeavor highly non-trivial. 这将使这项工作非常轻而易举。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM