aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-06-29 17:18:57 +0200
committerDaniel Gultsch <daniel@gultsch.de>2016-06-29 17:18:57 +0200
commitf7933c26d7c64edb60e00f83f67b000cd1d7c1cd (patch)
tree3e8f719e0293ce543903e3c49e566e2ccd8cccd5 /src/main/java/eu
parent1d79a677c88f6ac2c6d17a5ba7214a8846957659 (diff)
don't crash on broken base64 in omemo messages. fixes #1934
Diffstat (limited to 'src/main/java/eu')
-rw-r--r--src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java6
-rw-r--r--src/main/java/eu/siacs/conversations/parser/MessageParser.java16
2 files changed, 14 insertions, 8 deletions
diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java
index 93a73677..e8ec5426 100644
--- a/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java
+++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java
@@ -99,7 +99,7 @@ public class XmppAxolotlMessage {
case KEYTAG:
try {
Integer recipientId = Integer.parseInt(keyElement.getAttribute(REMOTEID));
- byte[] key = Base64.decode(keyElement.getContent(), Base64.DEFAULT);
+ byte[] key = Base64.decode(keyElement.getContent().trim(), Base64.DEFAULT);
this.keys.put(recipientId, key);
} catch (NumberFormatException e) {
throw new IllegalArgumentException(e);
@@ -109,7 +109,7 @@ public class XmppAxolotlMessage {
if (this.iv != null) {
throw new IllegalArgumentException("Duplicate iv entry");
}
- iv = Base64.decode(keyElement.getContent(), Base64.DEFAULT);
+ iv = Base64.decode(keyElement.getContent().trim(), Base64.DEFAULT);
break;
default:
Log.w(Config.LOGTAG, "Unexpected element in header: " + keyElement.toString());
@@ -118,7 +118,7 @@ public class XmppAxolotlMessage {
}
Element payloadElement = axolotlMessage.findChild(PAYLOAD);
if (payloadElement != null) {
- ciphertext = Base64.decode(payloadElement.getContent(), Base64.DEFAULT);
+ ciphertext = Base64.decode(payloadElement.getContent().trim(), Base64.DEFAULT);
}
}
diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java
index ff66c30f..4c446632 100644
--- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java
+++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java
@@ -146,17 +146,23 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
}
private Message parseAxolotlChat(Element axolotlMessage, Jid from, Conversation conversation, int status) {
- Message finishedMessage = null;
AxolotlService service = conversation.getAccount().getAxolotlService();
- XmppAxolotlMessage xmppAxolotlMessage = XmppAxolotlMessage.fromElement(axolotlMessage, from.toBareJid());
+ XmppAxolotlMessage xmppAxolotlMessage;
+ try {
+ xmppAxolotlMessage = XmppAxolotlMessage.fromElement(axolotlMessage, from.toBareJid());
+ } catch (Exception e) {
+ Log.d(Config.LOGTAG,conversation.getAccount().getJid().toBareJid()+": invalid omemo message received "+e.getMessage());
+ return null;
+ }
XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = service.processReceivingPayloadMessage(xmppAxolotlMessage);
if(plaintextMessage != null) {
- finishedMessage = new Message(conversation, plaintextMessage.getPlaintext(), Message.ENCRYPTION_AXOLOTL, status);
+ Message finishedMessage = new Message(conversation, plaintextMessage.getPlaintext(), Message.ENCRYPTION_AXOLOTL, status);
finishedMessage.setFingerprint(plaintextMessage.getFingerprint());
Log.d(Config.LOGTAG, AxolotlService.getLogprefix(finishedMessage.getConversation().getAccount())+" Received Message with session fingerprint: "+plaintextMessage.getFingerprint());
+ return finishedMessage;
+ } else {
+ return null;
}
-
- return finishedMessage;
}
private class Invite {