aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2015-03-21 16:07:17 +0100
committeriNPUTmice <daniel@gultsch.de>2015-03-21 16:07:17 +0100
commit99b2ef7e9d571dcfa386df4d0190ce626e657232 (patch)
treec3916fd5c3d9214ed26d29abbc618f7711e31d05 /src
parent825278971e869012e71dedbbd0da2792c3182157 (diff)
respond to unreadable OTR messages with error message. fixed #1021
Diffstat (limited to '')
-rw-r--r--src/main/java/eu/siacs/conversations/crypto/OtrEngine.java18
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Conversation.java9
-rw-r--r--src/main/java/eu/siacs/conversations/generator/MessageGenerator.java13
-rw-r--r--src/main/java/eu/siacs/conversations/parser/MessageParser.java2
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java3
5 files changed, 42 insertions, 3 deletions
diff --git a/src/main/java/eu/siacs/conversations/crypto/OtrEngine.java b/src/main/java/eu/siacs/conversations/crypto/OtrEngine.java
index c85864d0..20427d7b 100644
--- a/src/main/java/eu/siacs/conversations/crypto/OtrEngine.java
+++ b/src/main/java/eu/siacs/conversations/crypto/OtrEngine.java
@@ -201,9 +201,21 @@ public class OtrEngine extends OtrCryptoEngineImpl implements OtrEngineHost {
}
@Override
- public void messageFromAnotherInstanceReceived(SessionID id) {
- Log.d(Config.LOGTAG,
- "unreadable message received from " + id.getAccountID());
+ public void messageFromAnotherInstanceReceived(SessionID session) {
+ try {
+ Jid jid = Jid.fromSessionID(session);
+ Conversation conversation = mXmppConnectionService.find(account, jid);
+ String id = conversation == null ? null : conversation.getLastReceivedOtrMessageId();
+ if (id != null) {
+ MessagePacket packet = mXmppConnectionService.getMessageGenerator().generateOtrError(jid,id);
+ packet.setFrom(account.getJid());
+ mXmppConnectionService.sendMessagePacket(account,packet);
+ Log.d(Config.LOGTAG,packet.toString());
+ Log.d(Config.LOGTAG,account.getJid().toBareJid().toString()+": unreadable OTR message in "+conversation.getName());
+ }
+ } catch (InvalidJidException e) {
+ return;
+ }
}
@Override
diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java
index c150fb91..bfee5007 100644
--- a/src/main/java/eu/siacs/conversations/entities/Conversation.java
+++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java
@@ -78,6 +78,7 @@ public class Conversation extends AbstractEntity implements Blockable {
private boolean messagesLeftOnServer = true;
private ChatState mOutgoingChatState = Config.DEFAULT_CHATSTATE;
private ChatState mIncomingChatState = Config.DEFAULT_CHATSTATE;
+ private String mLastReceivedOtrMessageId = null;
public boolean hasMessagesLeftOnServer() {
return messagesLeftOnServer;
@@ -234,6 +235,14 @@ public class Conversation extends AbstractEntity implements Blockable {
return getContact().getBlockedJid();
}
+ public String getLastReceivedOtrMessageId() {
+ return this.mLastReceivedOtrMessageId;
+ }
+
+ public void setLastReceivedOtrMessageId(String id) {
+ this.mLastReceivedOtrMessageId = id;
+ }
+
public interface OnMessageFound {
public void onMessageFound(final Message message);
diff --git a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java
index 7f2f10a1..8f6a90b9 100644
--- a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java
+++ b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java
@@ -171,4 +171,17 @@ public class MessageGenerator extends AbstractGenerator {
received.setAttribute("id", originalMessage.getId());
return receivedPacket;
}
+
+ public MessagePacket generateOtrError(Jid to, String id) {
+ MessagePacket packet = new MessagePacket();
+ packet.setType(MessagePacket.TYPE_ERROR);
+ packet.setAttribute("id",id);
+ packet.setTo(to);
+ Element error = packet.addChild("error");
+ error.setAttribute("code","406");
+ error.setAttribute("type","modify");
+ error.addChild("not-acceptable","urn:ietf:params:xml:ns:xmpp-stanzas");
+ error.addChild("text").setContent("unreadable OTR message received");
+ return packet;
+ }
}
diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java
index aa6aa4dc..72ece046 100644
--- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java
+++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java
@@ -118,6 +118,7 @@ public class MessageParser extends AbstractParser implements
}
}
try {
+ conversation.setLastReceivedOtrMessageId(packet.getId());
Session otrSession = conversation.getOtrSession();
SessionStatus before = otrSession.getSessionStatus();
body = otrSession.transformReceiving(body);
@@ -145,6 +146,7 @@ public class MessageParser extends AbstractParser implements
finishedMessage.markable = isMarkable(packet);
finishedMessage.setCounterpart(from);
extractChatState(conversation, packet);
+ conversation.setLastReceivedOtrMessageId(null);
return finishedMessage;
} catch (Exception e) {
conversation.resetOtrSession();
diff --git a/src/main/java/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java b/src/main/java/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java
index 61465ae0..93aaa68c 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java
@@ -39,6 +39,9 @@ public class MessagePacket extends AbstractStanza {
break;
case TYPE_NORMAL:
break;
+ case TYPE_ERROR:
+ this.setAttribute("type","error");
+ break;
default:
this.setAttribute("type", "chat");
break;