element-hq / element-hq/element-ios

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

Open
#2,536 2 comments 0 reactions 0 assignees View on GitHub
A-Aggregations A-Message-Editing feature T-Enhancement
Dominant language
Swift
Stars
1.8k
Forks
544
PR merge metrics
PR metrics pending

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

Research direction

No source file, test, or entry point is named in the issue. Start by tracing encrypted m.replace event handling in the iOS client and reviewing the linked Matrix discussion; done means m.new_content is encrypted separately in the shown format while the remaining message content and edit behavior continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
mobile-dev, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.