use of net.java.otr4j.session.TLV in project Zom-Android by zom.
the class OtrChatListener method onIncomingMessage.
@Override
public boolean onIncomingMessage(ChatSession session, Message msg, boolean notifyUser) {
OtrDebugLogger.log("processing incoming message: " + msg.getID());
boolean result = false;
if (mOtrChatManager == null || msg.getType() != Imps.MessageType.INCOMING) {
if (!TextUtils.isEmpty(msg.getBody())) {
result = mMessageListener.onIncomingMessage(session, msg, notifyUser);
} else {
OtrDebugLogger.log("incoming body was empty");
}
return result;
} else {
// Do the OTR decryption thing
String body = msg.getBody();
String remoteAddress = msg.getFrom().getAddress();
String localAddress = msg.getTo().getAddress();
SessionID sessionID = mOtrChatManager.getSessionId(localAddress, remoteAddress);
SessionStatus otrStatus = mOtrChatManager.getSessionStatus(sessionID);
if (otrStatus == SessionStatus.ENCRYPTED) {
boolean verified = mOtrChatManager.getKeyManager().isVerified(sessionID);
if (verified) {
msg.setType(Imps.MessageType.INCOMING_ENCRYPTED_VERIFIED);
} else {
msg.setType(Imps.MessageType.INCOMING_ENCRYPTED);
}
}
List<TLV> tlvs = new ArrayList<TLV>();
try {
body = mOtrChatManager.decryptMessage(localAddress, remoteAddress, body, tlvs);
if (!TextUtils.isEmpty(body)) {
msg.setBody(body);
result = mMessageListener.onIncomingMessage(session, msg, notifyUser);
} else {
OtrDebugLogger.log("Decrypted incoming body was null (otrdata?)");
}
for (TLV tlv : tlvs) {
if (tlv.getType() == TLV_DATA_REQUEST) {
OtrDebugLogger.log("Got a TLV Data Request: " + new String(tlv.getValue()));
mMessageListener.onIncomingDataRequest(session, msg, tlv.getValue());
result = true;
} else if (tlv.getType() == TLV_DATA_RESPONSE) {
OtrDebugLogger.log("Got a TLV Data Response: " + new String(tlv.getValue()));
mMessageListener.onIncomingDataResponse(session, msg, tlv.getValue());
result = true;
}
}
} catch (OtrException oe) {
OtrDebugLogger.log("error decrypting message: " + msg.getID());
// mOtrChatManager.refreshSession(sessionID.getLocalUserId(),sessionID.getRemoteUserId());
// msg.setBody("[" + "You received an unreadable encrypted message" + "]");
// mMessageListener.onIncomingMessage(session, msg);
mOtrChatManager.injectMessage(sessionID, "");
}
SessionStatus newStatus = mOtrChatManager.getSessionStatus(sessionID.getLocalUserId(), sessionID.getRemoteUserId());
if (newStatus != otrStatus) {
OtrDebugLogger.log("OTR status changed from: " + otrStatus + " to " + newStatus);
mMessageListener.onStatusChanged(session, newStatus);
}
return result;
}
}
use of net.java.otr4j.session.TLV 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);
}
Aggregations