Skip to content

Commit

Permalink
Issue #370: Improved MOAT implementation. Use Meek directly instead o…
Browse files Browse the repository at this point in the history
…f via Tor with the newly available IPtProxy.

Unfortunately couldn't fully test, as meek-azure seems broken for me. But this should do it.
  • Loading branch information
tladesignz committed Dec 15, 2020
1 parent d0aa2e0 commit cb5f1c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 43 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;
Expand Down Expand Up @@ -47,14 +48,9 @@
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.
Expand All @@ -68,7 +64,7 @@
*/
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;
Expand All @@ -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);
Expand Down Expand Up @@ -179,48 +175,25 @@ public boolean onPrepareOptionsMenu(Menu menu) {
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
Expand Down

0 comments on commit cb5f1c4

Please sign in to comment.