Merge branch 'mxlength' of cwtch.im/cwtch into master
This commit is contained in:
commit
d56a00842e
|
@ -36,6 +36,10 @@ type Profile struct {
|
||||||
lock sync.Mutex
|
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() {
|
func (p *PublicProfile) init() {
|
||||||
p.Attributes = make(map[string]string)
|
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
|
// EncryptMessageToGroup when given a message and a group, encrypts and signs the message under the group and
|
||||||
// profile
|
// profile
|
||||||
func (p *Profile) EncryptMessageToGroup(message string, groupID string) ([]byte, []byte, error) {
|
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)
|
group := p.GetGroupByGroupID(groupID)
|
||||||
if group != nil {
|
if group != nil {
|
||||||
timestamp := time.Now().Unix()
|
timestamp := time.Now().Unix()
|
||||||
|
@ -365,7 +374,7 @@ func (p *Profile) EncryptMessageToGroup(message string, groupID string) ([]byte,
|
||||||
prevSig = group.SignedGroupID
|
prevSig = group.SignedGroupID
|
||||||
}
|
}
|
||||||
|
|
||||||
lenPadding := 1024 - len(message)
|
lenPadding := MaxGroupMessageLength - len(message)
|
||||||
padding := make([]byte, lenPadding)
|
padding := make([]byte, lenPadding)
|
||||||
getRandomness(&padding)
|
getRandomness(&padding)
|
||||||
|
|
||||||
|
|
|
@ -151,6 +151,11 @@ func TestProfileGroup(t *testing.T) {
|
||||||
t.Errorf("Initial Message was not stored properly: %v", im)
|
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 := GenerateNewProfile("bob")
|
||||||
bob.AddContact(alice.Onion, &alice.PublicProfile)
|
bob.AddContact(alice.Onion, &alice.PublicProfile)
|
||||||
bob.ProcessInvite(gci2.GetGroupChatInvite(), alice.Onion)
|
bob.ProcessInvite(gci2.GetGroupChatInvite(), alice.Onion)
|
||||||
|
|
Loading…
Reference in New Issue