use of net.java.otr4j.session.OtrSm in project Zom-Android by zom.
the class OtrChatManager method abortSmp.
public void abortSmp(SessionID sessionID) throws OtrException {
OtrSm otrSm = mOtrSms.get(sessionID.toString());
if (otrSm == null)
return;
List<TLV> tlvs = otrSm.abortSmp();
String encrypted = mOtrEngine.transformSending(sessionID, "", tlvs);
mOtrEngineHost.injectMessage(sessionID, encrypted);
}
use of net.java.otr4j.session.OtrSm 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.OtrSm in project Zom-Android by zom.
the class OtrChatManager method respondSmp.
public void respondSmp(SessionID sessionID, String secret) throws OtrException {
OtrSm otrSm = mOtrSms.get(sessionID.toString());
List<TLV> tlvs;
if (otrSm == null) {
showError(sessionID, "Could not respond to verification because conversation is not encrypted");
return;
}
tlvs = otrSm.initRespondSmp(null, secret, false);
String encrypted = mOtrEngine.transformSending(sessionID, "", tlvs);
mOtrEngineHost.injectMessage(sessionID, encrypted);
}
use of net.java.otr4j.session.OtrSm in project Zom-Android by zom.
the class OtrChatManager method decryptMessage.
public String decryptMessage(String localUserId, String remoteUserId, String msg, List<TLV> tlvs) throws OtrException {
String plain = null;
SessionID sessionId = getSessionId(localUserId, remoteUserId);
if (mOtrEngine != null && sessionId != null) {
mOtrEngineHost.putSessionResource(sessionId, processResource(remoteUserId));
plain = mOtrEngine.transformReceiving(sessionId, msg, tlvs);
OtrSm otrSm = mOtrSms.get(sessionId.toString());
if (otrSm != null) {
List<TLV> smTlvs = otrSm.getPendingTlvs();
if (smTlvs != null) {
String encrypted = mOtrEngine.transformSending(sessionId, "", smTlvs);
mOtrEngineHost.injectMessage(sessionId, encrypted);
}
}
// not null, but empty so make it null!
if (TextUtils.isEmpty(plain))
return null;
}
return plain;
}
use of net.java.otr4j.session.OtrSm in project Zom-Android by zom.
the class OtrChatManager method initSmp.
public void initSmp(SessionID sessionID, String question, String secret) throws OtrException {
OtrSm otrSm = mOtrSms.get(sessionID.toString());
List<TLV> tlvs;
if (otrSm == null) {
showError(sessionID, "Could not perform verification because conversation is not encrypted");
return;
}
tlvs = otrSm.initRespondSmp(question, secret, true);
String encrypted = mOtrEngine.transformSending(sessionID, "", tlvs);
mOtrEngineHost.injectMessage(sessionID, encrypted);
}