added config param to use a random resource at every bind

This commit is contained in:
Christian Schneppe 2018-02-26 19:44:18 +01:00
parent 06014f81e5
commit ef5bcf1809
3 changed files with 6 additions and 3 deletions

View file

@ -50,6 +50,8 @@ public final class Config {
public static final boolean SINGLE_ACCOUNT = true; //set to true to allow only one account
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

View file

@ -101,7 +101,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) {

View file

@ -1100,7 +1100,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) {
@ -1400,7 +1401,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) {