-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
connector/saml: clean up SAML verification logic and comments #898
Conversation
connector/saml/saml.go
Outdated
// | ||
// * Verify signature on XML document (or verify sig on assertion elements). | ||
// * Verify various parts of the Assertion element. Conditions, audience, etc. | ||
// * Map the Assertion's attribute elements to |
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.
Incomplete sentence.
connector/saml/saml.go
Outdated
@@ -315,16 +329,25 @@ func (p *provider) HandlePOST(s connector.Scopes, samlResponse, inResponseTo str | |||
if assertion == nil { | |||
return ident, fmt.Errorf("response did not contain an assertion") | |||
} | |||
|
|||
// Even though subject is optional, without it we can pull the user ID, |
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.
"Even though subject is optional, without it we can --> cannot pull the user ID,"
connector/saml/saml.go
Outdated
@@ -336,53 +359,57 @@ func (p *provider) HandlePOST(s connector.Scopes, samlResponse, inResponseTo str | |||
return ident, fmt.Errorf("subject does not contain an NameID element") | |||
} | |||
|
|||
// After verifying the assertion, map data in the attribute statements to | |||
// varous user info. |
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.
varous --> various?
connector/saml/saml.go
Outdated
@@ -396,96 +423,105 @@ func (p *provider) validateStatus(resp *response) error { | |||
return nil | |||
} | |||
|
|||
// Multiple subject SubjectConfirmation can be in the assertion | |||
// and at least one SubjectConfirmation must be valid. | |||
// validateSubject ensure the response is to the request we expect. |
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.
ensure --> ensures
connector/saml/saml.go
Outdated
} | ||
if !validSubjectConfirmation { | ||
return fmt.Errorf("no valid SubjectConfirmation was found on this Response") | ||
if len(errs) == 1 { |
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.
Can this value never be greater than 1?
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.
it's either going to be 1 or greater than 1.
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.
Should we change the condition to if len(errs) >= 1
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.
that's handled by the next return. This is just saying "if there's only one element in the slice, return that element, rather than the entire slice."
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.
👍
@@ -355,152 +354,3 @@ func TestVerifySignedMessageAndSignedAssertion(t *testing.T) { | |||
func TestVerifyUnsignedMessageAndUnsignedAssertion(t *testing.T) { | |||
runVerify(t, "testdata/idp-cert.pem", "testdata/idp-resp.xml", false) | |||
} |
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.
Are we planning to add other tests in its place?
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.
yes
connector/saml/types.go
Outdated
@@ -115,7 +116,7 @@ type conditions struct { | |||
NotBefore xmlTime `xml:"NotBefore,attr,omitempty"` | |||
NotOnOrAfter xmlTime `xml:"NotOnOrAfter,attr,omitempty"` | |||
|
|||
AudienceRestriction *audienceRestriction `xml:"AudienceRestriction,omitempty"` | |||
AudienceRestriction []*audienceRestriction `xml:"AudienceRestriction,omitempty"` |
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.
Is this one not meant to be an "attr"?
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.
It's an element, not an attribute. So the XML will look like
<SubjectConfirmationData InResponseTo="foo">
<AudienceRestriction>
</AudienceRestriction>
<AudienceRestriction>
</AudienceRestriction>
</SubjectConfirmationData>
(with a lot more namespace annotations)
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.
ah ok got it
9896542
to
4d8441c
Compare
@rithujohn191 tests added. |
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.
lgtm
connector/saml: clean up SAML verification logic and comments
Intention is to make this code a little more understandable. Clean up some loops, add comments, etc.
Will add a bunch of tests tomorrow.
cc @rithujohn191 @squat