0

I am using Omemo and smack library for creating a chat application. I have the following scenario: I want to make a communication between two devices, device A and device B. A is sending a message to B. I want to discover the fingerprint of B so I can check if I trust or not on that device. What I am doing is using this method:

 HashMap<OmemoDevice, OmemoFingerprint> activeFingerprints =
                omemoManager.getActiveFingerprints(JidCreate.bareFrom(jid));
     for (final Map.Entry<OmemoDevice, OmemoFingerprint> entry : activeFingerprints.entrySet()) {
                result = omemoManager.isTrustedOmemoIdentity(entry.getKey(), entry.getValue());
                if (!result) {
                    break;
                }
            }

But this returns to me sometimes even 6 fingerprints and I don't know which is the exact one. Because of this I think that I am getting it very often this message:

2019-03-04 13:28:30.111 4291-5181/com.inpedio.sphone W/System.err: org.matrix.olm.OlmException: BAD_MESSAGE_MAC 2019-03-04 13:28:30.111 4291-5181/com.inpedio.sphone W/System.err: at org.matrix.olm.OlmSession.decryptMessage(OlmSession.java:336) 2019-03-04 13:28:30.112 4291-5181/com.inpedio.sphone W/System.err: at org.livesoftware.smackx.omemo.olm.OlmOmemoSession.decryptMessageKey(OlmOmemoSession.java:128) 2019-03-04 13:28:30.112 4291-5181/com.inpedio.sphone W/System.err: at org.jivesoftware.smackx.omemo.internal.OmemoSession.decryptTransportedKey(OmemoSession.java:109) 2019-03-04 13:28:30.112 4291-5181/com.inpedio.sphone W/System.err: at org.jivesoftware.smackx.omemo.OmemoService.decryptTransportedOmemoKey(OmemoService.java:917) 2019-03-04 13:28:30.112 4291-5181/com.inpedio.sphone W/System.err: at org.jivesoftware.smackx.omemo.OmemoService.decryptOmemoMessageElement(OmemoService.java:887) 2019-03-04 13:28:30.113 4291-5181/com.inpedio.sphone W/System.err: at org.jivesoftware.smackx.omemo.OmemoService.processReceivingMessage(OmemoService.java:711) 2019-03-04 13:28:30.114 4291-5181/com.inpedio.sphone W/System.err: at org.jivesoftware.smackx.omemo.OmemoService.access$200(OmemoService.java:104) 2019-03-04 13:28:30.114 4291-5181/com.inpedio.sphone W/System.err: at org.jivesoftware.smackx.omemo.OmemoService$OmemoStanzaListener.processStanza(OmemoService.java:1238) 2019-03-04 13:28:30.114 4291-5181/com.inpedio.sphone W/System.err: at org.jivesoftware.smack.AbstractXMPPConnection$4.run(AbstractXMPPConnection.java:1204) 2019-03-04 13:28:30.115 4291-5181/com.inpedio.sphone W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 2019-03-04 13:28:30.115 4291-5181/com.inpedio.sphone W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 2019-03-04 13:28:30.115 4291-5181/com.inpedio.sphone W/System.err: at java.lang.Thread.run(Thread.java:764) 2019-03-04 13:28:30.116 4291-5181/com.inpedio.sphone W/OmemoService: internal omemoMessageListener failed to decrypt incoming OMEMO message: Transported key could not be decrypted, since no provided message key. Provides keys: [1546815194]

I am using OlmOmemo and smack library.

f.trajkovski
  • 794
  • 9
  • 24

1 Answers1

2

smack-omemo author here.

You probably want to make sure that you got all the fingerprints of your contact by calling OmemoManager.requestDeviceListUpdateFor(contactJid). After that you should have a complete list of your contacts devices after calling your code.

As to how to know, which fingerprint belongs to which device: Generally you want to present the user with a list of fingerprints of both their own and their contacts devices. That way you can find out, which device is which by comparing fingerprints.

In the OMEMO protocol keys are deliberatly not identified by a descriptive name (eg. "phone", "desktop" and so on) in order to motivate users to verify fingerprints by scanning QR-codes. The exception you included in your question is an indicator that your sending device "forgot" to trust your receiving device, resulting in the message not being encrypted for your receiving device. Ideally you would present the user with a warning if they try to send a message to a contact that has "undecided" devices and prompt them to verify that device / decide, whether or not to trust that device - again, ideally by scanning a QR code.

BTW: Can you share a link to OlmOmemo? I can't find anything with Google, but I'd love to take a look at how they implemented my smack-omemo interfaces :)

vanitasvitae
  • 185
  • 8
  • Tnx a lot, this helped. Do you maybe know why I am getting that BAD_MESSAGE_MAC. It's happening when I programmatically send a message from one client to another. I am making the subscription and everything but I am getting the error from above. – f.trajkovski Mar 05 '19 at 10:28
  • It's kinda hard to diagnose this problem without access to the source code. However, I'd say that its probably a bug within your olm code. – vanitasvitae Mar 06 '19 at 12:03