added tethering support

This commit is contained in:
Nathan Freitas 2011-06-02 16:21:50 -04:00
parent 422ba4bbcd
commit ddb4793b0a
4 changed files with 713 additions and 637 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,37 +0,0 @@
package org.torproject.android.boot;
import org.torproject.android.service.ITorService;
import org.torproject.android.service.TorService;
import org.torproject.android.service.TorServiceConstants;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
public class OnbootBroadcastReceiver extends BroadcastReceiver implements TorServiceConstants {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "received on boot notification");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean startOnBoot = prefs.getBoolean("pref_start_boot",true);
Log.d(TAG, "startOnBoot:" + startOnBoot);
if (startOnBoot)
{
Intent serviceIntent = new Intent(context,TorService.class);
serviceIntent.setAction("onboot");
context.startService(serviceIntent);
}
//bindService(new Intent(ITorService.class.getName()),
// mConnection, Context.BIND_AUTO_CREATE);
}
}

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2009, Nathan Freitas, Orbot / The Guardian Project - http://openideals.com/guardian */ /* Copyright (c) 2009-2011, Nathan Freitas, Orbot / The Guardian Project - http://openideals.com/guardian */
/* See LICENSE for licensing information */ /* See LICENSE for licensing information */
package org.torproject.android.service; package org.torproject.android.service;
@ -545,6 +545,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
boolean enableTransparentProxy = prefs.getBoolean("pref_transparent", false); boolean enableTransparentProxy = prefs.getBoolean("pref_transparent", false);
boolean transProxyAll = prefs.getBoolean("pref_transparent_all", false); boolean transProxyAll = prefs.getBoolean("pref_transparent_all", false);
boolean transProxyPortFallback = prefs.getBoolean("pref_transparent_port_fallback", false); boolean transProxyPortFallback = prefs.getBoolean("pref_transparent_port_fallback", false);
boolean transProxyTethering = prefs.getBoolean("pref_transparent_tethering", false);
TorService.logMessage ("Transparent Proxying: " + enableTransparentProxy); TorService.logMessage ("Transparent Proxying: " + enableTransparentProxy);
@ -581,6 +582,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
showAlert("Status", "Setting up app-based transparent proxying..."); showAlert("Status", "Setting up app-based transparent proxying...");
code = TorTransProxy.setTransparentProxyingByApp(this,AppManager.getApps(this)); code = TorTransProxy.setTransparentProxyingByApp(this,AppManager.getApps(this));
} }
} }
TorService.logMessage ("TorTransProxy resp code: " + code); TorService.logMessage ("TorTransProxy resp code: " + code);
@ -588,12 +590,23 @@ public class TorService extends Service implements TorServiceConstants, Runnable
if (code == 0) if (code == 0)
{ {
showAlert("Status", "Transparent proxying ENABLED"); showAlert("Status", "Transparent proxying ENABLED");
if (transProxyTethering)
{
showAlert("Status", "TransProxy enabled for Tethering!");
TorTransProxy.enableTetheringRules(this);
}
} }
else else
{ {
showAlert("Status", "WARNING: error starting transparent proxying!"); showAlert("Status", "WARNING: error starting transparent proxying!");
} }
return true; return true;
} }

View File

@ -313,14 +313,12 @@ public class TorTransProxy implements TorServiceConstants {
return code; return code;
} }
public static int enableWifiHotspotRules (Context context) throws Exception public static int enableTetheringRules (Context context) throws Exception
{ {
boolean runRoot = true; boolean runRoot = true;
boolean waitFor = true; boolean waitFor = true;
//redirectDNSResolvConf(); //not working yet
String ipTablesPath = new File(context.getDir("bin", 0),"iptables").getAbsolutePath(); String ipTablesPath = new File(context.getDir("bin", 0),"iptables").getAbsolutePath();
StringBuilder script = new StringBuilder(); StringBuilder script = new StringBuilder();
@ -328,25 +326,24 @@ public class TorTransProxy implements TorServiceConstants {
StringBuilder res = new StringBuilder(); StringBuilder res = new StringBuilder();
int code = -1; int code = -1;
script.append(ipTablesPath); String[] hwinterfaces = {"usb0","wl0.1"};
script.append(" -I FORWARD");
script.append(" -m state --state ESTABLISHED,RELATED -j ACCEPT");
script.append(" || exit\n");
script.append(ipTablesPath); for (int i = 0; i < hwinterfaces.length; i++)
script.append(" -I FORWARD"); {
script.append(" -j ACCEPT"); script.append(ipTablesPath);
script.append(" || exit\n"); script.append(" -t nat -A PREROUTING -i ");
script.append(hwinterfaces[i]);
script.append(" -p udp --dport 53 -j REDIRECT --to-ports ");
script.append(TOR_DNS_PORT);
script.append(" || exit\n");
/* script.append(ipTablesPath);
script.append(ipTablesPath); script.append(" -t nat -A PREROUTING -i ");
script.append(" -P FORWARD DROP"); script.append(hwinterfaces[i]);
script.append(" || exit\n"); script.append(" -p tcp -j REDIRECT --to-ports ");
*/ script.append(TOR_TRANSPROXY_PORT);
script.append(" || exit\n");
script.append(ipTablesPath); }
script.append(" -t nat -I POSTROUTING -j MASQUERADE");
script.append(" || exit\n");
String[] cmdAdd = {script.toString()}; String[] cmdAdd = {script.toString()};
@ -374,8 +371,6 @@ public class TorTransProxy implements TorServiceConstants {
purgeIptables(context); purgeIptables(context);
enableWifiHotspotRules(context);
int torUid = context.getApplicationInfo().uid; int torUid = context.getApplicationInfo().uid;
// Set up port redirection // Set up port redirection