matrix-js-sdk icon indicating copy to clipboard operation
matrix-js-sdk copied to clipboard

E2ee working example for 6.1.0

Open aleixq opened this issue 5 years ago • 3 comments

I am going crazy trying to make matrix-js-sdk deal with encrypted rooms messages. I tried a lot of implementations and look at riot client tests. The matrix recorder ( https://github.com/vector-im/riot-web/issues/4782#issuecomment-354667209 )works for me. But if i try to follow the same strategy with recent versions (6.1.0) and olm (3.1.4) it doesn't work and cannot decrypt the messages...could you provide a simple example to be able to add e2ee?

I examined and tried other solutions of "e2ee is not working" Issues: rpc, rivescript, basic-bot... but all of they are using old versions of sdk also...

Thanks!

aleixq avatar May 20 '20 22:05 aleixq

Replying myself, after cooking the code a little I found a working way the code is in https://gitlab.com/aleixq/matrix-js-sdk-bot-template . It only works when using LocalStorageCryptoStore . If using memorycryptostore ( https://gitlab.com/aleixq/matrix-js-sdk-bot-template/-/blob/master/index.js#L49 ) then it work the first time but the second it throws:

Error decrypting event (id=$Zu3K85nYSI6gh6IOMa33z75FW3hToCNIbaedRi9OJuM): DecryptionError[msg: The secure channel with
 the sender was corrupted. Trying to create a new secure channel and re-requesting the keys., session: ...]

Also it is based on the autoverification code (https://gitlab.com/aleixq/matrix-js-sdk-bot-template/-/blob/master/index.js#L209 )done by the bot whenever it finds an unverified device in the room.

As a starting raw template it must be adapted to scope.

aleixq avatar May 28 '20 17:05 aleixq

memorycryptostore

This store doesn't persist anything. It stores things only in memory, so obviously if you restart the script it won't have access to encrypted history.

t3chguy avatar May 28 '20 18:05 t3chguy

Ok thank's! It's clear now... It was not so clear when I looked code of other old bot implementations, as there was no mention of LocalStorageCryptoStore, but it's ok now

aleixq avatar May 28 '20 22:05 aleixq