Skip to content

Commit

Permalink
feat(pairing)!: Add fallback flow to pairing
Browse files Browse the repository at this point in the history
feat(pairing)!: add fallback flow to pairing

This commit includes the following changes:

*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:
- Version is not used. Better not to use something than to use it wrongly, rarely version is needed if the protocol is correctly upgraded.
- 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 should be supported (a new might be able to parse a v2 client, but not the other way around). It is to be considered a complete breaking change. 2.30 -> 2.30 syncing only is supported, but going forward there's a clear strategy on how to update the protocol (append parameters, don't change existing one).

*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

1) Client A1 shows a QR code
2) Client A2 scans a QR code
3) If connection fails on A2, the user will be prompted to enter a seed phrase.
4) 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.
5) 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.
  • Loading branch information
cammellos committed Jul 24, 2024
1 parent 7c4b43b commit 7d0468b
Show file tree
Hide file tree
Showing 31 changed files with 869 additions and 570 deletions.
20 changes: 16 additions & 4 deletions api/geth_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ var _ StatusBackend = (*GethStatusBackend)(nil)
type GethStatusBackend struct {
mu sync.Mutex
// rootDataDir is the same for all networks.
rootDataDir string
appDB *sql.DB
walletDB *sql.DB
config *params.NodeConfig
rootDataDir string
appDB *sql.DB
walletDB *sql.DB
config *params.NodeConfig
installationID string
keyUID string

statusNode *node.StatusNode
personalAPI *personal.PublicAPI
Expand Down Expand Up @@ -2658,11 +2660,21 @@ func (b *GethStatusBackend) injectAccountsIntoWakuService(w types.WakuKeyManager
b.statusNode.ChatService(accDB).Init(messenger)
b.statusNode.EnsService().Init(messenger.SyncEnsNamesWithDispatchMessage)
b.statusNode.CommunityTokensService().Init(messenger)
b.installationID = messenger.InstallationID()
b.keyUID = messenger.KeyUID()
}

return nil
}

func (b *GethStatusBackend) InstallationID() string {
return b.installationID
}

func (b *GethStatusBackend) KeyUID() string {
return b.keyUID
}

func (b *GethStatusBackend) injectAccountsIntoServices() error {
if b.statusNode.WakuService() != nil {
return b.injectAccountsIntoWakuService(b.statusNode.WakuService(), func() *ext.Service {
Expand Down
29 changes: 26 additions & 3 deletions mobile/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,18 @@ func GetConnectionStringForBootstrappingAnotherDevice(configJSON string) string
return cs
}

type inputConnectionStringForBootstrappingResponse struct {
InstallationID string `json:"installationId"`
KeyUID string `json:"keyUID"`
Error error `json:"error"`
}

func (i *inputConnectionStringForBootstrappingResponse) toJSON(err error) string {
i.Error = err
j, _ := json.Marshal(i)
return string(j)
}

// InputConnectionStringForBootstrapping starts a pairing.ReceiverClient
// The given server.ConnectionParams string will determine the server.Mode
//
Expand All @@ -1202,18 +1214,29 @@ func InputConnectionStringForBootstrapping(cs, configJSON string) string {
return makeJSONResponse(fmt.Errorf("no config given, ReceiverClientConfig is expected"))
}

params := &pairing.ConnectionParams{}
err = params.FromString(cs)
if err != nil {
return makeJSONResponse(fmt.Errorf("could not parse connection string"))
}
response := &inputConnectionStringForBootstrappingResponse{
InstallationID: params.InstallationID(),
KeyUID: params.KeyUID(),
}

err = statusBackend.LocalPairingStateManager.StartPairing(cs)
defer func() { statusBackend.LocalPairingStateManager.StopPairing(cs, err) }()
if err != nil {
return makeJSONResponse(err)
return response.toJSON(err)
}

err = pairing.StartUpReceivingClient(statusBackend, cs, configJSON)
if err != nil {
return makeJSONResponse(err)
return response.toJSON(err)

}

return makeJSONResponse(statusBackend.Logout())
return response.toJSON(statusBackend.Logout())
}

// InputConnectionStringForBootstrappingAnotherDevice starts a pairing.SendingClient
Expand Down
4 changes: 4 additions & 0 deletions protocol/encryption/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,10 @@ func (p *Protocol) ProcessPublicBundle(myIdentityKey *ecdsa.PrivateKey, bundle *
return p.multidevice.AddInstallations(bundle.GetIdentity(), bundle.GetTimestamp(), installations, enabled)
}

func (p *Protocol) AddInstallation(identity []byte, timestamp int64, installation *multidevice.Installation, enabled bool) ([]*multidevice.Installation, error) {
return p.multidevice.AddInstallations(identity, timestamp, []*multidevice.Installation{installation}, enabled)
}

func (p *Protocol) GetMultiDevice() *multidevice.Multidevice {
return p.multidevice
}
Expand Down
Loading

0 comments on commit 7d0468b

Please sign in to comment.