fixes for superuser and iptables check code

This commit is contained in:
Nathan Freitas 2013-08-20 13:25:42 -04:00
parent 9d6f3c836b
commit 82fcea0dab
4 changed files with 15 additions and 96 deletions

View File

@ -253,22 +253,8 @@ public class TorBinaryInstaller implements TorServiceConstants {
// Check iptables_g1 // Check iptables_g1
File file = new File(ctx.getDir("bin",0), "iptables"); File file = new File(ctx.getDir("bin",0), "iptables");
copyRawFile(ctx, R.raw.iptables, file, CHMOD_EXEC, false);
if ((!file.exists()) && isARMv6()) {
copyRawFile(ctx, R.raw.iptables_g1, file, CHMOD_EXEC, false);
changed = true;
}
// Check iptables_n1
file = new File(ctx.getDir("bin",0), "iptables");
if ((!file.exists()) && (!isARMv6())) {
copyRawFile(ctx, R.raw.iptables_n1, file, CHMOD_EXEC, false);
changed = true;
}
return true; return true;
} }

View File

@ -16,59 +16,6 @@ import android.util.Log;
public class TorServiceUtils implements TorServiceConstants { public class TorServiceUtils implements TorServiceConstants {
public static boolean isRootPossible()
{
StringBuilder log = new StringBuilder();
try {
// Check if Superuser.apk exists
File fileSU = new File("/system/app/Superuser.apk");
if (fileSU.exists())
return true;
fileSU = new File("/system/app/superuser.apk");
if (fileSU.exists())
return true;
fileSU = new File("/system/bin/su");
if (fileSU.exists())
{
String[] cmd = {"su"};
int exitCode = TorServiceUtils.doShellCommand(cmd, log, false, true);
if (exitCode != 0)
return false;
else
return true;
}
//Check for 'su' binary
String[] cmd = {"which su"};
int exitCode = TorServiceUtils.doShellCommand(cmd, log, false, true);
if (exitCode == 0) {
Log.d(TorConstants.TAG,"root exists, but not sure about permissions");
return true;
}
} catch (IOException e) {
//this means that there is no root to be had (normally) so we won't log anything
Log.e(TorConstants.TAG,"Error checking for root access",e);
}
catch (Exception e) {
Log.e(TorConstants.TAG,"Error checking for root access",e);
//this means that there is no root to be had (normally)
}
Log.e(TorConstants.TAG,"Could not acquire root permissions");
return false;
}
public static int findProcessId(String command) public static int findProcessId(String command)
{ {

View File

@ -14,7 +14,6 @@ import android.util.Log;
public class TorTransProxy implements TorServiceConstants { public class TorTransProxy implements TorServiceConstants {
private boolean useSystemIpTables = false; private boolean useSystemIpTables = false;
private boolean mBundledFailed = false;
private String mSysIptables = null; private String mSysIptables = null;
private TorService mTorService = null; private TorService mTorService = null;
@ -35,7 +34,7 @@ public class TorTransProxy implements TorServiceConstants {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
useSystemIpTables = prefs.getBoolean(TorConstants.PREF_USE_SYSTEM_IPTABLES, false); useSystemIpTables = prefs.getBoolean(TorConstants.PREF_USE_SYSTEM_IPTABLES, false);
if (useSystemIpTables || mBundledFailed) if (useSystemIpTables)
{ {
ipTablesPath = findSystemIPTables(); ipTablesPath = findSystemIPTables();
} }
@ -45,19 +44,6 @@ public class TorTransProxy implements TorServiceConstants {
ipTablesPath = new File(context.getDir("bin", 0),"iptables").getAbsolutePath(); ipTablesPath = new File(context.getDir("bin", 0),"iptables").getAbsolutePath();
try
{
if (testOwnerModule(context,ipTablesPath) != 0)
{
mBundledFailed = true;
ipTablesPath = findSystemIPTables();
}
}
catch (Exception e)
{
ipTablesPath = findSystemIPTables();
mBundledFailed = true;
}
} }
return ipTablesPath; return ipTablesPath;
@ -73,14 +59,14 @@ public class TorTransProxy implements TorServiceConstants {
{ {
//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/xbin/iptables");
if (fileIpt.exists()) if (fileIpt.exists())
mSysIptables = fileIpt.getAbsolutePath(); mSysIptables = fileIpt.getAbsolutePath();
else else
{ {
fileIpt = new File("/system/xbin/iptables"); fileIpt = new File("/system/bin/iptables");
if (fileIpt.exists()) if (fileIpt.exists())
mSysIptables = fileIpt.getAbsolutePath(); mSysIptables = fileIpt.getAbsolutePath();
@ -201,7 +187,7 @@ public class TorTransProxy implements TorServiceConstants {
return code; return code;
} }
*/ */
/*
public int testOwnerModule(Context context, String ipTablesPath) throws Exception public int testOwnerModule(Context context, String ipTablesPath) throws Exception
{ {
@ -245,6 +231,7 @@ public class TorTransProxy implements TorServiceConstants {
return code; return code;
} }
*/
public int setTransparentProxyingByApp (Context context, ArrayList<TorifiedApp> apps) throws Exception public int setTransparentProxyingByApp (Context context, ArrayList<TorifiedApp> apps) throws Exception
{ {

View File

@ -2,10 +2,7 @@ package org.torproject.android.wizard;
import org.torproject.android.R; import org.torproject.android.R;
import org.torproject.android.TorConstants; import org.torproject.android.TorConstants;
import org.torproject.android.R.drawable; import org.torproject.android.service.Root;
import org.torproject.android.R.id;
import org.torproject.android.R.layout;
import org.torproject.android.R.string;
import org.torproject.android.service.TorService; import org.torproject.android.service.TorService;
import org.torproject.android.service.TorServiceUtils; import org.torproject.android.service.TorServiceUtils;
import org.torproject.android.service.TorTransProxy; import org.torproject.android.service.TorTransProxy;
@ -22,8 +19,8 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -69,7 +66,7 @@ public class Permissions extends Activity implements TorConstants {
private void stepThree(){ private void stepThree(){
boolean isRootPossible = TorServiceUtils.isRootPossible(); boolean isRootPossible = new Root().isDeviceRooted();
if (isRootPossible) if (isRootPossible)
{ {
@ -150,9 +147,8 @@ public class Permissions extends Activity implements TorConstants {
if (!hasRoot) if (!hasRoot)
{ {
hasRoot = new Root().isDeviceRooted();
hasRoot = TorServiceUtils.isRootPossible();
Editor pEdit = prefs.edit(); Editor pEdit = prefs.edit();
pEdit.putBoolean(PREF_HAS_ROOT,hasRoot); pEdit.putBoolean(PREF_HAS_ROOT,hasRoot);
pEdit.commit(); pEdit.commit();
@ -162,7 +158,9 @@ public class Permissions extends Activity implements TorConstants {
if (hasRoot) if (hasRoot)
{ {
try { try {
/*
TorTransProxy ttProxy = new TorTransProxy(); TorTransProxy ttProxy = new TorTransProxy();
int resp = ttProxy.testOwnerModule(context,ttProxy.getIpTablesPath(context)); int resp = ttProxy.testOwnerModule(context,ttProxy.getIpTablesPath(context));
if (resp != 0) if (resp != 0)
@ -173,6 +171,7 @@ public class Permissions extends Activity implements TorConstants {
Log.i(TorService.TAG,"ERROR: IPTables OWNER module not available"); Log.i(TorService.TAG,"ERROR: IPTables OWNER module not available");
stepFour(); stepFour();
} }
*/
} catch (Exception e) { } catch (Exception e) {