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

connector/saml: clean up SAML verification logic and comments #898

Merged
merged 1 commit into from
Apr 7, 2017

Conversation

ericchiang
Copy link
Contributor

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

//
// * 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incomplete sentence.

@@ -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,
Copy link
Contributor

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,"

@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

varous --> various?

@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensure --> ensures

}
if !validSubjectConfirmation {
return fmt.Errorf("no valid SubjectConfirmation was found on this Response")
if len(errs) == 1 {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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."

Copy link
Contributor

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)
}
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@@ -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"`
Copy link
Contributor

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"?

Copy link
Contributor Author

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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok got it

@ericchiang ericchiang force-pushed the saml-cleanup branch 2 times, most recently from 9896542 to 4d8441c Compare April 7, 2017 20:49
@ericchiang
Copy link
Contributor Author

@rithujohn191 tests added.

Copy link
Contributor

@rithujohn191 rithujohn191 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ericchiang ericchiang merged commit 943253f into dexidp:master Apr 7, 2017
@ericchiang ericchiang deleted the saml-cleanup branch April 7, 2017 21:22
mmrath pushed a commit to mmrath/dex that referenced this pull request Sep 2, 2019
connector/saml: clean up SAML verification logic and comments
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