From 4d491da8dedf45e6d134e80d4e9af72df80c835c Mon Sep 17 00:00:00 2001 From: Igor Sirotin Date: Wed, 15 Feb 2023 17:42:12 +0300 Subject: [PATCH] LocalPairing minor fixes. `ValidateConnectionString` method. (#3184) * fix(pairing): Added ConnectionParams::FromString input length check * feat: Added `IsValidConnectionString` method * Renamed IsValidConnectionString to ValidateConnectionString * Bump version --- VERSION | 2 +- mobile/status.go | 8 ++++++++ server/pairing/connection.go | 11 +++++++++++ server/pairing/events.go | 13 ++++++------- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/VERSION b/VERSION index 6f4162c9d..2c5f4d727 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.131.4 +0.131.5 diff --git a/mobile/status.go b/mobile/status.go index 6b5dc7f77..606503371 100644 --- a/mobile/status.go +++ b/mobile/status.go @@ -1012,6 +1012,14 @@ func InputConnectionStringForBootstrapping(cs, configJSON string) string { return makeJSONResponse(err) } +func ValidateConnectionString(cs string) string { + err := pairing.ValidateConnectionString(cs) + if err == nil { + return "" + } + return err.Error() +} + func EncodeTransfer(to string, value string) string { result, err := abi_spec.EncodeTransfer(to, value) if err != nil { diff --git a/server/pairing/connection.go b/server/pairing/connection.go index 4be589ef7..9ce323ef0 100644 --- a/server/pairing/connection.go +++ b/server/pairing/connection.go @@ -75,6 +75,11 @@ func (cp *ConnectionParams) ToString() string { // FromString parses a connection params string required for to securely connect to another Status device. // This function parses a connection string generated by ToString func (cp *ConnectionParams) FromString(s string) error { + + if len(s) < 2 { + return fmt.Errorf("connection string is invalid: '%s'", s) + } + if s[:2] != connectionStringID { return fmt.Errorf("connection string doesn't begin with identifier '%s'", connectionStringID) } @@ -192,3 +197,9 @@ func (cp *ConnectionParams) URL() (*url.URL, error) { } return u, nil } + +func ValidateConnectionString(cs string) error { + ccp := ConnectionParams{} + err := ccp.FromString(cs) + return err +} diff --git a/server/pairing/events.go b/server/pairing/events.go index 39a969c1e..bb578169f 100644 --- a/server/pairing/events.go +++ b/server/pairing/events.go @@ -4,17 +4,16 @@ package pairing type EventType string const ( - EventConnectionError EventType = "connection-error" + // both client and server + EventConnectionError EventType = "connection-error" EventConnectionSuccess EventType = "connection-success" + EventTransferError EventType = "transfer-error" + EventTransferSuccess EventType = "transfer-success" - EventTransferError EventType = "transfer-error" - - EventTransferSuccess EventType = "transfer-success" - + // Only receiver side EventProcessSuccess EventType = "process-success" - - EventProcessError EventType = "process-error" + EventProcessError EventType = "process-error" ) // Event is a type for transfer events.