简体   繁体   English

使用iText将单独的签名和单独的ocsp字节添加到PDF

[英]Add separate signature and separate ocsp bytes to PDF with iText

I have an array with signature bytes and an array with ocsp bytes to add ltv information to my pdf. 我有一个带签名字节的数组和一个带ocsp字节的数组,可将ltv信息添加到我的pdf中。 The signature is a timestamp signature. 签名是时间戳签名。 Now I try to add this information to a pdf file which works with 现在,我尝试将这些信息添加到与

//add signature
PdfLiteral pdfLiteral = (PdfLiteral) pdfSignature.get( PdfName.CONTENTS );
byte[] outc = new byte[ ( pdfLiteral.getPosLength( ) - 2 ) / 2 ];
Arrays.fill( outc, (byte) 0 );
System.arraycopy( externalSignature, 0, outc, 0, externalSignature.length );
PdfDictionary dic2 = new PdfDictionary( );
PdfString pdfString = new PdfString( outc ).setHexWriting( true );
dic2.put( PdfName.CONTENTS, pdfString );

pdfSignatureAppearance.close( dic2 );

... ...

//add LTV
for ( String sigName : stamper.getAcroFields( ).getSignatureNames( ) ) {
        addVerification = validation.addVerification(
                sigName, // Signature Name
                ocspColl, // OCSP
                crlColl, // CRL
                null // certs
        );
    }

validation.merge( );
stamper.close( );

OK, this works. 好,这有效。 But in the signature I have to set the flag certification level 1 (no changes are allowed) and my application will not work. 但是在签名中,我必须将标志认证级别设置为1(不允许更改),并且我的应用程序将无法运行。 Because with adding LTV I change the document. 因为添加LTV会更改文档。 I tried creating my own DSS-dictionary and add it to my document but it failed. 我尝试创建自己的DSS词典并将其添加到我的文档中,但是失败了。 Anyone who can help, please? 有人可以帮忙吗? Thanks in advance 提前致谢

As a member of the ISO committee for ISO-32000-2, I have access to the specification, so allow me to explain a couple of things. 作为ISO-32000-2的ISO委员会的成员,我可以使用该规范,因此请允许我解释一些事情。

There can be 3 types of signatures (*) in a PDF document: PDF文档中可以有3种签名(*):

  • At most one certification signature (aka author signature), 最多有一个认证签名(即作者签名),
  • One or more approval signatures (aka recipient signatures), 一个或多个批准签名(又称收件人签名),
  • Any number of document time stamp signatures (of which the SubFilter value is ETSI.RFC3161). 任何数量的文档时间戳签名(其SubFilter值为ETSI.RFC3161)。

(*) There is a fourth type, called a usage rights signature, but that will be deprecated in PDF 2.0. (*)有第四种类型,称为使用权限签名,但是在PDF 2.0中将不再使用。

Source: section 12.8.1 entitled "General" in section 12.8 entitled "Digital Signatures" of ISO 32000-2 (Draft) 来源:ISO 32000-2(草稿)第12.8节标题为“数字签名”的标题为“一般”的12.8.1节

You are talking about a document time stamp signature (added for LTV reasons), but you are also talking about DocMDP (MDP stands for Modification Detection and Prevention). 您正在谈论文档时间戳签名(出于LTV的原因而添加),但是您也在谈论DocMDP(MDP代表修改检测和预防)。

MDP is available for certification signatures only: MDP仅适用于认证签名:

The DocMDP transform method shall be used to detect modifications relative to a signature field that is signed by the author of a document (the person applying a certification signature). DocMDP转换方法应用于检测相对于文档作者(申请证书签名的人)签名的签名字段的修改。 A document can contain only one signature field that contains a DocMDP transform method. 一个文档只能包含一个包含DocMDP转换方法的签名字段。 It enables the author to specify what changes shall be permitted to be made to the document and what changes invalidate the author's signature. 它使作者可以指定允许对文档进行哪些更改,以及哪些更改会使作者的签名无效。

Source: section 12.8.2.2.1 entitled "General" in section 12.8.2.2 entitled "DocMDP" of ISO 32000-2 (Draft) 来源:ISO 32000-2(草案)中名为“ DocMDP”的第12.8.2.2节中名为“常规”的节12.8.2.2.1

Granted, you can add a Reference entry to the signature dictionary that contains "An array of signature reference dictionaries". 当然,您可以向包含“签名参考字典数组”的签名字典添加参考条目。

A signature reference dictionary can have a TransformMethod entry with values: 签名参考字典可以具有一个TransformMethod条目,其值如下:

  • DocMDP: Used to detect modifications to a document relative to a signature field that is signed by the originator of a document. DocMDP:用于检测相对于文档创建者签名的签名字段的文档修改。
  • FieldMDP: Used to detect modifications to a list of form fields specified in TransformParams. FieldMDP:用于检测对TransformParams中指定的表单域列表的修改。

Source: Table 259 "Entries in a signature reference dictionary" in section 12.8.1 of ISO 32000-1 来源:ISO 32000-1第12.8.1节中的表259“签名参考词典中的条目”

If MDP is what you want, you can use DocMDP in case of certification signatures, and FieldMDP in case of other signatures. 如果需要MDP,则在使用证书签名的情况下可以使用DocMDP,在使用其他签名的情况下可以使用FieldMDP。 However, if we look at the Reference entry in Table 255: Entries in a signature dictionary , we see that "If SubFilter is ETSI.RFC3161, this entry shall not be used." 但是,如果我们查看表255:签名字典中的条目中的引用”条目,则会看到“如果SubFilter是ETSI.RFC3161,则不应使用此条目。”

In other words, you can't have a DocMDP or FieldMDP for Document time stamps. 换句话说,您不能拥有用于文档时间戳的DocMDP或FieldMDP。 That's kind of normal, because as we read in section 12.8.5.1 "General" of section 12.8.5 "Document time-stamp (DTS) dictionary": 这很正常,因为正如我们在第12.8.5节“文档时间戳(DTS)字典”的第12.8.5.1节“常规”中所述:

A document time-stamp dictionary establishes the exact contents of the complete PDF file at the time indicated in the time-stamp token. 文档时间戳字典会在时间戳记标记中指示的时间建立完整PDF文件的确切内容。

It doesn't say anything about the ability to set a flag to "certification level 1 (no changes are allowed)". 它没有说明将标记设置为“证书级别1(不允许更改)”的能力。 That's not what a document time stamp is for. 那不是文档时间戳的目的。 It is normal that the code fails. 代码失败是正常的。

Setting the certification level is something that can only be done with the first signature, in case that signature is a certification signature. 如果签名是认证签名,则只能使用第一个签名来设置认证级别。 Whoever told you to set the certification level using a document time stamp signature (ETSI.RFC3161) is asking you to do something that is impossible according to the upcoming ISO standard for PDF 2.0. 谁告诉您使用文档时间戳签名(ETSI.RFC3161)设置认证级别,就会要求您根据即将发布的PDF 2.0 ISO标准执行一些不可能的事情。

If your follow-up question is: then how was it done in ISO 32000-1, then the answer is simple: document timestamp signatures didn't exist in ISO 32000-1. 如果您的后续问题是:那么它是如何在ISO 32000-1中完成的,那么答案很简单:文档时间戳签名在ISO 32000-1中不存在。

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

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