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

This commit is contained in:
Dan Ballard 2018-12-03 19:22:20 +00:00 committed by Gogs
커밋 d56a00842e
2개의 변경된 파일15개의 추가작업 그리고 1개의 파일을 삭제

파일 보기

@ -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)

파일 보기

@ -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)