AddServer return new server onion #403
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue