-
Notifications
You must be signed in to change notification settings - Fork 262
refactor: introduce encryption persistence interface #6998
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
Open
osmaczko
wants to merge
1
commit into
develop
Choose a base branch
from
refactor/messaging-persistence-interfaces
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,360
−1,860
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -6,22 +6,21 @@ import ( | |||||||||||||
|
||||||||||||||
"github.com/golang/protobuf/proto" | ||||||||||||||
"github.com/libp2p/go-libp2p/core/peer" | ||||||||||||||
bindata "github.com/status-im/migrate/v4/source/go_bindata" | ||||||||||||||
datasyncproto "github.com/status-im/mvds/protobuf" | ||||||||||||||
"github.com/stretchr/testify/suite" | ||||||||||||||
"go.uber.org/zap" | ||||||||||||||
|
||||||||||||||
datasyncproto "github.com/status-im/mvds/protobuf" | ||||||||||||||
|
||||||||||||||
"github.com/status-im/status-go/appdatabase" | ||||||||||||||
"github.com/status-im/status-go/crypto" | ||||||||||||||
"github.com/status-im/status-go/messaging/adapters" | ||||||||||||||
"github.com/status-im/status-go/messaging/datasync" | ||||||||||||||
"github.com/status-im/status-go/messaging/layers/encryption" | ||||||||||||||
"github.com/status-im/status-go/messaging/layers/encryption/migrations" | ||||||||||||||
"github.com/status-im/status-go/messaging/layers/transport" | ||||||||||||||
messagingtypes "github.com/status-im/status-go/messaging/types" | ||||||||||||||
wakuv2 "github.com/status-im/status-go/messaging/waku" | ||||||||||||||
wakutypes "github.com/status-im/status-go/messaging/waku/types" | ||||||||||||||
"github.com/status-im/status-go/protocol/protobuf" | ||||||||||||||
"github.com/status-im/status-go/protocol/sqlite" | ||||||||||||||
v1protocol "github.com/status-im/status-go/protocol/v1" | ||||||||||||||
"github.com/status-im/status-go/t/helpers" | ||||||||||||||
) | ||||||||||||||
|
@@ -56,13 +55,16 @@ func (s *MessageSenderSuite) SetupTest() { | |||||||||||||
identity, err := crypto.GenerateKey() | ||||||||||||||
s.Require().NoError(err) | ||||||||||||||
|
||||||||||||||
database, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{}) | ||||||||||||||
s.Require().NoError(err) | ||||||||||||||
err = sqlite.Migrate(database) | ||||||||||||||
db, err := helpers.SetupTestMemorySQLDB(helpers.NewTestDBInitializer(bindata.Resource( | ||||||||||||||
migrations.AssetNames(), | ||||||||||||||
func(name string) ([]byte, error) { | ||||||||||||||
return migrations.Asset(name) | ||||||||||||||
}, | ||||||||||||||
Comment on lines
+59
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
))) | ||||||||||||||
s.Require().NoError(err) | ||||||||||||||
|
||||||||||||||
encryptionProtocol := encryption.New( | ||||||||||||||
database, | ||||||||||||||
encryption.NewSQLitePersistence(db), | ||||||||||||||
"installation-1", | ||||||||||||||
s.logger, | ||||||||||||||
) | ||||||||||||||
|
@@ -80,7 +82,7 @@ func (s *MessageSenderSuite) SetupTest() { | |||||||||||||
s.Require().NoError(err) | ||||||||||||||
s.Require().NoError(shh.Start()) | ||||||||||||||
|
||||||||||||||
stubPersistence := NewStubPersistence() | ||||||||||||||
stubPersistence := NewPersistenceInMemory() | ||||||||||||||
|
||||||||||||||
transport, err := transport.NewTransport( | ||||||||||||||
shh, | ||||||||||||||
|
@@ -94,7 +96,7 @@ func (s *MessageSenderSuite) SetupTest() { | |||||||||||||
|
||||||||||||||
s.sender, err = NewMessageSender( | ||||||||||||||
identity, | ||||||||||||||
database, | ||||||||||||||
db, | ||||||||||||||
stubPersistence, | ||||||||||||||
transport, | ||||||||||||||
encryptionProtocol, | ||||||||||||||
|
@@ -196,13 +198,16 @@ func (s *MessageSenderSuite) TestHandleDecodedMessagesDatasyncEncrypted() { | |||||||||||||
s.Require().NoError(err) | ||||||||||||||
|
||||||||||||||
// Create sender encryption protocol. | ||||||||||||||
senderDatabase, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{}) | ||||||||||||||
s.Require().NoError(err) | ||||||||||||||
err = sqlite.Migrate(senderDatabase) | ||||||||||||||
senderDatabase, err := helpers.SetupTestMemorySQLDB(helpers.NewTestDBInitializer(bindata.Resource( | ||||||||||||||
migrations.AssetNames(), | ||||||||||||||
func(name string) ([]byte, error) { | ||||||||||||||
return migrations.Asset(name) | ||||||||||||||
}, | ||||||||||||||
))) | ||||||||||||||
s.Require().NoError(err) | ||||||||||||||
|
||||||||||||||
senderEncryptionProtocol := encryption.New( | ||||||||||||||
senderDatabase, | ||||||||||||||
encryption.NewSQLitePersistence(senderDatabase), | ||||||||||||||
"installation-2", | ||||||||||||||
s.logger, | ||||||||||||||
) | ||||||||||||||
|
@@ -246,13 +251,16 @@ func (s *MessageSenderSuite) TestHandleOutOfOrderHashRatchet() { | |||||||||||||
s.Require().NoError(err) | ||||||||||||||
|
||||||||||||||
// Create sender encryption protocol. | ||||||||||||||
senderDatabase, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{}) | ||||||||||||||
s.Require().NoError(err) | ||||||||||||||
err = sqlite.Migrate(senderDatabase) | ||||||||||||||
senderDatabase, err := helpers.SetupTestMemorySQLDB(helpers.NewTestDBInitializer(bindata.Resource( | ||||||||||||||
migrations.AssetNames(), | ||||||||||||||
func(name string) ([]byte, error) { | ||||||||||||||
return migrations.Asset(name) | ||||||||||||||
}, | ||||||||||||||
))) | ||||||||||||||
s.Require().NoError(err) | ||||||||||||||
|
||||||||||||||
senderEncryptionProtocol := encryption.New( | ||||||||||||||
senderDatabase, | ||||||||||||||
encryption.NewSQLitePersistence(senderDatabase), | ||||||||||||||
"installation-2", | ||||||||||||||
s.logger, | ||||||||||||||
) | ||||||||||||||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part confuses me.
Sorry I had to write it down to consume, you probably know all of this 😄
Part 1. Interfaces
In
newCore
we get apersistence
pointer from the user as part ofparams
:status-go/messaging/core.go
Line 79 in 78d6e84
status-go/messaging/core.go
Line 70 in 78d6e84
types.Persistence
is expected to provideEncryptionPersistence
:status-go/messaging/types/persistence.go
Line 10 in 78d6e84
Yet the
encryption
package expects it's own internalPersistence
interface:status-go/messaging/layers/encryption/persistence.go
Lines 33 to 37 in 78d6e84
That's why we use this
EncryptionPersistence
adapter herestatus-go/messaging/core.go
Lines 92 to 93 in 78d6e84
Part 2. Adapter.
The adapter works, because
status-go
uses the default sqlite encryption persistence:status-go/protocol/messaging_persistence.go
Lines 253 to 255 in 78d6e84
... which, by the way is marked as "internal implementation" 🤔
status-go/messaging/sqlite_persistence.go
Lines 58 to 64 in 78d6e84
The implementation of
SQLiteEncryptionPersistence
is simply empty:status-go/messaging/internal/sqlite_encryption_persistence.go
Lines 7 to 37 in 78d6e84
... yet it composes
encryption.SQLitePersistence
.And this is what the adapter relies on.
Part 3. Question
messagingtypes.EncryptionPersistence
seem to be completely unused 🤔Do we really need it? And the other persistence adapters?
Maybe we could just re-export the internal interfaces from
messaging
module?