mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Pull-Merge of latest changes from main repo
This commit is contained in:
@@ -93,8 +93,8 @@
|
||||
</plurals>
|
||||
<string name="settings_title">Settings</string>
|
||||
<string name="bluetooth_setting_title">BLUETOOTH</string>
|
||||
<string name="bluetooth_setting">Turn on Bluetooth</string>
|
||||
<string name="bluetooth_setting_enabled">While signed in</string>
|
||||
<string name="bluetooth_setting">Connect via Bluetooth</string>
|
||||
<string name="bluetooth_setting_enabled">Whenever contacts are nearby</string>
|
||||
<string name="bluetooth_setting_disabled">Only when adding contacts</string>
|
||||
<string name="notification_settings_title">NOTIFICATIONS</string>
|
||||
<string name="notify_private_messages_setting">Show alerts for private messages</string>
|
||||
|
||||
@@ -133,10 +133,7 @@ public class PasswordActivity extends RoboActivity {
|
||||
continueButton.setVisibility(GONE);
|
||||
progress.setVisibility(VISIBLE);
|
||||
// Decrypt the database key in a background thread
|
||||
int length = e.length();
|
||||
final char[] password = new char[length];
|
||||
e.getChars(0, length, password, 0);
|
||||
e.delete(0, length);
|
||||
final String password = e.toString();
|
||||
cryptoExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
byte[] key = crypto.decryptWithPassword(encrypted, password);
|
||||
|
||||
@@ -19,7 +19,6 @@ import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP;
|
||||
import static org.briarproject.api.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
import static org.briarproject.api.crypto.PasswordStrengthEstimator.WEAK;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -43,7 +42,6 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
@@ -187,18 +185,16 @@ OnEditorActionListener {
|
||||
else strengthMeter.setVisibility(INVISIBLE);
|
||||
String nickname = nicknameEntry.getText().toString();
|
||||
int nicknameLength = StringUtils.toUtf8(nickname).length;
|
||||
char[] firstPassword = getChars(passwordEntry.getText());
|
||||
char[] secondPassword = getChars(passwordConfirmation.getText());
|
||||
boolean passwordsMatch = Arrays.equals(firstPassword, secondPassword);
|
||||
String firstPassword = passwordEntry.getText().toString();
|
||||
String secondPassword = passwordConfirmation.getText().toString();
|
||||
boolean passwordsMatch = firstPassword.equals(secondPassword);
|
||||
float strength = strengthEstimator.estimateStrength(firstPassword);
|
||||
for(int i = 0; i < firstPassword.length; i++) firstPassword[i] = 0;
|
||||
for(int i = 0; i < secondPassword.length; i++) secondPassword[i] = 0;
|
||||
strengthMeter.setStrength(strength);
|
||||
if(nicknameLength > MAX_AUTHOR_NAME_LENGTH) {
|
||||
feedback.setText(R.string.name_too_long);
|
||||
} else if(firstPassword.length == 0) {
|
||||
} else if(firstPassword.length() == 0) {
|
||||
feedback.setText("");
|
||||
} else if(secondPassword.length == 0 || passwordsMatch) {
|
||||
} else if(secondPassword.length() == 0 || passwordsMatch) {
|
||||
if(strength < PasswordStrengthEstimator.WEAK)
|
||||
feedback.setText(R.string.password_too_weak);
|
||||
else feedback.setText("");
|
||||
@@ -212,13 +208,6 @@ OnEditorActionListener {
|
||||
&& passwordsMatch && strength >= WEAK);
|
||||
}
|
||||
|
||||
private char[] getChars(Editable e) {
|
||||
int length = e.length();
|
||||
char[] c = new char[length];
|
||||
e.getChars(0, length, c, 0);
|
||||
return c;
|
||||
}
|
||||
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
// Hide the soft keyboard
|
||||
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
||||
@@ -231,18 +220,14 @@ OnEditorActionListener {
|
||||
feedback.setVisibility(GONE);
|
||||
continueButton.setVisibility(GONE);
|
||||
progress.setVisibility(VISIBLE);
|
||||
// Copy the passwords and erase the originals
|
||||
final String nickname = nicknameEntry.getText().toString();
|
||||
final char[] password = getChars(passwordEntry.getText());
|
||||
delete(passwordEntry.getText());
|
||||
delete(passwordConfirmation.getText());
|
||||
final String password = passwordEntry.getText().toString();
|
||||
// Store the DB key and create the identity in a background thread
|
||||
cryptoExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
byte[] key = crypto.generateSecretKey().getEncoded();
|
||||
byte[] key = crypto.generateSecretKey().getBytes();
|
||||
databaseConfig.setEncryptionKey(key);
|
||||
byte[] encrypted = encryptDatabaseKey(key, password);
|
||||
for(int i = 0; i < password.length; i++) password[i] = 0;
|
||||
storeEncryptedDatabaseKey(encrypted);
|
||||
LocalAuthor localAuthor = createLocalAuthor(nickname);
|
||||
showDashboard(referenceManager.putReference(localAuthor,
|
||||
@@ -251,10 +236,6 @@ OnEditorActionListener {
|
||||
});
|
||||
}
|
||||
|
||||
private void delete(Editable e) {
|
||||
e.delete(0, e.length());
|
||||
}
|
||||
|
||||
private void storeEncryptedDatabaseKey(final byte[] encrypted) {
|
||||
long now = System.currentTimeMillis();
|
||||
SharedPreferences prefs = getSharedPreferences("db", MODE_PRIVATE);
|
||||
@@ -266,7 +247,7 @@ OnEditorActionListener {
|
||||
LOG.info("Key storage took " + duration + " ms");
|
||||
}
|
||||
|
||||
private byte[] encryptDatabaseKey(byte[] key, char[] password) {
|
||||
private byte[] encryptDatabaseKey(byte[] key, String password) {
|
||||
long now = System.currentTimeMillis();
|
||||
byte[] encrypted = crypto.encryptWithPassword(key, password);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
|
||||
@@ -69,8 +69,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
private final SecureRandom secureRandom;
|
||||
private final Clock clock;
|
||||
private final DuplexPluginCallback callback;
|
||||
private final int maxFrameLength;
|
||||
private final long maxLatency, pollingInterval;
|
||||
private final int maxLatency, pollingInterval;
|
||||
|
||||
private volatile boolean running = false;
|
||||
private volatile boolean wasDisabled = false;
|
||||
@@ -82,15 +81,14 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
|
||||
DroidtoothPlugin(Executor ioExecutor, AndroidExecutor androidExecutor,
|
||||
Context appContext, SecureRandom secureRandom, Clock clock,
|
||||
DuplexPluginCallback callback, int maxFrameLength, long maxLatency,
|
||||
long pollingInterval) {
|
||||
DuplexPluginCallback callback, int maxLatency,
|
||||
int pollingInterval) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.androidExecutor = androidExecutor;
|
||||
this.appContext = appContext;
|
||||
this.secureRandom = secureRandom;
|
||||
this.clock = clock;
|
||||
this.callback = callback;
|
||||
this.maxFrameLength = maxFrameLength;
|
||||
this.maxLatency = maxLatency;
|
||||
this.pollingInterval = pollingInterval;
|
||||
}
|
||||
@@ -99,12 +97,13 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public int getMaxFrameLength() {
|
||||
return maxFrameLength;
|
||||
public int getMaxLatency() {
|
||||
return maxLatency;
|
||||
}
|
||||
|
||||
public long getMaxLatency() {
|
||||
return maxLatency;
|
||||
public int getMaxIdleTime() {
|
||||
// Bluetooth detects dead connections so we don't need keepalives
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
public boolean start() throws IOException {
|
||||
@@ -240,7 +239,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
return true;
|
||||
}
|
||||
|
||||
public long getPollingInterval() {
|
||||
public int getPollingInterval() {
|
||||
return pollingInterval;
|
||||
}
|
||||
|
||||
@@ -361,6 +360,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
|
||||
private class BluetoothStateReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context ctx, Intent intent) {
|
||||
int state = intent.getIntExtra(EXTRA_STATE, 0);
|
||||
if(state == STATE_ON) {
|
||||
|
||||
@@ -15,9 +15,8 @@ import android.content.Context;
|
||||
|
||||
public class DroidtoothPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final int MAX_FRAME_LENGTH = 1024;
|
||||
private static final long MAX_LATENCY = 60 * 1000; // 1 minute
|
||||
private static final long POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes
|
||||
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
||||
private static final int POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes
|
||||
|
||||
private final Executor ioExecutor;
|
||||
private final AndroidExecutor androidExecutor;
|
||||
@@ -41,7 +40,6 @@ public class DroidtoothPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||
return new DroidtoothPlugin(ioExecutor, androidExecutor, appContext,
|
||||
secureRandom, clock, callback, MAX_FRAME_LENGTH, MAX_LATENCY,
|
||||
POLLING_INTERVAL);
|
||||
secureRandom, clock, callback, MAX_LATENCY, POLLING_INTERVAL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,10 +39,6 @@ class DroidtoothTransportConnection implements DuplexTransportConnection {
|
||||
|
||||
private class Reader implements TransportConnectionReader {
|
||||
|
||||
public int getMaxFrameLength() {
|
||||
return plugin.getMaxFrameLength();
|
||||
}
|
||||
|
||||
public long getMaxLatency() {
|
||||
return plugin.getMaxLatency();
|
||||
}
|
||||
@@ -60,12 +56,12 @@ class DroidtoothTransportConnection implements DuplexTransportConnection {
|
||||
|
||||
private class Writer implements TransportConnectionWriter {
|
||||
|
||||
public int getMaxFrameLength() {
|
||||
return plugin.getMaxFrameLength();
|
||||
public int getMaxLatency() {
|
||||
return plugin.getMaxLatency();
|
||||
}
|
||||
|
||||
public long getMaxLatency() {
|
||||
return plugin.getMaxLatency();
|
||||
public int getMaxIdleTime() {
|
||||
return plugin.getMaxIdleTime();
|
||||
}
|
||||
|
||||
public long getCapacity() {
|
||||
|
||||
@@ -26,10 +26,9 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
|
||||
private volatile BroadcastReceiver networkStateReceiver = null;
|
||||
|
||||
AndroidLanTcpPlugin(Executor ioExecutor, Context appContext,
|
||||
DuplexPluginCallback callback, int maxFrameLength, long maxLatency,
|
||||
long pollingInterval) {
|
||||
super(ioExecutor, callback, maxFrameLength, maxLatency,
|
||||
pollingInterval);
|
||||
DuplexPluginCallback callback, int maxLatency,
|
||||
int maxIdleTime, int pollingInterval) {
|
||||
super(ioExecutor, callback, maxLatency, maxIdleTime, pollingInterval);
|
||||
this.appContext = appContext;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@ import android.content.Context;
|
||||
|
||||
public class AndroidLanTcpPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final int MAX_FRAME_LENGTH = 1024;
|
||||
private static final long MAX_LATENCY = 60 * 1000; // 1 minute
|
||||
private static final long POLLING_INTERVAL = 60 * 1000; // 1 minute
|
||||
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
||||
private static final int MAX_IDLE_TIME = 30 * 1000; // 30 seconds
|
||||
private static final int POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes
|
||||
|
||||
private final Executor ioExecutor;
|
||||
private final Context appContext;
|
||||
@@ -29,6 +29,6 @@ public class AndroidLanTcpPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||
return new AndroidLanTcpPlugin(ioExecutor, appContext, callback,
|
||||
MAX_FRAME_LENGTH, MAX_LATENCY, POLLING_INTERVAL);
|
||||
MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,8 +75,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
private final Context appContext;
|
||||
private final LocationUtils locationUtils;
|
||||
private final DuplexPluginCallback callback;
|
||||
private final int maxFrameLength;
|
||||
private final long maxLatency, pollingInterval;
|
||||
private final int maxLatency, maxIdleTime, pollingInterval, socketTimeout;
|
||||
private final File torDirectory, torFile, geoIpFile, configFile, doneFile;
|
||||
private final File cookieFile, hostnameFile;
|
||||
private final AtomicBoolean circuitBuilt;
|
||||
@@ -90,14 +89,17 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
|
||||
TorPlugin(Executor ioExecutor, Context appContext,
|
||||
LocationUtils locationUtils, DuplexPluginCallback callback,
|
||||
int maxFrameLength, long maxLatency, long pollingInterval) {
|
||||
int maxLatency, int maxIdleTime, int pollingInterval) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.appContext = appContext;
|
||||
this.locationUtils = locationUtils;
|
||||
this.callback = callback;
|
||||
this.maxFrameLength = maxFrameLength;
|
||||
this.maxLatency = maxLatency;
|
||||
this.maxIdleTime = maxIdleTime;
|
||||
this.pollingInterval = pollingInterval;
|
||||
if(maxIdleTime > Integer.MAX_VALUE / 2)
|
||||
socketTimeout = Integer.MAX_VALUE;
|
||||
else socketTimeout = maxIdleTime * 2;
|
||||
torDirectory = appContext.getDir("tor", MODE_PRIVATE);
|
||||
torFile = new File(torDirectory, "tor");
|
||||
geoIpFile = new File(torDirectory, "geoip");
|
||||
@@ -112,12 +114,12 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public int getMaxFrameLength() {
|
||||
return maxFrameLength;
|
||||
public int getMaxLatency() {
|
||||
return maxLatency;
|
||||
}
|
||||
|
||||
public long getMaxLatency() {
|
||||
return maxLatency;
|
||||
public int getMaxIdleTime() {
|
||||
return maxIdleTime;
|
||||
}
|
||||
|
||||
public boolean start() throws IOException {
|
||||
@@ -446,6 +448,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
Socket s;
|
||||
try {
|
||||
s = ss.accept();
|
||||
s.setSoTimeout(socketTimeout);
|
||||
} catch(IOException e) {
|
||||
// This is expected when the socket is closed
|
||||
if(LOG.isLoggable(INFO)) LOG.info(e.toString());
|
||||
@@ -494,7 +497,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
return true;
|
||||
}
|
||||
|
||||
public long getPollingInterval() {
|
||||
public int getPollingInterval() {
|
||||
return pollingInterval;
|
||||
}
|
||||
|
||||
@@ -529,6 +532,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
Socks5Proxy proxy = new Socks5Proxy("127.0.0.1", SOCKS_PORT);
|
||||
proxy.resolveAddrLocally(false);
|
||||
Socket s = new SocksSocket(proxy, onion, 80);
|
||||
s.setSoTimeout(socketTimeout);
|
||||
if(LOG.isLoggable(INFO)) LOG.info("Connected to " + onion);
|
||||
return new TorTransportConnection(this, s);
|
||||
} catch(IOException e) {
|
||||
|
||||
@@ -17,9 +17,9 @@ public class TorPluginFactory implements DuplexPluginFactory {
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(TorPluginFactory.class.getName());
|
||||
|
||||
private static final int MAX_FRAME_LENGTH = 1024;
|
||||
private static final long MAX_LATENCY = 60 * 1000; // 1 minute
|
||||
private static final long POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes
|
||||
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
||||
private static final int MAX_IDLE_TIME = 30 * 1000; // 30 seconds
|
||||
private static final int POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes
|
||||
|
||||
private final Executor ioExecutor;
|
||||
private final Context appContext;
|
||||
@@ -43,6 +43,6 @@ public class TorPluginFactory implements DuplexPluginFactory {
|
||||
return null;
|
||||
}
|
||||
return new TorPlugin(ioExecutor,appContext, locationUtils, callback,
|
||||
MAX_FRAME_LENGTH, MAX_LATENCY, POLLING_INTERVAL);
|
||||
MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,10 +38,6 @@ class TorTransportConnection implements DuplexTransportConnection {
|
||||
|
||||
private class Reader implements TransportConnectionReader {
|
||||
|
||||
public int getMaxFrameLength() {
|
||||
return plugin.getMaxFrameLength();
|
||||
}
|
||||
|
||||
public long getMaxLatency() {
|
||||
return plugin.getMaxLatency();
|
||||
}
|
||||
@@ -59,12 +55,12 @@ class TorTransportConnection implements DuplexTransportConnection {
|
||||
|
||||
private class Writer implements TransportConnectionWriter {
|
||||
|
||||
public int getMaxFrameLength() {
|
||||
return plugin.getMaxFrameLength();
|
||||
public int getMaxLatency() {
|
||||
return plugin.getMaxLatency();
|
||||
}
|
||||
|
||||
public long getMaxLatency() {
|
||||
return plugin.getMaxLatency();
|
||||
public int getMaxIdleTime() {
|
||||
return plugin.getMaxIdleTime();
|
||||
}
|
||||
|
||||
public long getCapacity() {
|
||||
|
||||
Reference in New Issue
Block a user