Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encryption doesn't seem to work on Dendrite #333

Open
LunaSquee opened this issue Aug 1, 2023 · 4 comments
Open

Encryption doesn't seem to work on Dendrite #333

LunaSquee opened this issue Aug 1, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@LunaSquee
Copy link

Describe the bug
When setting up a RustSdkCryptoStorageProvider on the MatrixClient, it keeps throwing the error user_id or device_id mismatch in the log and doesn't actually seem to synchronize beyond that point.

MatrixHttpClient (REQ-371) POST http://localhost/_matrix/client/v3/keys/upload
Trace: MatrixHttpClient (REQ-371) body = {"device_keys":null,"fallback_keys":{"signed_curve25519:AAAAAAAAAAA":{"fallback":true,"key":"redacted key","signatures":{"@bot:localhost":{"ed25519:p2ivEVrj":"redacted key"}}}},"one_time_keys":{}}
MatrixHttpClient (REQ-371) {                      
  '@bot:localhost': {               
    p2ivEVrj: {                                                                                                
      error: 'user_id or device_id mismatch: users:  - @bot:localhost, devices:  - p2ivEVrj'
    }
  }
}                                           

and also the following messages are thrown

MatrixHttpClient (REQ-432) GET http://localhost/_matrix/client/v3/rooms/<room id>/state/m.room.encryption/                                                                                 
MatrixHttpClient (REQ-432) {                                                                                   
  errcode: 'M_NOT_FOUND',                                                                                      
  error: 'Cannot find state event for "m.room.encryption"'                                                     
}                                                                                                              

and

MatrixClientLite Error handling sync [object Object]                
MatrixClientLite Backing off for 12581.64578790571ms

To Reproduce
Steps to reproduce the behavior:

  1. Setup a dendrite server or use a public one.
  2. Connect to the server, the user must be in an encrypted room.
  3. Observe logs. No messages are coming through as sync seems to be failing.

Very minimal example code:

import {
  MatrixClient,
  SimpleFsStorageProvider,
  RustSdkCryptoStorageProvider,
  AutojoinRoomsMixin,
} from 'matrix-bot-sdk';
import { StoreType } from '@matrix-org/matrix-sdk-crypto-nodejs';

const storage = new SimpleFsStorageProvider('.matrix.db.json');
const cryptoStorage = new RustSdkCryptoStorageProvider('.matrix-sled', StoreType.Sled);    

const client = new MatrixClient('localhost', 'access token', storage, cryptoStorage);
AutojoinRoomsMixin.setupOnClient(client);

client.on('room.message', (...dargs) => console.log(...dargs));
client.start();

I also tried with password auth in code directly so that the room ID would immediately be associated with this crypto storage but that to also no avail (just using passwordLogin and taking the accessToken from the created MatrixClient)

Expected behavior
It should handle encrypted rooms correctly.

Log snippet
Dendrite log:

time="2023-08-01T18:45:51.815739336Z" level=error msg="Failed to upload one or more keys" key_errors="map[@bot:localhost:map[p2ivEVrj:user_id or device_id mismatch: users:  - @bot:localhost, devices:  - p2ivEVrj]]" req.id=mJFiUUqjzVpV req.method=POST req.path=/_matrix/client/v3/keys/upload user_id="@bot:localhost"

Additional context
I could trace the error back to this request https:/turt2live/matrix-bot-sdk/blob/main/src/e2ee/RustEngine.ts#L136 but im not exactly sure how to interpret this as im not familiar with "OlmMachine".

Dendrite source code I speculate the error might be from but im not absolutely sure about it: https:/matrix-org/dendrite/blob/main/userapi/internal/key_api.go#L685-L695

@LunaSquee LunaSquee added the bug Something isn't working label Aug 1, 2023
@turt2live
Copy link
Owner

This is probably caused by device_keys: null in the request, which the spec doesn't clarify as being allowed to be null or not.

@LunaSquee
Copy link
Author

Could this be an upstream rust-sdk issue then? I have no real way to test that

@turt2live
Copy link
Owner

it's most likely a bot-sdk bug, but it's arguable that Dendrite is overly strict here.

LunaSquee added a commit to LunaSquee/matrix-bot-sdk that referenced this issue Aug 6, 2023
@pix
Copy link

pix commented Jan 14, 2024

I can confirm this is fixing the issue for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants