From c082066118431a380dc62892c4363f73591b6666 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 16 Aug 2015 11:50:33 +0200 Subject: [PATCH 1/5] catch null pointer in ScramSHA1 sasl --- .../java/eu/siacs/conversations/crypto/sasl/ScramSha1.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/eu/siacs/conversations/crypto/sasl/ScramSha1.java b/src/main/java/eu/siacs/conversations/crypto/sasl/ScramSha1.java index c95a62df3..f47677f6e 100644 --- a/src/main/java/eu/siacs/conversations/crypto/sasl/ScramSha1.java +++ b/src/main/java/eu/siacs/conversations/crypto/sasl/ScramSha1.java @@ -101,6 +101,9 @@ public class ScramSha1 extends SaslMechanism { public String getResponse(final String challenge) throws AuthenticationException { switch (state) { case AUTH_TEXT_SENT: + if (challenge == null) { + throw new AuthenticationException("challenge can not be null"); + } serverFirstMessage = Base64.decode(challenge, Base64.DEFAULT); final Tokenizer tokenizer = new Tokenizer(serverFirstMessage); String nonce = ""; From 51a2645349e43c5e780b352f7e76fc5aeae1cfde Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 16 Aug 2015 12:12:22 +0200 Subject: [PATCH 2/5] synchronize packetCallbacks --- .../conversations/xmpp/XmppConnection.java | 55 ++++++++++--------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 5ac089766..44e146146 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -152,7 +152,6 @@ public class XmppConnection implements Runnable { shouldAuthenticate = shouldBind = !account.isOptionSet(Account.OPTION_REGISTER); tagReader = new XmlReader(wakeLock); tagWriter = new TagWriter(); - packetCallbacks.clear(); this.changeStatus(Account.State.CONNECTING); if (DNSHelper.isIp(account.getServer().toString())) { socket = new Socket(); @@ -489,26 +488,28 @@ public class XmppConnection implements Runnable { this.jingleListener.onJinglePacketReceived(account,(JinglePacket) packet); } } else { - if (packetCallbacks.containsKey(packet.getId())) { - final Pair packetCallbackDuple = packetCallbacks.get(packet.getId()); - // Packets to the server should have responses from the server - if (packetCallbackDuple.first.toServer(account)) { - if (packet.fromServer(account)) { - packetCallbackDuple.second.onIqPacketReceived(account, packet); - packetCallbacks.remove(packet.getId()); + synchronized (this.packetCallbacks) { + if (packetCallbacks.containsKey(packet.getId())) { + final Pair packetCallbackDuple = packetCallbacks.get(packet.getId()); + // Packets to the server should have responses from the server + if (packetCallbackDuple.first.toServer(account)) { + if (packet.fromServer(account)) { + packetCallbackDuple.second.onIqPacketReceived(account, packet); + packetCallbacks.remove(packet.getId()); + } else { + Log.e(Config.LOGTAG, account.getJid().toBareJid().toString() + ": ignoring spoofed iq packet"); + } } else { - Log.e(Config.LOGTAG,account.getJid().toBareJid().toString()+": ignoring spoofed iq packet"); - } - } else { - if (packet.getFrom().equals(packetCallbackDuple.first.getTo())) { - packetCallbackDuple.second.onIqPacketReceived(account, packet); - packetCallbacks.remove(packet.getId()); - } else { - Log.e(Config.LOGTAG,account.getJid().toBareJid().toString()+": ignoring spoofed iq packet"); + if (packet.getFrom().equals(packetCallbackDuple.first.getTo())) { + packetCallbackDuple.second.onIqPacketReceived(account, packet); + packetCallbacks.remove(packet.getId()); + } else { + Log.e(Config.LOGTAG, account.getJid().toBareJid().toString() + ": ignoring spoofed iq packet"); + } } + } else if (packet.getType() == IqPacket.TYPE.GET || packet.getType() == IqPacket.TYPE.SET) { + this.unregisteredIqListener.onIqPacketReceived(account, packet); } - } else if (packet.getType() == IqPacket.TYPE.GET|| packet.getType() == IqPacket.TYPE.SET) { - this.unregisteredIqListener.onIqPacketReceived(account, packet); } } } @@ -739,13 +740,15 @@ public class XmppConnection implements Runnable { } private void clearIqCallbacks() { - Log.d(Config.LOGTAG,account.getJid().toBareJid()+": clearing iq iq callbacks"); + Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": clearing iq iq callbacks"); final IqPacket failurePacket = new IqPacket(IqPacket.TYPE.ERROR); - Iterator>> iterator = this.packetCallbacks.entrySet().iterator(); - while(iterator.hasNext()) { - Entry> entry = iterator.next(); - entry.getValue().second.onIqPacketReceived(account,failurePacket); - iterator.remove(); + synchronized (this.packetCallbacks) { + Iterator>> iterator = this.packetCallbacks.entrySet().iterator(); + while (iterator.hasNext()) { + Entry> entry = iterator.next(); + entry.getValue().second.onIqPacketReceived(account, failurePacket); + iterator.remove(); + } } } @@ -917,7 +920,9 @@ public class XmppConnection implements Runnable { packet.setAttribute("id", id); } if (callback != null) { - packetCallbacks.put(packet.getId(), new Pair<>(packet, callback)); + synchronized (this.packetCallbacks) { + packetCallbacks.put(packet.getId(), new Pair<>(packet, callback)); + } } this.sendPacket(packet); } From d7b3060fc856ca5fb0f4bcc1022531487e96e58f Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 16 Aug 2015 14:55:24 +0200 Subject: [PATCH 3/5] catch broken base64 in avatars --- .../eu/siacs/conversations/persistance/FileBackend.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 6e5a1ae35..f18266d99 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -358,11 +358,7 @@ public class FileBackend { file.delete(); return false; } - } catch (FileNotFoundException e) { - return false; - } catch (IOException e) { - return false; - } catch (NoSuchAlgorithmException e) { + } catch (IllegalArgumentException | IOException | NoSuchAlgorithmException e) { return false; } finally { close(os); From 5b1dda91486aab7130aee56ba3f98aa966a9b3fb Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 16 Aug 2015 14:55:40 +0200 Subject: [PATCH 4/5] deal with broken frameworks --- .../java/eu/siacs/conversations/xmpp/XmppConnection.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 44e146146..17b3c3ffb 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -198,10 +198,7 @@ public class XmppConnection implements Runnable { socket = new Socket(); socket.connect(addr, Config.SOCKET_TIMEOUT * 1000); socketError = false; - } catch (final UnknownHostException e) { - Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": " + e.getMessage()); - i++; - } catch (final IOException e) { + } catch (final Throwable e) { Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": " + e.getMessage()); i++; } From 569bc435d35e79e667045aa5ed861439ebf5363c Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 16 Aug 2015 15:00:27 +0200 Subject: [PATCH 5/5] increased version code --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index d6f77ebf5..0537d3961 100644 --- a/build.gradle +++ b/build.gradle @@ -48,7 +48,7 @@ android { defaultConfig { minSdkVersion 14 targetSdkVersion 21 - versionCode 83 + versionCode 84 versionName "1.6.0" }