|
|
|
@ -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
|
|
|
|
@ -775,7 +772,7 @@ const importBundlePrefix = "importBundle"
|
|
|
|
|
|
|
|
|
|
func (cp *cwtchPeer) ImportBundle(importString string) error {
|
|
|
|
|
if tor.IsValidHostname(importString) {
|
|
|
|
|
_,err := cp.NewContactConversation(importString, model.DefaultP2PAccessControl(), true)
|
|
|
|
|
_, err := cp.NewContactConversation(importString, model.DefaultP2PAccessControl(), true)
|
|
|
|
|
if err == nil {
|
|
|
|
|
return ConstructResponse(importBundlePrefix, "success")
|
|
|
|
|
} else {
|
|
|
|
@ -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")
|
|
|
|
@ -1167,7 +1164,7 @@ func (cp *cwtchPeer) attemptInsertOrAcknowledgeLegacyGroupConversation(conversat
|
|
|
|
|
} else {
|
|
|
|
|
cp.mutex.Lock()
|
|
|
|
|
cp.storage.InsertMessage(conversationID, 0, dm.Text, model.Attributes{constants.AttrAck: constants.True, "PreviousSignature": base64.StdEncoding.EncodeToString(dm.PreviousMessageSig), constants.AttrAuthor: dm.Onion, constants.AttrSentTimestamp: time.Unix(int64(dm.Timestamp), 0).Format(time.RFC3339Nano)}, signature, model.CalculateContentHash(dm.Onion, dm.Text))
|
|
|
|
|
newTotal,_ := cp.storage.GetChannelMessageCount(conversationID, 0)
|
|
|
|
|
newTotal, _ := cp.storage.GetChannelMessageCount(conversationID, 0)
|
|
|
|
|
cp.mutex.Unlock()
|
|
|
|
|
cp.eventBus.Publish(event.NewEvent(event.NewMessageFromGroup, map[event.Field]string{event.ConversationID: strconv.Itoa(conversationID), event.TimestampSent: time.Unix(int64(dm.Timestamp), 0).Format(time.RFC3339Nano), event.RemotePeer: dm.Onion, event.Index: strconv.Itoa(newTotal)}))
|
|
|
|
|
return nil
|
|
|
|
|