From dde0c71cfc7de711c432689ec2f38b8c96eed958 Mon Sep 17 00:00:00 2001 From: Samuel Hawksby-Robinson Date: Wed, 5 Oct 2022 10:57:12 +0100 Subject: [PATCH] Added string identifier for Connection String --- VERSION | 2 +- server/connection.go | 15 ++++++++++++--- server/connection_test.go | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index 8e0467180..e5dbd0294 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.111.2 +0.111.3 diff --git a/server/connection.go b/server/connection.go index aea25b84a..0996590f0 100644 --- a/server/connection.go +++ b/server/connection.go @@ -24,6 +24,10 @@ const ( Sending ) +const ( + connectionStringID = "cs" +) + type ConnectionParams struct { version ConnectionParamVersion netIP net.IP @@ -47,9 +51,10 @@ func NewConnectionParams(netIP net.IP, port int, publicKey *ecdsa.PublicKey, aes // ToString generates a string required for generating a secure connection to another Status device. // // The returned string will look like below: -// - "2:4FHRnp:H6G:uqnnMwVUfJc2Fkcaojet8F1ufKC3hZdGEt47joyBx9yd:BbnZ7Gc66t54a9kEFCf7FW8SGQuYypwHVeNkRYeNoqV6:2" +// - "cs2:4FHRnp:H6G:uqnnMwVUfJc2Fkcaojet8F1ufKC3hZdGEt47joyBx9yd:BbnZ7Gc66t54a9kEFCf7FW8SGQuYypwHVeNkRYeNoqV6:2" // // Format bytes encoded into a base58 string, delimited by ":" +// - string type identifier // - version // - net.IP // - port @@ -64,15 +69,19 @@ func (cp *ConnectionParams) ToString() string { ek := base58.Encode(cp.aesKey) m := base58.Encode(new(big.Int).SetInt64(int64(cp.serverMode)).Bytes()) - return fmt.Sprintf("%s:%s:%s:%s:%s:%s", v, ip, p, k, ek, m) + return fmt.Sprintf("%s%s:%s:%s:%s:%s:%s", connectionStringID, v, ip, p, k, ek, m) } // 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 s[:2] != connectionStringID { + return fmt.Errorf("connection string doesn't begin with identifier '%s'", connectionStringID) + } + requiredParams := 6 - sData := strings.Split(s, ":") + sData := strings.Split(s[2:], ":") if len(sData) != requiredParams { return fmt.Errorf("expected data '%s' to have length of '%d', received '%d'", s, requiredParams, len(sData)) } diff --git a/server/connection_test.go b/server/connection_test.go index f2369c451..30f051406 100644 --- a/server/connection_test.go +++ b/server/connection_test.go @@ -7,7 +7,7 @@ import ( ) var ( - connectionString = "2:4FHRnp:Q4:uqnnMwVUfJc2Fkcaojet8F1ufKC3hZdGEt47joyBx9yd:BbnZ7Gc66t54a9kEFCf7FW8SGQuYypwHVeNkRYeNoqV6:3" + connectionString = "cs2:4FHRnp:Q4:uqnnMwVUfJc2Fkcaojet8F1ufKC3hZdGEt47joyBx9yd:BbnZ7Gc66t54a9kEFCf7FW8SGQuYypwHVeNkRYeNoqV6:3" ) func TestConnectionParamsSuite(t *testing.T) {