summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2024-10-26 04:51:59 +0200
committercyberta <cyberta@riseup.net>2024-12-11 00:09:34 +0000
commit6c1b8f8c0ed8915de7247a603481e4e434ebd6da (patch)
tree041afc3a3fca2b6b6b8b651f7c4d5b9947fb450b
parent2f79616938eb8d570bad779f6846644e09cfefa4 (diff)
add support for running bitmask-core's apiv5 bootstrap via tor + snowflake
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java1
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java5
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java1
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV5.java5
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiTorHandler.java4
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/tor/TorServiceCommand.java15
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/tor/TorStatusObservable.java10
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerTest.java5
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV3Test.java5
9 files changed, 50 insertions, 1 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java
index c2c73c82..bb342f0f 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java
@@ -452,6 +452,7 @@ public class PreferenceHelper {
putBoolean(USE_SNOWFLAKE, isEnabled);
if (!isEnabled) {
TorStatusObservable.setProxyPort(-1);
+ TorStatusObservable.setSocksProxyPort(-1);
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java
index 751bf1dc..63ae3731 100644
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java
+++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java
@@ -140,6 +140,11 @@ public class ProviderAPI extends JobIntentService implements ProviderApiManagerB
}
@Override
+ public int getTorSocksProxyPort() {
+ return TorServiceCommand.getSocksProxyPort(this);
+ }
+
+ @Override
public boolean hasNetworkConnection() {
try {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java
index 3032bd4f..4093f25c 100644
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java
+++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java
@@ -78,6 +78,7 @@ public abstract class ProviderApiManagerBase {
boolean startTorService() throws InterruptedException, IllegalStateException, TimeoutException;
void stopTorService();
int getTorHttpTunnelPort();
+ int getTorSocksProxyPort();
boolean hasNetworkConnection();
void saveProvider(Provider p);
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV5.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV5.java
index 6e748afa..9981feb1 100644
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV5.java
+++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV5.java
@@ -56,6 +56,8 @@ import se.leap.bitmaskclient.tor.TorStatusObservable;
public class ProviderApiManagerV5 extends ProviderApiManagerBase implements IProviderApiManager {
private static final String TAG = ProviderApiManagerV5.class.getSimpleName();
+ private static final String PROXY_HOST = "127.0.0.1";
+ private static final String SOCKS_PROXY_SCHEME = "socks5://";
ProviderApiManagerV5(Resources resources, ProviderApiServiceCallback callback) {
super(resources, callback);
@@ -189,6 +191,9 @@ public class ProviderApiManagerV5 extends ProviderApiManagerBase implements IPro
BitmaskMobile bm;
try {
bm = new BitmaskMobile(provider.getMainUrl(), new PreferenceHelper.SharedPreferenceStore());
+ if (TorStatusObservable.isRunning() && TorStatusObservable.getSocksProxyPort() != -1) {
+ bm.setSocksProxy(SOCKS_PROXY_SCHEME + PROXY_HOST + ":" + TorStatusObservable.getSocksProxyPort());
+ }
} catch (IllegalStateException e) {
// TODO: improve error message
return eventSender.setErrorResult(currentDownload, R.string.config_error_found, null);
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiTorHandler.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiTorHandler.java
index b551cea0..3b7d4247 100644
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiTorHandler.java
+++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiTorHandler.java
@@ -29,7 +29,9 @@ public class ProviderApiTorHandler {
}
int port = serviceCallback.getTorHttpTunnelPort();
TorStatusObservable.setProxyPort(port);
- return port != -1;
+ int socksPort = serviceCallback.getTorSocksProxyPort();
+ TorStatusObservable.setSocksProxyPort(socksPort);
+ return port != -1 && socksPort != -1;
}
return false;
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/tor/TorServiceCommand.java b/app/src/main/java/se/leap/bitmaskclient/tor/TorServiceCommand.java
index abc029ff..4c6ddaba 100644
--- a/app/src/main/java/se/leap/bitmaskclient/tor/TorServiceCommand.java
+++ b/app/src/main/java/se/leap/bitmaskclient/tor/TorServiceCommand.java
@@ -134,6 +134,21 @@ public class TorServiceCommand {
return -1;
}
+ @WorkerThread
+ public static int getSocksProxyPort(Context context) {
+ try {
+ TorServiceConnection torServiceConnection = initTorServiceConnection(context);
+ if (torServiceConnection != null) {
+ int tunnelPort = torServiceConnection.getService().getSocksPort();
+ torServiceConnection.close();
+ return tunnelPort;
+ }
+ } catch (InterruptedException | IllegalStateException e) {
+ e.printStackTrace();
+ }
+ return -1;
+ }
+
private static boolean isNotCancelled() {
return !TorStatusObservable.isCancelled();
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/tor/TorStatusObservable.java b/app/src/main/java/se/leap/bitmaskclient/tor/TorStatusObservable.java
index b1ad6084..5a49fda2 100644
--- a/app/src/main/java/se/leap/bitmaskclient/tor/TorStatusObservable.java
+++ b/app/src/main/java/se/leap/bitmaskclient/tor/TorStatusObservable.java
@@ -95,6 +95,7 @@ public class TorStatusObservable {
private String lastTorLog = "";
private String lastSnowflakeLog = "";
private int port = -1;
+ private int socksPort = -1;
private int bootstrapPercent = -1;
private int retrySnowflakeRendezVous = 0;
private final Vector<String> lastLogs = new Vector<>(100);
@@ -321,6 +322,15 @@ public class TorStatusObservable {
return getInstance().port;
}
+ public static void setSocksProxyPort(int port) {
+ getInstance().socksPort = port;
+ instance.notifyObservers();
+ }
+
+ public static int getSocksProxyPort() {
+ return getInstance().socksPort;
+ }
+
@Nullable
public static String getLastTorLog() {
diff --git a/app/src/test/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerTest.java
index 2978edc7..86f9dc8e 100644
--- a/app/src/test/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerTest.java
@@ -117,6 +117,11 @@ public class ProviderApiManagerTest {
}
@Override
+ public int getTorSocksProxyPort() {
+ return 9050;
+ }
+
+ @Override
public boolean hasNetworkConnection() {
return hasNetworkConnection;
}
diff --git a/app/src/test/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV3Test.java b/app/src/test/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV3Test.java
index 646d32d8..db43970c 100644
--- a/app/src/test/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV3Test.java
+++ b/app/src/test/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV3Test.java
@@ -150,6 +150,11 @@ public class ProviderApiManagerV3Test {
}
@Override
+ public int getTorSocksProxyPort() {
+ return 9050;
+ }
+
+ @Override
public boolean hasNetworkConnection() {
return hasNetworkConnection;
}