use of net.java.otr4j.session.TLV 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.TLV in project Zom-Android by zom.
the class OtrChatManager method transformPushWhitelistTokenSending.
/**
* Create a message body describing the ChatSecure-Push Whitelist Token Exchange.
* See <a href="https://github.com/ChatSecure/ChatSecure-Push-Server/wiki/Chat-Client-Implementation-Notes#json-whitelist-token-exchange">JSON Whitelist Token Exchange</a>
*
* @param message A {@link Message} providing the 'to' & 'from' addresses, as well as
* any message body text (this is currently unused by the ChatSecure-Push
* spec).
* @param whitelistTokens An Array of one or more ChatSecure-Push Whitelist tokens
*/
public boolean transformPushWhitelistTokenSending(@NonNull Message message, @NonNull String[] whitelistTokens) {
String localUserId = message.getFrom().getAddress();
String remoteUserId = message.getTo().getAddress();
String body = message.getBody();
SessionID sessionId = getSessionId(localUserId, remoteUserId);
try {
List<TLV> tlvs = new ArrayList<>(1);
if (mOtrEngine != null && sessionId != null) {
SessionStatus sessionStatus = mOtrEngine.getSessionStatus(sessionId);
if (sessionStatus != SessionStatus.ENCRYPTED) {
// Cannot send Whitelist token without OTR.
// TODO: Is it possible to Postpone-send a TLV message?
OtrDebugLogger.log("Could not send ChatSecure-Push Whitelist Token TLV. Session not encrypted.");
return false;
}
OtrDebugLogger.log("session status: " + sessionStatus);
body = mOtrEngine.transformSending(sessionId, body, tlvs);
message.setTo(mOtrEngineHost.appendSessionResource(sessionId, message.getTo()));
}
message.setBody(body);
return true;
} catch (Exception e) {
OtrDebugLogger.log("error encrypting", e);
return false;
}
}
use of net.java.otr4j.session.TLV 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.TLV 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.TLV in project Zom-Android by zom.
the class OtrEngineImpl method transformSending.
public String transformSending(SessionID sessionID, String msgText, boolean isResponse, byte[] data) throws OtrException {
List<TLV> tlvs = null;
if (data != null) {
tlvs = new ArrayList<TLV>(1);
tlvs.add(new TLV(isResponse ? TLV_DATA_RESPONSE : TLV_DATA_REQUEST, data));
}
return this.getSession(sessionID).transformSending(msgText, tlvs);
}
Aggregations