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

node: Validate session tokens attached to objects #2731

Merged
merged 1 commit into from
Jan 25, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Changelog for NeoFS Node
- IR compares and logs public keys difference, not hash of keys difference at SN verification check (#2711)
- Incorrect handling of notary request leading to inability to collect signatures in some cases (#2715)
- Deadlock in autodeploy routine (#2720)
- SN now validates session tokens attached to objects (#1159)

### Changed
- Created files are not group writable (#2589)
Expand Down
17 changes: 16 additions & 1 deletion pkg/core/object/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,22 @@
return errors.New("missing signature")
}

// FIXME: #1159 perform token verification
token := obj.SessionToken()
if token == nil {
return nil
}

if !token.AssertAuthKey(sig.PublicKey()) {
return errors.New("session token is not for object's signer")

Check warning on line 146 in pkg/core/object/fmt.go

View check run for this annotation

Codecov / codecov/patch

pkg/core/object/fmt.go#L146

Added line #L146 was not covered by tests
}

if !token.VerifySignature() {
return errors.New("incorrect session token signature")

Check warning on line 150 in pkg/core/object/fmt.go

View check run for this annotation

Codecov / codecov/patch

pkg/core/object/fmt.go#L150

Added line #L150 was not covered by tests
}

if issuer, owner := token.Issuer(), obj.OwnerID(); !issuer.Equals(*owner) { // nil check was performed above
return fmt.Errorf("different object owner %s and session issuer %s", owner, issuer)

Check warning on line 154 in pkg/core/object/fmt.go

View check run for this annotation

Codecov / codecov/patch

pkg/core/object/fmt.go#L154

Added line #L154 was not covered by tests
}

return nil
}
Expand Down
44 changes: 41 additions & 3 deletions pkg/core/object/fmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (

"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto"
neofsecdsa "github.com/nspcc-dev/neofs-sdk-go/crypto/ecdsa"
"github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
sessiontest "github.com/nspcc-dev/neofs-sdk-go/session/test"
"github.com/nspcc-dev/neofs-sdk-go/storagegroup"
"github.com/nspcc-dev/neofs-sdk-go/user"
usertest "github.com/nspcc-dev/neofs-sdk-go/user/test"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -89,16 +90,53 @@ func TestFormatValidator_Validate(t *testing.T) {

obj := object.New()
obj.SetContainerID(cidtest.ID())
tok := sessiontest.ObjectSigned(signer)
tok := sessiontest.Object()
tok.SetAuthKey((*neofsecdsa.PublicKey)(&ownerKey.PrivateKey.PublicKey))
require.NoError(t, tok.Sign(signer))
obj.SetSessionToken(&tok)
owner := usertest.ID(t)
owner := signer.UserID()
obj.SetOwnerID(&owner)

require.NoError(t, obj.SetIDWithSignature(signer))

require.NoError(t, v.Validate(obj, false))
})

t.Run("incorrect session token", func(t *testing.T) {
signer := user.NewAutoIDSignerRFC6979(ownerKey.PrivateKey)

obj := object.New()
obj.SetContainerID(cidtest.ID())
tok := sessiontest.ObjectSigned(signer)
obj.SetSessionToken(&tok)
owner := signer.UserID()
obj.SetOwnerID(&owner)

t.Run("wrong signature", func(t *testing.T) {
require.NoError(t, obj.SetIDWithSignature(signer))

obj.SetSignature(&neofscrypto.Signature{})
require.Error(t, v.Validate(obj, false))
})

t.Run("wrong owner", func(t *testing.T) {
obj.SetOwnerID(&user.ID{})

require.NoError(t, obj.SetIDWithSignature(signer))
require.Error(t, v.Validate(obj, false))
})

t.Run("wrong signer", func(t *testing.T) {
wrongOwner, err := keys.NewPrivateKey()
require.NoError(t, err)

wrongSigner := user.NewAutoIDSignerRFC6979(wrongOwner.PrivateKey)

require.NoError(t, obj.SetIDWithSignature(wrongSigner))
require.Error(t, v.Validate(obj, false))
})
})

t.Run("correct w/o session token", func(t *testing.T) {
signer := user.NewAutoIDSigner(ownerKey.PrivateKey)
obj := blankValidObject(signer)
Expand Down
Loading