|
|
|
@ -18,8 +18,6 @@ import (
|
|
|
|
|
"sync"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"cwtch.im/cwtch/model/constants"
|
|
|
|
|
|
|
|
|
|
"cwtch.im/cwtch/event"
|
|
|
|
|
"cwtch.im/cwtch/model"
|
|
|
|
|
"cwtch.im/cwtch/model/attr"
|
|
|
|
@ -599,7 +597,7 @@ func (cp *cwtchPeer) StartGroup(name string, server string) (int, error) {
|
|
|
|
|
// 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.
|
|
|
|
|
// Status: Ready for 1.5
|
|
|
|
|
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 {
|
|
|
|
@ -623,7 +621,7 @@ func (cp *cwtchPeer) AddServer(serverSpecification string) error {
|
|
|
|
|
if conversationInfo == nil {
|
|
|
|
|
_, err := cp.NewContactConversation(onion, model.DefaultP2PAccessControl(), true)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -635,7 +633,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
|
|
|
|
@ -647,13 +645,12 @@ func (cp *cwtchPeer) AddServer(serverSpecification string) error {
|
|
|
|
|
cp.SetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ServerKeyZone.ConstructZonedPath(k)), v)
|
|
|
|
|
}
|
|
|
|
|
cp.SetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ServerKeyZone.ConstructZonedPath(string(model.BundleType))), serverSpecification)
|
|
|
|
|
|
|
|
|
|
return onion, err
|
|
|
|
|
} else {
|
|
|
|
|
return err
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
return "", model.InconsistentKeyBundleError
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetServers returns an unordered list of servers
|
|
|
|
@ -795,7 +792,7 @@ func (cp *cwtchPeer) ImportBundle(importString string) error {
|
|
|
|
|
// Server Key Bundles are prefixed with
|
|
|
|
|
bundle, err := base64.StdEncoding.DecodeString(importString[len(serverPrefix):])
|
|
|
|
|
if err == nil {
|
|
|
|
|
if err = cp.AddServer(string(bundle)); err != nil {
|
|
|
|
|
if _, err = cp.AddServer(string(bundle)); err != nil {
|
|
|
|
|
return ConstructResponse(importBundlePrefix, err.Error())
|
|
|
|
|
}
|
|
|
|
|
return ConstructResponse(importBundlePrefix, "success")
|
|
|
|
|