fix: discard backed up messages if `ProcessBackedupMessages` is not set to `true`

If user followed onboarding flow to recover his account using seed phrase or keycard,
then `ProcessBackedupMessages` property of node config json object should be set to
`true`, otherwise it should be set to `false` or be omitted.
This commit is contained in:
Sale Djenic 2023-07-20 12:08:57 +02:00 committed by saledjenic
parent d60beb2283
commit 7c72d5ec99
10 changed files with 33 additions and 11 deletions

View File

@ -1 +1 @@
0.162.7
0.162.8

View File

@ -17,7 +17,7 @@ import (
type StatusBackend interface {
// IsNodeRunning() bool // NOTE: Only used in tests
StartNode(config *params.NodeConfig) error // NOTE: Only used in canary
StartNodeWithKey(acc multiaccounts.Account, password string, keyHex string) error
StartNodeWithKey(acc multiaccounts.Account, password string, keyHex string, conf *params.NodeConfig) error
StartNodeWithAccount(acc multiaccounts.Account, password string, conf *params.NodeConfig) error
StartNodeWithAccountAndInitialConfig(account multiaccounts.Account, password string, settings settings.Settings, conf *params.NodeConfig, subaccs []*accounts.Account) error
StopNode() error

View File

@ -688,7 +688,7 @@ func TestLoginWithKey(t *testing.T) {
b.UpdateRootDataDir(conf.DataDir)
require.NoError(t, b.OpenAccounts())
require.NoError(t, b.StartNodeWithKey(main, "test-pass", keyhex))
require.NoError(t, b.StartNodeWithKey(main, "test-pass", keyhex, conf))
defer func() {
assert.NoError(t, b.Logout())
assert.NoError(t, b.StopNode())

View File

@ -374,7 +374,7 @@ func (b *GethStatusBackend) setupLogSettings() error {
// and uses it in application.
// TODO: we should use a proper struct with optional values instead of duplicating the regular functions
// with small variants for keycard, this created too many bugs
func (b *GethStatusBackend) startNodeWithKey(acc multiaccounts.Account, password string, keyHex string) error {
func (b *GethStatusBackend) startNodeWithKey(acc multiaccounts.Account, password string, keyHex string, inputNodeCfg *params.NodeConfig) error {
if acc.KDFIterations == 0 {
kdfIterations, err := b.multiaccountsDB.GetAccountKDFIterationsNumber(acc.KeyUID)
if err != nil {
@ -389,7 +389,7 @@ func (b *GethStatusBackend) startNodeWithKey(acc multiaccounts.Account, password
return err
}
err = b.loadNodeConfig(nil)
err = b.loadNodeConfig(inputNodeCfg)
if err != nil {
return err
}
@ -449,8 +449,8 @@ func (b *GethStatusBackend) startNodeWithKey(acc multiaccounts.Account, password
return nil
}
func (b *GethStatusBackend) StartNodeWithKey(acc multiaccounts.Account, password string, keyHex string) error {
err := b.startNodeWithKey(acc, password, keyHex)
func (b *GethStatusBackend) StartNodeWithKey(acc multiaccounts.Account, password string, keyHex string, nodecfg *params.NodeConfig) error {
err := b.startNodeWithKey(acc, password, keyHex, nodecfg)
if err != nil {
// Stop node for clean up
_ = b.StopNode()
@ -1308,7 +1308,7 @@ func (b *GethStatusBackend) SaveAccountAndStartNodeWithKey(account multiaccounts
if err != nil {
return err
}
return b.StartNodeWithKey(account, password, keyHex)
return b.StartNodeWithKey(account, password, keyHex, nodecfg)
}
// StartNodeWithAccountAndInitialConfig is used after account and config was generated.

View File

@ -440,15 +440,20 @@ func SaveAccountAndLoginWithKeycard(accountData, password, settingsJSON, configJ
// LoginWithKeycard initializes an account with a chat key and encryption key used for PFS.
// It purges all the previous identities from Whisper, and injects the key as shh identity.
func LoginWithKeycard(accountData, password, keyHex string) string {
func LoginWithKeycard(accountData, password, keyHex string, configJSON string) string {
var account multiaccounts.Account
err := json.Unmarshal([]byte(accountData), &account)
if err != nil {
return makeJSONResponse(err)
}
var conf params.NodeConfig
err = json.Unmarshal([]byte(configJSON), &conf)
if err != nil {
return makeJSONResponse(err)
}
api.RunAsync(func() error {
log.Debug("start a node with account", "key-uid", account.KeyUID)
err := statusBackend.StartNodeWithKey(account, password, keyHex)
err := statusBackend.StartNodeWithKey(account, password, keyHex, &conf)
if err != nil {
log.Error("failed to start a node", "key-uid", account.KeyUID, "error", err)
return err

View File

@ -485,6 +485,9 @@ type NodeConfig struct {
PushNotificationServerConfig pushnotificationserver.Config `json:"PushNotificationServerConfig"`
OutputMessageCSVEnabled bool
// ProcessBackedupMessages should be set to true when user follows recovery (using seed phrase or keycard) onboarding flow
ProcessBackedupMessages bool
}
type TokenOverride struct {

View File

@ -171,6 +171,8 @@ type Messenger struct {
// flag to disable checking #hasPairedDevices
localPairing bool
// flag to enable backedup messages processing, false by default
processBackedupMessages bool
}
type connStatus int
@ -595,6 +597,10 @@ func (m *Messenger) SetP2PServer(server *p2p.Server) {
m.server = server
}
func (m *Messenger) EnableBackedupMessagesProcessing() {
m.processBackedupMessages = true
}
func (m *Messenger) processSentMessages(ids []string) error {
if m.connectionState.Offline {
return errors.New("Can't mark message as sent while offline")
@ -3781,6 +3787,9 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
}
case protobuf.Backup:
if !m.processBackedupMessages {
continue
}
if !common.IsPubKeyEqual(messageState.CurrentMessageState.PublicKey, &m.identity.PublicKey) {
logger.Warn("not coming from us, ignoring")
continue

View File

@ -115,6 +115,8 @@ func newMessengerWithKey(shh types.Waku, privateKey *ecdsa.PrivateKey, logger *z
return nil, err
}
m.EnableBackedupMessagesProcessing()
_, err = m.Start()
if err != nil {
return nil, err

View File

@ -97,7 +97,7 @@ func (s *SyncRawMessageHandler) HandleRawMessage(accountPayload *AccountPayload,
if len(accountPayload.chatKey) == 0 {
err = s.backend.StartNodeWithAccount(*account, accountPayload.password, nodeConfig)
} else {
err = s.backend.StartNodeWithKey(*account, accountPayload.password, accountPayload.chatKey)
err = s.backend.StartNodeWithKey(*account, accountPayload.password, accountPayload.chatKey, nodeConfig)
}
} else {
accountManager := s.backend.AccountManager()

View File

@ -173,6 +173,9 @@ func (s *Service) InitProtocol(nodeName string, identity *ecdsa.PrivateKey, db *
}
s.messenger = messenger
s.messenger.SetP2PServer(s.server)
if s.config.ProcessBackedupMessages {
s.messenger.EnableBackedupMessagesProcessing()
}
return messenger.Init()
}