SAML 令牌:为什么使用多个 Hash/Digest 算法:sha256 和 sha1?

SAML Token: Why use multiple Hash/Digest Algorithms: sha256 and sha1?

我正在阅读这篇 IBM Developer Works SAML article,您可以在其中看到下面两种不同的 signature/digest 算法:sha1 和 sha256。我很好奇为什么两者都被列出以及通过哪种方法签署了什么。那篇文章说,"the [IdP] applies a hashing algorithm to the content of the Assertion element." 好像是sha256,那为什么要提DigestMethod sha1呢?如果两种方法都对相同的内容进行哈希处理,当 sha1 是 DigestMethod 时,服务提供商 (SP) 如何知道使用 sha256 验证签名?

这是正确的解释吗?

...the DigestMethod Algorithm elements refer to their parent Reference element. You can have different DigestMethod Algorithms for your multiple Reference elements, and again a different SignatureMethod Algorithm to hash and sign all the References.

<saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"
      ID="Assertion1487321564650" IssueInstant="2017-02-17T08:52:44.650Z"
      Version="2.0"> 
    <saml2:Issuer>samlsso.sample.net</saml2:Issuer> 
    <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> 
      <ds:SignedInfo> 
        <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /> 
        <ds:SignatureMethod
          Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" /> 
        <ds:Reference URI="#Assertion1487321564650"> 
          <ds:Transforms> 
            <ds:Transform
              Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /> 
            <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /> 
           </ds:Transforms> 
          <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /> 
          <ds:DigestValue>nKYxEAMG1LY4H+LqR22KJ/vqyb8=</ds:DigestValue> 
        </ds:Reference> 
      </ds:SignedInfo> 
      <ds:SignatureValue> 
m5V44OFKU1PMdibileobvVVA8NVZMKRmKAauOin2f+Kr1WQ   [...]   Z/5JcU/qw== 
      </ds:SignatureValue> 
      <ds:KeyInfo> 
        <ds:X509Data> 
          <ds:X509Certificate> 
MIIDRzCCAi+gAwIBAgIEKa/crTANBgkq

XML 元素 SignedInfo 是使用私钥和 SHA-256 签名的内容。未显示实际的签名算法,但如果您查找 rsa-sha256,您会发现它使用 PKCS#1 v1.5 签名方案而不是较新的 PSS。

SignedInfo 包含对签名数据的引用、转换(规范化)和签名数据的签名值。这不是常规签名生成中的数据的一部分;只能包含一个哈希值。所以元信息也被签名了。 SignedInfo.

中可以有多个引用和不同类型的转换

当然,引用本身必须与数据的散列一起签名;否则你可以例如在两个数据块被散列时切换数据。

但是,您仍应验证哈希值是否覆盖了您应用程序中的正确数据。否则您将验证 XML 中的某些数据,同时处理完全不同的数据。这当然应该由 SAML 实现来执行。

当然可以从 the XML-digsig standard 中检索更多信息。


是的,链接到 Whosebug post 是正确的。


我不会为使用 SHA-1 计算数据哈希值而感到遗憾。 SHA-1 已损坏,不应再使用;当然不是用于数据散列或签名生成。