diff --git a/VERSION b/VERSION index 748cc0213..177d8c577 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.162.7 +0.162.8 \ No newline at end of file diff --git a/api/backend.go b/api/backend.go index 983ad2dad..cf022aceb 100644 --- a/api/backend.go +++ b/api/backend.go @@ -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 diff --git a/api/backend_test.go b/api/backend_test.go index 14b95a83d..c2fbec909 100644 --- a/api/backend_test.go +++ b/api/backend_test.go @@ -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()) diff --git a/api/geth_backend.go b/api/geth_backend.go index 926db2d93..f791653c5 100644 --- a/api/geth_backend.go +++ b/api/geth_backend.go @@ -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. diff --git a/mobile/status.go b/mobile/status.go index 83967ac94..409a6cb3b 100644 --- a/mobile/status.go +++ b/mobile/status.go @@ -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 diff --git a/params/config.go b/params/config.go index 143de4f7d..c46784647 100644 --- a/params/config.go +++ b/params/config.go @@ -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 { diff --git a/protocol/messenger.go b/protocol/messenger.go index 0e7fe7125..5a8d7511d 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -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 diff --git a/protocol/messenger_base_test.go b/protocol/messenger_base_test.go index 151f34e59..dc1e938f0 100644 --- a/protocol/messenger_base_test.go +++ b/protocol/messenger_base_test.go @@ -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 diff --git a/server/pairing/raw_message_handler.go b/server/pairing/raw_message_handler.go index 8bf073847..cce308460 100644 --- a/server/pairing/raw_message_handler.go +++ b/server/pairing/raw_message_handler.go @@ -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() diff --git a/services/ext/service.go b/services/ext/service.go index 0ed8f4980..6563cebe9 100644 --- a/services/ext/service.go +++ b/services/ext/service.go @@ -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() }