Search in sources :

Example 11 with OtrException

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

the class OTRManager method abortSmp.

/**
 * Abort SM negotiation.
 */
public void abortSmp(AccountJid account, UserJid user) throws NetworkException {
    LogManager.i(this, "aborting smp... " + user);
    removeSMRequest(account.toString(), user.toString());
    removeSMProgress(account.toString(), user.toString());
    try {
        getOrCreateSession(account.toString(), user.toString()).abortSmp();
    } catch (OtrException e) {
        throw new NetworkException(R.string.OTR_ERROR, e);
    }
}
Also used : OtrException(net.java.otr4j.OtrException) NetworkException(com.xabber.android.data.NetworkException)

Example 12 with OtrException

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

the class OTRManager method refreshSession.

private void refreshSession(String account, String user) throws NetworkException {
    LogManager.i(this, "Refreshing session for " + user);
    try {
        getOrCreateSession(account, user).refreshSession();
    } catch (OtrException e) {
        throw new NetworkException(R.string.OTR_ERROR, e);
    }
    LogManager.i(this, "Refreshed session for " + user);
}
Also used : OtrException(net.java.otr4j.OtrException) NetworkException(com.xabber.android.data.NetworkException)

Example 13 with OtrException

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

the class OTRManager method endSession.

private void endSession(String account, String user) throws NetworkException {
    LogManager.i(this, "Ending session for " + user);
    try {
        getOrCreateSession(account, user).endSession();
    } catch (OtrException e) {
        throw new NetworkException(R.string.OTR_ERROR, e);
    }
    AbstractChat abstractChat = getChat(account, user);
    if (abstractChat != null) {
        SSNManager.getInstance().setSessionOtrMode(account, user, abstractChat.getThreadId(), OtrMode.concede);
        LogManager.i(this, "Ended session for " + user);
    }
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) OtrException(net.java.otr4j.OtrException) NetworkException(com.xabber.android.data.NetworkException)

Example 14 with OtrException

use of net.java.otr4j.OtrException 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)

Example 15 with OtrException

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

the class OTRManager method injectMessage.

private void injectMessage(String account, String user, String msg) throws OtrException {
    LogManager.i(this, "injectMessage. user: " + user + " message: " + msg);
    AbstractChat abstractChat = getChat(account, user);
    SSNManager.getInstance().setSessionOtrMode(account, user, abstractChat.getThreadId(), OtrMode.prefer);
    Message message = abstractChat.createMessagePacket(msg);
    CarbonManager.getInstance().setMessageToIgnoreCarbons(message);
    try {
        StanzaSender.sendStanza(abstractChat.getAccount(), message);
    } catch (NetworkException e) {
        throw new OtrException(e);
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) AbstractChat(com.xabber.android.data.message.AbstractChat) OtrException(net.java.otr4j.OtrException) NetworkException(com.xabber.android.data.NetworkException)

Aggregations

OtrException (net.java.otr4j.OtrException)23 NetworkException (com.xabber.android.data.NetworkException)11 Session (net.java.otr4j.session.Session)9 AbstractChat (com.xabber.android.data.message.AbstractChat)3 Message (org.jivesoftware.smack.packet.Message)3 OTRUnencryptedException (com.xabber.android.data.extension.otr.OTRUnencryptedException)2 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)2 SessionImpl (net.java.otr4j.session.SessionImpl)2 Presence (org.jivesoftware.smack.packet.Presence)2 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)2 RegularChat (com.xabber.android.data.message.RegularChat)1 Account (eu.siacs.conversations.entities.Account)1 PublicKey (java.security.PublicKey)1 OtrCryptoEngine (net.java.otr4j.crypto.OtrCryptoEngine)1 OtrCryptoEngineImpl (net.java.otr4j.crypto.OtrCryptoEngineImpl)1 OtrCryptoException (net.java.otr4j.crypto.OtrCryptoException)1 SessionID (net.java.otr4j.session.SessionID)1 SessionStatus (net.java.otr4j.session.SessionStatus)1 Resourcepart (org.jxmpp.jid.parts.Resourcepart)1