2023-01-06 12:21:14 +00:00
|
|
|
package pairing
|
2022-06-15 14:49:31 +00:00
|
|
|
|
|
|
|
import (
|
2022-06-15 15:36:17 +00:00
|
|
|
"crypto/ecdsa"
|
2022-08-31 11:44:12 +00:00
|
|
|
"crypto/elliptic"
|
2022-08-19 12:45:50 +00:00
|
|
|
"crypto/rand"
|
2023-03-23 11:44:15 +00:00
|
|
|
"encoding/json"
|
2022-06-15 15:36:17 +00:00
|
|
|
"net"
|
2022-08-31 11:44:12 +00:00
|
|
|
"time"
|
2022-08-19 12:45:50 +00:00
|
|
|
|
2023-11-07 01:51:15 +00:00
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
"go.uber.org/zap"
|
2022-08-31 12:47:16 +00:00
|
|
|
|
2023-11-07 01:51:15 +00:00
|
|
|
"github.com/status-im/status-go/timesource"
|
|
|
|
|
2023-02-17 13:02:42 +00:00
|
|
|
"github.com/status-im/status-go/api"
|
2022-10-21 12:15:39 +00:00
|
|
|
"github.com/status-im/status-go/logutils"
|
2023-02-17 13:02:42 +00:00
|
|
|
"github.com/status-im/status-go/server"
|
2022-06-15 14:49:31 +00:00
|
|
|
)
|
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| type BaseServer struct {
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2022-06-15 15:36:17 +00:00
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
type BaseServer struct {
|
|
|
|
server.Server
|
2023-03-20 20:16:38 +00:00
|
|
|
challengeGiver *ChallengeGiver
|
2023-03-23 11:44:15 +00:00
|
|
|
|
2023-08-22 16:18:14 +00:00
|
|
|
config ServerConfig
|
2022-06-15 14:49:31 +00:00
|
|
|
}
|
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
// NewBaseServer returns a *BaseServer init from the given *SenderServerConfig
|
|
|
|
func NewBaseServer(logger *zap.Logger, e *PayloadEncryptor, config *ServerConfig) (*BaseServer, error) {
|
2023-03-20 20:16:38 +00:00
|
|
|
cg, err := NewChallengeGiver(e, logger)
|
2023-03-23 11:44:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-07-01 15:37:53 +00:00
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
bs := &BaseServer{
|
|
|
|
Server: server.NewServer(
|
|
|
|
config.Cert,
|
2023-08-22 16:18:14 +00:00
|
|
|
config.ListenIP.String(),
|
2023-03-23 11:44:15 +00:00
|
|
|
nil,
|
|
|
|
logger,
|
|
|
|
),
|
2023-03-20 20:16:38 +00:00
|
|
|
challengeGiver: cg,
|
2023-08-22 16:18:14 +00:00
|
|
|
config: *config,
|
2023-03-23 11:44:15 +00:00
|
|
|
}
|
|
|
|
bs.SetTimeout(config.Timeout)
|
|
|
|
return bs, nil
|
2022-06-15 14:49:31 +00:00
|
|
|
}
|
|
|
|
|
2022-06-15 15:36:17 +00:00
|
|
|
// MakeConnectionParams generates a *ConnectionParams based on the Server's current state
|
2023-03-23 11:44:15 +00:00
|
|
|
func (s *BaseServer) MakeConnectionParams() (*ConnectionParams, error) {
|
feat(pairing)_: Fallback pairing seed (#5614) (#5627)
* feat(pairing)!: Add extra parameters and remove v2 compatibility
This commit includes the following changes:
I have added a flag to maintain 2.29 compatibility.
Breaking change in connection string
The local pairing code that was parsing the connection string had a few non-upgradable features:
It was strictly checking the number of parameters, throwing an error if the number was different. This made it impossible to add parameters to it without breaking.
It was strictly checking the version number. This made increasing the version number impossible as older client would just refuse to connect.
The code has been changed so that:
Two parameters have been added, installation-id and key-uid. Those are needed for the fallback flow.
I have also removed version from the payload, since it wasn't used.
This means that we don't support v1 anymore. V2 parsing is supported . Going forward there's a clear strategy on how to update the protocol (append parameters, don't change existing one).
https://www.youtube.com/watch?v=oyLBGkS5ICk Is a must watch video for understanding the strategy
Changed MessengerResponse to use internally a map of installations rather than an array (minor)
Just moving towards maps as arrays tend to lead to subtle bugs.
Moved pairing methods to messenger_pairing.go
Just moved some methods
Added 2 new methods for the fallback flow
FinishPairingThroughSeedPhraseProcess
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R29
EnableAndSyncInstallation
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R18
Flow for clients
Client A1 is logged in
Client A2 is logged out
Client A1 shows a QR code
Client A2 scans a QR code
If connection fails on A2, the user will be prompted to enter a seed phrase.
If the generated account matches the key-uid from the QR code, A2 should call FinishPairingThroughSeedPhraseProcess with the installation id passed in the QR code. This will send installation information over waku. The user should be shown its own installation id and prompted to check the other device.
Client A1 will receive new installation data through waku, if they are still on the qr code page, they should show a popup to the user showing the received installation id, and a way to Enable and Sync, which should call the EnableAndSyncInstallation endpoint. This should finish the fallback syncing flow.
Current issues
Currently I haven't tested that all the data is synced after finishing the flow. I see that the two devices are paired correctly, but for example the DisplayName is not changed on the receiving device. I haven't had time to look into it further.
* test_: add more test for connection string parser
* fix_: fix panic when parse old connection string
* test_: add comments for TestMessengerPairAfterSeedPhrase
* fix_: correct error description
* feat_:rename FinishPairingThroughSeedPhraseProcess to EnableInstallationAndPair
* fix_: delete leftover
* fix_: add UniqueKey method
* fix_: unify the response for InputConnectionStringForBootstrapping
* fix_: remove fields installationID and keyUID in GethStatusBackend
* fix_: rename messenger_pairing to messenger_pairing_and_syncing
---------
Co-authored-by: frank <lovefree103@gmail.com>
Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2024-07-30 16:03:43 +00:00
|
|
|
return NewConnectionParams(s.config.IPAddresses, s.MustGetPort(), s.config.PK, s.config.EK, s.config.InstallationID, s.config.KeyUID), nil
|
2022-06-15 14:49:31 +00:00
|
|
|
}
|
2022-06-10 15:32:15 +00:00
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
func MakeServerConfig(config *ServerConfig) error {
|
|
|
|
tlsKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
2022-08-31 12:47:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
AESKey := make([]byte, 32)
|
|
|
|
_, err = rand.Read(AESKey)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-08-22 16:18:14 +00:00
|
|
|
ips, err := server.GetLocalAddressesForPairingServer()
|
2023-03-23 11:44:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-11-13 19:06:32 +00:00
|
|
|
now := timesource.GetCurrentTime()
|
2023-11-07 01:51:15 +00:00
|
|
|
log.Debug("pairing server generate cert", "system time", time.Now().String(), "timesource time", now.String())
|
2023-11-13 19:06:32 +00:00
|
|
|
tlsCert, _, err := GenerateCertFromKey(tlsKey, now, ips, []string{})
|
2023-03-23 11:44:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
config.PK = &tlsKey.PublicKey
|
|
|
|
config.EK = AESKey
|
|
|
|
config.Cert = &tlsCert
|
2023-08-22 16:18:14 +00:00
|
|
|
config.IPAddresses = ips
|
|
|
|
config.ListenIP = net.IPv4zero
|
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| type SenderServer struct {
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
| With AccountPayloadMounter, RawMessagePayloadMounter and InstallationPayloadMounterReceiver
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
type SenderServer struct {
|
|
|
|
*BaseServer
|
|
|
|
accountMounter PayloadMounter
|
2023-03-30 10:00:32 +00:00
|
|
|
rawMessageMounter PayloadMounter
|
2023-04-02 23:08:29 +00:00
|
|
|
installationMounter PayloadMounterReceiver
|
2023-12-01 11:30:42 +00:00
|
|
|
backend *api.GethStatusBackend
|
2023-03-23 11:44:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewSenderServer returns a *SenderServer init from the given *SenderServerConfig
|
|
|
|
func NewSenderServer(backend *api.GethStatusBackend, config *SenderServerConfig) (*SenderServer, error) {
|
|
|
|
logger := logutils.ZapLogger().Named("SenderServer")
|
|
|
|
e := NewPayloadEncryptor(config.ServerConfig.EK)
|
|
|
|
|
|
|
|
bs, err := NewBaseServer(logger, e, config.ServerConfig)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
am, rmm, imr, err := NewPayloadMounters(logger, e, backend, config.SenderConfig)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &SenderServer{
|
|
|
|
BaseServer: bs,
|
|
|
|
accountMounter: am,
|
|
|
|
rawMessageMounter: rmm,
|
|
|
|
installationMounter: imr,
|
2023-12-01 11:30:42 +00:00
|
|
|
backend: backend,
|
2023-03-23 11:44:15 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SenderServer) startSendingData() error {
|
2023-12-01 11:30:42 +00:00
|
|
|
logger := s.GetLogger()
|
|
|
|
beforeSending := func() {
|
|
|
|
if s.backend != nil {
|
|
|
|
err := s.backend.LocalPairingStarted()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("startSendingData backend.LocalPairingStarted()", zap.Error(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-06 12:21:14 +00:00
|
|
|
s.SetHandlers(server.HandlerPatternMap{
|
2023-03-16 14:15:07 +00:00
|
|
|
pairingChallenge: handlePairingChallenge(s.challengeGiver),
|
2023-12-01 11:30:42 +00:00
|
|
|
pairingSendAccount: middlewareChallenge(s.challengeGiver, handleSendAccount(logger, s.accountMounter, beforeSending)),
|
|
|
|
pairingSendSyncDevice: middlewareChallenge(s.challengeGiver, handlePairingSyncDeviceSend(logger, s.rawMessageMounter, beforeSending)),
|
2023-03-23 11:44:15 +00:00
|
|
|
// TODO implement refactor of installation data exchange to follow the send/receive pattern of
|
|
|
|
// the other handlers.
|
|
|
|
// https://github.com/status-im/status-go/issues/3304
|
2023-02-28 12:32:45 +00:00
|
|
|
// receive installation data from receiver
|
2023-04-04 11:11:04 +00:00
|
|
|
pairingReceiveInstallation: middlewareChallenge(s.challengeGiver, handleReceiveInstallation(s.GetLogger(), s.installationMounter)),
|
2022-08-19 12:45:50 +00:00
|
|
|
})
|
2022-06-10 15:32:15 +00:00
|
|
|
return s.Start()
|
|
|
|
}
|
2022-08-31 11:44:12 +00:00
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
// MakeFullSenderServer generates a fully configured and randomly seeded SenderServer
|
2023-03-21 13:08:28 +00:00
|
|
|
func MakeFullSenderServer(backend *api.GethStatusBackend, config *SenderServerConfig) (*SenderServer, error) {
|
feat(pairing)_: Fallback pairing seed (#5614) (#5627)
* feat(pairing)!: Add extra parameters and remove v2 compatibility
This commit includes the following changes:
I have added a flag to maintain 2.29 compatibility.
Breaking change in connection string
The local pairing code that was parsing the connection string had a few non-upgradable features:
It was strictly checking the number of parameters, throwing an error if the number was different. This made it impossible to add parameters to it without breaking.
It was strictly checking the version number. This made increasing the version number impossible as older client would just refuse to connect.
The code has been changed so that:
Two parameters have been added, installation-id and key-uid. Those are needed for the fallback flow.
I have also removed version from the payload, since it wasn't used.
This means that we don't support v1 anymore. V2 parsing is supported . Going forward there's a clear strategy on how to update the protocol (append parameters, don't change existing one).
https://www.youtube.com/watch?v=oyLBGkS5ICk Is a must watch video for understanding the strategy
Changed MessengerResponse to use internally a map of installations rather than an array (minor)
Just moving towards maps as arrays tend to lead to subtle bugs.
Moved pairing methods to messenger_pairing.go
Just moved some methods
Added 2 new methods for the fallback flow
FinishPairingThroughSeedPhraseProcess
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R29
EnableAndSyncInstallation
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R18
Flow for clients
Client A1 is logged in
Client A2 is logged out
Client A1 shows a QR code
Client A2 scans a QR code
If connection fails on A2, the user will be prompted to enter a seed phrase.
If the generated account matches the key-uid from the QR code, A2 should call FinishPairingThroughSeedPhraseProcess with the installation id passed in the QR code. This will send installation information over waku. The user should be shown its own installation id and prompted to check the other device.
Client A1 will receive new installation data through waku, if they are still on the qr code page, they should show a popup to the user showing the received installation id, and a way to Enable and Sync, which should call the EnableAndSyncInstallation endpoint. This should finish the fallback syncing flow.
Current issues
Currently I haven't tested that all the data is synced after finishing the flow. I see that the two devices are paired correctly, but for example the DisplayName is not changed on the receiving device. I haven't had time to look into it further.
* test_: add more test for connection string parser
* fix_: fix panic when parse old connection string
* test_: add comments for TestMessengerPairAfterSeedPhrase
* fix_: correct error description
* feat_:rename FinishPairingThroughSeedPhraseProcess to EnableInstallationAndPair
* fix_: delete leftover
* fix_: add UniqueKey method
* fix_: unify the response for InputConnectionStringForBootstrapping
* fix_: remove fields installationID and keyUID in GethStatusBackend
* fix_: rename messenger_pairing to messenger_pairing_and_syncing
---------
Co-authored-by: frank <lovefree103@gmail.com>
Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2024-07-30 16:03:43 +00:00
|
|
|
config.ServerConfig.InstallationID = backend.InstallationID()
|
|
|
|
config.ServerConfig.KeyUID = backend.KeyUID()
|
2023-03-23 11:44:15 +00:00
|
|
|
err := MakeServerConfig(config.ServerConfig)
|
2022-08-31 11:44:12 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
config.SenderConfig.DB = backend.GetMultiaccountDB()
|
|
|
|
return NewSenderServer(backend, config)
|
|
|
|
}
|
|
|
|
|
2023-03-21 13:08:28 +00:00
|
|
|
// StartUpSenderServer generates a SenderServer, starts the sending server
|
2023-03-23 11:44:15 +00:00
|
|
|
// and returns the ConnectionParams string to allow a ReceiverClient to make a successful connection.
|
2023-03-21 13:08:28 +00:00
|
|
|
func StartUpSenderServer(backend *api.GethStatusBackend, configJSON string) (string, error) {
|
2023-03-23 11:44:15 +00:00
|
|
|
conf := NewSenderServerConfig()
|
|
|
|
err := json.Unmarshal([]byte(configJSON), conf)
|
2022-08-31 11:44:12 +00:00
|
|
|
if err != nil {
|
2023-03-23 11:44:15 +00:00
|
|
|
return "", err
|
2022-08-31 11:44:12 +00:00
|
|
|
}
|
2023-06-09 06:43:51 +00:00
|
|
|
if len(conf.SenderConfig.ChatKey) == 0 {
|
|
|
|
err = validateAndVerifyPassword(conf, conf.SenderConfig)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2023-03-29 15:51:01 +00:00
|
|
|
}
|
2022-08-31 11:44:12 +00:00
|
|
|
|
2023-03-21 13:08:28 +00:00
|
|
|
ps, err := MakeFullSenderServer(backend, conf)
|
2022-08-31 11:44:12 +00:00
|
|
|
if err != nil {
|
2023-03-23 11:44:15 +00:00
|
|
|
return "", err
|
2022-08-31 11:44:12 +00:00
|
|
|
}
|
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
err = ps.startSendingData()
|
2022-08-31 11:44:12 +00:00
|
|
|
if err != nil {
|
2023-03-23 11:44:15 +00:00
|
|
|
return "", err
|
2022-08-31 11:44:12 +00:00
|
|
|
}
|
2023-02-28 12:32:45 +00:00
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
cp, err := ps.MakeConnectionParams()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
2023-02-28 12:32:45 +00:00
|
|
|
}
|
2023-03-23 11:44:15 +00:00
|
|
|
|
|
|
|
return cp.ToString(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| ReceiverServer
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
| With AccountPayloadReceiver, RawMessagePayloadReceiver, InstallationPayloadMounterReceiver
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
type ReceiverServer struct {
|
|
|
|
*BaseServer
|
|
|
|
accountReceiver PayloadReceiver
|
|
|
|
rawMessageReceiver PayloadReceiver
|
|
|
|
installationReceiver PayloadMounterReceiver
|
2023-12-01 11:30:42 +00:00
|
|
|
backend *api.GethStatusBackend
|
2023-03-23 11:44:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewReceiverServer returns a *SenderServer init from the given *ReceiverServerConfig
|
|
|
|
func NewReceiverServer(backend *api.GethStatusBackend, config *ReceiverServerConfig) (*ReceiverServer, error) {
|
|
|
|
logger := logutils.ZapLogger().Named("SenderServer")
|
|
|
|
e := NewPayloadEncryptor(config.ServerConfig.EK)
|
|
|
|
|
|
|
|
bs, err := NewBaseServer(logger, e, config.ServerConfig)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2023-02-28 12:32:45 +00:00
|
|
|
}
|
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
ar, rmr, imr, err := NewPayloadReceivers(logger, e, backend, config.ReceiverConfig)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-08-31 11:44:12 +00:00
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
return &ReceiverServer{
|
|
|
|
BaseServer: bs,
|
|
|
|
accountReceiver: ar,
|
|
|
|
rawMessageReceiver: rmr,
|
|
|
|
installationReceiver: imr,
|
2023-12-01 11:30:42 +00:00
|
|
|
backend: backend,
|
2023-03-23 11:44:15 +00:00
|
|
|
}, nil
|
|
|
|
}
|
2022-08-31 11:44:12 +00:00
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
func (s *ReceiverServer) startReceivingData() error {
|
2023-12-01 11:30:42 +00:00
|
|
|
logger := s.GetLogger()
|
|
|
|
beforeSending := func() {
|
|
|
|
if s.backend != nil {
|
|
|
|
err := s.backend.LocalPairingStarted()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("startSendingData backend.LocalPairingStarted()", zap.Error(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-23 11:44:15 +00:00
|
|
|
s.SetHandlers(server.HandlerPatternMap{
|
2023-03-20 20:16:38 +00:00
|
|
|
pairingChallenge: handlePairingChallenge(s.challengeGiver),
|
2023-12-01 11:30:42 +00:00
|
|
|
pairingReceiveAccount: handleReceiveAccount(logger, s.accountReceiver),
|
|
|
|
pairingReceiveSyncDevice: handleParingSyncDeviceReceive(logger, s.rawMessageReceiver),
|
2023-03-23 11:44:15 +00:00
|
|
|
// TODO implement refactor of installation data exchange to follow the send/receive pattern of
|
|
|
|
// the other handlers.
|
|
|
|
// https://github.com/status-im/status-go/issues/3304
|
|
|
|
// send installation data back to sender
|
2023-12-01 11:30:42 +00:00
|
|
|
pairingSendInstallation: middlewareChallenge(s.challengeGiver, handleSendInstallation(logger, s.installationReceiver, beforeSending)),
|
2022-08-31 11:44:12 +00:00
|
|
|
})
|
2023-03-23 11:44:15 +00:00
|
|
|
return s.Start()
|
|
|
|
}
|
|
|
|
|
|
|
|
// MakeFullReceiverServer generates a fully configured and randomly seeded ReceiverServer
|
2023-03-21 13:08:28 +00:00
|
|
|
func MakeFullReceiverServer(backend *api.GethStatusBackend, config *ReceiverServerConfig) (*ReceiverServer, error) {
|
feat(pairing)_: Fallback pairing seed (#5614) (#5627)
* feat(pairing)!: Add extra parameters and remove v2 compatibility
This commit includes the following changes:
I have added a flag to maintain 2.29 compatibility.
Breaking change in connection string
The local pairing code that was parsing the connection string had a few non-upgradable features:
It was strictly checking the number of parameters, throwing an error if the number was different. This made it impossible to add parameters to it without breaking.
It was strictly checking the version number. This made increasing the version number impossible as older client would just refuse to connect.
The code has been changed so that:
Two parameters have been added, installation-id and key-uid. Those are needed for the fallback flow.
I have also removed version from the payload, since it wasn't used.
This means that we don't support v1 anymore. V2 parsing is supported . Going forward there's a clear strategy on how to update the protocol (append parameters, don't change existing one).
https://www.youtube.com/watch?v=oyLBGkS5ICk Is a must watch video for understanding the strategy
Changed MessengerResponse to use internally a map of installations rather than an array (minor)
Just moving towards maps as arrays tend to lead to subtle bugs.
Moved pairing methods to messenger_pairing.go
Just moved some methods
Added 2 new methods for the fallback flow
FinishPairingThroughSeedPhraseProcess
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R29
EnableAndSyncInstallation
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R18
Flow for clients
Client A1 is logged in
Client A2 is logged out
Client A1 shows a QR code
Client A2 scans a QR code
If connection fails on A2, the user will be prompted to enter a seed phrase.
If the generated account matches the key-uid from the QR code, A2 should call FinishPairingThroughSeedPhraseProcess with the installation id passed in the QR code. This will send installation information over waku. The user should be shown its own installation id and prompted to check the other device.
Client A1 will receive new installation data through waku, if they are still on the qr code page, they should show a popup to the user showing the received installation id, and a way to Enable and Sync, which should call the EnableAndSyncInstallation endpoint. This should finish the fallback syncing flow.
Current issues
Currently I haven't tested that all the data is synced after finishing the flow. I see that the two devices are paired correctly, but for example the DisplayName is not changed on the receiving device. I haven't had time to look into it further.
* test_: add more test for connection string parser
* fix_: fix panic when parse old connection string
* test_: add comments for TestMessengerPairAfterSeedPhrase
* fix_: correct error description
* feat_:rename FinishPairingThroughSeedPhraseProcess to EnableInstallationAndPair
* fix_: delete leftover
* fix_: add UniqueKey method
* fix_: unify the response for InputConnectionStringForBootstrapping
* fix_: remove fields installationID and keyUID in GethStatusBackend
* fix_: rename messenger_pairing to messenger_pairing_and_syncing
---------
Co-authored-by: frank <lovefree103@gmail.com>
Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2024-07-30 16:03:43 +00:00
|
|
|
config.ServerConfig.InstallationID = backend.InstallationID()
|
|
|
|
config.ServerConfig.KeyUID = backend.KeyUID()
|
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
err := MakeServerConfig(config.ServerConfig)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-09-21 00:32:16 +00:00
|
|
|
// ignore err because we allow no active account here
|
2023-03-23 11:44:15 +00:00
|
|
|
activeAccount, _ := backend.GetActiveAccount()
|
|
|
|
if activeAccount != nil {
|
|
|
|
config.ReceiverConfig.LoggedInKeyUID = activeAccount.KeyUID
|
|
|
|
}
|
|
|
|
config.ReceiverConfig.DB = backend.GetMultiaccountDB()
|
|
|
|
|
|
|
|
return NewReceiverServer(backend, config)
|
2022-08-31 11:44:12 +00:00
|
|
|
}
|
2022-08-31 12:47:16 +00:00
|
|
|
|
2023-03-21 13:08:28 +00:00
|
|
|
// StartUpReceiverServer generates a ReceiverServer, starts the sending server
|
2023-03-23 11:44:15 +00:00
|
|
|
// and returns the ConnectionParams string to allow a SenderClient to make a successful connection.
|
2023-03-21 13:08:28 +00:00
|
|
|
func StartUpReceiverServer(backend *api.GethStatusBackend, configJSON string) (string, error) {
|
2023-03-23 11:44:15 +00:00
|
|
|
conf := NewReceiverServerConfig()
|
|
|
|
err := json.Unmarshal([]byte(configJSON), conf)
|
2022-08-31 12:47:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2024-04-22 12:33:23 +00:00
|
|
|
receiverConf := conf.ReceiverConfig
|
|
|
|
if err = setDefaultNodeConfig(receiverConf.NodeConfig); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
err = validateAndVerifyNodeConfig(conf, receiverConf)
|
2023-03-29 15:51:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2022-08-31 12:47:16 +00:00
|
|
|
|
2023-03-21 13:08:28 +00:00
|
|
|
ps, err := MakeFullReceiverServer(backend, conf)
|
2022-08-31 12:47:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
err = ps.startReceivingData()
|
2022-08-31 12:47:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
cp, err := ps.MakeConnectionParams()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return cp.ToString(), nil
|
|
|
|
}
|
2023-08-18 08:51:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| type KeystoreFilesSenderServer struct {
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
type KeystoreFilesSenderServer struct {
|
|
|
|
*BaseServer
|
|
|
|
keystoreFilesMounter PayloadMounter
|
2023-12-01 11:30:42 +00:00
|
|
|
backend *api.GethStatusBackend
|
2023-08-18 08:51:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewKeystoreFilesSenderServer(backend *api.GethStatusBackend, config *KeystoreFilesSenderServerConfig) (*KeystoreFilesSenderServer, error) {
|
|
|
|
logger := logutils.ZapLogger().Named("SenderServer")
|
|
|
|
e := NewPayloadEncryptor(config.ServerConfig.EK)
|
|
|
|
|
|
|
|
bs, err := NewBaseServer(logger, e, config.ServerConfig)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
kfm, err := NewKeystoreFilesPayloadMounter(backend, e, config.SenderConfig, logger)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &KeystoreFilesSenderServer{
|
|
|
|
BaseServer: bs,
|
|
|
|
keystoreFilesMounter: kfm,
|
2023-12-01 11:30:42 +00:00
|
|
|
backend: backend,
|
2023-08-18 08:51:16 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *KeystoreFilesSenderServer) startSendingData() error {
|
2023-12-01 11:30:42 +00:00
|
|
|
logger := s.GetLogger()
|
|
|
|
beforeSending := func() {
|
|
|
|
if s.backend != nil {
|
|
|
|
err := s.backend.LocalPairingStarted()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("startSendingData backend.LocalPairingStarted()", zap.Error(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-08-18 08:51:16 +00:00
|
|
|
s.SetHandlers(server.HandlerPatternMap{
|
|
|
|
pairingChallenge: handlePairingChallenge(s.challengeGiver),
|
2023-12-01 11:30:42 +00:00
|
|
|
pairingSendAccount: middlewareChallenge(s.challengeGiver, handleSendAccount(logger, s.keystoreFilesMounter, beforeSending)),
|
2023-08-18 08:51:16 +00:00
|
|
|
})
|
|
|
|
return s.Start()
|
|
|
|
}
|
|
|
|
|
|
|
|
// MakeFullSenderServer generates a fully configured and randomly seeded KeystoreFilesSenderServer
|
|
|
|
func MakeKeystoreFilesSenderServer(backend *api.GethStatusBackend, config *KeystoreFilesSenderServerConfig) (*KeystoreFilesSenderServer, error) {
|
feat(pairing)_: Fallback pairing seed (#5614) (#5627)
* feat(pairing)!: Add extra parameters and remove v2 compatibility
This commit includes the following changes:
I have added a flag to maintain 2.29 compatibility.
Breaking change in connection string
The local pairing code that was parsing the connection string had a few non-upgradable features:
It was strictly checking the number of parameters, throwing an error if the number was different. This made it impossible to add parameters to it without breaking.
It was strictly checking the version number. This made increasing the version number impossible as older client would just refuse to connect.
The code has been changed so that:
Two parameters have been added, installation-id and key-uid. Those are needed for the fallback flow.
I have also removed version from the payload, since it wasn't used.
This means that we don't support v1 anymore. V2 parsing is supported . Going forward there's a clear strategy on how to update the protocol (append parameters, don't change existing one).
https://www.youtube.com/watch?v=oyLBGkS5ICk Is a must watch video for understanding the strategy
Changed MessengerResponse to use internally a map of installations rather than an array (minor)
Just moving towards maps as arrays tend to lead to subtle bugs.
Moved pairing methods to messenger_pairing.go
Just moved some methods
Added 2 new methods for the fallback flow
FinishPairingThroughSeedPhraseProcess
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R29
EnableAndSyncInstallation
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R18
Flow for clients
Client A1 is logged in
Client A2 is logged out
Client A1 shows a QR code
Client A2 scans a QR code
If connection fails on A2, the user will be prompted to enter a seed phrase.
If the generated account matches the key-uid from the QR code, A2 should call FinishPairingThroughSeedPhraseProcess with the installation id passed in the QR code. This will send installation information over waku. The user should be shown its own installation id and prompted to check the other device.
Client A1 will receive new installation data through waku, if they are still on the qr code page, they should show a popup to the user showing the received installation id, and a way to Enable and Sync, which should call the EnableAndSyncInstallation endpoint. This should finish the fallback syncing flow.
Current issues
Currently I haven't tested that all the data is synced after finishing the flow. I see that the two devices are paired correctly, but for example the DisplayName is not changed on the receiving device. I haven't had time to look into it further.
* test_: add more test for connection string parser
* fix_: fix panic when parse old connection string
* test_: add comments for TestMessengerPairAfterSeedPhrase
* fix_: correct error description
* feat_:rename FinishPairingThroughSeedPhraseProcess to EnableInstallationAndPair
* fix_: delete leftover
* fix_: add UniqueKey method
* fix_: unify the response for InputConnectionStringForBootstrapping
* fix_: remove fields installationID and keyUID in GethStatusBackend
* fix_: rename messenger_pairing to messenger_pairing_and_syncing
---------
Co-authored-by: frank <lovefree103@gmail.com>
Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2024-07-30 16:03:43 +00:00
|
|
|
config.ServerConfig.InstallationID = backend.InstallationID()
|
|
|
|
config.ServerConfig.KeyUID = backend.KeyUID()
|
|
|
|
|
2023-08-18 08:51:16 +00:00
|
|
|
err := MakeServerConfig(config.ServerConfig)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return NewKeystoreFilesSenderServer(backend, config)
|
|
|
|
}
|
|
|
|
|
|
|
|
// StartUpKeystoreFilesSenderServer generates a KeystoreFilesSenderServer, starts the sending server
|
|
|
|
// and returns the ConnectionParams string to allow a ReceiverClient to make a successful connection.
|
|
|
|
func StartUpKeystoreFilesSenderServer(backend *api.GethStatusBackend, configJSON string) (string, error) {
|
|
|
|
conf := NewKeystoreFilesSenderServerConfig()
|
|
|
|
err := json.Unmarshal([]byte(configJSON), conf)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = validateKeystoreFilesConfig(backend, conf)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
ps, err := MakeKeystoreFilesSenderServer(backend, conf)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = ps.startSendingData()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
cp, err := ps.MakeConnectionParams()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return cp.ToString(), nil
|
|
|
|
}
|