Search in sources :

Example 1 with Session

use of net.java.otr4j.session.Session in project Conversations by siacs.

the class XmppConnectionService method renewSymmetricKey.

public boolean renewSymmetricKey(Conversation conversation) {
    Account account = conversation.getAccount();
    byte[] symmetricKey = new byte[32];
    this.mRandom.nextBytes(symmetricKey);
    Session otrSession = conversation.getOtrSession();
    if (otrSession != null) {
        MessagePacket packet = new MessagePacket();
        packet.setType(MessagePacket.TYPE_CHAT);
        packet.setFrom(account.getJid());
        MessageGenerator.addMessageHints(packet);
        packet.setAttribute("to", otrSession.getSessionID().getAccountID() + "/" + otrSession.getSessionID().getUserID());
        try {
            packet.setBody(otrSession.transformSending(CryptoHelper.FILETRANSFER + CryptoHelper.bytesToHex(symmetricKey))[0]);
            sendMessagePacket(account, packet);
            conversation.setSymmetricKey(symmetricKey);
            return true;
        } catch (OtrException e) {
            return false;
        }
    }
    return false;
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Account(eu.siacs.conversations.entities.Account) OtrException(net.java.otr4j.OtrException) Session(net.java.otr4j.session.Session)

Example 2 with Session

use of net.java.otr4j.session.Session 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 3 with Session

use of net.java.otr4j.session.Session in project Conversations by siacs.

the class MessageGenerator method generateOtrChat.

public MessagePacket generateOtrChat(Message message) {
    Session otrSession = message.getConversation().getOtrSession();
    if (otrSession == null) {
        return null;
    }
    MessagePacket packet = preparePacket(message);
    addMessageHints(packet);
    try {
        String content;
        if (message.hasFileOnRemoteHost()) {
            content = message.getFileParams().url.toString();
        } else {
            content = message.getBody();
        }
        packet.setBody(otrSession.transformSending(content)[0]);
        packet.addChild("encryption", "urn:xmpp:eme:0").setAttribute("namespace", "urn:xmpp:otr:0");
        return packet;
    } catch (OtrException e) {
        return null;
    }
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) OtrException(net.java.otr4j.OtrException) Session(net.java.otr4j.session.Session)

Example 4 with Session

use of net.java.otr4j.session.Session in project Conversations by siacs.

the class VerifyOTRActivity method abortSmp.

protected boolean abortSmp() {
    final Session session = mConversation.getOtrSession();
    if (session != null) {
        try {
            session.abortSmp();
            mConversation.smp().status = Conversation.Smp.STATUS_NONE;
            mConversation.smp().hint = null;
            mConversation.smp().secret = null;
            return true;
        } catch (OtrException e) {
            return false;
        }
    } else {
        return false;
    }
}
Also used : OtrException(net.java.otr4j.OtrException) Session(net.java.otr4j.session.Session)

Example 5 with Session

use of net.java.otr4j.session.Session in project xabber-android by redsolution.

the class OTRManager method getOrCreateSession.

private Session getOrCreateSession(String account, String user) {
    Session session = sessions.get(account, user);
    if (session != null) {
        LogManager.i(this, "Found session with id " + session.getSessionID() + " with status " + session.getSessionStatus() + " for user " + user);
        return session;
    }
    LogManager.i(this, "Creating new session for " + user);
    session = new SessionImpl(new SessionID(account, user, "xmpp"), this);
    session.addOtrEngineListener(this);
    sessions.put(account, user, session);
    return session;
}
Also used : SessionImpl(net.java.otr4j.session.SessionImpl) SessionID(net.java.otr4j.session.SessionID) Session(net.java.otr4j.session.Session)

Aggregations

Session (net.java.otr4j.session.Session)20 OtrException (net.java.otr4j.OtrException)13 SessionID (net.java.otr4j.session.SessionID)4 SessionStatus (net.java.otr4j.session.SessionStatus)4 MessagePacket (de.pixart.messenger.xmpp.stanzas.MessagePacket)3 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)3 SessionImpl (net.java.otr4j.session.SessionImpl)3 XmppAxolotlMessage (de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage)2 Account (de.pixart.messenger.entities.Account)2 Message (de.pixart.messenger.entities.Message)2 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)2 Account (eu.siacs.conversations.entities.Account)2 Message (eu.siacs.conversations.entities.Message)2 PublicKey (java.security.PublicKey)2 AbstractChat (com.xabber.android.data.message.AbstractChat)1 RegularChat (com.xabber.android.data.message.RegularChat)1 OtrService (de.pixart.messenger.crypto.OtrService)1 Conversation (de.pixart.messenger.entities.Conversation)1 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)1 OtrService (eu.siacs.conversations.crypto.OtrService)1