From 63cd8e598177b6b5757ab8518a48a44928dbe387 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 24 Feb 2018 20:47:02 +0100 Subject: [PATCH] added config param to use a random resource at every bind --- src/main/java/eu/siacs/conversations/Config.java | 2 ++ src/main/java/eu/siacs/conversations/utils/CryptoHelper.java | 2 +- .../java/eu/siacs/conversations/xmpp/XmppConnection.java | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java index 09f9fd4d2..0e1801f84 100644 --- a/src/main/java/eu/siacs/conversations/Config.java +++ b/src/main/java/eu/siacs/conversations/Config.java @@ -43,6 +43,8 @@ public final class Config { public static final String MAGIC_CREATE_DOMAIN = "conversations.im"; public static final boolean DISALLOW_REGISTRATION_IN_UI = false; //hide the register checkbox + public static final boolean USE_RANDOM_RESOURCE_ON_EVERY_BIND = false; + public static final boolean ALLOW_NON_TLS_CONNECTIONS = false; //very dangerous. you should have a good reason to set this to true public static final boolean FORCE_ORBOT = false; // always use TOR public static final boolean HIDE_MESSAGE_TEXT_IN_NOTIFICATION = false; diff --git a/src/main/java/eu/siacs/conversations/utils/CryptoHelper.java b/src/main/java/eu/siacs/conversations/utils/CryptoHelper.java index 0fef5a5aa..cd4d9073b 100644 --- a/src/main/java/eu/siacs/conversations/utils/CryptoHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/CryptoHelper.java @@ -102,7 +102,7 @@ public final class CryptoHelper { public static String random(int length, SecureRandom random) { final byte[] bytes = new byte[length]; random.nextBytes(bytes); - return Base64.encodeToString(bytes,Base64.NO_PADDING|Base64.NO_WRAP); + return Base64.encodeToString(bytes,Base64.NO_PADDING|Base64.NO_WRAP|Base64.URL_SAFE); } public static String prettifyFingerprint(String fingerprint) { diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index a6b72ed0c..d266b1f61 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -1070,7 +1070,8 @@ public class XmppConnection implements Runnable { } clearIqCallbacks(); final IqPacket iq = new IqPacket(IqPacket.TYPE.SET); - iq.addChild("bind", Namespace.BIND).addChild("resource").setContent(account.getResource()); + final String resource = Config.USE_RANDOM_RESOURCE_ON_EVERY_BIND ? nextRandomId() : account.getResource(); + iq.addChild("bind", Namespace.BIND).addChild("resource").setContent(resource); this.sendUnmodifiedIqPacket(iq, new OnIqPacketReceived() { @Override public void onIqPacketReceived(final Account account, final IqPacket packet) { @@ -1370,7 +1371,7 @@ public class XmppConnection implements Runnable { } private String nextRandomId() { - return CryptoHelper.random(50, mXmppConnectionService.getRNG()); + return CryptoHelper.random(10, mXmppConnectionService.getRNG()); } public String sendIqPacket(final IqPacket packet, final OnIqPacketReceived callback) {