Search in sources :

Example 1 with OutdatedSenderException

use of eu.siacs.conversations.crypto.axolotl.OutdatedSenderException in project Conversations by siacs.

the class MessageParser method parseAxolotlChat.

private Message parseAxolotlChat(Element axolotlMessage, Jid from, Conversation conversation, int status, final boolean checkedForDuplicates, boolean postpone) {
    final AxolotlService service = conversation.getAccount().getAxolotlService();
    final XmppAxolotlMessage xmppAxolotlMessage;
    try {
        xmppAxolotlMessage = XmppAxolotlMessage.fromElement(axolotlMessage, from.asBareJid());
    } catch (Exception e) {
        Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": invalid omemo message received " + e.getMessage());
        return null;
    }
    if (xmppAxolotlMessage.hasPayload()) {
        final XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage;
        try {
            plaintextMessage = service.processReceivingPayloadMessage(xmppAxolotlMessage, postpone);
        } catch (BrokenSessionException e) {
            if (checkedForDuplicates) {
                if (service.trustedOrPreviouslyResponded(from.asBareJid())) {
                    service.reportBrokenSessionException(e, postpone);
                    return new Message(conversation, "", Message.ENCRYPTION_AXOLOTL_FAILED, status);
                } else {
                    Log.d(Config.LOGTAG, "ignoring broken session exception because contact was not trusted");
                    return new Message(conversation, "", Message.ENCRYPTION_AXOLOTL_FAILED, status);
                }
            } else {
                Log.d(Config.LOGTAG, "ignoring broken session exception because checkForDuplicates failed");
                return null;
            }
        } catch (NotEncryptedForThisDeviceException e) {
            return new Message(conversation, "", Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE, status);
        } catch (OutdatedSenderException e) {
            return new Message(conversation, "", Message.ENCRYPTION_AXOLOTL_FAILED, status);
        }
        if (plaintextMessage != null) {
            Message finishedMessage = new Message(conversation, plaintextMessage.getPlaintext(), Message.ENCRYPTION_AXOLOTL, status);
            finishedMessage.setFingerprint(plaintextMessage.getFingerprint());
            Log.d(Config.LOGTAG, AxolotlService.getLogprefix(finishedMessage.getConversation().getAccount()) + " Received Message with session fingerprint: " + plaintextMessage.getFingerprint());
            return finishedMessage;
        }
    } else {
        Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": received OMEMO key transport message");
        service.processReceivingKeyTransportMessage(xmppAxolotlMessage, postpone);
    }
    return null;
}
Also used : OutdatedSenderException(eu.siacs.conversations.crypto.axolotl.OutdatedSenderException) AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) Message(eu.siacs.conversations.entities.Message) BrokenSessionException(eu.siacs.conversations.crypto.axolotl.BrokenSessionException) XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) NotEncryptedForThisDeviceException(eu.siacs.conversations.crypto.axolotl.NotEncryptedForThisDeviceException) BrokenSessionException(eu.siacs.conversations.crypto.axolotl.BrokenSessionException) NotEncryptedForThisDeviceException(eu.siacs.conversations.crypto.axolotl.NotEncryptedForThisDeviceException) OutdatedSenderException(eu.siacs.conversations.crypto.axolotl.OutdatedSenderException)

Aggregations

AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)1 BrokenSessionException (eu.siacs.conversations.crypto.axolotl.BrokenSessionException)1 NotEncryptedForThisDeviceException (eu.siacs.conversations.crypto.axolotl.NotEncryptedForThisDeviceException)1 OutdatedSenderException (eu.siacs.conversations.crypto.axolotl.OutdatedSenderException)1 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)1 Message (eu.siacs.conversations.entities.Message)1