Browse Source

Merge branch 'mxlength' of cwtch.im/cwtch into master

pull/174/head
Dan Ballard Gogs 1 year ago
parent
commit
d56a00842e
2 changed files with 15 additions and 1 deletions
  1. +10
    -1
      model/profile.go
  2. +5
    -0
      model/profile_test.go

+ 10
- 1
model/profile.go View File

@@ -36,6 +36,10 @@ type Profile struct {
lock sync.Mutex
}

// MaxGroupMessageLength is the maximum length of a message posted to a server group.
// TODO: Should this be per server?
const MaxGroupMessageLength = 1024

func (p *PublicProfile) init() {
p.Attributes = make(map[string]string)
}
@@ -354,6 +358,11 @@ func getRandomness(arr *[]byte) {
// EncryptMessageToGroup when given a message and a group, encrypts and signs the message under the group and
// profile
func (p *Profile) EncryptMessageToGroup(message string, groupID string) ([]byte, []byte, error) {

if len(message) > MaxGroupMessageLength {
return nil, nil, errors.New("group message is too long")
}

group := p.GetGroupByGroupID(groupID)
if group != nil {
timestamp := time.Now().Unix()
@@ -365,7 +374,7 @@ func (p *Profile) EncryptMessageToGroup(message string, groupID string) ([]byte,
prevSig = group.SignedGroupID
}

lenPadding := 1024 - len(message)
lenPadding := MaxGroupMessageLength - len(message)
padding := make([]byte, lenPadding)
getRandomness(&padding)



+ 5
- 0
model/profile_test.go View File

@@ -151,6 +151,11 @@ func TestProfileGroup(t *testing.T) {
t.Errorf("Initial Message was not stored properly: %v", im)
}

_, _, err := sarah.EncryptMessageToGroup(string(make([]byte, MaxGroupMessageLength*2)), group2.GroupID)
if err == nil {
t.Errorf("Overly long message should have returned an error")
}

bob := GenerateNewProfile("bob")
bob.AddContact(alice.Onion, &alice.PublicProfile)
bob.ProcessInvite(gci2.GetGroupChatInvite(), alice.Onion)


Loading…
Cancel
Save