2

Good day,

We used ITfoxtec library version 1.2.2. This solution worked correctly.

We are now integrating the version 4.0.5 library. We need to use SHA-256 encoding. We used the 4.0.5 library from Nugets. According to the implementation example https://github.com/ITfoxtec/ITfoxtec.Identity.Saml2.

The SAML request was sent successfully. Arrived SAML response. Exception is throw on the method AssertionConsumerService() in line binding.ReadSamlResponse(Request.ToGenericHttpRequest(), saml2AuthnResponse);.

Throw exception: ITfoxtec.Identity.Saml2.Saml2RequestException: 'There is not exactly one Assertion element.'

This is my SAML response:

<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>

This SAML response is not correct SAML? Using library 1.2.2, the same SAML response was accepted. Why is it not accepted when using the 4.0.5 library?

Please help. Well thank you. DM

2 Answers2

0

Generally the new ITfoxtec Identity SAML library is much more restrictive and secure then the old library.

The decrypted SAML Authn Response looks correct.

To troubleshoot:

  • Is the decryption certificate configured in config.DecryptionCertificate with the private key?
  • After the Exception, is the binding.XmlDocument.OuterXml in the AuthController.AssertionConsumerService method then decrypted?

If the the XML in the binding.XmlDocument.OuterXml should be decrypted at the point where the exceptions is thrown, otherwise there the problem is in relation to decryption.

Anders Revsgaard
  • 3,636
  • 1
  • 9
  • 25
  • 1
    Decrypted SAML from SAML Tracker tool contain "Assertion". But in the method "private XmlElement GetAssertionElementReference ()" contain "EncryptedAssertion". – Daniel Mudrák Jul 20 '20 at 13:49
0

This is decrypted SAML from SAML Tracker tool:

<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://zzz/saml/post/ac" ID="id-0v6rnx86H21iac3g666IWswoc2QDD-ECzGZ6FQNo" InResponseTo="_705c6a70-d335-496b-aa00-1f09760f5d6e" IssueInstant="2020-07-17T05:18:02Z" 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-0v6rnx86H21iac3g666IWswoc2QDD-ECzGZ6FQNo">
                <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>TJSWg8IdPf2dm3mmI7sllXWjPq3kmW7FjwWtMdr256I=</dsig:DigestValue>
            </dsig:Reference>
        </dsig:SignedInfo>
        <dsig:SignatureValue>i3cOo...</dsig:SignatureValue>
        <dsig:KeyInfo>
            <dsig:X509Data>
                <dsig:X509Certificate>MIIDUTCCA...</dsig:X509Certificate>
            </dsig:X509Data>
        </dsig:KeyInfo>
    </dsig:Signature>
    <samlp:Status>
        <samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
    </samlp:Status>
    <saml:Assertion ID="id-AVyUEGJACHdCqUGL4k1EzdEHhnPbwp31S44hFIwI" IssueInstant="2020-07-17T05:18:02Z" 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-AVyUEGJACHdCqUGL4k1EzdEHhnPbwp31S44hFIwI">
                    <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>53ThYIAb6b/K79YvgKijhlb+TE5OPJVUtHDjKrnp4Gc=</dsig:DigestValue>
                </dsig:Reference>
            </dsig:SignedInfo>
            <dsig:SignatureValue>EWGE0k4...</dsig:SignatureValue>
            <dsig:KeyInfo>
                <dsig:X509Data>
                    <dsig:X509Certificate>MIIDUTCC...</dsig:X509Certificate>
                </dsig:X509Data>
            </dsig:KeyInfo>
        </dsig:Signature>
        <saml:Subject>
            <saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient" NameQualifier="https://yyy/oam/fed" SPNameQualifier="http://xxx.sk">id-npAtUDygjM-XA-WWIIMK2sR9KkVgS-rj7UMo8-Pi</saml:NameID>
            <saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
                <saml:SubjectConfirmationData InResponseTo="_705c6a70-d335-496b-aa00-1f09760f5d6e" NotOnOrAfter="2020-07-17T05:38:02Z" Recipient="https://zzz/saml/post/ac"/>
            </saml:SubjectConfirmation>
        </saml:Subject>
        <saml:Conditions NotBefore="2020-07-17T05:18:02Z" NotOnOrAfter="2020-07-17T05:38:02Z">
            <saml:AudienceRestriction>
                <saml:Audience>http://xxx.sk</saml:Audience>
            </saml:AudienceRestriction>
        </saml:Conditions>
        <saml:AuthnStatement AuthnInstant="2020-07-17T05:18:01Z" SessionIndex="id-sQ0oOmh3quTIgiosRU4SguBx957VEmXNJ8KGJI0M" SessionNotOnOrAfter="2020-07-17T05:38:02Z">
            <saml:AuthnContext>
                <saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef>
            </saml:AuthnContext>
        </saml:AuthnStatement>
        <saml:AttributeStatement>
            <saml:Attribute Name="SubjectIDSector" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
                <saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">SECTOR_DDD</saml:AttributeValue>
            </saml:Attribute>
            <saml:Attribute Name="Actor.AuthResourceType" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
                <saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">1</saml:AttributeValue>
            </saml:Attribute>
            <saml:Attribute Name="Actor.AuthResourceSubType" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
                <saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"/>
            </saml:Attribute>
            ...
        </saml:AttributeStatement>
    </saml:Assertion>
</samlp:Response>

But in the method "private XmlElement GetAssertionElementReference ()" is this SAML response (does not contain "Assertion"):

<samlp:Response xmlns:samlp="urn:oasis:namesSAML: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:namesSAML:2.0:assertion" xmlns:x500="urn:oasis:namesSAML:2.0:profiles:attribute:X500" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Destination="https://xxx/saml/post/ac" ID="id-8g-TC7zKiftlwjMuiPmvaaEaabPJr0pLnOthXlUEJE" InResponseTo="_7d3ab415-2c83-4f45-a5f9-2aa2d690c1fe" IssueInstant="2020-07-20T13:13:28Z" Version="2.0">
    <saml:Issuer Format="urn:oasis:namesSAML: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-8g-TC7zKiftlwjMuiPmvEbaaPJr0pLnOthXlUEJE">
                <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>eMPiWff...</dsig:DigestValue>
            </dsig:Reference>
        </dsig:SignedInfo>
        <dsig:SignatureValue>GEr6eKff...</dsig:SignatureValue>
        <dsig:KeyInfo>
            <dsig:X509Data>
                <dsig:X509Certificate>MIIDUTCCAjm...</dsig:X509Certificate>
            </dsig:X509Data>
        </dsig:KeyInfo>
    </dsig:Signature>
    <samlp:Status>
        <samlp:StatusCode Value="urn:oasis:namesSAML:2.0:status:Success" />
    </samlp:Status>
    <saml20:EncryptedAssertion xmlns:saml20="urn:oasis:namesSAML:2.0:assertion">
        <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Id="id-i9cF6A0M7-HLqav1DoaaqMrDlr20rUzeNL7fvq3S" 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-VmiCL-pXfnwU13AYHv-v9FSMaaZ3WPsjRGwk4MoD" />
            </KeyInfo>
            <xenc:CipherData>
                <xenc:CipherValue>dj2AfxCBA...</xenc:CipherValue>
            </xenc:CipherData>
        </xenc:EncryptedData>
        <xenc:EncryptedKey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Id="id-VmiCL-pXfnwU13AYHv-v9FSMmqZ3WPsjRGwk4MoD">
            <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
            <dsig:KeyInfo>
                <dsig:X509Data>
                    <dsig:X509Certificate>MIIDNDCCA...</dsig:X509Certificate>
                </dsig:X509Data>
            </dsig:KeyInfo>
            <xenc:CipherData>
                <xenc:CipherValue>DlGyVs...</xenc:CipherValue>
            </xenc:CipherData>
            <xenc:ReferenceList>
                <xenc:DataReference URI="#id-i9cF6A0M7-HLqav1Dot0qaaDlr20rUzeNL7fvq3S" />
            </xenc:ReferenceList>
        </xenc:EncryptedKey>
    </saml20:EncryptedAssertion>
</samlp:Response>