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);
}
}
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();
}
});
}
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;
}
}
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;
}
}
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;
}
}
Aggregations