Search in sources :

Example 1 with OtrService

use of de.pixart.messenger.crypto.OtrService in project Pix-Art-Messenger by kriztan.

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…");
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                body = Html.fromHtml(body, Html.FROM_HTML_MODE_LEGACY).toString();
            } else {
                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(de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage) Message(de.pixart.messenger.entities.Message) OtrService(de.pixart.messenger.crypto.OtrService) SessionStatus(net.java.otr4j.session.SessionStatus) Session(net.java.otr4j.session.Session)

Example 2 with OtrService

use of de.pixart.messenger.crypto.OtrService in project Pix-Art-Messenger by kriztan.

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(de.pixart.messenger.crypto.axolotl.AxolotlService) OtrService(de.pixart.messenger.crypto.OtrService) PgpDecryptionService(de.pixart.messenger.crypto.PgpDecryptionService)

Aggregations

OtrService (de.pixart.messenger.crypto.OtrService)2 PgpDecryptionService (de.pixart.messenger.crypto.PgpDecryptionService)1 AxolotlService (de.pixart.messenger.crypto.axolotl.AxolotlService)1 XmppAxolotlMessage (de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage)1 Message (de.pixart.messenger.entities.Message)1 Session (net.java.otr4j.session.Session)1 SessionStatus (net.java.otr4j.session.SessionStatus)1