Removed server mode from pairing

This commit is contained in:
Samuel Hawksby-Robinson 2023-03-21 13:08:28 +00:00
parent 013c5addd6
commit fae7e8dba5
7 changed files with 28 additions and 69 deletions

View File

@ -1017,7 +1017,7 @@ func GetConnectionStringForBeingBootstrapped(configJSON string) string {
if configJSON == "" {
return makeJSONResponse(fmt.Errorf("no config given, PayloadSourceConfig is expected"))
}
cs, err := pairing.StartUpReceiverServer(statusBackend, pairing.Receiving, configJSON)
cs, err := pairing.StartUpReceiverServer(statusBackend, configJSON)
if err != nil {
return makeJSONResponse(err)
}
@ -1034,7 +1034,7 @@ func GetConnectionStringForBootstrappingAnotherDevice(configJSON string) string
if configJSON == "" {
return makeJSONResponse(fmt.Errorf("no config given, SendingServerConfig is expected"))
}
cs, err := pairing.StartUpSenderServer(statusBackend, pairing.Sending, configJSON)
cs, err := pairing.StartUpSenderServer(statusBackend, configJSON)
if err != nil {
return makeJSONResponse(err)
}

View File

@ -46,7 +46,6 @@ type ServerConfig struct {
EK []byte `json:"-"`
Cert *tls.Certificate `json:"-"`
Hostname string `json:"-"`
Mode Mode `json:"-"`
}
type ClientConfig struct{}

View File

@ -13,45 +13,37 @@ import (
)
type ConnectionParamVersion int
type Mode int
const (
Version1 ConnectionParamVersion = iota + 1
)
const (
Receiving Mode = iota + 1
Sending
)
const (
connectionStringID = "cs"
)
type ConnectionParams struct {
version ConnectionParamVersion
netIP net.IP
port int
publicKey *ecdsa.PublicKey
aesKey []byte
serverMode Mode
version ConnectionParamVersion
netIP net.IP
port int
publicKey *ecdsa.PublicKey
aesKey []byte
}
func NewConnectionParams(netIP net.IP, port int, publicKey *ecdsa.PublicKey, aesKey []byte, mode Mode) *ConnectionParams {
func NewConnectionParams(netIP net.IP, port int, publicKey *ecdsa.PublicKey, aesKey []byte) *ConnectionParams {
cp := new(ConnectionParams)
cp.version = Version1
cp.netIP = netIP
cp.port = port
cp.publicKey = publicKey
cp.aesKey = aesKey
cp.serverMode = mode
return cp
}
// ToString generates a string required for generating a secure connection to another Status device.
//
// The returned string will look like below:
// - "cs2:4FHRnp:H6G:uqnnMwVUfJc2Fkcaojet8F1ufKC3hZdGEt47joyBx9yd:BbnZ7Gc66t54a9kEFCf7FW8SGQuYypwHVeNkRYeNoqV6:2"
// - "cs2:4FHRnp:H6G:uqnnMwVUfJc2Fkcaojet8F1ufKC3hZdGEt47joyBx9yd:BbnZ7Gc66t54a9kEFCf7FW8SGQuYypwHVeNkRYeNoqV6"
//
// Format bytes encoded into a base58 string, delimited by ":"
// - string type identifier
@ -60,19 +52,14 @@ func NewConnectionParams(netIP net.IP, port int, publicKey *ecdsa.PublicKey, aes
// - port
// - ecdsa CompressedPublicKey
// - AES encryption key
// - server mode
func (cp *ConnectionParams) ToString() string {
v := base58.Encode(new(big.Int).SetInt64(int64(cp.version)).Bytes())
ip := base58.Encode(cp.netIP)
p := base58.Encode(new(big.Int).SetInt64(int64(cp.port)).Bytes())
k := base58.Encode(elliptic.MarshalCompressed(cp.publicKey.Curve, cp.publicKey.X, cp.publicKey.Y))
ek := base58.Encode(cp.aesKey)
m := base58.Encode(new(big.Int).SetInt64(int64(cp.serverMode)).Bytes())
// TODO remove server mode from the connection string, rely on specific function calls rather than algorithmic orchestration
// https://github.com/status-im/status-go/issues/3301
return fmt.Sprintf("%s%s:%s:%s:%s:%s:%s", connectionStringID, v, ip, p, k, ek, m)
return fmt.Sprintf("%s%s:%s:%s:%s:%s", connectionStringID, v, ip, p, k, ek)
}
// FromString parses a connection params string required for to securely connect to another Status device.
@ -87,7 +74,7 @@ func (cp *ConnectionParams) FromString(s string) error {
return fmt.Errorf("connection string doesn't begin with identifier '%s'", connectionStringID)
}
requiredParams := 6
requiredParams := 5
sData := strings.Split(s[2:], ":")
if len(sData) != requiredParams {
@ -101,7 +88,6 @@ func (cp *ConnectionParams) FromString(s string) error {
cp.publicKey.X, cp.publicKey.Y = elliptic.UnmarshalCompressed(elliptic.P256(), base58.Decode(sData[3]))
cp.publicKey.Curve = elliptic.P256()
cp.aesKey = base58.Decode(sData[4])
cp.serverMode = Mode(new(big.Int).SetBytes(base58.Decode(sData[5])).Int64())
return cp.validate()
}
@ -127,12 +113,7 @@ func (cp *ConnectionParams) validate() error {
return err
}
err = cp.validateAESKey()
if err != nil {
return err
}
return cp.validateServerMode()
return cp.validateAESKey()
}
func (cp *ConnectionParams) validateVersion() error {
@ -179,15 +160,6 @@ func (cp *ConnectionParams) validateAESKey() error {
return nil
}
func (cp *ConnectionParams) validateServerMode() error {
switch cp.serverMode {
case 0, Receiving, Sending:
return nil
default:
return fmt.Errorf("invalid server mode '%d'", cp.serverMode)
}
}
func (cp *ConnectionParams) URL() (*url.URL, error) {
err := cp.validate()
if err != nil {

View File

@ -10,7 +10,7 @@ import (
)
var (
connectionString = "cs2:4FHRnp:Q4:uqnnMwVUfJc2Fkcaojet8F1ufKC3hZdGEt47joyBx9yd:BbnZ7Gc66t54a9kEFCf7FW8SGQuYypwHVeNkRYeNoqV6:3"
connectionString = "cs2:4FHRnp:Q4:uqnnMwVUfJc2Fkcaojet8F1ufKC3hZdGEt47joyBx9yd:BbnZ7Gc66t54a9kEFCf7FW8SGQuYypwHVeNkRYeNoqV6"
)
func TestConnectionParamsSuite(t *testing.T) {
@ -42,7 +42,6 @@ func (s *ConnectionParamsSuite) SetupSuite() {
Server: bs,
pk: &s.PK.PublicKey,
ek: s.AES,
mode: Sending,
}
}
@ -59,8 +58,6 @@ func (s *ConnectionParamsSuite) TestConnectionParams_Generate() {
err := cp.FromString(connectionString)
s.Require().NoError(err)
s.Require().Exactly(Sending, cp.serverMode)
u, err := cp.URL()
s.Require().NoError(err)

View File

@ -31,9 +31,6 @@ type BaseServer struct {
pk *ecdsa.PublicKey
ek []byte
// TODO remove mode from pairing process
// https://github.com/status-im/status-go/issues/3301
mode Mode
}
// NewBaseServer returns a *BaseServer init from the given *SenderServerConfig
@ -53,7 +50,6 @@ func NewBaseServer(logger *zap.Logger, e *PayloadEncryptor, config *ServerConfig
challengeGiver: cg,
pk: config.PK,
ek: config.EK,
mode: config.Mode,
}
bs.SetTimeout(config.Timeout)
return bs, nil
@ -72,7 +68,7 @@ func (s *BaseServer) MakeConnectionParams() (*ConnectionParams, error) {
netIP = netIP4
}
return NewConnectionParams(netIP, s.MustGetPort(), s.pk, s.ek, s.mode), nil
return NewConnectionParams(netIP, s.MustGetPort(), s.pk, s.ek), nil
}
func MakeServerConfig(config *ServerConfig) error {
@ -158,7 +154,7 @@ func (s *SenderServer) startSendingData() error {
}
// MakeFullSenderServer generates a fully configured and randomly seeded SenderServer
func MakeFullSenderServer(backend *api.GethStatusBackend, mode Mode, config *SenderServerConfig) (*SenderServer, error) {
func MakeFullSenderServer(backend *api.GethStatusBackend, config *SenderServerConfig) (*SenderServer, error) {
err := MakeServerConfig(config.ServerConfig)
if err != nil {
return nil, err
@ -168,16 +164,16 @@ func MakeFullSenderServer(backend *api.GethStatusBackend, mode Mode, config *Sen
return NewSenderServer(backend, config)
}
// StartUpSenderServer generates a SenderServer, starts the sending server in the correct mode
// StartUpSenderServer generates a SenderServer, starts the sending server
// and returns the ConnectionParams string to allow a ReceiverClient to make a successful connection.
func StartUpSenderServer(backend *api.GethStatusBackend, mode Mode, configJSON string) (string, error) {
func StartUpSenderServer(backend *api.GethStatusBackend, configJSON string) (string, error) {
conf := NewSenderServerConfig()
err := json.Unmarshal([]byte(configJSON), conf)
if err != nil {
return "", err
}
ps, err := MakeFullSenderServer(backend, mode, conf)
ps, err := MakeFullSenderServer(backend, conf)
if err != nil {
return "", err
}
@ -249,7 +245,7 @@ func (s *ReceiverServer) startReceivingData() error {
}
// MakeFullReceiverServer generates a fully configured and randomly seeded ReceiverServer
func MakeFullReceiverServer(backend *api.GethStatusBackend, mode Mode, config *ReceiverServerConfig) (*ReceiverServer, error) {
func MakeFullReceiverServer(backend *api.GethStatusBackend, config *ReceiverServerConfig) (*ReceiverServer, error) {
err := MakeServerConfig(config.ServerConfig)
if err != nil {
return nil, err
@ -264,16 +260,16 @@ func MakeFullReceiverServer(backend *api.GethStatusBackend, mode Mode, config *R
return NewReceiverServer(backend, config)
}
// StartUpReceiverServer generates a ReceiverServer, starts the sending server in the correct mode
// StartUpReceiverServer generates a ReceiverServer, starts the sending server
// and returns the ConnectionParams string to allow a SenderClient to make a successful connection.
func StartUpReceiverServer(backend *api.GethStatusBackend, mode Mode, configJSON string) (string, error) {
func StartUpReceiverServer(backend *api.GethStatusBackend, configJSON string) (string, error) {
conf := NewReceiverServerConfig()
err := json.Unmarshal([]byte(configJSON), conf)
if err != nil {
return "", err
}
ps, err := MakeFullReceiverServer(backend, mode, conf)
ps, err := MakeFullReceiverServer(backend, conf)
if err != nil {
return "", err
}

View File

@ -79,7 +79,6 @@ func (s *PairingServerSuite) TestPairingServer_StartPairingSend() {
// Replace PairingServer.accountMounter with a MockPayloadMounter
pm := NewMockPayloadMounter(s.EphemeralAES)
s.SS.accountMounter = pm
s.SS.mode = Sending
err := s.SS.startSendingData()
s.Require().NoError(err)
@ -127,8 +126,6 @@ func (s *PairingServerSuite) TestPairingServer_StartPairingReceive() {
pm := NewMockPayloadReceiver(s.EphemeralAES)
s.RS.accountReceiver = pm
s.RS.mode = Receiving
err := s.RS.startReceivingData()
s.Require().NoError(err)
@ -172,7 +169,6 @@ func (s *PairingServerSuite) sendingSetup() *ReceiverClient {
// Replace PairingServer.PayloadManager with a MockPayloadReceiver
pm := NewMockPayloadMounter(s.EphemeralAES)
s.SS.accountMounter = pm
s.SS.mode = Sending
err := s.SS.startSendingData()
s.Require().NoError(err)
@ -290,7 +286,6 @@ func makeThingToSay() (string, error) {
}
func (s *PairingServerSuite) TestGetOutboundIPWithFullServerE2e() {
s.SS.mode = Sending
s.SS.SetHandlers(server.HandlerPatternMap{"/hello": testHandler(s.T())})
err := s.SS.Start()

View File

@ -153,7 +153,7 @@ func (s *SyncDeviceSuite) TestPairingSyncDeviceClientAsSender() {
serverNodeConfig.RootDataDir = serverTmpDir
serverConfigBytes, err := json.Marshal(serverPayloadSourceConfig)
require.NoError(s.T(), err)
cs, err := StartUpReceiverServer(serverBackend, Receiving, string(serverConfigBytes))
cs, err := StartUpReceiverServer(serverBackend, string(serverConfigBytes))
require.NoError(s.T(), err)
// generate some data for the client
@ -207,7 +207,7 @@ func (s *SyncDeviceSuite) TestPairingSyncDeviceClientAsSender() {
require.False(s.T(), serverMessenger.HasPairedDevices())
// repeat local pairing, we should expect no error after receiver logged in
cs, err = StartUpReceiverServer(serverBackend, Receiving, string(serverConfigBytes))
cs, err = StartUpReceiverServer(serverBackend, string(serverConfigBytes))
require.NoError(s.T(), err)
err = StartUpSendingClient(clientBackend, cs, string(clientConfigBytes))
require.NoError(s.T(), err)
@ -216,7 +216,7 @@ func (s *SyncDeviceSuite) TestPairingSyncDeviceClientAsSender() {
// test if it's okay when account already exist but not logged in
require.NoError(s.T(), serverBackend.Logout())
cs, err = StartUpReceiverServer(serverBackend, Receiving, string(serverConfigBytes))
cs, err = StartUpReceiverServer(serverBackend, string(serverConfigBytes))
require.NoError(s.T(), err)
err = StartUpSendingClient(clientBackend, cs, string(clientConfigBytes))
require.NoError(s.T(), err)
@ -247,7 +247,7 @@ func (s *SyncDeviceSuite) TestPairingSyncDeviceClientAsReceiver() {
}
configBytes, err := json.Marshal(config)
require.NoError(s.T(), err)
cs, err := StartUpSenderServer(serverBackend, Sending, string(configBytes))
cs, err := StartUpSenderServer(serverBackend, string(configBytes))
require.NoError(s.T(), err)
// generate some data for the server
@ -308,7 +308,7 @@ func (s *SyncDeviceSuite) TestPairingSyncDeviceClientAsReceiver() {
require.False(s.T(), clientMessenger.HasPairedDevices())
// repeat local pairing, we should expect no error after receiver logged in
cs, err = StartUpSenderServer(serverBackend, Sending, string(configBytes))
cs, err = StartUpSenderServer(serverBackend, string(configBytes))
require.NoError(s.T(), err)
err = StartUpReceivingClient(clientBackend, cs, string(clientConfigBytes))
require.NoError(s.T(), err)
@ -317,7 +317,7 @@ func (s *SyncDeviceSuite) TestPairingSyncDeviceClientAsReceiver() {
// test if it's okay when account already exist but not logged in
require.NoError(s.T(), clientBackend.Logout())
cs, err = StartUpSenderServer(serverBackend, Sending, string(configBytes))
cs, err = StartUpSenderServer(serverBackend, string(configBytes))
require.NoError(s.T(), err)
err = StartUpReceivingClient(clientBackend, cs, string(clientConfigBytes))
require.NoError(s.T(), err)