Search in sources :

Example 6 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 7 with Session

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

the class OTRManager method onContactUnAvailable.

public void onContactUnAvailable(String account, String user) {
    Session session = sessions.get(account, user);
    if (session == null) {
        return;
    }
    if (session.getSessionStatus() == SessionStatus.ENCRYPTED) {
        try {
            LogManager.i(this, "onContactUnAvailable. Refresh session for " + user);
            session.refreshSession();
        } catch (OtrException e) {
            LogManager.exception(this, e);
        }
    }
}
Also used : OtrException(net.java.otr4j.OtrException) Session(net.java.otr4j.session.Session)

Example 8 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 9 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 10 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)

Aggregations

Session (net.java.otr4j.session.Session)10 OtrException (net.java.otr4j.OtrException)7 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)3 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)2 Account (eu.siacs.conversations.entities.Account)2 Message (eu.siacs.conversations.entities.Message)2 SessionID (net.java.otr4j.session.SessionID)2 SessionStatus (net.java.otr4j.session.SessionStatus)2 AccountItem (com.xabber.android.data.account.AccountItem)1 OtrService (eu.siacs.conversations.crypto.OtrService)1 Conversation (eu.siacs.conversations.entities.Conversation)1 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)1 PublicKey (java.security.PublicKey)1 OtrCryptoException (net.java.otr4j.crypto.OtrCryptoException)1