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

[Fixed] import token validation: validate activation/allow signing keys #124

Merged
merged 1 commit into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions v2/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,14 @@ func (i *Import) Validate(actPubKey string, vr *ValidationResults) {
}

if act != nil {
if act.Issuer != i.Account {
vr.AddWarning("activation token doesn't match account for import %q", i.Subject)
if !(act.Issuer == i.Account || act.IssuerAccount == i.Account) {
vr.AddError("activation token doesn't match account for import %q", i.Subject)
}

if act.ClaimsData.Subject != actPubKey {
vr.AddWarning("activation token doesn't match account it is being included in, %q", i.Subject)
vr.AddError("activation token doesn't match account it is being included in, %q", i.Subject)
}
act.Validate(vr)
} else {
vr.AddWarning("no activation provided for import %s", i.Subject)
}
Expand Down
60 changes: 60 additions & 0 deletions v2/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,66 @@ func TestImportValidation(t *testing.T) {
}
}

func TestImportValidationExpiredToken(t *testing.T) {
ak := createAccountNKey(t)
ak2 := createAccountNKey(t)
akp := publicKey(ak, t)
akp2 := publicKey(ak2, t)
i := &Import{Subject: "test", Account: akp2, To: "bar", Type: Stream}

activation := NewActivationClaims(akp)
activation.Expires = time.Now().Add(-time.Hour).UTC().Unix()
activation.ImportSubject = "test"
activation.ImportType = Stream
i.Token = encode(activation, ak2, t)
vr := CreateValidationResults()
i.Validate(akp, vr)
if vr.IsEmpty() || !vr.IsBlocking(true) || vr.IsBlocking(false) {
t.Errorf("Expired token needs to result in a time check error")
}
}

func TestImportValidationDifferentAccount(t *testing.T) {
ak := createAccountNKey(t)
ak2 := createAccountNKey(t)
akp := publicKey(ak, t)
akp2 := publicKey(ak2, t)
otherAccount := publicKey(createAccountNKey(t), t)
i := &Import{Subject: "test", Account: akp2, To: "bar", Type: Stream}

activation := NewActivationClaims(otherAccount)
activation.Expires = time.Now().Add(-time.Hour).UTC().Unix()
activation.ImportSubject = "test"
activation.ImportType = Stream
i.Token = encode(activation, ak2, t)
vr := CreateValidationResults()
i.Validate(akp, vr)
if vr.IsEmpty() || !vr.IsBlocking(false) {
t.Errorf("Expired import needs to result in a time check error")
}
}

func TestImportValidationSigningKey(t *testing.T) {
ak := createAccountNKey(t)
ak2 := createAccountNKey(t)
ak2Sk := createAccountNKey(t)
akp := publicKey(ak, t)
akp2 := publicKey(ak2, t)
i := &Import{Subject: "test", Account: akp2, To: "bar", Type: Stream}

activation := NewActivationClaims(akp)
activation.Expires = time.Now().Add(time.Hour).UTC().Unix()
activation.ImportSubject = "test"
activation.ImportType = Stream
activation.IssuerAccount = akp2
i.Token = encode(activation, ak2Sk, t)
vr := CreateValidationResults()
i.Validate(akp, vr)
if !vr.IsEmpty() {
t.Errorf("Expired import needs to not result in an error")
}
}

func TestInvalidImportType(t *testing.T) {
ak := createAccountNKey(t)
akp := publicKey(ak, t)
Expand Down