Encryption SAML身份验证响应解密失败

Encryption SAML身份验证响应解密失败,encryption,saml-2.0,adfs2.0,openam,federation,Encryption,Saml 2.0,Adfs2.0,Openam,Federation,我对收到的身份验证响应SAML消息的解密有问题。 我的应用程序与两个不同类型的IdP连接。第一个是锻造岩石,OpenAM 第二个是微软的ADFS服务器。 向两个IDP提供了相同的服务提供商元数据文档,其中包含相同的 用于加密和签名的证书公钥 案例01 IdP:OpenAM,福格洛克 结果:正确处理解密和响应 案例02 IdP:ADFS 2.0,微软 结果:解密失败,错误为:加密异常,数据错误 对于同一不对称密钥对,IdP端的加密是否可能不同? 或者我有什么不对劲 正如我看到的,Encrypted

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

案例01 IdP:OpenAM,福格洛克 结果:正确处理解密和响应

案例02 IdP:ADFS 2.0,微软 结果:解密失败,错误为:加密异常,数据错误

对于同一不对称密钥对,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>

CN=证书名
-18xxxxxx

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


谢谢,

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

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

没有数据!!!
没有数据!!!
示例应如何:


CN=name,O=name,S=CA,C=us
0
qSMgmgpO0+1vhdt5wvyhNT+uh3BhmOlFD4IiWTPoj2N90nOUzwEoEkWCuGzHDizxq6rvc5eoikjgcbz5TYFlIX+eizyxcJQFl02t。。。这里有一些值=
RSCxYAMJ7RaD+MTECNME9EWLMVDJGTSX5MOKJYUJIAMQWZILNOLZQYT5XGUPHJAD+co/POWWIFWUOBHWDCLFWBMR/lAqWAHIQldP+ro。。。这里有一些值=

通常证书的密钥不描述算法;这是协议的一部分。我敢肯定,证书序列号的负值表示证书生成软件中存在缺陷(忘记用
00
字节填充ASN.1整数,该整数是有符号的)。请注意,我不是SAML专家。我已将消息中的负十进制值转换为十六进制值,因此我认为这不是问题所在。不,我也不认为这与问题直接相关,但不管怎样,这可能是一个错误。我不知道你是如何解密的,MS使用的是AES 256(如果没有无限加密,可能会导致Java平台出现问题)和OAEP,这是一种更新、更安全的加密方法。不清楚你的SP软件是什么。由于SP进行解密,我想您应该首先检查它是否正确实现了解密。此外,如果SP是Java应用程序,那么您应该确保在JVM上安装了“Java加密扩展(JCE)JDK/JRE的无限强度权限策略文件”。