使用 iText 使用 OCSP 签名

Signing with OCSP by using iText

我可以毫无问题地签署 pdf 文档。我的应用程序逻辑是; 1- 在 pdf 中创建一个空字段用于签名 2- 将字段的哈希码发送到签名 web 服务 3- 获取签名对象 4- 将此对象嵌入到字段中。

这是我的代码
感谢@mlk,帮我解决了这个问题。

但我意识到我在撤销方面遇到了问题。

从图中可以看出,我的签名不包含 OCSP。在信任部分,'Certify documents' 选项失败(红叉)

webservice的响应已经包含crl和ocsp

<sc:RevocationInformation>
 <sc:CRLs>
  <sc:CRL> .... CRL .... </sc:CRL>
 </sc:CRLs>
 <sc:OCSPs>
  <sc:OCSP> ..... ocsp content..... </sc:OCSP>
 </sc:OCSPs>
</sc:RevocationInformation>

但我只使用签名对象

我的问题是如何将 CRL 和 OCSP 嵌入到 pdf 中。

正如我看到的一些示例,已使用 SignDetached 方法而不是 SignDeferred 方法。如果我还必须使用 SignDetached 方法,那么我应该在 pdf 文件中创建一个字段。因为我需要这个字段的哈希码。这个过程是如何运作的。

编辑:当我打开我的测试 pdf 文件和一个由 swisscom 签名的 pdf 时,我看到这个 windows。

瑞士电信

这是我的测试pdf

正如蜜蜂所见,在验证方面存在差异。所以我单击签名字段并进行验证,所以我得到了这个 window。

这与swisscom原始签名文件相同。但我需要做额外的 'validate'。我需要验证的签名中缺少什么?

编辑 2:

瑞士电信签署http://documents.swisscom.com/product/1000255-Digital_Signing_Service/Documents/Reference_Guide/Reference_Guide-All-in-Signing-Service-en.pdf

和我签名的测试文件

https://app.box.com/s/ju7xgkxucw0rwif7k3052rx5n8f9omwq

您的问题实际上有两个不同的方面,一方面您想知道为什么两个文档(您创建的文档和 Swisscom 提供的文档)在您的 Adob​​e Reader 中表现不同,以及另一方面,您询问如何将 CRL 和 OCSP 嵌入 pdf

签名文档之间的差异

Adobe Reader 版本问题

首先,您观察到的两个文档的不同 Adob​​e Reader 行为只发生在旧的 Adob​​e Reader 版本上,您在 Adob​​e Reader DC 中的两个文件都是 立即生效 带有绿色勾号。

因此,不仅 Reader 的行为不再不同,现在开箱即用的签名也被认为是有效的!信任锚是从 Adob​​e Approved Trust List 中获取的。

此外,您可以看到两个签名都被视为 "LTV-enabled"。因此,包含 Adob​​e Reader 验证所需的所有信息,特别是撤销信息(CRL 和 OCSP 响应)。

不同签名过滤

两个签名的主要区别在于PDF签名的过滤器

  • 5.PDF_1_.pdf 具有签名 FilterETSI.RFC3161
  • Reference_Guide-All-in-Signing-Service-en.pdf 有一个签名 FilterAdobe.PPKLite.

你签名的文件中的FilterETSI.RFC3161没有意义:这个值是保留的SubFilter 文档 时间戳 的值! SwissCom签名文件中的FilterAdobe.PPKLite确实是一个过滤器名称,它是Adobe签名处理程序的名称。

根据 PDF 规范 ISO 32000-1 和 ISO 32000-2:

The name of the preferred signature handler to use when validating this signature. If the Prop_Build entry is not present, it shall be also the name of the signature handler that was used to create the signature. If Prop_Build is present, it may be used to determine the name of the handler that created the signature (which is typically the same as Filter but is not needed to be). A conforming reader may substitute a different handler when verifying the signature, as long as it supports the specified SubFilter format. Example signature handlers are Adobe.PPKLite, Entrust.PPKEF, CICI.SignIt, and VeriSign.PPKVS.

Filter 值的意义随着时间的推移而减弱。早期的 Adob​​e Reader 版本(以及其他签名验证器的版本)仅自动处理具有某些 Filter 值的签名,而现在 Filter 值基本上被忽略了。

因此,您观察到不同行为的 Adob​​e Reader 版本必须是旧版本,它仍然只立即处理带有已知过滤器的签名,而只有在需要时才处理未知过滤器。

您参考了 的源代码,其中特别包含

IExternalSignatureContainer external = new ExternalBlankSignatureContainer(PdfName.ADOBE_PPKLITE, PdfName.ADBE_PKCS7_DETACHED);
PdfSignature external2 = new PdfSignature(PdfName.ADOBE_PPKLITE, PdfName.ADBE_PKCS7_DETACHED);//ADBE_PKCS7_SHA1);
//as pdf name I tried also PdfName.ETSI_RFC3161

显然,您使用尝试的代码创建了签名,您 也尝试过 PdfName.ETSI_RFC3161...

将 CRL 和 OCSP 嵌入到 pdf 中

你的上下文中的这个问题实际上已经成为一个有争议的问题,因为你的签名被识别为 LTV 启用,即特别是包括所需的所有撤销信息(CRL,OCSP 响应)通过 Adob​​e Reader 的签名验证程序。因此,我将只笼统地介绍它。

基本上有两个地方可以在 PDF 中放置撤销信息:

  • 签名容器中 Adob​​e 定义的特殊属性或
  • 一个特殊的、ETSI 定义的字典,在以后的增量更新中。

adbe 吊销信息属性

相关属性已在 PDF 规范 ISO 32000-1 中指定:

The PKCS#7 object should contain the following:

[...]

  • Revocation information as an signed attribute (PDF 1.6): This attribute may include all the revocation information that is necessary to carry out revocation checks for the signer's certificate and its issuer certificates. Since revocation information is a signed attribute, it must be obtained before the computation of the digital signature.

[...]

The adbe Revocation Information attribute:

adbe-revocationInfoArchival OBJECT IDENTIFIER ::=
                              { adbe(1.2.840.113583) acrobat(1) security(1) 8 }

The value of the revocation information attribute can include any of the following data types:

  • Certificate Revocation Lists (CRLs), described in RFC 3280 (see the Bibliography): CRLs are generally large and therefore should not be embedded in the PKCS#7 object.

  • Online Certificate Status Protocol (OCSP) Responses, described in RFC 2560, X.509 Internet Public Key Infrastructure Online Certificate Status Protocol—OCSP (see the Bibliography): These are generally small and constant in size and should be the data type included in the PKCS#7 object.

  • Custom revocation information: The format is not prescribed by this specification, other than that it be encoded as an OCTET STRING. The application should be able to determine the type of data contained within the OCTET STRING by looking at the associated OBJECT IDENTIFIER.

adbe's Revocation Information attribute value has ASN.1 type RevocationInfoArchival:

   RevocationInfoArchival ::= SEQUENCE {
     crl [0] EXPLICIT SEQUENCE of CRLs, OPTIONAL
     ocsp [1] EXPLICIT SEQUENCE of OCSP Responses, OPTIONAL
     otherRevInfo [2] EXPLICIT SEQUENCE of OtherRevInfo, OPTIONAL
   }
   OtherRevInfo ::= SEQUENCE {
     Type OBJECT IDENTIFIER
     Value OCTET STRING
   }

这种嵌入方式甚至在第一个 ISO PDF 规范 ISO 32000-1 之前就已经为人所知,因此,对于大多数验证器来说应该是可用的。缺点是此属性已签名,因此必须及早检索信息。这可能并不总是可能的。

顺便说一句,这也是将这些信息嵌入到您的文档中的方式,SwissCom 为您将此属性嵌入到签名容器中。

ETSI 文档安全存储 (DSS) 字典

该字典及其处理由 ETSI 指定,例如在 ETSI EN 319 142-1 中,并已复制到 PDF 规范更新 ISO 32000-2:

The Document Security Store (DSS) shall be a dictionary that shall have the value DSS as key in the document catalog dictionary. This dictionary is used to provide a single place where all of the validation-related information for some or all signatures in the document should be placed.

The DSS dictionary, if present, shall contain validation-related information only for document and time-stamps signatures represented in PKCS#7 and CMS (and its derivatives) format or for XAdES signatures of forms signing dynamic XFA [i.7].

NOTE: See ETSI EN 319 142-2 [i.11] for specification of XAdES signatures of forms signing dynamic XFA.

Entries in a DSS Dictionary

Type Name (Optional) It shall be DSS for a document security store dictionary.

VRI Dictionary (Optional) This dictionary contains Signature VRI dictionaries in the document. The key of each entry in this dictionary is the base-16-encoded (uppercase) SHA1 digest of the signature to which it applies and the value is the Signature VRI dictionary which contains the validation-related information for that signature. (See additional requirements a, b, c.).

Certs Array (Optional) An array of indirect references to streams, each containing one DER-encoded X.509 certificate (that shall be as defined in IETF RFC 5280 [4]). This array contains certificates that can be used in the validation of any signatures in the document.

OCSPs Array (Optional) An array of indirect references to streams, each containing a DER-encoded Online Certificate Status Protocol (OCSP) response (that shall be as defined in IETF RFC 6960 [5]). This array contains OCSPs that can be used in the validation of any signatures in the document.

CRLs Array (Optional) An array of indirect references to streams, each containing a DER-encoded Certificate Revocation List (CRL) (that shall be as defined in IETF RFC 5280 [4]). This array contains CRLs that can be used in the validation of any signatures in the document.

由于在第一个 ISO PDF 规范 ISO 32000-1 中还不知道这种嵌入方式,因此许多验证器可能不知道如何处理这些信息。好处是这个字典不用签名,签名后就可以取回信息。这在某些用例中可能是必要的。