element-hq / element-hq/element-android

Encrypt m.new_content separately for message edits to aid server-side aggregation

Open
#244 2 comments 0 reactions 0 assignees View on GitHub
A-Aggregations A-Message-Editing
Dominant language
Kotlin
Stars
3.7k
Forks
917
PR merge metrics
No merged PRs in 30d

Description

From riot-web created by [bwindels](https://github.com/bwindels): vector-im/riot-web#10203

Server-side aggregation of m.replace events should replace the original event's `content` with the `m.new_content` in the `content` of the replacing event. As it stands, riot on all platforms encrypts `m.new_content` as part of encrypting the whole `content`, so the server can't access it.

As a consequence, clients that don't support edits (and ignore `m.new_content`) would show the fallback content of the replacement when receiving the original message after server-side aggregation has happened. The original event would also look like a relation, although that can be safely ignored by unsupporting clients.

We need to encrypt `m.new_content` separately, so the server can pick it out to replace the original content with it, while preserving the rest of the original message.

The new format of an edit in an encrypted room (after encryption) would look like this:
```
"content": {
"algorithm": "m.megolm.v1.aes-sha2",
"ciphertext": "AwgDErABDBWSkLKJ5IQRePEP/kjpmVETrDzJp5jpWRJ0IIB/XAI0i6J8Cgpe/UEzhB9IpwJCMaWh7QKqN1h4kJn+nA55S/VgJEE01/g5Trihg5YGsaC5KGhEuH6gGG4tbtgX9hhwdN4PyTvmdSWxMtS8egKKBwS7Wux/461BX4UsSz25XqECIu6P8u7X/uBh5c6tTae6wTLVCvUTDtdYUnRk956GAbDnYgc27m8A16W8ex2BcgIE2MkzGJphZUm6PMa7vC9QOdTNACpylxtCrSEJhUWH8y4KseVXavVLi28lt4QhoRw8dLcId6LDJfexf+I8wMFr4HQ6DSd6iAg",
"device_id": "JHYBCAOWGF",
"m.relates_to": {
"event_id": "$5xJzoD0Cbz7vxIFcyPOCIJ2ORy4_MpHQUW4nIUdlmvg",
"rel_type": "m.replace"
},
"sender_key": "Ern8B3Dj56iXRvFeubfe5PDHp8bYWaHZbLiUcK1oAAc",
"session_id": "6/cfdpp8mMCEgbDJsmxAY66sBHlDeTfarVLeLu5VRzw",
"m.new_content": {
"algorithm": "m.megolm.v1.aes-sha2",
"ciphertext": "AwgDErABDBWSkLKJ5IQRePEP/kjpmVETrDzJp5jpWRJ0IIB/XAI0i6J8Cgpe/UEzhB9IpwJCMaWh7QKqN1h4kJn+nA55S/VgJEE01/g5Trihg5YGsaC5KGhEuH6gGG4tbtgX9hhwdN4PyTvmdSWxMtS8egKKBwS7Wux/461BX4UsSz25XqECIu6P8u7X/uBh5c6tTae6wTLVCvUTDtdYUnRk956GAbDnYgc27m8A16W8ex2BcgIE2MkzGJphZUm6PMa7vC9QOdTNACpylxtCrSEJhUWH8y4KseVXavVLi28lt4QhoRw8dLcId6LDJfexf+I8wMFr4HQ6DSd6iAg",
"device_id": "JHYBCAOWGF",
"sender_key": "Ern8B3Dj56iXRvFeubfe5PDHp8bYWaHZbLiUcK1oAAc",
"session_id": "6/cfdpp8mMCEgbDJsmxAY66sBHlDeTfarVLeLu5VRzw"
}
```

Also see [discussion on matrix](https://riot.im/develop/#/room/!fuiphBbxmgKxJjXYFn:matrix.org/$1561467081263487UpsIa:matrix.org?via=matrix.org&via=lant.uk&via=jki.re).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.