From 6c1b8f8c0ed8915de7247a603481e4e434ebd6da Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 26 Oct 2024 04:51:59 +0200 Subject: add support for running bitmask-core's apiv5 bootstrap via tor + snowflake --- .../main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java | 5 +++++ .../se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java | 1 + .../se/leap/bitmaskclient/providersetup/ProviderApiManagerV5.java | 5 +++++ .../se/leap/bitmaskclient/providersetup/ProviderApiTorHandler.java | 4 +++- 4 files changed, 14 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/providersetup') 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 @@ -139,6 +139,11 @@ public class ProviderAPI extends JobIntentService implements ProviderApiManagerB return TorServiceCommand.getHttpTunnelPort(this); } + @Override + public int getTorSocksProxyPort() { + return TorServiceCommand.getSocksProxyPort(this); + } + @Override public boolean hasNetworkConnection() { try { 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; } -- cgit v1.2.3