Search in sources :

Example 16 with Session

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

the class OTRManager method transformReceiving.

/**
     * Transform incoming message after receiving.
     */
public String transformReceiving(String account, String user, String content) throws OtrException {
    LogManager.i(this, "transform incoming message... " + content);
    Session session = getOrCreateSession(account, user);
    try {
        String s = session.transformReceiving(content);
        LogManager.i(this, "transformed incoming message: " + s + " session status: " + session.getSessionStatus());
        return s;
    } catch (UnsupportedOperationException e) {
        throw new OtrException(e);
    }
}
Also used : OtrException(net.java.otr4j.OtrException) Session(net.java.otr4j.session.Session)

Example 17 with Session

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

the class XmppConnectionService method onOtrSessionEstablished.

public void onOtrSessionEstablished(Conversation conversation) {
    final Account account = conversation.getAccount();
    final Session otrSession = conversation.getOtrSession();
    Log.d(Config.LOGTAG, account.getJid().toBareJid() + " otr session established with " + conversation.getJid() + "/" + otrSession.getSessionID().getUserID());
    conversation.findUnsentMessagesWithEncryption(Message.ENCRYPTION_OTR, new Conversation.OnMessageFound() {

        @Override
        public void onMessageFound(Message message) {
            SessionID id = otrSession.getSessionID();
            try {
                message.setCounterpart(Jid.fromString(id.getAccountID() + "/" + id.getUserID()));
            } catch (InvalidJidException e) {
                return;
            }
            if (message.needsUploading()) {
                mJingleConnectionManager.createNewConnection(message);
            } else {
                MessagePacket outPacket = mMessageGenerator.generateOtrChat(message);
                if (outPacket != null) {
                    mMessageGenerator.addDelay(outPacket, message.getTimeSent());
                    message.setStatus(Message.STATUS_SEND);
                    databaseBackend.updateMessage(message);
                    sendMessagePacket(account, outPacket);
                }
            }
            updateConversationUi();
        }
    });
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Account(eu.siacs.conversations.entities.Account) XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) Message(eu.siacs.conversations.entities.Message) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) Conversation(eu.siacs.conversations.entities.Conversation) SessionID(net.java.otr4j.session.SessionID) Session(net.java.otr4j.session.Session)

Example 18 with Session

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

the class VerifyOTRActivity method initSmp.

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

Example 19 with Session

use of net.java.otr4j.session.Session in project Zom-Android by zom.

the class OtrEngineImpl method getSession.

public Session getSession(SessionID sessionID) {
    if (sessionID == null || sessionID.equals(SessionID.Empty))
        throw new IllegalArgumentException();
    if (!sessions.containsKey(sessionID.toString())) {
        Session session = new SessionImpl(sessionID, getHost());
        sessions.put(sessionID.toString(), session);
        session.addOtrEngineListener(new OtrEngineListener() {

            public void sessionStatusChanged(SessionID sessionID) {
                for (int i = 0; i < listeners.size(); i++) listeners.get(i).sessionStatusChanged(sessionID);
            }
        });
        return session;
    } else {
        SessionImpl session = (SessionImpl) sessions.get(sessionID.toString());
        // make sure latest instance is stored in session (in case JIDs get updated)
        session.setSessionID(sessionID);
        return session;
    }
}
Also used : SessionImpl(net.java.otr4j.session.SessionImpl) SessionID(net.java.otr4j.session.SessionID) Session(net.java.otr4j.session.Session)

Example 20 with Session

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

the class OTRManager method transformReceivingIfSessionExist.

public String transformReceivingIfSessionExist(AccountJid account, UserJid user, String content) throws OtrException {
    LogManager.i(this, "transform incoming message... " + content, "transform incoming message... ***");
    Session session = getSession(account.toString(), user.toString());
    SecurityLevel securityLevel = OTRManager.getInstance().getSecurityLevel(account, user);
    if (session != null && (securityLevel == SecurityLevel.encrypted || securityLevel == SecurityLevel.verified)) {
        try {
            String s = ((SessionImpl) session).transformReceivingWithoutInject(content);
            LogManager.i(this, "transformed incoming message: " + s + " session status: " + session.getSessionStatus(), "transformed incoming message: " + "***" + " session status: " + session.getSessionStatus());
            return s;
        } catch (UnsupportedOperationException e) {
            throw new OtrException(e);
        }
    } else {
        return content;
    }
}
Also used : SessionImpl(net.java.otr4j.session.SessionImpl) OtrException(net.java.otr4j.OtrException) 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