Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass full EncryptedAssertion node to decrypt #83

Merged
merged 2 commits into from
Sep 13, 2016
Merged

Pass full EncryptedAssertion node to decrypt #83

merged 2 commits into from
Sep 13, 2016

Conversation

sebreh
Copy link
Contributor

@sebreh sebreh commented Sep 11, 2016

When implementing SAML support with Okta as the IdP, I noticed they send encrypted assertions with the EncryptedKey node as a sibling to the EncryptedData node, not as a child node as expected by this library. Because only the EncryptedData node is passed to xmlenc.decrypt, it is unable to find the key referenced by URI from RetrievalMethod. Hence, it cannot determine the algorithm to use for decrypting the assertion.

example response:

<?xml version="1.0" encoding="UTF-8"?>
<saml2p:Response xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" ID="_2" Version="2.0" InResponseTo="_1" Destination="https://sp.example.com/assert">
  <saml2p:Status>
    <saml2p:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
  </saml2p:Status>
  <saml2:EncryptedAssertion xmlns:saml2="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#aes256-cbc" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"/>
      <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
        <ds:RetrievalMethod Type="http://www.w3.org/2001/04/xmlenc#EncryptedKey" URI="#_ad3ba8b1e8dbca2bb43001b189b0bc7c"/>
      </ds:KeyInfo>
      ...
    </xenc:EncryptedData>
    <xenc:EncryptedKey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Id="_ad3ba8b1e8dbca2bb43001b189b0bc7c">
      <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"/>
      ...
    </xenc:EncryptedKey>
  </saml2:EncryptedAssertion>
</saml2p:Response>

This fixes the issue by passing the full EncryptedAssertion node to xmlenc.decrypt, and upgrading the xml-encryption to include changes for improved algorithm detection.

This fixes an issue where some IDP responses (e.g. Okta) includes the EncryptedKey node as a sibling to EncryptedData instead of as a child.
@jefff
Copy link
Contributor

jefff commented Sep 13, 2016

Thanks for the PR! This lgtm.

@jefff jefff merged commit 07f6a7c into Clever:master Sep 13, 2016
@jefff
Copy link
Contributor

jefff commented Sep 13, 2016

Published as 1.10.0.

@sebreh
Copy link
Contributor Author

sebreh commented Sep 13, 2016

Awesome, thanks for the quick merge/publish 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants