XML 签名中 KeyInfo 的用途

Purpose of KeyInfo in XML signature

我正在阅读来自 w3 page

的 XML 签名

据我了解,签署XML:

  1. 创建要签名的 XML 数据的规范 XML。
  2. 使用 <DigestMethod/> 中提到的算法创建规范化 XML 数据的哈希(摘要)。哈希将进入 <DigestValue>
  3. 上面的加密使用了<SignatureMethod/>中提到的算法。该算法将以发送方的私钥作为输入。签名将进入 <SignatureValue>

验证(在接收端):

  1. <SignatureValue>的内容上使用发件人的public键来获取哈希。
  2. 使用算法<DigestMethod>
  3. 计算数据的哈希值(xPath/referece数据可以在<Reference>中找到)
  4. 检查这是否与 <DigestValue>
  5. 中的哈希匹配

我的问题:

  1. 我的理解正确吗?
  2. 鉴于发件人的 public 密钥足以验证,<KeyInfo> 在验证签名中的作用是什么?

What is the role of <KeyInfo> in verifying signature given that sender's public key is sufficient for verifying?

钥匙一定在某处,对吧?这就是地方。它将包含用于验证签名的密钥。如规范中所述,可以跳过 <KeyInfo> 元素:

If KeyInfo is omitted, the recipient is expected to be able to identify the key based on application context.

因此,当 <KeyInfo> 丢失时,application/user 必须从其他地方获取密钥。

As per my understanding, to Sign an XML:

  1. Create a Canonical XML of the XML Data to be signed.

  2. Create a hash (digest) of the Canonicalised XML Data using an algorithm mentioned in . Hash will go inside

  3. Encrypt above has using algorithm mentioned in . This algorithm will take Sender's private key as an input. Signature will go inside

不正确,请参阅您指出的 link 的 3.1.2 签名生成 部分。

<SignatureValue> 是根据 <SignedInfo> 节点的规范化内容计算得出的,其中包括 <SignatureMethod><CanonicalizationMethod> 和参考文献。 <Reference> 元素包含 <DigestMethod><DigestValue>

文档未加密,是用私钥签名的。它涉及类似的密码操作,但填充机制不同。参见 https://crypto.stackexchange.com/questions/15997/is-rsa-encryption-with-a-private-key-the-same-as-signature-generation

What is the role of <KeyInfo> in verifying signature given that sender's public key is sufficient for verifying?

它包含与用于签署文档的私钥相对应的签名证书。

验证方可以使用签名者的 public 密钥验证签名,而无需从 <KeyInfo> 元素中提取它,但这意味着接收方已经存储了每个签名者的 public 密钥。验证方通常有一个受信任的证书颁发机构列表,并检查签名证书是否由这些颁发机构之一颁发。

请注意 <KeyInfo> 的引用也包含在 <SignedInfo> 部分中,以准确了解哪个证书签署了文档(public 密钥可以包含在多个证书中)