use of net.java.otr4j.session.Session in project Zom-Android by zom.
the class OtrChatManager method sessionStatusChanged.
@Override
public void sessionStatusChanged(final SessionID sessionID) {
SessionStatus sStatus = mOtrEngine.getSessionStatus(sessionID);
OtrDebugLogger.log("session status changed: " + sStatus);
final Session session = mOtrEngine.getSession(sessionID);
OtrSm otrSm = mOtrSms.get(sessionID.toString());
if (sStatus == SessionStatus.ENCRYPTED) {
PublicKey remoteKey = mOtrEngine.getRemotePublicKey(sessionID);
mOtrEngineHost.storeRemoteKey(sessionID, remoteKey);
if (otrSm == null) {
// SMP handler - make sure we only add this once per session!
otrSm = new OtrSm(session, mOtrEngineHost.getKeyManager(), sessionID, OtrChatManager.this);
session.addTlvHandler(otrSm);
mOtrSms.put(sessionID.toString(), otrSm);
}
} else if (sStatus == SessionStatus.PLAINTEXT) {
if (otrSm != null) {
session.removeTlvHandler(otrSm);
mOtrSms.remove(sessionID.toString());
}
mOtrEngineHost.removeSessionResource(sessionID);
} else if (sStatus == SessionStatus.FINISHED) {
// Do nothing. The user must take affirmative action to
// restart or end the session, so that they don't send
// plaintext by mistake.
}
}
use of net.java.otr4j.session.Session in project xabber-android by redsolution.
the class OTRManager method sessionStatusChanged.
@Override
public void sessionStatusChanged(SessionID sessionID) {
removeSMRequest(sessionID.getAccountID(), sessionID.getUserID());
removeSMProgress(sessionID.getAccountID(), sessionID.getUserID());
Session session = sessions.get(sessionID.getAccountID(), sessionID.getUserID());
SessionStatus sStatus = session.getSessionStatus();
LogManager.i(this, "session status changed " + sessionID.getUserID() + " status: " + sStatus);
if (sStatus == SessionStatus.ENCRYPTED) {
finished.remove(sessionID.getAccountID(), sessionID.getUserID());
PublicKey remotePublicKey = session.getRemotePublicKey();
String value;
try {
OtrCryptoEngine otrCryptoEngine = new OtrCryptoEngineImpl();
value = otrCryptoEngine.getFingerprint(remotePublicKey);
} catch (OtrCryptoException e) {
LogManager.exception(this, e);
value = null;
}
if (value != null) {
actives.put(sessionID.getAccountID(), sessionID.getUserID(), value);
if (fingerprints.get(sessionID.getAccountID(), sessionID.getUserID(), value) == null) {
fingerprints.put(sessionID.getAccountID(), sessionID.getUserID(), value, false);
requestToWrite(sessionID.getAccountID(), sessionID.getUserID(), value, false);
}
}
newAction(sessionID.getAccountID(), sessionID.getUserID(), null, isVerified(sessionID.getAccountID(), sessionID.getUserID()) ? ChatAction.otr_verified : ChatAction.otr_encryption);
AbstractChat chat = getChat(sessionID.getAccountID(), sessionID.getUserID());
if (chat != null) {
chat.sendMessages();
}
} else if (sStatus == SessionStatus.PLAINTEXT) {
actives.remove(sessionID.getAccountID(), sessionID.getUserID());
sessions.remove(sessionID.getAccountID(), sessionID.getUserID());
finished.remove(sessionID.getAccountID(), sessionID.getUserID());
try {
session.endSession();
} catch (OtrException e) {
LogManager.exception(this, e);
}
newAction(sessionID.getAccountID(), sessionID.getUserID(), null, ChatAction.otr_plain);
} else if (sStatus == SessionStatus.FINISHED) {
actives.remove(sessionID.getAccountID(), sessionID.getUserID());
sessions.remove(sessionID.getAccountID(), sessionID.getUserID());
finished.put(sessionID.getAccountID(), sessionID.getUserID(), true);
newAction(sessionID.getAccountID(), sessionID.getUserID(), null, ChatAction.otr_finish);
// if session was finished then clear OTR-resource for this chat
RegularChat chat = (RegularChat) getChat(sessionID.getAccountID(), sessionID.getUserID());
if (chat != null) {
chat.setOTRresource(null);
}
} else {
throw new IllegalStateException();
}
onContactChanged(sessionID);
}
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;
}
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(AccountJid account, UserJid user, String content) throws OtrException {
LogManager.i(this, "transform incoming message... " + content, "transform incoming message... ***");
Session session = getOrCreateSession(account.toString(), user.toString());
try {
String s = session.transformReceiving(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);
}
}
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);
}
}
}
Aggregations