@@ -21,9 +21,9 @@ import (
2121 "github.com/russellhaering/gosaml2/types"
2222)
2323
24- //ErrParsing indicates that the value present in an assertion could not be
25- //parsed. It can be inspected for the specific tag name, the contents, and the
26- //intended type.
24+ // ErrParsing indicates that the value present in an assertion could not be
25+ // parsed. It can be inspected for the specific tag name, the contents, and the
26+ // intended type.
2727type ErrParsing struct {
2828 Tag , Value , Type string
2929}
@@ -32,14 +32,14 @@ func (ep ErrParsing) Error() string {
3232 return fmt .Sprintf ("Error parsing %s tag value as type %s" , ep .Tag , ep .Value )
3333}
3434
35- //Oft-used messages
35+ // Oft-used messages
3636const (
3737 ReasonUnsupported = "Unsupported"
3838 ReasonExpired = "Expired"
3939)
4040
41- //ErrInvalidValue indicates that the expected value did not match the received
42- //value.
41+ // ErrInvalidValue indicates that the expected value did not match the received
42+ // value.
4343type ErrInvalidValue struct {
4444 Key , Expected , Actual string
4545 Reason string
@@ -52,13 +52,13 @@ func (e ErrInvalidValue) Error() string {
5252 return fmt .Sprintf ("%s %s value, Expected: %s, Actual: %s" , e .Reason , e .Key , e .Expected , e .Actual )
5353}
5454
55- //Well-known methods of subject confirmation
55+ // Well-known methods of subject confirmation
5656const (
5757 SubjMethodBearer = "urn:oasis:names:tc:SAML:2.0:cm:bearer"
5858)
5959
60- //VerifyAssertionConditions inspects an assertion element and makes sure that
61- //all SAML2 contracts are upheld.
60+ // VerifyAssertionConditions inspects an assertion element and makes sure that
61+ // all SAML2 contracts are upheld.
6262func (sp * SAMLServiceProvider ) VerifyAssertionConditions (assertion * types.Assertion ) (* WarningInfo , error ) {
6363 warningInfo := & WarningInfo {}
6464 now := sp .Clock .Now ()
@@ -77,7 +77,9 @@ func (sp *SAMLServiceProvider) VerifyAssertionConditions(assertion *types.Assert
7777 return nil , ErrParsing {Tag : NotBeforeAttr , Value : conditions .NotBefore , Type : "time.RFC3339" }
7878 }
7979
80- if now .Before (notBefore ) {
80+ allowedSkew := sp .AllowClockSkew
81+
82+ if now .Before (notBefore .Add (- allowedSkew )) {
8183 warningInfo .InvalidTime = true
8284 }
8385
@@ -90,7 +92,7 @@ func (sp *SAMLServiceProvider) VerifyAssertionConditions(assertion *types.Assert
9092 return nil , ErrParsing {Tag : NotOnOrAfterAttr , Value : conditions .NotOnOrAfter , Type : "time.RFC3339" }
9193 }
9294
93- if now .After (notOnOrAfter ) {
95+ if now .After (notOnOrAfter . Add ( allowedSkew ) ) {
9496 warningInfo .InvalidTime = true
9597 }
9698
@@ -131,8 +133,8 @@ func (sp *SAMLServiceProvider) VerifyAssertionConditions(assertion *types.Assert
131133 return warningInfo , nil
132134}
133135
134- //Validate ensures that the assertion passed is valid for the current Service
135- //Provider.
136+ // Validate ensures that the assertion passed is valid for the current Service
137+ // Provider.
136138func (sp * SAMLServiceProvider ) Validate (response * types.Response ) error {
137139 err := sp .validateResponseAttributes (response )
138140 if err != nil {
0 commit comments