-
Notifications
You must be signed in to change notification settings - Fork 45
Add support for SAML 1 Tokens #12
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
Open
kcdragon
wants to merge
2
commits into
kbeckman:development
Choose a base branch
from
kcdragon:feature-saml-1
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module OmniAuth | ||
module Strategies | ||
class WSFed | ||
class SAML1Token | ||
|
||
attr_accessor :document | ||
|
||
def initialize(document) | ||
@document = document | ||
end | ||
|
||
def audience | ||
applies_to = REXML::XPath.first(document, '//t:RequestSecurityTokenResponse/wsp:AppliesTo', { 't' => WS_TRUST, 'wsp' => WS_POLICY }) | ||
REXML::XPath.first(applies_to, '//wsa:EndpointReference/wsa:Address').text | ||
end | ||
|
||
def issuer | ||
REXML::XPath.first(document, '//saml:Assertion').attributes['Issuer'] | ||
end | ||
|
||
def claims | ||
stmt_element = REXML::XPath.first(document, '//saml:Assertion/saml:AttributeStatement') | ||
|
||
return {} if stmt_element.nil? | ||
|
||
{}.tap do |result| | ||
stmt_element.each_element('saml:Attribute') do |attr_element| | ||
name = attr_element.attributes['AttributeName'] | ||
|
||
if attr_element.elements.count > 1 | ||
value = [] | ||
attr_element.elements.each { |element| value << element.text } | ||
else | ||
value = attr_element.elements.first.text.lstrip.rstrip | ||
end | ||
|
||
result[name] = value | ||
end | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module OmniAuth | ||
module Strategies | ||
class WSFed | ||
class SAML2Token | ||
|
||
attr_accessor :document | ||
|
||
def initialize(document) | ||
@document = document | ||
end | ||
|
||
def audience | ||
applies_to = REXML::XPath.first(document, '//t:RequestSecurityTokenResponse/wsp:AppliesTo', { 't' => WS_TRUST, 'wsp' => WS_POLICY }) | ||
REXML::XPath.first(applies_to, '//EndpointReference/Address').text | ||
end | ||
|
||
def issuer | ||
REXML::XPath.first(document, '//Assertion/Issuer').text | ||
end | ||
|
||
def claims | ||
stmt_element = REXML::XPath.first(document, '//Assertion/AttributeStatement') | ||
|
||
return {} if stmt_element.nil? | ||
|
||
{}.tap do |result| | ||
stmt_element.elements.each do |attr_element| | ||
name = attr_element.attributes['Name'] | ||
|
||
if attr_element.elements.count > 1 | ||
value = [] | ||
attr_element.elements.each { |element| value << element.text } | ||
else | ||
value = attr_element.elements.first.text.lstrip.rstrip | ||
end | ||
|
||
result[name] = value | ||
end | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,11 +39,13 @@ module XMLSecurity | |
class SignedDocument < REXML::Document | ||
DSIG = "http://www.w3.org/2000/09/xmldsig#" | ||
|
||
attr_accessor :signed_element_id | ||
attr_accessor :signed_element_id, :settings | ||
|
||
def initialize(response) | ||
def initialize(response, settings = {}) | ||
super(response) | ||
extract_signed_element_id | ||
|
||
self.settings = settings | ||
end | ||
|
||
def validate(idp_cert_fingerprint, soft = true) | ||
|
@@ -80,9 +82,11 @@ def validate_doc(base64_cert, soft = true) | |
sig_element.remove | ||
|
||
# check digests | ||
saml_version = settings[:saml_version] | ||
REXML::XPath.each(sig_element, "//ds:Reference", {"ds"=>DSIG}) do |ref| | ||
uri = ref.attributes.get_attribute("URI").value | ||
hashed_element = REXML::XPath.first(self, "//[@ID='#{uri[1,uri.size]}']") | ||
id = saml_version == '1' ? 'AssertionID' : 'ID' | ||
hashed_element = REXML::XPath.first(self, "//[@#{id}='#{uri[1,uri.size]}']") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that checking both would be the fastest way to solve this hashed_element = \
REXML::XPath.first(self, "//[@ID='#{uri[1,uri.size]}']") ||
REXML::XPath.first(self, "//[@AssertionID='#{uri[1,uri.size]}']") |
||
canoner = XML::Util::XmlCanonicalizer.new(false, true) | ||
canoner.inclusive_namespaces = inclusive_namespaces if canoner.respond_to?(:inclusive_namespaces) && !inclusive_namespaces.empty? | ||
canon_hashed_element = canoner.canonicalize(hashed_element) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<t:RequestSecurityTokenResponse xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust"> | ||
<t:Lifetime> | ||
<wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2014-06-27T19:45:38.263Z</wsu:Created> | ||
<wsu:Expires xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2014-06-27T20:45:38.263Z</wsu:Expires> | ||
</t:Lifetime> | ||
<wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> | ||
<wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/08/addressing"> | ||
<wsa:Address>http://rp.coding4streetcred.com/sample</wsa:Address> | ||
</wsa:EndpointReference> | ||
</wsp:AppliesTo> | ||
<t:RequestedSecurityToken> | ||
<saml:Assertion MajorVersion="1" MinorVersion="1" AssertionID="_fa0de02b-b5a1-49c5-a8c0-4b391295a789" Issuer="https://c4sc-identity.accesscontrol.windows.net/" IssueInstant="2014-06-27T19:45:38.263Z" xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion"> | ||
<saml:Conditions NotBefore="2014-06-27T19:45:38.263Z" NotOnOrAfter="2014-06-27T20:45:38.263Z"> | ||
<saml:AudienceRestrictionCondition> | ||
<saml:Audience>https://c4sc-identity.accesscontrol.windows.net</saml:Audience> | ||
</saml:AudienceRestrictionCondition> | ||
</saml:Conditions> | ||
<saml:AttributeStatement> | ||
<saml:Subject> | ||
<saml:SubjectConfirmation> | ||
<saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</saml:ConfirmationMethod> | ||
</saml:SubjectConfirmation> | ||
</saml:Subject> | ||
<saml:Attribute AttributeName="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" AttributeNamespace="http://schemas.xmlsoap.org/ws/2005/05/identity/claims"> | ||
<saml:AttributeValue>[email protected]</saml:AttributeValue> | ||
</saml:Attribute> | ||
<saml:Attribute AttributeName="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name" AttributeNamespace="http://schemas.microsoft.com/ws/2008/06/identity/claims"> | ||
<saml:AttributeValue>kbeckman.c4sc</saml:AttributeValue> | ||
</saml:Attribute> | ||
<saml:Attribute AttributeName="http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider" AttributeNamespace="http://schemas.xmlsoap.org/ws/2005/05/identity/claims"> | ||
<saml:AttributeValue>http://identity.c4sc.com/trust/</saml:AttributeValue> | ||
</saml:Attribute> | ||
</saml:AttributeStatement> | ||
<saml:AuthenticationStatement AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password" AuthenticationInstant="2014-06-27T19:45:38.232Z"> | ||
<saml:Subject> | ||
<saml:SubjectConfirmation> | ||
<saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</saml:ConfirmationMethod> | ||
</saml:SubjectConfirmation> | ||
</saml:Subject> | ||
</saml:AuthenticationStatement> | ||
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> | ||
<ds:SignedInfo> | ||
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /> | ||
<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" /> | ||
<ds:Reference URI="#_fa0de02b-b5a1-49c5-a8c0-4b391295a789"> | ||
<ds:Transforms> | ||
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /> | ||
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /> | ||
</ds:Transforms> | ||
<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" /> | ||
<ds:DigestValue>bdwpOR25Tiw03Y5gZsz/NDSrN2T1XAEUQl9/B2aDVjs=</ds:DigestValue> | ||
</ds:Reference> | ||
</ds:SignedInfo> | ||
<ds:SignatureValue>O3dJ5YtFIJJHk8SKAqdI2goSJUj7/oZebGwrm5yjVz8WT9TdHfJT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YJKoZIhvcNAQEFBQADggEBAB2RNPpJMNotdKMKtQkV/tEhttOOq+bXlMa42UQu6r+ikgJ6WcSecBxOs4KHw3lj7wO0l8CIOfvXy5KBePLQsUuk8tWCdKdpa+7uuGntIHdlTAvjlcVhXXAQQvyS+wUbnwj8rCN85e76EWMWCAVXzqwMURt5Rzmb+SdU40hRi+7u+HmZaQW5kDXD3CIm+1eOU7oyWpz6Ltx1DEJ88qt4xB2e6IGQUTdvq2jUnyzC1f9jdtRtZ3LiiVkA29rfRROJQb/PeEinUON0hP7/6VS9LZPL4vB1EIOBNahY1V4/75Hb+NGzb05w71hMUiJK2eu8w1WwqcRqUlu7GI921Od1oFQ=</X509Certificate> | ||
</X509Data> | ||
</KeyInfo> | ||
</ds:Signature> | ||
</saml:Assertion> | ||
</t:RequestedSecurityToken> | ||
<t:TokenType>urn:oasis:names:tc:SAML:1.0:assertion</t:TokenType> | ||
<t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType> | ||
<t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey</t:KeyType> | ||
</t:RequestSecurityTokenResponse> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you set
saml_version
as integer, this will not work, it would be better tocase settings[:saml_version].to_s