updates for transproxy iptables detection on JB

This commit is contained in:
n8fr8 2012-10-01 12:35:31 +05:30
parent 29e2452aea
commit 331daa07b4
2 changed files with 93 additions and 56 deletions

View File

@ -58,7 +58,7 @@ import android.util.Log;
public class TorService extends Service implements TorServiceConstants, TorConstants, Runnable, EventHandler
{
public static boolean ENABLE_DEBUG_LOG = false;
public static boolean ENABLE_DEBUG_LOG = true;
private static int currentStatus = STATUS_OFF;
@ -710,6 +710,9 @@ public class TorService extends Service implements TorServiceConstants, TorConst
TorService.logMessage ("Clearing TransProxy rules");
if (mTransProxy == null)
mTransProxy = new TorTransProxy();
if (mTransProxyAll)
mTransProxy.clearTransparentProxyingAll(this);
else
@ -1041,7 +1044,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
public void message(String severity, String msg) {
logNotice( "[Tor Control Port] " + severity + ": " + msg);
logNotice(severity + ": " + msg);
if (msg.indexOf(TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE)!=-1)
{
@ -1063,12 +1066,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
sendCallbackStatusMessage (msg);
}
//showToolbarNotification(msg, TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_notify);
public void newDescriptors(List<String> orList) {
}
@ -1076,23 +1075,20 @@ public class TorService extends Service implements TorServiceConstants, TorConst
public void orConnStatus(String status, String orName) {
if (ENABLE_DEBUG_LOG)
{
StringBuilder sb = new StringBuilder();
sb.append("orConnStatus (");
sb.append((orName) );
sb.append(parseNodeName(orName) );
sb.append("): ");
sb.append(status);
logNotice(sb.toString());
}
}
public void streamStatus(String status, String streamID, String target) {
if (ENABLE_DEBUG_LOG)
{
StringBuilder sb = new StringBuilder();
sb.append("StreamStatus (");
sb.append((streamID));
@ -1100,14 +1096,12 @@ public class TorService extends Service implements TorServiceConstants, TorConst
sb.append(status);
logNotice(sb.toString());
}
}
public void unrecognized(String type, String msg) {
if (ENABLE_DEBUG_LOG)
{
StringBuilder sb = new StringBuilder();
sb.append("Message (");
sb.append(type);
@ -1115,7 +1109,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
sb.append(msg);
logNotice(sb.toString());
}
}
@ -1142,21 +1136,44 @@ public class TorService extends Service implements TorServiceConstants, TorConst
public void circuitStatus(String status, String circID, String path) {
if (ENABLE_DEBUG_LOG)
{
StringBuilder sb = new StringBuilder();
sb.append("Circuit (");
sb.append((circID));
sb.append("): ");
sb.append(") ");
sb.append(status);
sb.append("; ");
sb.append(path);
sb.append(": ");
StringTokenizer st = new StringTokenizer(path,",");
String node = null;
while (st.hasMoreTokens())
{
node = st.nextToken();
sb.append(parseNodeName(node));
if (st.hasMoreTokens())
sb.append (" > ");
}
logNotice(sb.toString());
}
}
private String parseNodeName(String node)
{
if (node.indexOf('=')!=-1)
{
return (node.substring(node.indexOf("=")+1));
}
else if (node.indexOf('~')!=-1)
{
return (node.substring(node.indexOf("~")+1));
}
else
return node;
}
public IBinder onBind(Intent intent) {
@ -1512,6 +1529,16 @@ public class TorService extends Service implements TorServiceConstants, TorConst
try {
mBinder.updateConfiguration("DisableNetwork", noConnectivity ? "1" : "0", false);
mBinder.saveConfiguration();
if (noConnectivity)
{
logNotice("No network connectivity. Putting Tor to sleep...");
}
else
{
logNotice("Network connectivity is good. Waking Tor up...");
}
} catch (RemoteException e) {
logException ("error applying prefs",e);
}

View File

@ -13,44 +13,56 @@ import android.util.Log;
public class TorTransProxy implements TorServiceConstants {
private String ipTablesPath;
public String getIpTablesPath (Context context)
{
String ipTablesPath = null;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean useSystemIpTables = prefs.getBoolean(TorConstants.PREF_USE_SYSTEM_IPTABLES, false);
if (prefs.getBoolean(TorConstants.PREF_USE_SYSTEM_IPTABLES, false))
if (useSystemIpTables)
{
ipTablesPath = findSystemIPTables();
}
else
{
//use the bundled version
ipTablesPath = new File(context.getDir("bin", 0),"iptables").getAbsolutePath();
try
{
if (testOwnerModule(context,ipTablesPath) != 0)
ipTablesPath = findSystemIPTables();
}
catch (Exception e)
{
ipTablesPath = findSystemIPTables();
}
}
return ipTablesPath;
}
private String findSystemIPTables ()
{
String path = null;
//if the user wants us to use the built-in iptables, then we have to find it
File fileIpt = new File("/system/bin/iptables");
if (fileIpt.exists())
ipTablesPath = fileIpt.getAbsolutePath();
path = fileIpt.getAbsolutePath();
else
{
fileIpt = new File("/system/xbin/iptables");
if (fileIpt.exists())
return (ipTablesPath = fileIpt.getAbsolutePath());
else
{
//use the bundled version
ipTablesPath = new File(context.getDir("bin", 0),"iptables").getAbsolutePath();
}
}
}
else
{
//use the bundled version
ipTablesPath = new File(context.getDir("bin", 0),"iptables").getAbsolutePath();
path = fileIpt.getAbsolutePath();
}
return ipTablesPath;
return path;
}
public int flushIptablesAll(Context context) throws Exception {
@ -164,7 +176,7 @@ public class TorTransProxy implements TorServiceConstants {
}
*/
public int testOwnerModule(Context context) throws Exception
public int testOwnerModule(Context context, String ipTablesPath) throws Exception
{
TorBinaryInstaller.assertIpTablesBinaries(context, false);
@ -174,8 +186,6 @@ public class TorTransProxy implements TorServiceConstants {
int torUid = context.getApplicationInfo().uid;
String ipTablesPath = getIpTablesPath(context);
StringBuilder script = new StringBuilder();
StringBuilder res = new StringBuilder();