Skip to content

Commit 4e63121

Browse files
Andrew Mailletmcab
Andrew Maillet
authored andcommitted
feat: accept saml response with xml sig namespace at the root level
the xml dsig namespace can be specified at the root of the SAML response instead of on each Signature element. The canonincalized xml for the signature element requires that the namespace declaration be present on the siganture element.
1 parent b43eab4 commit 4e63121

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

lib/saml2.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ check_saml_signature = (_xml, certificate) ->
254254
return null unless signature.length is 1
255255
sig = new xmlcrypto.SignedXml()
256256
sig.keyInfoProvider = getKey: -> format_pem(certificate, 'CERTIFICATE')
257-
sig.loadSignature signature[0].toString()
257+
sig.loadSignature signature[0]
258258
valid = sig.checkSignature xml
259259
if valid
260260
return get_signed_data(doc, sig)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0"?>
2+
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" ID="pfxfaf187bb-5d8f-11ac-aee6-0d55a821cdfe" Version="2.0" InResponseTo="_1" Destination="https://sp.example.com/assert"><ds:Signature>
3+
<ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
4+
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
5+
<ds:Reference URI="#pfxfaf187bb-5d8f-11ac-aee6-0d55a821cdfe"><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/2000/09/xmldsig#sha1"/><ds:DigestValue>VmOQiP59NeSBPwrhe5MDQJlNw/E=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>pPycwjnj6ezRb9vrmEQ0CTBlkRa7inhDCHU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EFBQADggEBALhwpLS6C+97nWrEICI5yetQjexCJGltMESg1llNYjsbIuJ/S4XbrVzhN4nfNGMSbj8rb/9FT6TSru5QLjJQQmj38pqsWtEhR2vBLclqGqEcJfvPMdn1qAJhJfhrs0KUpsX6xFTnSkNoyGxCP8Wh2C1L0NL5r+x58lkma5vL6ncwWYY+0C3bt1XbBRdeOZHUwuYTIcD+BCNixQiNor7KjO1TzpOb6V3m1SKHu8idDM5fUcKooGbV3WuE7AJrAG5fvt59V9MtMPc2FklVFminfTeYKboEaxZJxuPDbQs2IyJ/0lI8P0Mv4LIKj4+OipQ/fGbZuE7cOioPKKl02dE7eCA=</ds:X509Certificate></ds:X509Data></ds:KeyInfo></ds:Signature>
7+
<samlp:Status>
8+
<samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
9+
</samlp:Status>
10+
<Assertion xmlns="urn:oasis:names:tc:SAML:2.0:assertion" ID="pfx676c4d46-c05b-c3ea-591e-4793d805ead6" IssueInstant="2014-03-12T21:35:05.392Z" Version="2.0">
11+
<Data ID="_5">This data has no meaning.</Data>
12+
<Issuer>http://idp.example.com/metadata.xml</Issuer><ds:Signature>
13+
<ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
14+
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
15+
<ds:Reference URI="#pfx676c4d46-c05b-c3ea-591e-4793d805ead6"><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/2000/09/xmldsig#sha1"/><ds:DigestValue>nS72XwOKD7SxpBrvb8MFkrmrPJM=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>cf4xvQneMFGQOsIgG/xrg8dpYbCvBZ5GUZkIMNA7BTT2tBuiP0djR/iS4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ICI5yetQjexCJGltMESg1llNYjsbIuJ/S4XbrVzhN4nfNGMSbj8rb/9FT6TSru5QLjJQQmj38pqsWtEhR2vBLclqGqEcJfvPMdn1qAJhJfhrs0KUpsX6xFTnSkNoyGxCP8Wh2C1L0NL5r+x58lkma5vL6ncwWYY+0C3bt1XbBRdeOZHUwuYTIcD+BCNixQiNor7KjO1TzpOb6V3m1SKHu8idDM5fUcKooGbV3WuE7AJrAG5fvt59V9MtMPc2FklVFminfTeYKboEaxZJxuPDbQs2IyJ/0lI8P0Mv4LIKj4+OipQ/fGbZuE7cOioPKKl02dE7eCA=</ds:X509Certificate></ds:X509Data></ds:KeyInfo></ds:Signature>
17+
<Subject>
18+
<NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient">tstudent</NameID>
19+
<SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
20+
<SubjectConfirmationData InResponseTo="_4" NotOnOrAfter="2014-03-12T21:40:05.392Z" Recipient="https://sp.example.com/assert"/>
21+
</SubjectConfirmation>
22+
</Subject>
23+
<Conditions NotBefore="2014-03-12T21:35:05.387Z" NotOnOrAfter="2014-03-12T22:35:05.387Z">
24+
<AudienceRestriction>
25+
<Audience>https://sp.example.com/metadata.xml</Audience>
26+
</AudienceRestriction>
27+
</Conditions>
28+
<AttributeStatement>
29+
<Attribute Name="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname">
30+
<AttributeValue>Test</AttributeValue>
31+
</Attribute>
32+
</AttributeStatement>
33+
<AuthnStatement AuthnInstant="2014-03-12T21:35:05.354Z" SessionIndex="_3">
34+
<AuthnContext>
35+
<AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</AuthnContextClassRef>
36+
</AuthnContext>
37+
</AuthnStatement>
38+
</Assertion>
39+
</samlp:Response>

test/saml2.coffee

+4
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ describe 'saml2', ->
187187
it 'validates a Response signature when a signature also exists within the Assertion', ->
188188
assert.notEqual null, saml2.check_saml_signature(get_test_file("good_response_twice_signed.xml"), get_test_file("test.crt"))
189189

190+
it 'validates a Response signature when the dsig namespace is declared at the root level', ->
191+
result = saml2.check_saml_signature(get_test_file("good_response_twice_signed_dsig_ns_at_top.xml"), get_test_file("test.crt"))
192+
assert.notEqual null, result
193+
190194
describe 'check_status_success', =>
191195
it 'accepts a valid success status', =>
192196
assert saml2.check_status_success(@good_response_dom), "Did not get 'true' for valid response."

0 commit comments

Comments
 (0)