Search in sources :

Example 1 with OtrService

use of eu.siacs.conversations.crypto.OtrService in project Conversations by siacs.

the class MessageParser method parseOtrChat.

private Message parseOtrChat(String body, Jid from, String id, Conversation conversation) {
    String presence;
    if (from.isBareJid()) {
        presence = "";
    } else {
        presence = from.getResourcepart();
    }
    if (body.matches("^\\?OTRv\\d{1,2}\\?.*")) {
        conversation.endOtrIfNeeded();
    }
    if (!conversation.hasValidOtrSession()) {
        conversation.startOtrSession(presence, false);
    } else {
        String foreignPresence = conversation.getOtrSession().getSessionID().getUserID();
        if (!foreignPresence.equals(presence)) {
            conversation.endOtrIfNeeded();
            conversation.startOtrSession(presence, false);
        }
    }
    try {
        conversation.setLastReceivedOtrMessageId(id);
        Session otrSession = conversation.getOtrSession();
        body = otrSession.transformReceiving(body);
        SessionStatus status = otrSession.getSessionStatus();
        if (body == null && status == SessionStatus.ENCRYPTED) {
            mXmppConnectionService.onOtrSessionEstablished(conversation);
            return null;
        } else if (body == null && status == SessionStatus.FINISHED) {
            conversation.resetOtrSession();
            mXmppConnectionService.updateConversationUi();
            return null;
        } else if (body == null || (body.isEmpty())) {
            return null;
        }
        if (body.startsWith(CryptoHelper.FILETRANSFER)) {
            String key = body.substring(CryptoHelper.FILETRANSFER.length());
            conversation.setSymmetricKey(CryptoHelper.hexToBytes(key));
            return null;
        }
        if (clientMightSendHtml(conversation.getAccount(), from)) {
            Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": received OTR message from bad behaving client. escaping HTML…");
            body = Html.fromHtml(body).toString();
        }
        final OtrService otrService = conversation.getAccount().getOtrService();
        Message finishedMessage = new Message(conversation, body, Message.ENCRYPTION_OTR, Message.STATUS_RECEIVED);
        finishedMessage.setFingerprint(otrService.getFingerprint(otrSession.getRemotePublicKey()));
        conversation.setLastReceivedOtrMessageId(null);
        return finishedMessage;
    } catch (Exception e) {
        conversation.resetOtrSession();
        return null;
    }
}
Also used : XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) Message(eu.siacs.conversations.entities.Message) OtrService(eu.siacs.conversations.crypto.OtrService) SessionStatus(net.java.otr4j.session.SessionStatus) Session(net.java.otr4j.session.Session)

Example 2 with OtrService

use of eu.siacs.conversations.crypto.OtrService in project Conversations by siacs.

the class Account method initAccountServices.

public void initAccountServices(final XmppConnectionService context) {
    this.mOtrService = new OtrService(context, this);
    this.axolotlService = new AxolotlService(this, context);
    this.pgpDecryptionService = new PgpDecryptionService(context);
    if (xmppConnection != null) {
        xmppConnection.addOnAdvancedStreamFeaturesAvailableListener(axolotlService);
    }
}
Also used : AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) OtrService(eu.siacs.conversations.crypto.OtrService) PgpDecryptionService(eu.siacs.conversations.crypto.PgpDecryptionService)

Aggregations

OtrService (eu.siacs.conversations.crypto.OtrService)2 PgpDecryptionService (eu.siacs.conversations.crypto.PgpDecryptionService)1 AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)1 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)1 Message (eu.siacs.conversations.entities.Message)1 Session (net.java.otr4j.session.Session)1 SessionStatus (net.java.otr4j.session.SessionStatus)1