Skip to content

Commit 2a6ae0a

Browse files
authored
Merge pull request #870 from Calpicow/fix_assertion_fallback
Fix assertion fallback
2 parents 5d49e18 + 6f9ef96 commit 2a6ae0a

File tree

14 files changed

+560
-266
lines changed

14 files changed

+560
-266
lines changed

connector/saml/saml.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/Sirupsen/logrus"
1818
"github.com/beevik/etree"
1919
dsig "github.com/russellhaering/goxmldsig"
20+
"github.com/russellhaering/goxmldsig/etreeutils"
2021

2122
"github.com/coreos/dex/connector"
2223
)
@@ -500,8 +501,9 @@ func verify(validator *dsig.ValidationContext, data []byte) (signed []byte, err
500501
verified = true
501502
doc.SetRoot(transformedResponse)
502503
}
503-
assertion := response.SelectElement("Assertion")
504-
if assertion == nil {
504+
// Ensures xmlns are copied down to the assertion element when they are defined in the root
505+
assertion, err := etreeutils.NSSelectOne(response, "urn:oasis:names:tc:SAML:2.0:assertion", "Assertion")
506+
if err != nil {
505507
return nil, fmt.Errorf("response does not contain an Assertion element")
506508
}
507509
transformedAssertion, err := validator.Validate(assertion)

connector/saml/saml_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ func TestVerify(t *testing.T) {
8686
runVerify(t, "testdata/okta-ca.pem", "testdata/okta-resp.xml", true)
8787
}
8888

89+
func TestVerifyUnsignedMessageAndSignedAssertionWithRootXmlNs(t *testing.T) {
90+
runVerify(t, "testdata/oam-ca.pem", "testdata/oam-resp.xml", true)
91+
}
92+
8993
func TestVerifySignedMessageAndUnsignedAssertion(t *testing.T) {
9094
runVerify(t, "testdata/idp-cert.pem", "testdata/idp-resp-signed-message.xml", true)
9195
}

connector/saml/testdata/oam-ca.pem

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIB/jCCAWegAwIBAgIBCjANBgkqhkiG9w0BAQQFADAkMSIwIAYDVQQDExlkZWFv
3+
YW0tZGV2MDIuanBsLm5hc2EuZ292MB4XDTE2MDYzMDA0NTQxNloXDTI2MDYyODA0
4+
NTQxNlowJDEiMCAGA1UEAxMZZGVhb2FtLWRldjAyLmpwbC5uYXNhLmdvdjCBnzAN
5+
BgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAht1N4lGdwUbl7YRyHwSCrnep6/e2I3+V
6+
eue0pSA/DGn8OuR/udM8UCja5utqlqJdq200ox4b4Mpz0Jg9kMckALtKe+1DgeES
7+
EIx9FpeuBdHlitYQNSbEr30HIG2nmeTOy4Vi5unBO54um3tNazcUTMA0/LJ6KQL8
8+
LeZSlB/IxwUCAwEAAaNAMD4wDAYDVR0TAQH/BAIwADAPBgNVHQ8BAf8EBQMDB9gA
9+
MB0GA1UdDgQWBBRYo1YjfrNonauLzj6/AsueWFGSszANBgkqhkiG9w0BAQQFAAOB
10+
gQACq7GHK/Zsg0+qC0WWa2ZjmOXE6Dqk/xuooG49QT7ihABs7k9U27Fw3xKF6MkC
11+
7pca1FwT82eZK1N3XKKpZe7Flu1fMKt2o/XSiBkDjWwUcChVnwGsUBe8hJFwFqg7
12+
olNJn1kaVBJUqZIiXF9kS0d+1H55rStOd0CNXAzp9utr2A==
13+
-----END CERTIFICATE-----

connector/saml/testdata/oam-resp.xml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<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="http://127.0.0.1:5556/callback" ID="id-IWlPTptSB-PlR80dwt8ZhVeG70mrz7nPvTVrhduK" InResponseTo="_e66b3a98-831c-4c96-5706-b63fe0549624" IssueInstant="2016-12-12T16:54:35Z" Version="2.0"><saml:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">https://deaoam-dev02.jpl.nasa.gov:14101/oam/fed</saml:Issuer><samlp:Status><samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/></samlp:Status><saml:Assertion ID="id-rT9rTqxdQC9j34YhVeNayUWC9EbIBgym6gp-MZt-" IssueInstant="2016-12-12T16:54:35Z" Version="2.0"><saml:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">https://deaoam-dev02.jpl.nasa.gov:14101/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/2000/09/xmldsig#rsa-sha1"/><dsig:Reference URI="#id-rT9rTqxdQC9j34YhVeNayUWC9EbIBgym6gp-MZt-"><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/2000/09/xmldsig#sha1"/><dsig:DigestValue>z1HD/59hv6UOd5+jeG+ihaFWLgI=</dsig:DigestValue></dsig:Reference></dsig:SignedInfo><dsig:SignatureValue>I99oG5kiOfIgbXYa21z/TOmzftTkFnXe9ObhBNSKit9kAhT93apYROqqXv4Ax96P144Ld7ERX1hgJsytK8LC2874Pk7QrSNm4zvW3x0D4GR4lM06CvJK/EhIur3TrCUJDPigvyP7TJitheCyBejwt0x0lqNP/OzR3tMbAIMRoho=</dsig:SignatureValue></dsig:Signature><saml:Subject><saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" NameQualifier="https://deaoam-dev02.jpl.nasa.gov:14101/oam/fed" SPNameQualifier="JSAuth">pkieu</saml:NameID><saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"><saml:SubjectConfirmationData InResponseTo="_e66b3a98-831c-4c96-5706-b63fe0549624" NotOnOrAfter="2016-12-12T16:59:35Z" Recipient="http://127.0.0.1:5556/callback"/></saml:SubjectConfirmation></saml:Subject><saml:Conditions NotBefore="2016-12-12T16:54:35Z" NotOnOrAfter="2016-12-12T16:59:35Z"><saml:AudienceRestriction><saml:Audience>JSAuth</saml:Audience></saml:AudienceRestriction></saml:Conditions><saml:AuthnStatement AuthnInstant="2016-12-12T16:54:10Z" SessionIndex="id-l3NCbxKoBfUZcuKhlotMuIF3ydgYJgGGG6BGTTU6" SessionNotOnOrAfter="2016-12-12T17:54:35Z"><saml:AuthnContext><saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef></saml:AuthnContext></saml:AuthnStatement></saml:Assertion></samlp:Response>

glide.lock

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import:
7373
- package: golang.org/x/oauth2
7474
version: 08c8d727d2392d18286f9f88ad775ad98f09ab33
7575
subpackages: []
76-
# The oauth2 package only imports the appengine code when it's given a
76+
# The oauth2 package only imports the appengine code when it's given a
7777
# specific build tags, but glide detects it anyway.
7878
#
7979
# https://github.com/golang/oauth2/blob/d5040cdd/client_appengine.go
@@ -133,7 +133,7 @@ import:
133133

134134
# XML signature validation for SAML connector
135135
- package: github.com/russellhaering/goxmldsig
136-
version: 51810e925e5fc495822fbddda8202f70a6e4a3f3
136+
version: eaac44c63fe007124f8f6255b09febc906784981
137137
- package: github.com/beevik/etree
138138
version: 4cd0dd976db869f817248477718071a28e978df0
139139
- package: github.com/jonboulle/clockwork

vendor/github.com/russellhaering/goxmldsig/canonicalize.go

+9-101
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/russellhaering/goxmldsig/etreeutils/canonicalize.go

+98
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)