当前位置: 首页 > 知识库问答 >
问题:

SAML认证响应解密失败

申屠恺
2023-03-14

我在解密收到的验证响应SAML消息时遇到问题。我的应用程序连接了两个不同类型的国内流离失所者。第一是ForgeRocks,OpenAM,第二是微软的ADFS服务器。为两个IDP提供了相同的服务提供商元数据文档,该文档包含用于加密和签名的相同证书公钥。

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

案例02 IdP:ADFS 2.0,Microsoft结果:解密失败并出现错误:Cry的异常,错误的数据。

对于同一非对称密钥对,IdP侧的加密是否可能不同?或者我做错了什么?

正如我所看到的,EnCryptedAssertion xml节点存在差异。加密方法算法不同。

以下是关键节点。

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>

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

谢谢

共有1个答案

姜志行
2023-03-14

您有此异常,因为在相应的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>
	
 类似资料:
  • 2016年8月1日11:34:39 AM org.apache.catalina.core.standardWrapperValve在路径为[/travelocity.com]的上下文中为servlet[jsp]调用严重:servlet.service()引发了异常[SAML响应的签名验证失败],根本原因为org.wso2.carbon.identity.sso.agent.exception.s

  • 我重写了类A的容器请求过滤器和类B的容器响应过滤器。 现在,每当有rest调用时,类a首先得到请求,然后它转到另一个类C。 流程是,请求到达类A,然后到达类C,最后到达类B。 现在当我看到有些东西不好,我需要发送响应时,我怎么能从A类做到这一点。我需要绕过C类。

  • 我可以通过HTTP-Redirect绑定登录和接收SAMLResponse,也可以使用privatekey解密和检索声明。 我的问题仍然是,我们需要验证saml响应(ADFS)吗?如果是如何做到这一点 我需要使用IP(身份提供商)公钥吗?它将在IP(元数据)中可用吗? 我在下面的请求参数中有SAML响应 SAMLACK=签名=hashvalue sigAlg=sha256 如何验证?

  • 我试图遵循以下规范来验证SAML响应的签名:https://www.w3.org/tr/xmldsig-core/#sec-pkcs1 下面是我的工作流程:我得到SAML响应。我去掉签名信封,我把它规范化,我检查摘要,然后我检查签名。我能够成功地计算转换的SAML响应的SHA1摘要,并对其进行验证。然而,RSA-SHA1签名检查仍然无法实现。 SAML响应包含签名方法算法:http://www.w

  • 我在验证从ADFS服务器获得的SAML响应时遇到了问题。我以url的形式获得响应,例如,而是http://www.w3.org/2001/04/xmldsig-more#rsa-sha256。我设法解码了响应,但无法找到使用给定签名验证响应的方法。 我的主要问题是签名有一个非常意外的格式。由于给定的签名算法,我希望签名的长度为32字节,但是当我base64-decode签名时,我得到的是长度为25

  • 我们需要实现基于SAML的安全身份验证。我们的IDP将是Okta和OneLogin。为此,我们在节点中使用“passport”“passport saml”。JSExpress应用程序。我们在SP端为Okta使用以下策略配置- 对于OneLogin,我们使用- 但对于Okta,它给出的错误是“无法读取未定义的属性'getAttribute',对于OneLogin,它给出的错误是“无效签名”。此外,