首页 > 解决方案 > ITfoxtec.Identity.Saml2.Saml2RequestException:“不完全是一个断言元素。”

问题描述

再会,

我们使用了 ITfoxtec 库版本 1.2.2。该解决方案正常工作。

我们现在正在集成 4.0.5 版库。我们需要使用 SHA-256 编码。我们使用了 Nugets 的 4.0.5 库。根据实现示例https://github.com/ITfoxtec/ITfoxtec.Identity.Saml2

SAML 请求已成功发送。到达 SAML 响应。在行binding.ReadSamlResponse(Request.ToGenericHttpRequest(), saml2AuthnResponse)中的方法AssertionConsumerService()上抛出异常;.

抛出异常:ITfoxtec.Identity.Saml2.Saml2RequestException:“不完全是一个断言元素。”

这是我的 SAML 回复:

<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
                xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"
                xmlns:enc="http://www.w3.org/2001/04/xmlenc#"
                xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
                xmlns:x500="urn:oasis:names:tc:SAML:2.0:profiles:attribute:X500"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                Destination="https://xxx/saml/post/ac"
                ID="id-cefHM2F1RpCggtiERcLI-Z5AwyqM43zoVhtjSan0"
                InResponseTo="_99a2e207-8b49-46ab-85a8-7448f32b34e9"
                IssueInstant="2020-07-14T11:03:49Z"
                Version="2.0"
                >
    <saml:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">https://yyy/oam/fed</saml:Issuer>
    <dsig:Signature>
        <dsig:SignedInfo>
            <dsig:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
            <dsig:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
            <dsig:Reference URI="#id-cefHM2F1RpCggtiERcLI-Z5AwyqM43zoVhtjSan0">
                <dsig:Transforms>
                    <dsig:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
                    <dsig:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
                </dsig:Transforms>
                <dsig:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
                <dsig:DigestValue>/pQoLtuBTH/YNe4OKD4V6+qc2Rxf+na6pa8HonSRNeY=</dsig:DigestValue>
            </dsig:Reference>
        </dsig:SignedInfo>
        <dsig:SignatureValue>WW5g8Kzh3XMvohJKsYKebvO...</dsig:SignatureValue>
        <dsig:KeyInfo>
            <dsig:X509Data>
                <dsig:X509Certificate>MIIDUTCCAjmgAwIBAgIKTAxTewAAAAA...</dsig:X509Certificate>
            </dsig:X509Data>
        </dsig:KeyInfo>
    </dsig:Signature>
    <samlp:Status>
        <samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" />
    </samlp:Status>
    <saml20:EncryptedAssertion xmlns:saml20="urn:oasis:names:tc:SAML:2.0:assertion">
        <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
                            Id="id-a7DCb68sppndtm1EJHGc7tGXeaybYZqovq6DSXUP"
                            Type="http://www.w3.org/2001/04/xmlenc#Element"
                            >
            <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" />
            <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
                <dsig:RetrievalMethod Type="http://www.w3.org/2001/04/xmlenc#EncryptedKey"
                                      URI="#id-OlT01t8FNBO2pIuB8ba-IlZ10dYXJEIgkMyiSOiZ"
                                      />
            </KeyInfo>
            <xenc:CipherData>
                <xenc:CipherValue>WNCrzgQXVzhAJ61coe4qClUi8hyZVUQ8Z...</xenc:CipherValue>
            </xenc:CipherData>
        </xenc:EncryptedData>
        <xenc:EncryptedKey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
                           Id="id-OlT01t8FNBO2pIuB8ba-IlZ10dYXJEIgkMyiSOiZ"
                           >
            <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
            <dsig:KeyInfo>
                <dsig:X509Data>
                    <dsig:X509Certificate>MIIDNDCCAhygAwIBAgIQhNtIL...</dsig:X509Certificate>
                </dsig:X509Data>
            </dsig:KeyInfo>
            <xenc:CipherData>
                <xenc:CipherValue>R5usMrow6yS8ulpX0HApH/ExWk...</xenc:CipherValue>
            </xenc:CipherData>
            <xenc:ReferenceList>
                <xenc:DataReference URI="#id-a7DCb68sppndtm1EJHGc7tGXeaybYZqovq6DSXUP" />
            </xenc:ReferenceList>
        </xenc:EncryptedKey>
    </saml20:EncryptedAssertion>
</samlp:Response>

此 SAML 响应不是正确的 SAML?使用库 1.2.2,接受了相同的 SAML 响应。为什么使用 4.0.5 库时不接受?

请帮忙。嗯,谢谢。DM

标签: c#.netmodel-view-controllersaml-2.0itfoxtec-identity-saml2

解决方案


一般来说,新的ITfoxtec Identity SAML库比旧库更具限制性和安全性。

解密的 SAML Authn 响应看起来是正确的。

要进行故障排除:

  • 解密证书是否配置config.DecryptionCertificate了私钥?
  • 在异常之后,方法binding.XmlDocument.OuterXml中的AuthController.AssertionConsumerService然后被解密了吗?

如果应该在引发异常的地方解密 中的 XML binding.XmlDocument.OuterXml,否则问题与解密有关。


推荐阅读