element-hq / element-android

A Matrix collaboration client for Android.
https://element.io/
GNU Affero General Public License v3.0
3.39k stars 731 forks source link

Cannot decrypt messages from specific user sent using specific device: `Unable to decrypt: OLM` #3429

Open calvinrw opened 3 years ago

calvinrw commented 3 years ago

Describe the bug

When using Element Android on a phone running Android 10, E2E messages received from one specific device belonging to another user are not immediately viewable. Instead, Waiting for this message, this may take a while is seen in place of the message contents, or ** Unable to decrypt: OLM ** when Developer mode is turned on in Element's advanced settings.

To Reproduce

A room exists consisting of me and my friend Ed, each using our own, self-hosted Synapse homeservers. We have not tested for this issue in other rooms.

Steps to reproduce the behavior:

  1. Ed uses his phone to send a message to this room.
  2. I observe the following: a. On my phone running Android 10: Often Unable to decrypt: OLM is shown in place of the message contents. Otherwise, the message contents are visible, as expected. b. On my phone running Android 6: The message contents are visible, as expected. c. On my computer with Element Desktop: The message contents visible, as expected.

For comparison, we tested the following:

  1. Ed uses his computer with Element Desktop to send a message to this room.
  2. I observe the following: a. On my phone running Android 10: The message contents visible, as expected. b. On my phone running Android 6: The message contents are visible, as expected. c. On my computer with Element Desktop: The message contents are visible, as expected.

We also tested:

  1. I use my Android 10 phone to send a message to this room.
  2. On Ed's phone: The message contents are visible, as expected.

Finally, we tested:

  1. In a new room, without E2E enabled, Ed uses his phone to send a message to the room.
  2. I observe the following: a. On my phone running Android 10: The message contents are visible, as expected. b. On my phone running Android 6: The message contents are visible, as expected. c. On my computer with Element Desktop: The message contents are visible, as expected.

Each test consisted of Ed (or myself) sending multiple messages in quick succession, and the 'failure' rate for my ability to view messages on the affected phone was 100%. But under normal, "real life" circumstances (i.e. an actual conversation), this only occurred once every few messages.

I've concluded that this issue only affects messages sent from Ed's phone when they're viewed on my Android 10 phone, and in a room with E2E enabled.

On the affected (Android 10) phone, logs were captured using logcat over adb. The following is shown repeatedly when affected messages are received:

05-24 21:55:02.212 27914  1430 E OlmJniNative:  ## decryptMessageJni(): failure - olm_group_decrypt Msg=BAD_MESSAGE_MAC
05-24 21:55:02.212 27914  1430 E OlmInboundGroupSession: ## decryptMessage() failed BAD_MESSAGE_MAC

The affected messages eventually become visible on the Android 10 phone, but I have not figured out how long the delay actually is. It appears to be greater than a few hours.

This issue has not affected communications with any other users yet.

Expected behavior

When Ed sends me a message, it will be viewable on every device I have Element and E2E correctly set up on in a reasonable amount of time, regardless of which of his devices he uses to send it.

Screenshots

Screenshots have been attached.

Smartphone (please complete the following information):

My phone affected by this issue
My phone unaffected by this issue
Ed's phone

Additional context

Screenshot_Android6_20210523-134331_resize Screenshot_Android10_20210523-134337_Element_resize

kescherCode commented 3 years ago

I seem to have this issue, where I am always one message behind in comparison to desktop in the only room this happens in. As soon as the other party sends another encrypted messages, the "Unable to decrypt: OLM" becomes visible, but that next message becomes "Unable to decrypt: OLM" once more.

jeffw387 commented 3 years ago

I was having this issue, I managed to solve it for now by signing out on the device then back in, and re-verifying the session.

kescherCode commented 3 years ago

@jeffw387 yes, but I don't want to relog every single time this issue occurs. This hinders the "encrypt only to verified sessions" feature.

ewsandor commented 3 years ago

Ed here from the original issue report.

We are now seeing the same issue in reverse. I am unable to see calvinrw's messages on Android with the same error message, but the same message comes through okay on the Element web client.

We are both now on Android Element version 1.1.9.

skylarkbe commented 3 years ago

Same kind of story over here. Where it becomes completely strange is when I receive the message properly on my desktop, on my Samsung Android tablet, but not on my Android phone, despite reverifying the session. When a new message arrives, I have to go back to the conversation list, reopen it and the missing messages are displayed ... except for the latest, but not for all conversations !

Current synapse version I run is 1.41.1 and element version from the play store 1.2.0

Could it be linked to https://github.com/vector-im/element-android/issues/1721 ?

BillCarsonFr commented 3 years ago

Need to check the code when there are several olm session, and we should try each one in turn

BillCarsonFr commented 3 years ago

https://github.com/matrix-org/element-android-rageshakes/issues/27676

https://github.com/matrix-org/element-android-rageshakes/issues/27675

meyerrj commented 3 years ago

This is happening for me as well. Pixel 4a, Android 12.

Long-pressing and selecting "Re-request encryption keys from your other sessions." does not work. I have it open on two desktops and an iPad and it never decrypts.

BillCarsonFr commented 3 years ago

A new RS https://github.com/matrix-org/element-android-rageshakes/issues/27806

HarHarLinks commented 2 years ago

I just submitted a rageshake for (probably) this issue

5HT2 commented 2 years ago

Just submitted a rageshake for this exact issue. Messages from a user work fine when sent from their desktop, Unable to decrypt: OLM from their phone. Only happens on my Pixel 2 / Android 12, not reproducible on desktop recipients.

hexxone commented 2 years ago

I just also had the Problem a 2nd time. After the first one I did a re-log, which fixxed it for about a week. Now Unable to decrypt: OLM randomly starts appearing again only on the Andoid App. Is there any progress on this issue?

HarHarLinks commented 2 years ago

Yes, this keeps happening to me now and then.

toshanmugaraj commented 2 years ago

yes this issue happens in iOS too olm_decrypt error: BAD_MESSAGE_MAC

HarHarLinks commented 2 years ago

I've noticed similar errors with https://github.com/anoadragon453/matrix-reminder-bot/issues/98 complaining that it can't decrypt some messages

mcg-matrix commented 1 year ago

Just happened to me for the first time, in a 1:1 room. I have several sessions for that Matrix account, and only one of the sessions was affected. The affected session is currently running Element-FDroid 1.5.30.

Restarting the affected Element-FDroid did not help.

Executing "Settings" "Security & Privacy" "Encrypted Messages Recovery" "RESTORE FROM BACKUP" did help. I presume that at least one of the other sessions had stored the missing secret into the central backup. So for anyone using this feature (that used to be called "secure backup", I believe), this might be a more feasible approach than logging out and back in.

ithinuel commented 3 months ago

Happening to me now. Messages sent from the desktop app cannot be received by (unverified) others (eg new encrypted rooms). Older channels seem to still work (with a verified peer).

I will try to sign out/sign in from this app and report if this helps or not.

EDIT: I confirm loging out then back in solved the issue (for now).