简体   繁体   English

PDF签名摘要

[英]PDF Signature digest

I have a quick question about calculating the digest of a PDF document to use for a digital signature (somewhat related to one of my earlier questions, I'm trying to figure out why you would need to know a client's certificate to create the correct digest). 我有一个关于计算用于数字签名的PDF文档摘要的快速问题(与我之前的一个问题有点相关,我试图弄清楚为什么你需要知道客户的证书才能创建正确的摘要)。 In Adobe's documentation about the PDF format the following is specified: 在Adobe有关PDF格式的文档中,指定了以下内容:

A byte range digest shall be computed over a range of bytes in the file, that shall be indicated by the ByteRange entry in the signature dictionary. 应在文件中的字节范围内计算字节范围摘要,该字节范围摘要应由签名字典中的ByteRange条目指示。 This range should be the entire file, including the signature dictionary but excluding the signature value itself (the Contents entry). 此范围应该是整个文件,包括签名字典,但不包括签名值本身(内容条目)。

So at this point things seem fairly simple, just digest everything except the /Contents entry in the /Sig dictionary. 所以在这一点上事情似乎相当简单,只是消化/ Sig字典中除/ Contents条目之外的所有内容。 The actual data in the /Contents entry is specified as followed: / Contents条目中的实际数据指定如下:

For public-key signatures, Contents should be either a DER-encoded PKCS#1 binary data object or a DER-encoded PKCS#7 binary data object. 对于公钥签名,Contents应该是DER编码的PKCS#1二进制数据对象或DER编码的PKCS#7二进制数据对象。

So still no problems, I can (probably) generate the digest, reserve space for the /Contents entry and attach this PKCS#7 object later on. 所以仍然没有问题,我可以(可能)生成摘要,为/ Contents条目保留空间并稍后附加此PKCS#7对象。 The confusion starts when I read the following: 当我阅读以下内容时,混乱就开始了:

Revocation information is a signed attribute, which means that the signing software must capture the revocation information before signing. 撤销信息是签名属性,这意味着签名软件必须在签名之前捕获吊销信息。 A similar requirement applies to the chain of certificates. 类似的要求适用于证书链。 The signing software must capture and validate the certificate's chain before signing. 签名软件必须在签名之前捕获并验证证书链。

So the thing I'm not quite getting: Apparently the /Contents entry (containing the certificate and signed digest) is not digested, yet the chain of certificates is a signed attribute (and thus needs to be digested?). 所以我没有得到的东西:显然/ Contents条目(包含证书和签名摘要)没有消化,但证书链是一个签名属性(因此需要被消化?)。

I would appreciate it if someone could further specify exactly what is digested, and perhaps better explain the signed attributes to me. 如果有人能够进一步确定消化的内容,我会很感激,也许更好地向我解释已签名的属性。 The main question that I want to answer is: Can I actually create a signable digest without knowing someone's certificate beforehand? 我想回答的主要问题是:我是否可以在事先不知道某人的证书的情况下创建一个可签名的摘要? (I'm working with a pkcs7 detached signature) (我正在使用pkcs7分离签名)

In short: 简而言之:

Can I actually create a signable digest without knowing someone's certificate beforehand? 我是否可以在事先不知道某人的证书的情况下创建一个可签名的摘要?

In case of SubFilter ETSI.CAdES.detached or adbe.pkcs7.detached you can create the document digest without knowing someone's certificate beforehand . 如果是SubFilter ETSI.CAdES.detachedadbe.pkcs7.detached,您可以在不事先知道某人的证书的情况下创建文档摘要

You usually, though, have to know the signer certificate before starting to generate the CMS signature container to embed into the PDF. 但是,在开始生成嵌入到PDF中的CMS签名容器之前,您通常必须知道签名者证书。

In detail: 详细地:

(Beware, the following is somewhat simplified.) (注意,以下内容有所简化。)

I can (probably) generate the digest, reserve space for the /Contents entry and attach this PKCS#7 object later on. 我可以(可能)生成摘要,为/ Contents条目保留空间,并在以后附加此PKCS#7对象。

If you first reserve space and thereafter generate the digest , this indeed is how things are done. 如果你先保留空间 然后生成摘要 ,这确实是事情的完成方式。

The confusion starts when I read the following: 当我阅读以下内容时,混乱就开始了:

Revocation information is a signed attribute, which means that the signing software must capture the revocation information before signing. 撤销信息是签名属性,这意味着签名软件必须在签名之前捕获吊销信息。 A similar requirement applies to the chain of certificates. 类似的要求适用于证书链。 The signing software must capture and validate the certificate's chain before signing. 签名软件必须在签名之前捕获并验证证书链。

So the thing I'm not quite getting: Apparently the /Contents entry (containing the certificate and signed digest) is not digested, yet the chain of certificates is a signed attribute (and thus needs to be digested?). 所以我没有得到的东西:显然/ Contents条目(包含证书和签名摘要)没有消化,但证书链是一个签名属性(因此需要被消化?)。

I would appreciate it if someone could further specify exactly what is digested, and perhaps better explain the signed attributes to me. 如果有人能够进一步确定消化的内容,我会很感激,也许更好地向我解释已签名的属性。

The main fact one has to be aware of is that in case of PKCS#7/CMS signature containers signing usually does not merely include one hash calculation but at least two ! 一个必须知道的主要事实是,在PKCS#7的情况下/ CMS签名签署的容器通常并不仅仅包括一个哈希计算,但至少有两个

The first hash, the document hash, is indeed calculated for the entire file, including the signature dictionary but excluding the signature value itself (the Contents entry) (you might want to read this answer for more details). 确实为整个文件计算了第一个散列,即文档散列, 包括签名字典,但不包括签名值本身( 内容条目) (您可能希望阅读此答案以获取更多详细信息)。

散列字节范围的图形草图

But this is not the hash immediately used when applying the signature algorithm. 但这不是应用签名算法时立即使用的哈希值。

During the generation of the PKCS#7/CMS signature container (unless in its most primitive form) you create a structure called "signed attributes". 在生成PKCS#7 / CMS签名容器期间(除非以其最原始的形式),您将创建一个名为“signed attributes”的结构。

You fill this structure with multiple attributes (name-value-pairs), among them the already calculated document hash but also others, eg the Adobe-style revocation information you read about. 您使用多个属性(名称 - 值对)填充此结构,其中包括已计算的文档哈希以及其他属性,例如您阅读的Adobe样式的吊销信息。

When you have finished creating that structure, you hash this structure and generate a signature for it . 完成创建该结构后,您将对此结构进行哈希并为其生成签名

You then can put together the PKCS#7/CMS signature container using these signed attributes, the signature, and some more information not signed by this signature, eg certificates, signature time stamps, ... 然后,您可以使用这些签名属性,签名以及未签名的更多信息(例如证书,签名时间戳,......)将PKCS#7 / CMS签名容器放在一起。

For more details concerning the signature container read this answer . 有关签名容器的更多详细信息,请阅读此答案

Finally you embed this signature container into the reserved space in the PDF. 最后,您将此签名容器嵌入到PDF中的保留空间中。

The main question that I want to answer is: Can I actually create a signable digest without knowing someone's certificate beforehand? 我想回答的主要问题是:我是否可以在事先不知道某人的证书的情况下创建一个可签名的摘要? (I'm working with a pkcs7 detached signature) (我正在使用pkcs7分离签名)

In case of SubFilter ETSI.CAdES.detached or adbe.pkcs7.detached you can create the document digest without knowing someone's certificate beforehand . 如果是SubFilter ETSI.CAdES.detachedadbe.pkcs7.detached,您可以在不事先知道某人的证书的情况下创建文档摘要

Depending on the CMS signature profile, though, you usually have to know the signer certificate before starting to generate the signature container because many profiles require the presence of a signed attribute referencing the signer certificate. 但是,根据CMS签名配置文件,您通常必须在开始生成签名容器之前知道签署者证书,因为许多配置文件需要存在引用签署者证书的签名属性。

Clarifications: 澄清:

The OP asked some follow-up questions in a comment: OP在评论中询问了一些后续问题:

1.: One of the signed attributes is the document hash(without the /contents), so if I understand correctly this is the unsigned hash? 1:签名属性之一是文档哈希(没有/ contents),所以如果我理解正确,这是无符号哈希?

As the "signed attributes" eventually are hashed and signed, that document hash therein is not immediately, directly signed but it is indirectly signed as part of this structure of attributes. 由于“签名属性”最终被哈希和签名,因此其中的文档哈希不是立即直接签名的, 而是作为此属性结构的一部分间接签名。 So I wouldn't call it unsigned... 所以我不会称它为无符号......

  1. In the end when the user really generates a signature, he signs the hash of the PKCS#7 object? 最后,当用户真正生成签名时,他会签署PKCS#7对象的哈希值?

No, the hash of the "Signed attributes" structure which is only a part of the PKCS#7 object, not all of it. 不,“签名属性”结构的哈希值只是PKCS#7对象的一部分,而不是全部。 There are multiple parts of the PKCS#7/CMS object which are unsigned. PKCS#7 / CMS对象的多个部分是无符号的。

  1. Does the /Contents entry still have a PKCS#7 object that's actually readable for us? / Contents条目是否还有一个实际上对我们可读的PKCS#7对象? (To extract certificates etc for verification) (提取证书等进行验证)

The Contents entry does contain a full-fledged PKCS#7/CMS signature container object as a binary string. Contents条目包含一个完整的PKCS#7 / CMS签名容器对象作为二进制字符串。 Thus, yes, you can read it (by reading the value of that binary string) and (if you have code that knows how to parse such a signature container) extract information from it. 因此,是的,您可以读取它(通过读取该二进制字符串的值)和(如果您有知道如何解析此类签名容器的代码)从中提取信息。

Beware, though, the signature container may not contain all data required for verification: Eg, if you verify using the chain (not shell) validation model, you might have to extract the signing time from the respective PDF signature dictionary entry. 但请注意,签名容器可能不包含验证所需的所有数据:例如,如果使用链(非shell)验证模型进行验证,则可能必须从相应的PDF签名字典条目中提取签名时间。

  1. When verifying a signature, do we simply extract the embedded PKCS#7 object, recalculate the digest, recalculate the digest of the PKCS#7 object and verify this against the signature using the certificate we get from the PKCS#7 object? 在验证签名时,我们是否只是提取嵌入的PKCS#7对象,重新计算摘要,重新计算PKCS#7对象的摘要,并使用我们从PKCS#7对象获得的证书对签名进行验证?

You obviously also have to calculate the digest of the signed PDF byte ranges and compare that value with the signed attribute containing the original document digest.(You might have meant that by recalculate the digest .) 您显然还必须计算已签名的PDF字节范围的摘要,并将该值与包含原始文档摘要的signed属性进行比较。(您可能已经意味着重新计算摘要 。)

As mentioned in the answer to 3, you might have to retrieve additional information from the PDF for use in the PKCS#7 verification. 如3的答案中所述,您可能必须从PDF中检索其他信息,以便在PKCS#7验证中使用。

Furthermore you say the certificate we get from the PKCS#7 object - please be aware that the PKCS#7/CMS signature container may contain multiple certificates. 此外,您说我们从PKCS#7对象获得的证书 - 请注意PKCS#7 / CMS签名容器可能包含多个证书。 You have to find the correct one. 你必须找到正确的。 The CMS SignerInfo SignerIdentifier and the ESS signed attributes shall be used for that. 应使用CMS SignerInfo SignerIdentifier和ESS签名属性。

Furthermore you also have to verify validity and trust of the signer certificate. 此外,您还必须验证签名者证书的有效性和信任。

  1. Is there any good documentation on what authenticated attributes there are? 有没有关于哪些经过身份验证的属性的良好文档?

You can start reading 你可以开始阅读

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

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