MangoCubes / remotrix

SMS <-> Matrix bridge for Android device. No Matrix admin access or additional server required.
Other
13 stars 0 forks source link

"Unable to decrypt messages" #20

Open fbievan opened 6 months ago

fbievan commented 6 months ago

Tracking this issue here As noted here this seems to a fairly common problem.

After unsuccessfully trying to recreate your solution in that thread, I'm making a issue here.

Logs needed Diagnostics needed

When I can- I'll go look into debug on my homeservers. Till then- this is just for tracking

MangoCubes commented 6 months ago

This is most likely a client issue rather than server because I occasionally encounter this. Unfortunately, I cannot recreate it reliably; It seems to happen randomly and I simply can't find what triggers this. :( I will test with updated Trixnity library first, and if that doesn't work, I am thinking of digging deep into the cryptography and the source code. I happen to be in a security lab now, and might do something related to Matrix as my next research topic.

fbievan commented 6 months ago

This is most likely a client issue rather than server because I occasionally encounter this. Unfortunately, I cannot recreate it reliably; It seems to happen randomly and I simply can't find what triggers this. :( I will test with updated Trixnity library first, and if that doesn't work, I am thinking of digging deep into the cryptography and the source code. I happen to be in a security lab now, and might do something related to Matrix as my next research topic.

Seems to happen consistent for me, I want to see what's different about what the clients are sending, to find out what the root cause is.

I'm using a conduit homeserver in my testing.

The only messages I can see from the bot is unencrypted ones.

There is a delay of unencrypted messages to encrypted messages when starting a new room is started by receiving an sms.

Not drawing any conclusions yet.

MangoCubes commented 6 months ago

Your setup is definitely different from mine as I test on my home server and the official Matrix server, both of which are running on Synapse server. Still, the issue happens on there, but not consistently. I suppose I could resort to having messages sent unencrypted if explicitly specified.

MangoCubes commented 6 months ago

I updated the Trixnity library this app uses, but the issue persists. It seems that the events are read before they are decrypted, but I can't figure out how to ensure the events are read after they are encrypted. I'll have to dig in further to sort this out. Interestingly, the library now provides bot mode, which may make things a bit less complicated. I'm currently rewriting the whole thing with this. Hopefully this bot mode is simple enough that I don't have to deal with this bug anymore.

Here's the APK if you want to test it with latest API though. app-release.zip

fbievan commented 6 months ago

I updated the Trixnity library this app uses, but the issue persists. It seems that the events are read before they are decrypted, but I can't figure out how to ensure the events are read after they are encrypted. I'll have to dig in further to sort this out. Interestingly, the library now provides bot mode, which may make things a bit less complicated. I'm currently rewriting the whole thing with this. Hopefully this bot mode is simple enough that I don't have to deal with this bug anymore.

Here's the APK if you want to test it with latest API though. app-release.zip

Cool, I'll continue watching in the mean time.

benkuly commented 6 months ago

The bot mode just disables some features of Trixnity, making it faster and saving less data into database.

benkuly commented 6 months ago

Could you describe the decryption problem a bit more? Maybe I can help (as maintained of Trixnity).

MangoCubes commented 6 months ago

Yes! I know you! :)

I forgot to push the updated version, but here is the gist of it: https://github.com/MangoCubes/remotrix/blob/9984a23c08c2a8a27075b82b32499258ed66f7ff/app/src/main/java/ch/skew/remotrix/background/CommandService.kt#L460

Currently, I am using getTimelineEventsFromNowOn, which if I understand correctly, receives events and triggers decryption if necessary. In the newer API, it resolves into one of the three:

This is the issue I am having. I am noticing that a fair number of messages are resolving to null instead of failure or success. I can't figure out a way to get the message after it is fully decrypted, or after it fails so I can diagnose further.

Thank you again.

benkuly commented 6 months ago

It's null because decryption timed out, which usually happens, when the sender did not send us the Megolm session...