matrix-org / matrix-org/matrix-js-sdk

Can't re-request e2ee key from your other sessions or other people in the room

Open
#2,558 1 comment 0 reactions 0 assignees View on GitHub

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
![Screenshot 2022-08-03 at 16 30 52](https://user-images.githubusercontent.com/2759317/182620485-8a329d8f-471b-4066-a54a-c414f7f6cafc.png)

Logs on the other device (from which the user expects to request keys)
![Screenshot 2022-08-03 at 16 31 06](https://user-images.githubusercontent.com/2759317/182620583-ccb7db7b-59df-4490-827d-2e7132adce04.png)

UI of the other device (from which the user expects to request keys)
![Screenshot 2022-08-03 at 16 31 18](https://user-images.githubusercontent.com/2759317/182620642-d952d140-c7d5-493a-a66d-2c9fead4f276.png)

**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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.