Skip to content

Commit

Permalink
Merge pull request #142 from nats-io/self-signed
Browse files Browse the repository at this point in the history
op.DidSign(op) was broken when strict sk usage was enforced
  • Loading branch information
matthiashanel committed Jan 29, 2021
2 parents 598d91f + 205ee9f commit f3ef7d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion v2/operator_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func NewOperatorClaims(subject string) *OperatorClaims {
}
c := &OperatorClaims{}
c.Subject = subject
c.Issuer = subject
return c
}

Expand All @@ -176,7 +177,10 @@ func (oc *OperatorClaims) DidSign(op Claims) bool {
}
issuer := op.Claims().Issuer
if issuer == oc.Subject {
return !oc.StrictSigningKeyUsage
if !oc.StrictSigningKeyUsage {
return true
}
return op.Claims().Subject == oc.Subject
}
return oc.SigningKeys.Contains(issuer)
}
Expand Down
6 changes: 6 additions & 0 deletions v2/operator_claims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ func TestSignedBy(t *testing.T) {
AssertEquals(uc2.DidSign(ac), true, t) // actual key
uc.SigningKeys.Add(publicKey(ckp2, t))
AssertEquals(uc.DidSign(ac), true, t) // signing key
uc.StrictSigningKeyUsage = true
AssertEquals(uc.DidSign(uc), true, t)
AssertEquals(uc.DidSign(ac), true, t)
uc2.StrictSigningKeyUsage = true
AssertEquals(uc2.DidSign(uc2), true, t)
AssertEquals(uc2.DidSign(ac), false, t)
}

func testAccountWithAccountServerURL(t *testing.T, u string) error {
Expand Down

0 comments on commit f3ef7d6

Please sign in to comment.