Commit de62a5af authored by sisbell's avatar sisbell
Browse files

Bug 30166: If custom bridges are specified, only use those bridges for connecting

parent 6a9314af
......@@ -32,10 +32,26 @@ public class CustomTorInstaller extends TorInstaller {
updateTorConfigCustom(torrcFile, content);
}
/**
* Opens bridges list as <code>InputStream</code>. First checks for user defined bridges from the user pref file.
* If it finds user defined bridges, then the stream will contain only these bridges. Otherwise, it returns
* a set of predefined bridges.
*/
@Override
public InputStream openBridgesStream() throws IOException {
ByteArrayInputStream userDefinedBridges = new ByteArrayInputStream((Prefs.getBridgesList() + "\r\n").getBytes());
return new SequenceInputStream(userDefinedBridges, context.getResources().getAssets().open("common/bridges.txt"));
/*
BridgesList is an overloaded field, which can cause some confusion. The list can be:
1) a filter like obfs4 or meek OR 2) it can be a custom bridge
For (1), we just pass back all bridges, the filter will occur elsewhere in the library.
For (2) we return the bridge list as a raw stream
If length is greater than 5, then we know this is a custom bridge
*/
String userDefinedBridgeList = Prefs.getBridgesList();
byte bridgeType = (byte) (userDefinedBridgeList.length() > 5 ? 1 : 0);
ByteArrayInputStream bridgeTypeStream = new ByteArrayInputStream(new byte[]{bridgeType});
InputStream bridgeStream = (bridgeType == 1) ? new ByteArrayInputStream((userDefinedBridgeList + "\r\n").getBytes())
: context.getResources().getAssets().open("common/bridges.txt");
return new SequenceInputStream(bridgeTypeStream, bridgeStream);
}
private static void copy(InputStream is, File target) throws IOException {
......
......@@ -290,37 +290,12 @@ public final class TorService extends Service implements TorServiceConstants, Or
private boolean setupTor() {
try {
onionProxyManager.setup();
return true;
} catch (Exception e) {
Log.e(OrbotConstants.TAG, "Error installing Tor binaries", e);
mEventBroadcaster.broadcastNotice("There was an error installing Tor binaries");
return false;
}
try {
mEventBroadcaster.broadcastNotice(getString(R.string
.updating_settings_in_tor_service));
TorConfigBuilder builder = onionProxyManager.getContext()
.newConfigBuilder().updateTorConfig();
File nativeDir = new File(getApplicationInfo().nativeLibraryDir);
File pluggableTransport = new File(nativeDir, "libObfs4proxy.so");
if(!pluggableTransport.canExecute()) pluggableTransport.setExecutable(true);
builder.configurePluggableTransportsFromSettings(pluggableTransport);
mDataService.updateConfigBuilder(builder);
onionProxyManager.getTorInstaller().updateTorConfigCustom
(builder.asString());
mEventBroadcaster.broadcastNotice("updating torrc custom configuration...");
mEventBroadcaster.broadcastDebug("torrc.custom=" + builder.asString());
mEventBroadcaster.broadcastNotice("success.");
} catch (Exception e) {
e.printStackTrace();
Log.e(OrbotConstants.TAG, e.getMessage());
mEventBroadcaster.broadcastNotice("Error configuring tor: " + e.toString());
return false;
}
return true;
}
private synchronized void startTor() {
......@@ -331,6 +306,7 @@ public final class TorService extends Service implements TorServiceConstants, Or
setTorNetworkEnabledAsync(true);
} else {
try {
updateTorrcConfig();
mEventBroadcaster.broadcastNotice("checking binary version: " + TOR_VERSION);
mEventBroadcaster.getStatus().starting();
notify(getString(R.string.status_starting_up), NOTIFY_ID,
......@@ -380,6 +356,38 @@ public final class TorService extends Service implements TorServiceConstants, Or
}).start();
}
/**
* Updates the torrc file based on the current user preferences
*/
private boolean updateTorrcConfig() {
try {
mEventBroadcaster.broadcastNotice(getString(R.string
.updating_settings_in_tor_service));
TorConfigBuilder builder = onionProxyManager.getContext()
.newConfigBuilder().updateTorConfig();
//Check bridges to see if we need this
File nativeDir = new File(getApplicationInfo().nativeLibraryDir);
File pluggableTransport = new File(nativeDir, "libObfs4proxy.so");
if(!pluggableTransport.canExecute()) pluggableTransport.setExecutable(true);
builder.configurePluggableTransportsFromSettings(pluggableTransport);
mDataService.updateConfigBuilder(builder);
onionProxyManager.getTorInstaller().updateTorConfigCustom
(builder.asString());
mEventBroadcaster.broadcastNotice("updating torrc custom configuration...");
mEventBroadcaster.broadcastDebug("torrc.custom=" + builder.asString());
mEventBroadcaster.broadcastNotice("success.");
} catch (Exception e) {
e.printStackTrace();
Log.e(OrbotConstants.TAG, e.getMessage());
mEventBroadcaster.broadcastNotice("Error configuring tor: " + e.toString());
return false;
}
return true;
}
private class ActionBroadcastReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
if (intent != null || CMD_NEWNYM.equals(intent.getAction())) {
......
......@@ -52,10 +52,9 @@ public class Prefs {
}
public static String getBridgesList() {
String defaultBridgeType = "obfs4";
if (Locale.getDefault().getLanguage().equals("fa"))
defaultBridgeType = "meek"; //if Farsi, use meek as the default bridge type
return prefs.getString(PREF_BRIDGES_LIST, defaultBridgeType);
String defaultBridgeType = (Locale.getDefault().getLanguage().equals("fa")) ? "meek": "obfs4";
String list = prefs.getString(PREF_BRIDGES_LIST, defaultBridgeType);
return (list.trim().isEmpty()) ? defaultBridgeType : list;
}
public static void setBridgesList(String value) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment