matrix-org / matrix-js-sdk

Matrix Client-Server SDK for JavaScript
Apache License 2.0
1.61k stars 589 forks source link

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

Open yasinishyn opened 2 years ago

yasinishyn commented 2 years ago

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.
  6. 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

    public async reshareKeyWithDevice(
        senderKey: string,
        sessionId: string,
        userId: string,
        device: DeviceInfo,
    ): Promise<void> {
        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

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

Logs on the other device (from which the user expects to request keys) Screenshot 2022-08-03 at 16 31 06

UI of the other device (from which the user expects to request keys) Screenshot 2022-08-03 at 16 31 18

Desktop (please complete the following information):

Additional context Tested with:

  1. web + web (different laptops);
  2. web + web (same laptops);
  3. web + mobile
AcidKiddo commented 1 year ago

how is it going? did you find out solution?