From 8b08cabed95656c4b8d3f7648f79aef1daa2edf5 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Fri, 5 Nov 2021 15:16:47 -0700 Subject: [PATCH] AddServer return new server onion --- peer/cwtch_peer.go | 15 ++++++++------- testing/cwtch_peer_server_integration_test.go | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index 3bc5a9c..862d6e1 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -214,7 +214,7 @@ type ModifyGroups interface { // ModifyServers provides write-only access to servers type ModifyServers interface { - AddServer(string) error + AddServer(string) (string, error) ResyncServer(onion string) error } @@ -452,12 +452,13 @@ func (cp *cwtchPeer) AddContact(nick, onion string, authorization model.Authoriz // AddServer takes in a serialized server specification (a bundle of related keys) and adds a contact for the // server assuming there are no errors and the contact doesn't already exist. +// Returns the onion of the new server if added // TODO in the future this function should also integrate with a trust provider to validate the key bundle. -func (cp *cwtchPeer) AddServer(serverSpecification string) error { +func (cp *cwtchPeer) AddServer(serverSpecification string) (string, error) { // This confirms that the server did at least sign the bundle keyBundle, err := model.DeserializeAndVerify([]byte(serverSpecification)) if err != nil { - return err + return "", err } log.Debugf("Got new key bundle %v", keyBundle.Serialize()) @@ -465,7 +466,7 @@ func (cp *cwtchPeer) AddServer(serverSpecification string) error { // keys or subsets of keys, but for now they must commit only to a complete set of keys required for Cwtch Groups // (that way we can be assured that the keybundle we store is a valid one) if !keyBundle.HasKeyType(model.KeyTypeTokenOnion) || !keyBundle.HasKeyType(model.KeyTypeServerOnion) || !keyBundle.HasKeyType(model.KeyTypePrivacyPass) { - return errors.New("keybundle is incomplete") + return "", errors.New("keybundle is incomplete") } if keyBundle.HasKeyType(model.KeyTypeServerOnion) { @@ -503,7 +504,7 @@ func (cp *cwtchPeer) AddServer(serverSpecification string) error { if exists { if val != v { // this is inconsistent! - return model.InconsistentKeyBundleError + return "", model.InconsistentKeyBundleError } } // we haven't seen this key associated with the server before @@ -519,9 +520,9 @@ func (cp *cwtchPeer) AddServer(serverSpecification string) error { cp.SetContactAttribute(onion, k, v) } - return nil + return onion, nil } - return err + return "", err } // GetContacts returns an unordered list of onions diff --git a/testing/cwtch_peer_server_integration_test.go b/testing/cwtch_peer_server_integration_test.go index c95eb8f..0a77b4f 100644 --- a/testing/cwtch_peer_server_integration_test.go +++ b/testing/cwtch_peer_server_integration_test.go @@ -180,7 +180,7 @@ func TestCwtchPeerIntegration(t *testing.T) { // ***** Peering, server joining, group creation / invite ***** fmt.Println("Alice joining server...") - if err := alice.AddServer(string(serverKeyBundle)); err != nil { + if _, err := alice.AddServer(string(serverKeyBundle)); err != nil { t.Fatalf("Failed to Add Server Bundle %v", err) } alice.JoinServer(ServerAddr)