Smack unable decrypt a encrypted message once received in onOmemoMessageReceived

Hi,

I am new to OMEMO encription and have implemented Smack 4.2.1-SNAPSHOT. Since there is a dedicated listener ‘OmemoMessageListener’ in OmemoManager for receiving encrypted message. But i am also getting callback for this encrypted message in ChatMessageListener(in org.jivesoftware.smack.chat). It throws an exception when i try to decrypt this encrypted message received in ChatMessageListener using OmemoManager.decrypt(BareJid sender, Message omemoMessage).

Exception :

org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException: Transported key could not be decrypted, since no provided message key. Provides keys: [1455851406]

Please tell me what i am doing wrong. And one more thing i want to know that, is there any way to decrypt OMEMO encrypted messages in offline state(When user not connected to XMPP) since user is not connected to XMPP when application has killed and user is receiving these OMEMO encrypted message through push notifications.

You can include the following statement in your ChatMessageListener(); The chatMessageListener() should just ignore any omemo encrypted messages.

// Leave handling of omemo message to onOmemoMessageReceived()
OmemoElement omemoMessage

= message.getExtension(OmemoElement.ENCRYPTED, OMEMO_NAMESPACE_V_AXOLOTL);
if (omemoMessage != null)
return;

1 Like

Hi!

OMEMO messages currently also get delivered to the ChatMessageListener, thats a little unfortunate. You should probably ignore OMEMO messages that arrive in the ChatMessageListener and use the OmemoMessageListener for OMEMO messages. The code that @cmeng provided should do the job.

Please note, that every OMEMO message can only be decrypted once, so I guess you get the exception because Smack already decrypted the message automatically for you within the OmemoMessageListener.

Currently it is not trivially possible to decrypt messages while offline. In theory it is possible, but the current API is not designed for that. I’ll set it on the list of desirable API changes though . Thank you for the feedback!

1 Like

Thanks for reply @cmeng.

I have included the code for ignoring OMEMO encrypted messages. We can also check it by using OmemoManager.stanzaContainsOmemoElement.

Hi,

Please refer to the link below. There is another scenario you need to take care.

Although the receipt of muc offline olmMessages is also tested working for conference in aTalk. However Smack Omemo MUST take care the following situation. otherwise errors/exceptions as attached log will occur.

When a user joins a chatRoom, some server is setup to re-sent some number of History olmMessages; with some of them can be duplication of exchanged olmMessages just before user last left the conference. aTalk takes care the muc plain messages with the following check. Hopefully smack omemo will implement similarly, to discard silently any duplication, and forward only new delayed olmMessage to the application.

1 Like