Fix OTR-Error messages

Send out OTR-Errors on unreadableMessageReceived() as well, not only on
messageFromAnotherInstanceReceived
This commit is contained in:
BrianBlade 2015-04-01 12:22:18 +02:00
parent 7eabdfd80f
commit db74cb52c4
2 changed files with 24 additions and 18 deletions

View file

@ -202,20 +202,7 @@ public class OtrEngine extends OtrCryptoEngineImpl implements OtrEngineHost {
@Override @Override
public void messageFromAnotherInstanceReceived(SessionID session) { public void messageFromAnotherInstanceReceived(SessionID session) {
try { sendOtrErrorMessage(session, "Message from another OTR-instance received");
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 @Override
@ -267,9 +254,28 @@ public class OtrEngine extends OtrCryptoEngineImpl implements OtrEngineHost {
} }
@Override @Override
public void unreadableMessageReceived(SessionID arg0) throws OtrException { public void unreadableMessageReceived(SessionID session) throws OtrException {
Log.d(Config.LOGTAG,"unreadable message received"); Log.d(Config.LOGTAG,"unreadable message received");
throw new OtrException(new Exception("unreadable message received")); sendOtrErrorMessage(session, "You sent me an unreadable OTR-encrypted message");
}
public void sendOtrErrorMessage(SessionID session, String errorText) {
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, errorText);
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 @Override

View file

@ -172,7 +172,7 @@ public class MessageGenerator extends AbstractGenerator {
return receivedPacket; return receivedPacket;
} }
public MessagePacket generateOtrError(Jid to, String id) { public MessagePacket generateOtrError(Jid to, String id, String errorText) {
MessagePacket packet = new MessagePacket(); MessagePacket packet = new MessagePacket();
packet.setType(MessagePacket.TYPE_ERROR); packet.setType(MessagePacket.TYPE_ERROR);
packet.setAttribute("id",id); packet.setAttribute("id",id);
@ -181,7 +181,7 @@ public class MessageGenerator extends AbstractGenerator {
error.setAttribute("code","406"); error.setAttribute("code","406");
error.setAttribute("type","modify"); error.setAttribute("type","modify");
error.addChild("not-acceptable","urn:ietf:params:xml:ns:xmpp-stanzas"); error.addChild("not-acceptable","urn:ietf:params:xml:ns:xmpp-stanzas");
error.addChild("text").setContent("unreadable OTR message received"); error.addChild("text").setContent("?OTR Error:" + errorText);
return packet; return packet;
} }
} }