Merge pull request 'remove unused events (libcwtch-rs audit); add anti dup on import' (#449) from cleanAndNoDupImport into master
continuous-integration/drone/push Build is passing Details

Reviewed-on: #449
Reviewed-by: Sarah Jamie Lewis <sarah@openprivacy.ca>
This commit is contained in:
Sarah Jamie Lewis 2022-07-30 23:33:06 +00:00
commit b95c2c12eb
4 changed files with 25 additions and 21 deletions

View File

@ -124,12 +124,6 @@ const (
// Password, NewPassword
ChangePassword = Type("ChangePassword")
// Error(err), EventID
ChangePasswordError = Type("ChangePasswordError")
// EventID
ChangePasswordSuccess = Type("ChangePasswordSuccess")
// a group has been successfully added or newly created
// attributes:
// Data [serialized *model.Group]
@ -138,9 +132,6 @@ const (
// RemotePeer
DeleteContact = Type("DeleteContact")
// GroupID
DeleteGroup = Type("DeleteGroup")
// PeerStateChange servers as a new incoming connection message as well, and can/is consumed by frontends to alert of new p2p connections
// RemotePeer
// ConnectionState
@ -192,9 +183,6 @@ const (
Syn = Type("Syn")
Ack = Type("Ack")
// For situations where we want to update $Identity -> $RemotePeer/$GroupID's total message count to be $Data
MessageCounterResync = Type("MessageCounterResync")
// File Handling Events
StopFileShare = Type("StopFileShare")
StopAllFileShares = Type("StopAllFileShares")

View File

@ -483,8 +483,14 @@ func (cp *cwtchPeer) ImportGroup(exportedInvite string) (int, error) {
return -1, err
}
cp.mutex.Lock()
conversationInfo, _ := cp.storage.GetConversationByHandle(gci.GroupID)
if conversationInfo != nil {
cp.mutex.Unlock()
return -1, fmt.Errorf("group already exists")
}
groupConversationID, err := cp.storage.NewConversation(gci.GroupID, map[string]string{}, model.AccessControlList{}, true)
cp.mutex.Unlock()
if err == nil {
cp.SetConversationAttribute(groupConversationID, attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.GroupID)), gci.GroupID)
cp.SetConversationAttribute(groupConversationID, attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.GroupServer)), gci.ServerHost)
@ -500,9 +506,13 @@ func (cp *cwtchPeer) ImportGroup(exportedInvite string) (int, error) {
func (cp *cwtchPeer) NewContactConversation(handle string, acl model.AccessControl, accepted bool) (int, error) {
cp.mutex.Lock()
defer cp.mutex.Unlock()
conversationInfo, _ := cp.storage.GetConversationByHandle(handle)
if conversationInfo == nil {
conversationID, err := cp.storage.NewConversation(handle, model.Attributes{event.SaveHistoryKey: event.DeleteHistoryDefault}, model.AccessControlList{handle: acl}, accepted)
cp.eventBus.Publish(event.NewEvent(event.ContactCreated, map[event.Field]string{event.ConversationID: strconv.Itoa(conversationID), event.RemotePeer: handle}))
return conversationID, err
}
return -1, fmt.Errorf("contact conversation already exists")
}
// AcceptConversation looks up a conversation by `handle` and sets the Accepted status to `true`
@ -604,7 +614,12 @@ func (cp *cwtchPeer) FetchConversationInfo(handle string) (*model.Conversation,
func (cp *cwtchPeer) DeleteConversation(id int) error {
cp.mutex.Lock()
defer cp.mutex.Unlock()
ci, err := cp.storage.GetConversation(id)
if err == nil && ci != nil {
cp.eventBus.Publish(event.NewEventList(event.DeleteContact, event.RemotePeer, ci.Handle))
return cp.storage.DeleteConversation(id)
}
return fmt.Errorf("could not delete conversation, did not exist")
}
// SetConversationAttribute sets the conversation attribute at path to value

View File

@ -102,7 +102,6 @@ func NewProtocolEngine(identity primitives.Identity, privateKey ed25519.PrivateK
engine.eventManager.Subscribe(event.SendGetValMessageToPeer, engine.queue)
engine.eventManager.Subscribe(event.SendRetValMessageToPeer, engine.queue)
engine.eventManager.Subscribe(event.DeleteContact, engine.queue)
engine.eventManager.Subscribe(event.DeleteGroup, engine.queue)
engine.eventManager.Subscribe(event.UpdateConversationAuthorization, engine.queue)
engine.eventManager.Subscribe(event.BlockUnknownPeers, engine.queue)
@ -166,8 +165,6 @@ func (e *engine) eventHandler() {
// We remove this peer from out blocklist which will prevent them from contacting us if we have "block unknown peers" turned on.
e.authorizations.Delete(ev.Data[event.RemotePeer])
e.deleteConnection(onion)
case event.DeleteGroup:
// TODO: There isn't a way here to determine if other Groups are using a server connection...
case event.SendMessageToGroup:
ciphertext, _ := base64.StdEncoding.DecodeString(ev.Data[event.Ciphertext])
signature, _ := base64.StdEncoding.DecodeString(ev.Data[event.Signature])

View File

@ -144,18 +144,20 @@ func TestCwtchPeerIntegration(t *testing.T) {
// ***** Peering, server joining, group creation / invite *****
log.Infoln("Alice peering with Bob...")
log.Infoln("Alice and Bob creating conversations...")
// Simulate Alice Adding Bob
log.Infof(" alice.NewConvo(bob)...")
alice2bobConversationID, err := alice.NewContactConversation(bob.GetOnion(), model.DefaultP2PAccessControl(), true)
if err != nil {
t.Fatalf("error adding conversaiton %v", alice2bobConversationID)
}
log.Infof(" bob.NewConvo(alice)...")
bob2aliceConversationID, err := bob.NewContactConversation(alice.GetOnion(), model.DefaultP2PAccessControl(), true)
if err != nil {
t.Fatalf("error adding conversaiton %v", bob2aliceConversationID)
}
log.Infof("Alice peering with Carol...")
log.Infof("Alice and Carol creating conversations...")
// Simulate Alice Adding Carol
alice2carolConversationID, err := alice.NewContactConversation(carol.GetOnion(), model.DefaultP2PAccessControl(), true)
if err != nil {
@ -166,7 +168,9 @@ func TestCwtchPeerIntegration(t *testing.T) {
t.Fatalf("error adding conversaiton %v", carol2aliceConversationID)
}
log.Infof("Alice peering with Bob...")
alice.PeerWithOnion(bob.GetOnion())
log.Infof("Alice Peering with Carol...")
alice.PeerWithOnion(carol.GetOnion())
// Test that we can rekey alice without issues...