【问题标题】:Decryption of SAML authenticaion response failedSAML 身份验证响应解密失败
【发布时间】:2014-08-17 07:03:29
【问题描述】:

我在解密收到的身份验证响应 SAML 消息时遇到问题。 我的应用程序与两个不同类型的 IdP 连接。首先是 ForgeRocks,OpenAM 第二个微软的 ADFS 服务器。 两个 IdP 都提供了相同的服务提供商元数据文档,其中包含相同的 用于加密和签名的证书公钥。

案例01 IdP:OpenAM、ForgeRock 结果:正确处理解密和响应。

案例 02 IdP:ADFS 2.0,微软 结果:解密失败并出现错误:CryptographicException,Bad Data。

对于相同的非对称密钥对,IdP 端的加密是否可能不同? 还是我搞错了?

正如我所见,EncryptedAssertion xml 节点存在差异。 EncryptionMethod 算法不同。

这里是关键节点。

OpenAM、ForgeRock

<saml:EncryptedAssertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
<xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
                    Type="http://www.w3.org/2001/04/xmlenc#Element"
                        >
  <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"
                         xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
                               />
  <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
    <xenc:EncryptedKey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
      <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"
                             xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
                                       />
      <xenc:CipherData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
        <xenc:CipherValue xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
        </xenc:CipherValue>
      </xenc:CipherData>
    </xenc:EncryptedKey>
  </ds:KeyInfo>
  <xenc:CipherData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
    <xenc:CipherValue xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
    </xenc:CipherValue>
  </xenc:CipherData>
</xenc:EncryptedData>

ADFS 2.0,微软

<EncryptedAssertion xmlns="urn:oasis:names:tc:SAML:2.0:assertion">
<xenc:EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
                    xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
                        >
  <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" />
  <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
    <e:EncryptedKey xmlns:e="http://www.w3.org/2001/04/xmlenc#">
      <e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p">
        <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
      </e:EncryptionMethod>
      <KeyInfo>
        <ds:X509Data xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
          <ds:X509IssuerSerial>
            <ds:X509IssuerName>CN=certName</ds:X509IssuerName>
            <ds:X509SerialNumber>-18xxxxxx</ds:X509SerialNumber>
          </ds:X509IssuerSerial>
        </ds:X509Data>
      </KeyInfo>
      <e:CipherData>
        <e:CipherValue></e:CipherValue>
      </e:CipherData>
    </e:EncryptedKey>
  </KeyInfo>
  <xenc:CipherData>
    <xenc:CipherValue></xenc:CipherValue>
  </xenc:CipherData>
</xenc:EncryptedData>

据我所知,使用的加密方法存在差异。在第二种情况下,还有证书的别名和序列号。序列号也有负值(可能是因为我使用的是自签名证书)。

谢谢,

【问题讨论】:

  • 通常证书的密钥不描述算法;这是协议的一部分。我很确定证书序列号的负值表示证书生成软件中的错误(忘记使用00 字节填充 ASN.1 INTEGER - 已签名)。请注意,我不是 SAML 专家。
  • 我已将消息中的负十进制值转换为适当的十六进制值序列号,所以我认为这不是问题。
  • 不,我认为这也与问题没有直接关系,但无论如何它可能是一个错误。我不知道你是如何解密的,MS 使用的是 AES 256(这可能会在没有无限加密的 Java 平台上导致问题)和 OAEP,这是一种更新、更安全的加密方法。
  • 不清楚你的SP软件是什么。由于 SP 进行了解密,我想您应该首先检查它是否正确实现了解密。此外,如果 SP 是 Java 应用程序,那么您应该确保在您的 JVM 上安装了“Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files for JDK/JRE”。

标签: encryption saml-2.0 adfs2.0 openam federation


【解决方案1】:

您有此异常,因为在相应的 xml 节点中没有要解密的数据,这就是原因:

<e:CipherData>
<e:CipherValue>No data!!!</e:CipherValue>
</e:CipherData>
</e:EncryptedKey>
</KeyInfo>
<xenc:CipherData>
<xenc:CipherValue>No data!!!</xenc:CipherValue>
</xenc:CipherData>

举例说明:

<EncryptedAssertion xmlns="urn:oasis:names:tc:SAML:2.0:assertion">
		<xenc:EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
				    xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
				    >
		    <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" />
		    <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
			<e:EncryptedKey xmlns:e="http://www.w3.org/2001/04/xmlenc#">
			    <e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p">
				<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
			    </e:EncryptionMethod>
			    <KeyInfo>
				<ds:X509Data xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
				    <ds:X509IssuerSerial>
					<ds:X509IssuerName>CN=name, O=Name, S=CA, C=us</ds:X509IssuerName>
					<ds:X509SerialNumber>0</ds:X509SerialNumber>
				    </ds:X509IssuerSerial>
				</ds:X509Data>
			    </KeyInfo>
			    <e:CipherData>
				<e:CipherValue>qSMgmgpO0+1vhdt5wvyhNT+uh3BhmOlFD4IiWTPoj2N90nOUzwEoEkWCuGzHDizxq6rvc5eoikjgcbz5TYFlIX+eizyxcJQFl02t...  SOME VALUES HERE=</e:CipherValue>
			    </e:CipherData>
			</e:EncryptedKey>
		    </KeyInfo>
		    <xenc:CipherData>
			<xenc:CipherValue>RSCxYAMJ7RaD+MtEcnmE9EwLmvDJgTsXx5MOKJYUJiAmQWziSLNolZQYt5xgUPHJaD+co/PoWwifWuobHdClFwBBMR/lAqWAHIQldP+ro ...  SOME VALUES HERE=</xenc:CipherValue>
		    </xenc:CipherData>
		</xenc:EncryptedData>
	    </EncryptedAssertion>
	

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-28
    • 2021-06-19
    • 1970-01-01
    • 2018-12-22
    • 1970-01-01
    相关资源
    最近更新 更多