use of net.java.otr4j.OtrException in project xabber-android by redsolution.
the class OTRManager method abortSmp.
/**
* Abort SM negotiation.
*/
public void abortSmp(String account, String user) throws NetworkException {
LogManager.i(this, "aborting smp... " + user);
removeSMRequest(account, user);
removeSMProgress(account, user);
try {
getOrCreateSession(account, user).abortSmp();
} catch (OtrException e) {
throw new NetworkException(R.string.OTR_ERROR, e);
}
}
use of net.java.otr4j.OtrException 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 {
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);
MessageManager.getInstance().getChat(sessionID.getAccountID(), sessionID.getUserID()).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);
} else {
throw new IllegalStateException();
}
RosterManager.getInstance().onContactChanged(sessionID.getAccountID(), sessionID.getUserID());
}
use of net.java.otr4j.OtrException in project xabber-android by redsolution.
the class RegularChat method onPacket.
@Override
protected boolean onPacket(String bareAddress, Stanza packet) {
if (!super.onPacket(bareAddress, packet))
return false;
final String resource = Jid.getResource(packet.getFrom());
if (packet instanceof Presence) {
final Presence presence = (Presence) packet;
if (this.resource != null && presence.getType() == Presence.Type.unavailable && this.resource.equals(resource)) {
this.resource = null;
}
if (presence.getType() == Presence.Type.unavailable) {
OTRManager.getInstance().onContactUnAvailable(account, user);
}
} else if (packet instanceof Message) {
final Message message = (Message) packet;
if (message.getType() == Message.Type.error)
return true;
MUCUser mucUser = MUC.getMUCUserExtension(message);
if (mucUser != null && mucUser.getInvite() != null)
return true;
String text = message.getBody();
if (text == null)
return true;
String thread = message.getThread();
updateThreadId(thread);
boolean unencrypted = false;
try {
text = OTRManager.getInstance().transformReceiving(account, user, text);
} catch (OtrException e) {
if (e.getCause() instanceof OTRUnencryptedException) {
text = ((OTRUnencryptedException) e.getCause()).getText();
unencrypted = true;
} else {
LogManager.exception(this, e);
// Invalid message received.
return true;
}
}
// System message received.
if (text == null || text.trim().equals(""))
return true;
if (!"".equals(resource))
this.resource = resource;
newMessage(resource, text, null, Delay.getDelay(message), true, true, unencrypted, Delay.isOfflineMessage(Jid.getServer(account), packet), MessageArchiveManager.getInstance().getSaveMode(account, user, getThreadId()) != SaveMode.fls);
}
return true;
}
use of net.java.otr4j.OtrException in project Conversations by siacs.
the class XmppConnectionService method renewSymmetricKey.
public boolean renewSymmetricKey(Conversation conversation) {
Account account = conversation.getAccount();
byte[] symmetricKey = new byte[32];
this.mRandom.nextBytes(symmetricKey);
Session otrSession = conversation.getOtrSession();
if (otrSession != null) {
MessagePacket packet = new MessagePacket();
packet.setType(MessagePacket.TYPE_CHAT);
packet.setFrom(account.getJid());
MessageGenerator.addMessageHints(packet);
packet.setAttribute("to", otrSession.getSessionID().getAccountID() + "/" + otrSession.getSessionID().getUserID());
try {
packet.setBody(otrSession.transformSending(CryptoHelper.FILETRANSFER + CryptoHelper.bytesToHex(symmetricKey))[0]);
sendMessagePacket(account, packet);
conversation.setSymmetricKey(symmetricKey);
return true;
} catch (OtrException e) {
return false;
}
}
return false;
}
use of net.java.otr4j.OtrException in project Conversations by siacs.
the class MessageGenerator method generateOtrChat.
public MessagePacket generateOtrChat(Message message) {
Session otrSession = message.getConversation().getOtrSession();
if (otrSession == null) {
return null;
}
MessagePacket packet = preparePacket(message);
addMessageHints(packet);
try {
String content;
if (message.hasFileOnRemoteHost()) {
content = message.getFileParams().url.toString();
} else {
content = message.getBody();
}
packet.setBody(otrSession.transformSending(content)[0]);
packet.addChild("encryption", "urn:xmpp:eme:0").setAttribute("namespace", "urn:xmpp:otr:0");
return packet;
} catch (OtrException e) {
return null;
}
}
Aggregations