status-go/server/pairing/config.go

149 lines
4.8 KiB
Go
Raw Normal View History

package pairing
import (
"crypto/ecdsa"
"crypto/tls"
"net"
"github.com/status-im/status-go/multiaccounts"
"github.com/status-im/status-go/params"
)
type SenderConfig struct {
// SenderConfig.KeystorePath must end with keyUID
2023-03-29 15:51:01 +00:00
KeystorePath string `json:"keystorePath" validate:"required,keystorepath"`
// DeviceType SendPairInstallation need this information
2023-03-29 15:51:01 +00:00
DeviceType string `json:"deviceType" validate:"required"`
KeyUID string `json:"keyUID" validate:"required,keyuid"`
Password string `json:"password" validate:"required"`
ChatKey string `json:"chatKey"` // set only in case of a Keycard user, otherwise empty
DB *multiaccounts.Database `json:"-"`
}
type ReceiverConfig struct {
2023-03-29 15:51:01 +00:00
// nodeConfig is required, but we'll validate it separately
NodeConfig *params.NodeConfig `json:"nodeConfig"`
// ReceiverConfig.KeystorePath must not end with keyUID (because keyUID is not known yet)
2023-03-29 15:51:01 +00:00
KeystorePath string `json:"keystorePath" validate:"required,not_end_keyuid"`
// DeviceType SendPairInstallation need this information
2023-03-29 15:51:01 +00:00
DeviceType string `json:"deviceType" validate:"required"`
KDFIterations int `json:"kdfIterations" validate:"gte=0"`
// SettingCurrentNetwork corresponding to field current_network from table settings, so that we can override current network from sender
2023-03-29 15:51:01 +00:00
SettingCurrentNetwork string `json:"settingCurrentNetwork" validate:"required"`
DeviceName string `json:"deviceName"`
DB *multiaccounts.Database `json:"-"`
LoggedInKeyUID string `json:"-"`
}
type KeystoreFilesConfig struct {
KeystorePath string `json:"keystorePath" validate:"required,keystorepath"`
LoggedInKeyUID string `json:"loggedInKeyUid" validate:"required,keyuid"`
Password string `json:"password" validate:"required"`
}
type KeystoreFilesSenderConfig struct {
KeystoreFilesConfig
KeypairsToExport []string `json:"keypairsToExport" validate:"required"`
}
type KeystoreFilesReceiverConfig struct {
KeystoreFilesConfig
KeypairsToImport []string `json:"keypairsToImport" validate:"required"`
}
type ServerConfig struct {
// Timeout the number of milliseconds after which the pairing server will automatically terminate
2023-03-29 15:51:01 +00:00
Timeout uint `json:"timeout" validate:"omitempty,gte=0"`
// Connection fields, not json (un)marshalled
// Required for the server, but MUST NOT come from client
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
PK *ecdsa.PublicKey `json:"-"`
EK []byte `json:"-"`
Cert *tls.Certificate `json:"-"`
ListenIP net.IP `json:"-"`
IPAddresses []net.IP `json:"-"`
InstallationID string `json:"-"`
KeyUID string `json:"-"`
}
type ClientConfig struct{}
type SenderServerConfig struct {
2023-03-29 15:51:01 +00:00
SenderConfig *SenderConfig `json:"senderConfig" validate:"required"`
ServerConfig *ServerConfig `json:"serverConfig" validate:"omitempty,dive"`
}
type KeystoreFilesSenderServerConfig struct {
SenderConfig *KeystoreFilesSenderConfig `json:"senderConfig" validate:"required"`
ServerConfig *ServerConfig `json:"serverConfig" validate:"omitempty,dive"`
}
type SenderClientConfig struct {
2023-03-29 15:51:01 +00:00
SenderConfig *SenderConfig `json:"senderConfig" validate:"required"`
ClientConfig *ClientConfig `json:"clientConfig"`
}
type ReceiverClientConfig struct {
2023-03-29 15:51:01 +00:00
ReceiverConfig *ReceiverConfig `json:"receiverConfig" validate:"required"`
ClientConfig *ClientConfig `json:"clientConfig"`
}
type KeystoreFilesReceiverClientConfig struct {
ReceiverConfig *KeystoreFilesReceiverConfig `json:"receiverConfig" validate:"required"`
ClientConfig *ClientConfig `json:"clientConfig"`
}
type ReceiverServerConfig struct {
2023-03-29 15:51:01 +00:00
ReceiverConfig *ReceiverConfig `json:"receiverConfig" validate:"required"`
ServerConfig *ServerConfig `json:"serverConfig" validate:"omitempty,dive"`
}
func NewSenderServerConfig() *SenderServerConfig {
return &SenderServerConfig{
SenderConfig: new(SenderConfig),
ServerConfig: new(ServerConfig),
}
}
func NewKeystoreFilesSenderServerConfig() *KeystoreFilesSenderServerConfig {
return &KeystoreFilesSenderServerConfig{
SenderConfig: new(KeystoreFilesSenderConfig),
ServerConfig: new(ServerConfig),
}
}
func NewSenderClientConfig() *SenderClientConfig {
return &SenderClientConfig{
SenderConfig: new(SenderConfig),
ClientConfig: new(ClientConfig),
}
}
func NewReceiverClientConfig() *ReceiverClientConfig {
return &ReceiverClientConfig{
ReceiverConfig: new(ReceiverConfig),
ClientConfig: new(ClientConfig),
}
}
func NewKeystoreFilesReceiverClientConfig() *KeystoreFilesReceiverClientConfig {
return &KeystoreFilesReceiverClientConfig{
ReceiverConfig: new(KeystoreFilesReceiverConfig),
ClientConfig: new(ClientConfig),
}
}
func NewReceiverServerConfig() *ReceiverServerConfig {
return &ReceiverServerConfig{
ReceiverConfig: new(ReceiverConfig),
ServerConfig: new(ServerConfig),
}
}