Fixups from merging AddServer PR
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
Sarah Jamie Lewis 2021-11-19 00:09:19 -08:00
parent c1428762f8
commit cb8960f893
3 changed files with 11 additions and 14 deletions

View File

@ -18,8 +18,6 @@ import (
"sync" "sync"
"time" "time"
"cwtch.im/cwtch/model/constants"
"cwtch.im/cwtch/event" "cwtch.im/cwtch/event"
"cwtch.im/cwtch/model" "cwtch.im/cwtch/model"
"cwtch.im/cwtch/model/attr" "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 // 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. // TODO in the future this function should also integrate with a trust provider to validate the key bundle.
// Status: Ready for 1.5 // 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 // This confirms that the server did at least sign the bundle
keyBundle, err := model.DeserializeAndVerify([]byte(serverSpecification)) keyBundle, err := model.DeserializeAndVerify([]byte(serverSpecification))
if err != nil { if err != nil {
@ -623,7 +621,7 @@ func (cp *cwtchPeer) AddServer(serverSpecification string) error {
if conversationInfo == nil { if conversationInfo == nil {
_, err := cp.NewContactConversation(onion, model.DefaultP2PAccessControl(), true) _, err := cp.NewContactConversation(onion, model.DefaultP2PAccessControl(), true)
if err != nil { if err != nil {
return err return "", err
} }
} }
@ -635,7 +633,7 @@ func (cp *cwtchPeer) AddServer(serverSpecification string) error {
if exists { if exists {
if val != v { if val != v {
// this is inconsistent! // this is inconsistent!
return model.InconsistentKeyBundleError return "", model.InconsistentKeyBundleError
} }
} }
// we haven't seen this key associated with the server before // 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(k)), v)
} }
cp.SetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ServerKeyZone.ConstructZonedPath(string(model.BundleType))), serverSpecification) cp.SetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ServerKeyZone.ConstructZonedPath(string(model.BundleType))), serverSpecification)
return onion, err
} else { } else {
return err return "", err
} }
return nil
} }
return nil return "", model.InconsistentKeyBundleError
} }
// GetServers returns an unordered list of servers // GetServers returns an unordered list of servers
@ -775,7 +772,7 @@ const importBundlePrefix = "importBundle"
func (cp *cwtchPeer) ImportBundle(importString string) error { func (cp *cwtchPeer) ImportBundle(importString string) error {
if tor.IsValidHostname(importString) { if tor.IsValidHostname(importString) {
_,err := cp.NewContactConversation(importString, model.DefaultP2PAccessControl(), true) _, err := cp.NewContactConversation(importString, model.DefaultP2PAccessControl(), true)
if err == nil { if err == nil {
return ConstructResponse(importBundlePrefix, "success") return ConstructResponse(importBundlePrefix, "success")
} else { } else {
@ -795,7 +792,7 @@ func (cp *cwtchPeer) ImportBundle(importString string) error {
// Server Key Bundles are prefixed with // Server Key Bundles are prefixed with
bundle, err := base64.StdEncoding.DecodeString(importString[len(serverPrefix):]) bundle, err := base64.StdEncoding.DecodeString(importString[len(serverPrefix):])
if err == nil { 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, err.Error())
} }
return ConstructResponse(importBundlePrefix, "success") return ConstructResponse(importBundlePrefix, "success")
@ -1167,7 +1164,7 @@ func (cp *cwtchPeer) attemptInsertOrAcknowledgeLegacyGroupConversation(conversat
} else { } else {
cp.mutex.Lock() 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)) 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.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)})) 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 return nil

View File

@ -40,7 +40,7 @@ type ModifyGroups interface {
// ModifyServers provides write-only access to servers // ModifyServers provides write-only access to servers
type ModifyServers interface { type ModifyServers interface {
AddServer(string) error AddServer(string) (string, error)
ResyncServer(onion string) error ResyncServer(onion string) error
} }

View File

@ -208,7 +208,7 @@ func TestCwtchPeerIntegration(t *testing.T) {
// Simulate Alice Creating a Group // Simulate Alice Creating a Group
fmt.Println("Alice joining server...") 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) t.Fatalf("Failed to Add Server Bundle %v", err)
} }