Skip to content
Snippets Groups Projects
Commit 4330f4be authored by Ximin Luo's avatar Ximin Luo
Browse files

don't start tor if it's probably blocked

parent 48e5d512
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@ import org.briarproject.api.plugins.duplex.DuplexPluginConfig;
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
import org.briarproject.api.plugins.simplex.SimplexPluginConfig;
import org.briarproject.api.plugins.simplex.SimplexPluginFactory;
import org.briarproject.api.system.LocationUtils;
import org.briarproject.plugins.droidtooth.DroidtoothPluginFactory;
import org.briarproject.plugins.tcp.LanTcpPluginFactory;
import org.briarproject.plugins.tor.TorPluginFactory;
......@@ -39,12 +40,13 @@ public class AndroidPluginsModule extends AbstractModule {
DuplexPluginConfig getDuplexPluginConfig(
@PluginExecutor Executor pluginExecutor,
AndroidExecutor androidExecutor, Context appContext,
CryptoComponent crypto, ShutdownManager shutdownManager) {
CryptoComponent crypto, LocationUtils locationUtils,
ShutdownManager shutdownManager) {
DuplexPluginFactory droidtooth = new DroidtoothPluginFactory(
pluginExecutor, androidExecutor, appContext,
crypto.getSecureRandom());
DuplexPluginFactory tor = new TorPluginFactory(pluginExecutor,
appContext, shutdownManager);
appContext, locationUtils, shutdownManager);
DuplexPluginFactory lan = new LanTcpPluginFactory(pluginExecutor);
final Collection<DuplexPluginFactory> factories =
Arrays.asList(droidtooth, tor, lan);
......
package org.briarproject.plugins.tor;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Logger;
import org.briarproject.api.system.LocationUtils;
public class TorNetworkMetadata {
private static final Logger LOG =
Logger.getLogger(TorNetworkMetadata.class.getName());
// for country codes see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
// below list from https://trac.torproject.org/projects/tor/wiki/doc/OONI/censorshipwiki
// TODO: get a more complete list
public static final Set<String> BLOCKED_IN_COUNTRIES = new HashSet<String>(Arrays.asList(
"CN",
"IR",
"SY",
//"ET", // possibly lifted - https://metrics.torproject.org/users.html?graph=userstats-relay-country&start=2012-02-08&end=2014-02-06&country=et&events=off#userstats-relay-country
//"KZ", // unclear due to botnet - https://metrics.torproject.org/users.html?graph=userstats-relay-country&start=2012-02-08&end=2014-02-06&country=kz&events=off#userstats-relay-country
//"PH", // unclear due to botnet - https://metrics.torproject.org/users.html?graph=userstats-relay-country&start=2012-02-08&end=2014-02-06&country=ph&events=off#userstats-relay-country
//"AE", // unclear due to botnet - https://metrics.torproject.org/users.html?graph=userstats-relay-country&start=2012-02-08&end=2014-02-06&country=ae&events=off#userstats-relay-country
//"GB", // for testing
"ZZ"
));
public static boolean isTorProbablyBlocked(LocationUtils locationUtils) {
String countryCode = locationUtils.getCurrentCountry();
if (BLOCKED_IN_COUNTRIES.contains(countryCode)) {
LOG.info("Tor is probably blocked in your country: " + countryCode);
return true;
}
return false;
}
}
package org.briarproject.plugins.tor;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import org.briarproject.api.TransportId;
import org.briarproject.api.lifecycle.ShutdownManager;
import org.briarproject.api.plugins.duplex.DuplexPlugin;
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
import org.briarproject.api.system.LocationUtils;
import org.briarproject.plugins.AndroidPluginsModule;
import org.briarproject.plugins.tor.TorNetworkMetadata;
import android.content.Context;
import android.os.Build;
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 final Executor pluginExecutor;
private final Context appContext;
private final LocationUtils locationUtils;
private final ShutdownManager shutdownManager;
public TorPluginFactory(Executor pluginExecutor, Context appContext,
ShutdownManager shutdownManager) {
LocationUtils locationUtils, ShutdownManager shutdownManager) {
this.pluginExecutor = pluginExecutor;
this.appContext = appContext;
this.locationUtils = locationUtils;
this.shutdownManager = shutdownManager;
}
......@@ -35,6 +44,11 @@ public class TorPluginFactory implements DuplexPluginFactory {
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
// Check that we have a Tor binary for this architecture
if(!Build.CPU_ABI.startsWith("armeabi")) return null;
// Check that we don't know that Tor is blocked here
if (TorNetworkMetadata.isTorProbablyBlocked(locationUtils)) {
LOG.info("Tor has been pre-emptively disabled since it is probably blocked");
return null;
}
return new TorPlugin(pluginExecutor,appContext, shutdownManager,
callback, MAX_FRAME_LENGTH, MAX_LATENCY, POLLING_INTERVAL);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment