Skylar-Tech / node-red-contrib-matrix-chat

Matrix chat server support for Node-RED
GNU General Public License v3.0
31 stars 10 forks source link

Will not send or receive encrypted messages #31

Closed short-circuit closed 1 year ago

short-circuit commented 2 years ago

Generated a bot user directly from NodeRED.

Undefined cross signing keys: got cross-signing keys for @xxx:xxxxxxxxx.xxx: { master: undefined, self_signing: undefined, user_signing: undefined }

Every sent message is unencrypted.

Every received message is lost, with following event: Decrypted event on retry (id=someidentificationstring)

Basically makes the flows useless in e2ee enabled servers. The only device login is NodeRED for this user, so it is not a problem with the user not being able to be verified.

Any guesses?

skylord123 commented 2 years ago

@short-circuit I need some additional information to figure this out.

In the message did @xxx:xxxxxxxxx.xxx match the identifier of the user you are using? Can you provide additional logs? What server are you using and is it self-hosted or public?

short-circuit commented 2 years ago

The user is the bot itself and it matches the user string. It's on a self hosted server, federated and reachable from the public. Other users can use e2e without problem. For the kind of server it's synapse, if that's what you meant?

What additional logs do you need and where can I find them?

skylord123 commented 2 years ago

What additional logs do you need and where can I find them?

How do you run Node-RED? That will determine how to get your logs (i.e. if you run in Docker you can fetch the logs from the container).

short-circuit commented 2 years ago

How do you run Node-RED? That will determine how to get your logs (i.e. if you run in Docker you can fetch the logs from the container).

Running through docker, and this is what I get when trying to send a message to the bot:

nodered        | enqueueing key request for !qPTTaphsqAgEcFgOOk:domain.tld / sQPGlAOAf4eBAeh7btIWsRIPw0vPHkFkZVCiJ4qRnZ4
nodered        | Error decrypting event (id=$wuvmvkm5m1mPJEUcpdqvsnacKZuWOGfzRGqpFNVPQ4M): DecryptionError[msg: The sender's device has not sent us the keys for this message., session: +lOaGB65URpiXohdyykRROaghjm9VCLBKyLnqiHLmWE|sQPGlAOAf4eBAeh7btIWsRIPw0vPHkFkZVCiJ4qRnZ4]
nodered        | Requesting keys for !qPTTaphsqAgEcFgOOk:domain.tld / sQPGlAOAf4eBAeh7btIWsRIPw0vPHkFkZVCiJ4qRnZ4 from [@BOT:domain.tld:*,@username:domain.tld:FXFHAYSVIO](id m1638513627270.1)
nodered        | PUT /sendToDevice/m.room_key_request/m1638513627270.1 {
nodered        |   '@BOT:domain.tld': [ '*' ],
nodered        |   '@username:domain.tld': [ 'FXFHAYSVIO' ]
nodered        | }
nodered        | received to_device m.room_key_request from: @BOT:domain.tld id: undefined
nodered        | m.room_key_request from @BOT:domain.tld:WHPLXBYDBE for !qPTTaphsqAgEcFgOOk:domain.tld / sQPGlAOAf4eBAeh7btIWsRIPw0vPHkFkZVCiJ4qRnZ4 (id m1638513627270.1)
nodered        | Ignoring room key request from ourselves

So, even though the bot was created and only used from nodered, it is not capable to get the decryption keys. Am I understanding this correctly? Does it have anything to do with the synapse server in case? Even though I can reach the server through any matrix client from in/outside of the server network without problems and login works for all users.

skylord123 commented 2 years ago

So, even though the bot was created and only used from nodered, it is not capable to get the decryption keys. Am I understanding this correctly?

Yes, this is correct. I have a WIP branch to add in key sharing but I just haven't had the time to finalize it yet. This is why I have everyone create a fresh user and only use it within Node-RED so that it always has the necessary keys. Even in this case though I have had my own bot lose encryption keys for some reason. I am wondering if it has to do with a recent power outage that my UPS didn't protect my servers from. It could have shutdown before saving the keys. Hoping to have key sharing and backup added in the near future to fix this.

Does it have anything to do with the synapse server in case? Even though I can reach the server through any matrix client from in/outside of the server network without problems and login works for all users.

It shouldn't be a problem if you are running a recent version of the Synapse server. If you were running an old version it could cause some problems.

I did just launch version 0.3.0 which fixed issues with slow responding servers (if the server didn't send the message to Node-RED within a second the message would be classified as "old" and would be skipped). Try that version out and see if it fixes the problem for you. Since you are sending unencrypted messages encryption shouldn't be affecting those at all.