Skip to content

Commit

Permalink
satellite/metabase: use storj.Nonce instead []byte
Browse files Browse the repository at this point in the history
We were using mixed types for nonce fields. Protobuf
have storj.Nonce, metabase have []byte. This change
is a refactoring to have everywere its possible only
storj.Nonce.

Change-Id: Id54bd8481f30c721cdaf3df79206d25e7cfdab55
  • Loading branch information
mniewrzal committed Oct 11, 2021
1 parent b7405db commit 1ef06fa
Show file tree
Hide file tree
Showing 33 changed files with 175 additions and 197 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ require (
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/segmentio/analytics-go.v3 v3.1.0
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
storj.io/common v0.0.0-20210928143209-230bee624465
storj.io/common v0.0.0-20210930095923-69f9cd032051
storj.io/drpc v0.0.26
storj.io/monkit-jaeger v0.0.0-20210426161729-debb1cbcbbd7
storj.io/private v0.0.0-20210810102517-434aeab3f17d
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,8 @@ sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3
storj.io/common v0.0.0-20200424175742-65ac59022f4f/go.mod h1:pZyXiIE7bGETIRXtfs0nICqMwp7PM8HqnDuyUeldNA0=
storj.io/common v0.0.0-20210805073808-8e0feb09e92a/go.mod h1:mhZYWpTojKsACxWE66RfXNz19zbyr/uEDVWHJH8dHog=
storj.io/common v0.0.0-20210916151047-6aaeb34bb916/go.mod h1:objobGrIWQwhmTSpSm6Y7ykd40wZjB7CezNfic5YLKg=
storj.io/common v0.0.0-20210928143209-230bee624465 h1:sEVHROo+9i7+Sl3zuR8OKQnykJ2MmPMsRygjvUkiBns=
storj.io/common v0.0.0-20210928143209-230bee624465/go.mod h1:objobGrIWQwhmTSpSm6Y7ykd40wZjB7CezNfic5YLKg=
storj.io/common v0.0.0-20210930095923-69f9cd032051 h1:dZquqe+DsSdqTnIcoXCVMa5hpAg04cnI9PsTXNWjfPQ=
storj.io/common v0.0.0-20210930095923-69f9cd032051/go.mod h1:objobGrIWQwhmTSpSm6Y7ykd40wZjB7CezNfic5YLKg=
storj.io/drpc v0.0.11/go.mod h1:TiFc2obNjL9/3isMW1Rpxjy8V9uE0B2HMeMFGiiI7Iw=
storj.io/drpc v0.0.24/go.mod h1:ofQUDPQbbIymRDKE0tms48k8bLP5Y+dsI9CbXGv3gko=
storj.io/drpc v0.0.26 h1:T6jJzjby7QUa/2XHR1qMxTCENpDHEw4/o+kfDfZQqQI=
Expand Down
2 changes: 1 addition & 1 deletion satellite/metabase/bench_expired_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (s *expiredScenario) run(ctx *testcontext.Context, b *testing.B, db *metaba

segmentSize := testrand.Intn(64*memory.MiB.Int()) + 1
encryptedKey := testrand.BytesInt(storj.KeySize)
encryptedKeyNonce := testrand.BytesInt(storj.NonceSize)
encryptedKeyNonce := testrand.Nonce()

err = db.CommitSegment(ctx, metabase.CommitSegment{
ObjectStream: objectStream,
Expand Down
4 changes: 2 additions & 2 deletions satellite/metabase/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (s *scenario) run(ctx *testcontext.Context, b *testing.B, db *metabase.DB)

segmentSize := testrand.Intn(64*memory.MiB.Int()) + 1
encryptedKey := testrand.BytesInt(storj.KeySize)
encryptedKeyNonce := testrand.BytesInt(storj.NonceSize)
encryptedKeyNonce := testrand.Nonce()

commitRemoteSegment.Record(func() {
err := db.CommitSegment(ctx, metabase.CommitSegment{
Expand All @@ -173,7 +173,7 @@ func (s *scenario) run(ctx *testcontext.Context, b *testing.B, db *metabase.DB)
segmentSize := testrand.Intn(4*memory.KiB.Int()) + 1
inlineData := testrand.BytesInt(segmentSize)
encryptedKey := testrand.BytesInt(storj.KeySize)
encryptedKeyNonce := testrand.BytesInt(storj.NonceSize)
encryptedKeyNonce := testrand.Nonce()

commitInlineSegment.Record(func() {
err := db.CommitInlineSegment(ctx, metabase.CommitInlineSegment{
Expand Down
10 changes: 5 additions & 5 deletions satellite/metabase/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ type CommitSegment struct {

ExpiresAt *time.Time

EncryptedKeyNonce []byte
EncryptedKeyNonce storj.Nonce
EncryptedKey []byte

PlainOffset int64 // offset in the original data stream
Expand Down Expand Up @@ -270,7 +270,7 @@ func (db *DB) CommitSegment(ctx context.Context, opts CommitSegment) (err error)
return ErrInvalidRequest.New("RootPieceID missing")
case len(opts.EncryptedKey) == 0:
return ErrInvalidRequest.New("EncryptedKey missing")
case len(opts.EncryptedKeyNonce) == 0:
case opts.EncryptedKeyNonce.IsZero():
return ErrInvalidRequest.New("EncryptedKeyNonce missing")
case opts.EncryptedSize <= 0:
return ErrInvalidRequest.New("EncryptedSize negative or zero")
Expand Down Expand Up @@ -344,7 +344,7 @@ type CommitInlineSegment struct {

ExpiresAt *time.Time

EncryptedKeyNonce []byte
EncryptedKeyNonce storj.Nonce
EncryptedKey []byte

PlainOffset int64 // offset in the original data stream
Expand All @@ -368,7 +368,7 @@ func (db *DB) CommitInlineSegment(ctx context.Context, opts CommitInlineSegment)
switch {
case len(opts.EncryptedKey) == 0:
return ErrInvalidRequest.New("EncryptedKey missing")
case len(opts.EncryptedKeyNonce) == 0:
case opts.EncryptedKeyNonce.IsZero():
return ErrInvalidRequest.New("EncryptedKeyNonce missing")
case opts.PlainSize <= 0 && validatePlainSize:
return ErrInvalidRequest.New("PlainSize negative or zero")
Expand Down Expand Up @@ -425,7 +425,7 @@ type CommitObject struct {
Encryption storj.EncryptionParameters

EncryptedMetadata []byte
EncryptedMetadataNonce []byte
EncryptedMetadataNonce storj.Nonce
EncryptedMetadataEncryptedKey []byte
}

Expand Down
2 changes: 1 addition & 1 deletion satellite/metabase/commit_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type CommitObjectWithSegments struct {
ObjectStream

EncryptedMetadata []byte
EncryptedMetadataNonce []byte
EncryptedMetadataNonce storj.Nonce
EncryptedMetadataEncryptedKey []byte

// TODO: this probably should use segment ranges rather than individual items
Expand Down
24 changes: 12 additions & 12 deletions satellite/metabase/commit_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func TestCommitObjectWithSegments(t *testing.T) {
Version: 5,
StreamID: obj.StreamID,
},
EncryptedMetadataNonce: encryptedMetadataNonce[:],
EncryptedMetadataNonce: encryptedMetadataNonce,
EncryptedMetadata: encryptedMetadata,
EncryptedMetadataEncryptedKey: encryptedMetadataKey,
},
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestCommitObjectWithSegments(t *testing.T) {
CreatedAt: now,
Status: metabase.Committed,

EncryptedMetadataNonce: encryptedMetadataNonce[:],
EncryptedMetadataNonce: encryptedMetadataNonce,
EncryptedMetadata: encryptedMetadata,
EncryptedMetadataEncryptedKey: encryptedMetadataKey,

Expand Down Expand Up @@ -228,13 +228,13 @@ func TestCommitObjectWithSegments(t *testing.T) {
rootPieceID00 := testrand.PieceID()
pieces00 := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
encryptedKey00 := testrand.Bytes(32)
encryptedKeyNonce00 := testrand.Bytes(32)
encryptedKeyNonce00 := testrand.Nonce()

pos01 := metabase.SegmentPosition{Part: 0, Index: 1}
rootPieceID01 := testrand.PieceID()
pieces01 := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
encryptedKey01 := testrand.Bytes(32)
encryptedKeyNonce01 := testrand.Bytes(32)
encryptedKeyNonce01 := testrand.Nonce()

metabasetest.CommitSegment{
Opts: metabase.CommitSegment{
Expand Down Expand Up @@ -336,12 +336,12 @@ func TestCommitObjectWithSegments(t *testing.T) {
pos00 := metabase.SegmentPosition{Part: 0, Index: 0}
data00 := testrand.Bytes(32)
encryptedKey00 := testrand.Bytes(32)
encryptedKeyNonce00 := testrand.Bytes(32)
encryptedKeyNonce00 := testrand.Nonce()

pos01 := metabase.SegmentPosition{Part: 0, Index: 1}
data01 := testrand.Bytes(1024)
encryptedKey01 := testrand.Bytes(32)
encryptedKeyNonce01 := testrand.Bytes(32)
encryptedKeyNonce01 := testrand.Nonce()

metabasetest.CommitInlineSegment{
Opts: metabase.CommitInlineSegment{
Expand Down Expand Up @@ -433,13 +433,13 @@ func TestCommitObjectWithSegments(t *testing.T) {
rootPieceID00 := testrand.PieceID()
pieces00 := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
encryptedKey00 := testrand.Bytes(32)
encryptedKeyNonce00 := testrand.Bytes(32)
encryptedKeyNonce00 := testrand.Nonce()

pos01 := metabase.SegmentPosition{Part: 0, Index: 1}
rootPieceID01 := testrand.PieceID()
pieces01 := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
encryptedKey01 := testrand.Bytes(32)
encryptedKeyNonce01 := testrand.Bytes(32)
encryptedKeyNonce01 := testrand.Nonce()

metabasetest.CommitSegment{
Opts: metabase.CommitSegment{
Expand Down Expand Up @@ -557,13 +557,13 @@ func TestCommitObjectWithSegments(t *testing.T) {
rootPieceID00 := testrand.PieceID()
pieces00 := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
encryptedKey00 := testrand.Bytes(32)
encryptedKeyNonce00 := testrand.Bytes(32)
encryptedKeyNonce00 := testrand.Nonce()

pos10 := metabase.SegmentPosition{Part: 1, Index: 0}
rootPieceID10 := testrand.PieceID()
pieces10 := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
encryptedKey10 := testrand.Bytes(32)
encryptedKeyNonce10 := testrand.Bytes(32)
encryptedKeyNonce10 := testrand.Nonce()

metabasetest.CommitSegment{
Opts: metabase.CommitSegment{
Expand Down Expand Up @@ -681,13 +681,13 @@ func TestCommitObjectWithSegments(t *testing.T) {
rootPieceID00 := testrand.PieceID()
pieces00 := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
encryptedKey00 := testrand.Bytes(32)
encryptedKeyNonce00 := testrand.Bytes(32)
encryptedKeyNonce00 := testrand.Nonce()

pos02 := metabase.SegmentPosition{Part: 0, Index: 2}
rootPieceID02 := testrand.PieceID()
pieces02 := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
encryptedKey02 := testrand.Bytes(32)
encryptedKeyNonce02 := testrand.Bytes(32)
encryptedKeyNonce02 := testrand.Nonce()

metabasetest.CommitSegment{
Opts: metabase.CommitSegment{
Expand Down
44 changes: 22 additions & 22 deletions satellite/metabase/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ func TestCommitSegment(t *testing.T) {
}},

EncryptedKey: testrand.Bytes(32),
EncryptedKeyNonce: testrand.Bytes(32),
EncryptedKeyNonce: testrand.Nonce(),

EncryptedSize: -1,
},
Expand All @@ -1019,7 +1019,7 @@ func TestCommitSegment(t *testing.T) {
}},

EncryptedKey: testrand.Bytes(32),
EncryptedKeyNonce: testrand.Bytes(32),
EncryptedKeyNonce: testrand.Nonce(),

EncryptedSize: 1024,
PlainSize: -1,
Expand All @@ -1040,7 +1040,7 @@ func TestCommitSegment(t *testing.T) {
}},

EncryptedKey: testrand.Bytes(32),
EncryptedKeyNonce: testrand.Bytes(32),
EncryptedKeyNonce: testrand.Nonce(),

EncryptedSize: 1024,
PlainSize: 512,
Expand All @@ -1061,7 +1061,7 @@ func TestCommitSegment(t *testing.T) {
}},

EncryptedKey: testrand.Bytes(32),
EncryptedKeyNonce: testrand.Bytes(32),
EncryptedKeyNonce: testrand.Nonce(),

EncryptedSize: 1024,
PlainSize: 512,
Expand All @@ -1087,7 +1087,7 @@ func TestCommitSegment(t *testing.T) {
RootPieceID: testrand.PieceID(),
Redundancy: redundancy,
EncryptedKey: testrand.Bytes(32),
EncryptedKeyNonce: testrand.Bytes(32),
EncryptedKeyNonce: testrand.Nonce(),

EncryptedSize: 1024,
PlainSize: 512,
Expand Down Expand Up @@ -1127,7 +1127,7 @@ func TestCommitSegment(t *testing.T) {
rootPieceID := testrand.PieceID()
pieces := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
encryptedKey := testrand.Bytes(32)
encryptedKeyNonce := testrand.Bytes(32)
encryptedKeyNonce := testrand.Nonce()

metabasetest.BeginSegment{
Opts: metabase.BeginSegment{
Expand Down Expand Up @@ -1213,7 +1213,7 @@ func TestCommitSegment(t *testing.T) {
rootPieceID := testrand.PieceID()
pieces := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
encryptedKey := testrand.Bytes(32)
encryptedKeyNonce := testrand.Bytes(32)
encryptedKeyNonce := testrand.Nonce()

metabasetest.CommitSegment{
Opts: metabase.CommitSegment{
Expand Down Expand Up @@ -1242,7 +1242,7 @@ func TestCommitSegment(t *testing.T) {
rootPieceID := testrand.PieceID()
pieces := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
encryptedKey := testrand.Bytes(32)
encryptedKeyNonce := testrand.Bytes(32)
encryptedKeyNonce := testrand.Nonce()

now := time.Now()
metabasetest.BeginObjectExactVersion{
Expand Down Expand Up @@ -1296,7 +1296,7 @@ func TestCommitSegment(t *testing.T) {
rootPieceID := testrand.PieceID()
pieces := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
encryptedKey := testrand.Bytes(32)
encryptedKeyNonce := testrand.Bytes(32)
encryptedKeyNonce := testrand.Nonce()

now := time.Now()
expectedExpiresAt := now.Add(33 * time.Hour)
Expand Down Expand Up @@ -1367,7 +1367,7 @@ func TestCommitSegment(t *testing.T) {
rootPieceID := testrand.PieceID()
pieces := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
encryptedKey := testrand.Bytes(32)
encryptedKeyNonce := testrand.Bytes(32)
encryptedKeyNonce := testrand.Nonce()
encryptedETag := testrand.Bytes(32)

now := time.Now()
Expand Down Expand Up @@ -1499,7 +1499,7 @@ func TestCommitInlineSegment(t *testing.T) {
InlineData: []byte{1, 2, 3},

EncryptedKey: testrand.Bytes(32),
EncryptedKeyNonce: testrand.Bytes(32),
EncryptedKeyNonce: testrand.Nonce(),

PlainSize: -1,
},
Expand All @@ -1515,7 +1515,7 @@ func TestCommitInlineSegment(t *testing.T) {
InlineData: []byte{1, 2, 3},

EncryptedKey: testrand.Bytes(32),
EncryptedKeyNonce: testrand.Bytes(32),
EncryptedKeyNonce: testrand.Nonce(),

PlainSize: 512,
PlainOffset: -1,
Expand All @@ -1539,7 +1539,7 @@ func TestCommitInlineSegment(t *testing.T) {
}.Check(ctx, t, db)

encryptedKey := testrand.Bytes(32)
encryptedKeyNonce := testrand.Bytes(32)
encryptedKeyNonce := testrand.Nonce()

metabasetest.CommitInlineSegment{
Opts: metabase.CommitInlineSegment{
Expand Down Expand Up @@ -1605,7 +1605,7 @@ func TestCommitInlineSegment(t *testing.T) {
defer metabasetest.DeleteAll{}.Check(ctx, t, db)

encryptedKey := testrand.Bytes(32)
encryptedKeyNonce := testrand.Bytes(32)
encryptedKeyNonce := testrand.Nonce()

metabasetest.CommitInlineSegment{
Opts: metabase.CommitInlineSegment{
Expand All @@ -1629,7 +1629,7 @@ func TestCommitInlineSegment(t *testing.T) {
defer metabasetest.DeleteAll{}.Check(ctx, t, db)

encryptedKey := testrand.Bytes(32)
encryptedKeyNonce := testrand.Bytes(32)
encryptedKeyNonce := testrand.Nonce()

now := time.Now()

Expand Down Expand Up @@ -1665,7 +1665,7 @@ func TestCommitInlineSegment(t *testing.T) {
defer metabasetest.DeleteAll{}.Check(ctx, t, db)

encryptedKey := testrand.Bytes(32)
encryptedKeyNonce := testrand.Bytes(32)
encryptedKeyNonce := testrand.Nonce()
encryptedETag := testrand.Bytes(32)

now := time.Now()
Expand Down Expand Up @@ -1722,7 +1722,7 @@ func TestCommitInlineSegment(t *testing.T) {
defer metabasetest.DeleteAll{}.Check(ctx, t, db)

encryptedKey := testrand.Bytes(32)
encryptedKeyNonce := testrand.Bytes(32)
encryptedKeyNonce := testrand.Nonce()
encryptedETag := testrand.Bytes(32)

now := time.Now()
Expand Down Expand Up @@ -1781,7 +1781,7 @@ func TestCommitInlineSegment(t *testing.T) {
defer metabasetest.DeleteAll{}.Check(ctx, t, db)

encryptedKey := testrand.Bytes(32)
encryptedKeyNonce := testrand.Bytes(32)
encryptedKeyNonce := testrand.Nonce()
encryptedETag := testrand.Bytes(32)

now := time.Now()
Expand Down Expand Up @@ -1912,7 +1912,7 @@ func TestCommitObject(t *testing.T) {
Version: 5,
StreamID: obj.StreamID,
},
EncryptedMetadataNonce: encryptedMetadataNonce[:],
EncryptedMetadataNonce: encryptedMetadataNonce,
EncryptedMetadata: encryptedMetadata,
EncryptedMetadataEncryptedKey: encryptedMetadataKey,
},
Expand Down Expand Up @@ -1946,7 +1946,7 @@ func TestCommitObject(t *testing.T) {
CreatedAt: now,
Status: metabase.Committed,

EncryptedMetadataNonce: encryptedMetadataNonce[:],
EncryptedMetadataNonce: encryptedMetadataNonce,
EncryptedMetadata: encryptedMetadata,
EncryptedMetadataEncryptedKey: encryptedMetadataKey,

Expand All @@ -1971,7 +1971,7 @@ func TestCommitObject(t *testing.T) {
rootPieceID := testrand.PieceID()
pieces := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
encryptedKey := testrand.Bytes(32)
encryptedKeyNonce := testrand.Bytes(32)
encryptedKeyNonce := testrand.Nonce()

metabasetest.CommitSegment{
Opts: metabase.CommitSegment{
Expand Down Expand Up @@ -2084,7 +2084,7 @@ func TestCommitObject(t *testing.T) {
rootPieceID := testrand.PieceID()
pieces := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
encryptedKey := testrand.Bytes(32)
encryptedKeyNonce := testrand.Bytes(32)
encryptedKeyNonce := testrand.Nonce()

metabasetest.CommitSegment{
Opts: metabase.CommitSegment{
Expand Down

0 comments on commit 1ef06fa

Please sign in to comment.