AddServer return new server onion
continuous-integration/drone/push Build is pending Details
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Dan Ballard 2021-11-05 15:16:47 -07:00
parent 4a9a254b48
commit 8b08cabed9
2 changed files with 9 additions and 8 deletions

View File

@ -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

View File

@ -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)