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 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; private static int currentStatus = STATUS_OFF;
@ -710,6 +710,9 @@ public class TorService extends Service implements TorServiceConstants, TorConst
TorService.logMessage ("Clearing TransProxy rules"); TorService.logMessage ("Clearing TransProxy rules");
if (mTransProxy == null)
mTransProxy = new TorTransProxy();
if (mTransProxyAll) if (mTransProxyAll)
mTransProxy.clearTransparentProxyingAll(this); mTransProxy.clearTransparentProxyingAll(this);
else else
@ -1041,7 +1044,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
public void message(String severity, String msg) { 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) 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) { 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) { public void orConnStatus(String status, String orName) {
if (ENABLE_DEBUG_LOG)
{
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("orConnStatus ("); sb.append("orConnStatus (");
sb.append((orName) ); sb.append(parseNodeName(orName) );
sb.append("): "); sb.append("): ");
sb.append(status); sb.append(status);
logNotice(sb.toString()); logNotice(sb.toString());
}
} }
public void streamStatus(String status, String streamID, String target) { public void streamStatus(String status, String streamID, String target) {
if (ENABLE_DEBUG_LOG)
{
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("StreamStatus ("); sb.append("StreamStatus (");
sb.append((streamID)); sb.append((streamID));
@ -1100,14 +1096,12 @@ public class TorService extends Service implements TorServiceConstants, TorConst
sb.append(status); sb.append(status);
logNotice(sb.toString()); logNotice(sb.toString());
}
} }
public void unrecognized(String type, String msg) { public void unrecognized(String type, String msg) {
if (ENABLE_DEBUG_LOG)
{
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("Message ("); sb.append("Message (");
sb.append(type); sb.append(type);
@ -1115,7 +1109,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
sb.append(msg); sb.append(msg);
logNotice(sb.toString()); logNotice(sb.toString());
}
} }
@ -1142,21 +1136,44 @@ public class TorService extends Service implements TorServiceConstants, TorConst
public void circuitStatus(String status, String circID, String path) { public void circuitStatus(String status, String circID, String path) {
if (ENABLE_DEBUG_LOG)
{
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("Circuit ("); sb.append("Circuit (");
sb.append((circID)); sb.append((circID));
sb.append("): "); sb.append(") ");
sb.append(status); sb.append(status);
sb.append("; "); sb.append(": ");
sb.append(path);
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()); 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) { public IBinder onBind(Intent intent) {
@ -1512,6 +1529,16 @@ public class TorService extends Service implements TorServiceConstants, TorConst
try { try {
mBinder.updateConfiguration("DisableNetwork", noConnectivity ? "1" : "0", false); mBinder.updateConfiguration("DisableNetwork", noConnectivity ? "1" : "0", false);
mBinder.saveConfiguration(); mBinder.saveConfiguration();
if (noConnectivity)
{
logNotice("No network connectivity. Putting Tor to sleep...");
}
else
{
logNotice("Network connectivity is good. Waking Tor up...");
}
} catch (RemoteException e) { } catch (RemoteException e) {
logException ("error applying prefs",e); logException ("error applying prefs",e);
} }

View File

@ -13,44 +13,56 @@ import android.util.Log;
public class TorTransProxy implements TorServiceConstants { public class TorTransProxy implements TorServiceConstants {
private String ipTablesPath;
public String getIpTablesPath (Context context) public String getIpTablesPath (Context context)
{ {
String ipTablesPath = null;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); 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 //if the user wants us to use the built-in iptables, then we have to find it
File fileIpt = new File("/system/bin/iptables"); File fileIpt = new File("/system/bin/iptables");
if (fileIpt.exists()) if (fileIpt.exists())
ipTablesPath = fileIpt.getAbsolutePath(); path = fileIpt.getAbsolutePath();
else else
{ {
fileIpt = new File("/system/xbin/iptables"); fileIpt = new File("/system/xbin/iptables");
if (fileIpt.exists()) if (fileIpt.exists())
return (ipTablesPath = fileIpt.getAbsolutePath()); path = 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();
} }
return path;
return ipTablesPath;
} }
public int flushIptablesAll(Context context) throws Exception { 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); TorBinaryInstaller.assertIpTablesBinaries(context, false);
@ -174,8 +186,6 @@ public class TorTransProxy implements TorServiceConstants {
int torUid = context.getApplicationInfo().uid; int torUid = context.getApplicationInfo().uid;
String ipTablesPath = getIpTablesPath(context);
StringBuilder script = new StringBuilder(); StringBuilder script = new StringBuilder();
StringBuilder res = new StringBuilder(); StringBuilder res = new StringBuilder();