matrix-org / matrix-org/matrix-js-sdk
Can't re-request e2ee key from your other sessions or other people in the room
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.2k
- Forks
- 704
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 40
Description
**Describe the bug**
When the encryption key is missing for a message you can't re-request it in your other sessions or with other people in the same encrypted room. There is nothing happening on UI and in-code behavior is not clear.
**To Reproduce**
Steps to reproduce the behavior:
1. Login with the same user with two different devices;
2. Make sure the e2ee encryption is setup;
3. Create an encrypted room;
4. Send few messaged in this encrypted room, and verify you see the messages on both devices;
5. re-login on one of the devices and skip the verification steps.
2. Click on "Re-request encryption keys from your other sessions."
Instead of step 1, you can have two different users, and the behavior is almost the same, except that it's a bit more clear why it doesn't work. The failure is with the session key not found in `src/crypto/algorithms/megolm.ts`
```js
public async reshareKeyWithDevice(
senderKey: string,
sessionId: string,
userId: string,
device: DeviceInfo,
): Promise {
const obSessionInfo = this.outboundSessions[sessionId];
console.log('AY sessionId', sessionId)
console.log('AY obSessionInfo', obSessionInfo)
console.log('AY this.outboundSessions', this.outboundSessions)
if (!obSessionInfo) {
logger.debug(`megolm session ${sessionId} not found: not re-sharing keys`);
return;
}
// ...
```
For the same user (different devices), The execution flow ends on
```js
this.emit(CryptoEvent.RoomKeyRequest, req);
```
inside `src/crypto/index.ts`
however, there is no listener for the `CryptoEvent.RoomKeyRequest` event nor any other log output (error/info, etc..).
**Expected behavior**
E2EE keys are shared or a verification flow is started, and message becomes visible on the device.
**Screenshots**
Requesting keys

Logs on the other device (from which the user expects to request keys)

UI of the other device (from which the user expects to request keys)

**Desktop (please complete the following information):**
- OS: macOS 11.0.1
- Browser: Chrome
- Version: 103.0.5060.134 (Official Build) (arm64)
**Additional context**
Tested with:
1. web + web (different laptops);
2. web + web (same laptops);
3. web + mobile
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the re-request flow through src/crypto/index.ts, especially CryptoEvent.RoomKeyRequest, and inspect reshareKeyWithDevice in src/crypto/algorithms/megolm.ts. Reproduce the two-device scenario described in the issue and follow the existing logs and event handling; done means the missing E2EE key is shared or verification starts and the message becomes visible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100