commit cb5f1c4ed4a5678bab9709eb41aaff9746b3c46a Author: Benjamin Erhart berhart@netzarchitekten.com Date: Tue Dec 15 14:00:23 2020 +0100
Issue #370: Improved MOAT implementation. Use Meek directly instead of via Tor with the newly available IPtProxy.
Unfortunately couldn't fully test, as meek-azure seems broken for me. But this should do it. --- app/build.gradle | 2 +- .../android/ui/onboarding/MoatActivity.java | 57 ++++++---------------- 2 files changed, 16 insertions(+), 43 deletions(-)
diff --git a/app/build.gradle b/app/build.gradle index 867dcd6d..d9d7d917 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -119,7 +119,7 @@ dependencies { implementation 'com.android.volley:volley:1.1.1' implementation 'info.pluggabletransports.aptds:apt-dispatch-library:1.0.9' implementation 'info.pluggabletransports.aptds:apt-meek-obfs4-legacy:1.0.9' - implementation 'info.pluggabletransports.aptds:goptbundle:1.0.0' + implementation 'com.github.tladesignz:IPtProxy:0.5.0' }
// Map for the version code that gives each ABI a value. diff --git a/app/src/main/java/org/torproject/android/ui/onboarding/MoatActivity.java b/app/src/main/java/org/torproject/android/ui/onboarding/MoatActivity.java index 329c8aff..619a371b 100644 --- a/app/src/main/java/org/torproject/android/ui/onboarding/MoatActivity.java +++ b/app/src/main/java/org/torproject/android/ui/onboarding/MoatActivity.java @@ -10,6 +10,7 @@ import android.content.IntentFilter; import android.graphics.BitmapFactory; import android.os.Bundle; import android.os.Handler; +import android.os.Looper; import android.text.TextUtils; import android.util.Base64; import android.util.Log; @@ -47,14 +48,9 @@ import org.torproject.android.service.TorServiceConstants; import org.torproject.android.service.util.Prefs; import org.torproject.android.ui.dialog.MoatErrorDialogFragment;
-import java.util.ArrayList; -import java.util.Properties; +import java.io.File;
-import goptbundle.Goptbundle; -import info.pluggabletransports.dispatch.DispatchConstants; -import info.pluggabletransports.dispatch.Dispatcher; -import info.pluggabletransports.dispatch.Transport; -import info.pluggabletransports.dispatch.transports.legacy.MeekTransport; +import IPtProxy.IPtProxy;
/** * Implements the MOAT protocol: Fetches OBFS4 bridges via Meek Azure. @@ -68,7 +64,7 @@ import info.pluggabletransports.dispatch.transports.legacy.MeekTransport; */ public class MoatActivity extends AppCompatActivity implements View.OnClickListener, TextView.OnEditorActionListener {
- private static String moatBaseUrl = "https://bridges.torproject.org/moat"; + private static final String moatBaseUrl = "https://bridges.torproject.org/moat";
private ImageView mIvCaptcha; private ProgressBar mProgressBar; @@ -87,7 +83,7 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
private boolean mRequestInProgress = true;
- private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { + private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String host = intent.getStringExtra(OrbotService.EXTRA_SOCKS_PROXY_HOST); @@ -179,48 +175,25 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe protected void onResume() { super.onResume();
- new MeekTransport().register(); - - Properties options = new Properties(); - options.put(MeekTransport.OPTION_URL, "https://onion.azureedge.net/"); - options.put(MeekTransport.OPTION_FRONT, "ajax.aspnetcdn.com"); - - Transport transport = Dispatcher.get().getTransport(this, DispatchConstants.PT_TRANSPORTS_MEEK, options); - - if (transport != null) { - new Thread(() -> { - Goptbundle.setenv(DispatchConstants.TOR_PT_LOG_LEVEL, "DEBUG"); - Goptbundle.setenv(DispatchConstants.TOR_PT_CLIENT_TRANSPORTS, DispatchConstants.PT_TRANSPORTS_MEEK); - Goptbundle.setenv(DispatchConstants.TOR_PT_MANAGED_TRANSPORT_VER, "1"); - Goptbundle.setenv(DispatchConstants.TOR_PT_EXIT_ON_STDIN_CLOSE, "0"); - Goptbundle.load(getDir("pt-state", Context.MODE_PRIVATE).getAbsolutePath()); - }).start(); - - ArrayList<String> args = new ArrayList<>(); - - for (Object key : options.keySet()) { - String k = (String) key; + File fileCacheDir = new File(getCacheDir(),"pt"); + if (!fileCacheDir.exists()) { + //noinspection ResultOfMethodCallIgnored + fileCacheDir.mkdir(); + }
- args.add(String.format("%s=%s", k, options.getProperty(k))); - } + IPtProxy.setStateLocation(fileCacheDir.getAbsolutePath());
- StringBuilder sb = new StringBuilder(); + IPtProxy.startObfs4Proxy("DEBUG", false, false);
- for (String arg : args) { - sb.append(arg).append(";"); - } + ProxiedHurlStack phs = new ProxiedHurlStack("127.0.0.1", (int) IPtProxy.MeekSocksPort, + "url=https://meek.azureedge.net/;front=ajax.aspnetcdn.com", "\0");
- ProxiedHurlStack phs = new ProxiedHurlStack("127.0.0.1", 47352, - sb.toString(), "\0"); - - mQueue = Volley.newRequestQueue(MoatActivity.this, phs); + mQueue = Volley.newRequestQueue(MoatActivity.this, phs);
if (mCaptcha == null) { new Handler().postDelayed(this::fetchCaptcha, 1000); } } - -// sendIntentToService(TorServiceConstants.ACTION_STATUS); }
@Override
tor-commits@lists.torproject.org