From 82fcea0dab3b242047c54b64f1bbfde7e30ec95c Mon Sep 17 00:00:00 2001 From: Nathan Freitas Date: Tue, 20 Aug 2013 13:25:42 -0400 Subject: [PATCH] fixes for superuser and iptables check code --- .../android/service/TorBinaryInstaller.java | 18 +------ .../android/service/TorServiceUtils.java | 53 ------------------- .../android/service/TorTransProxy.java | 23 ++------ .../android/wizard/Permissions.java | 17 +++--- 4 files changed, 15 insertions(+), 96 deletions(-) diff --git a/src/org/torproject/android/service/TorBinaryInstaller.java b/src/org/torproject/android/service/TorBinaryInstaller.java index ffaeab3f..6a6ca8a6 100644 --- a/src/org/torproject/android/service/TorBinaryInstaller.java +++ b/src/org/torproject/android/service/TorBinaryInstaller.java @@ -253,22 +253,8 @@ public class TorBinaryInstaller implements TorServiceConstants { // Check iptables_g1 File file = new File(ctx.getDir("bin",0), "iptables"); - - 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; - } - - + copyRawFile(ctx, R.raw.iptables, file, CHMOD_EXEC, false); + return true; } diff --git a/src/org/torproject/android/service/TorServiceUtils.java b/src/org/torproject/android/service/TorServiceUtils.java index e21b7456..e9e929ef 100644 --- a/src/org/torproject/android/service/TorServiceUtils.java +++ b/src/org/torproject/android/service/TorServiceUtils.java @@ -16,59 +16,6 @@ import android.util.Log; 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) { diff --git a/src/org/torproject/android/service/TorTransProxy.java b/src/org/torproject/android/service/TorTransProxy.java index 76741b12..1528f9a3 100644 --- a/src/org/torproject/android/service/TorTransProxy.java +++ b/src/org/torproject/android/service/TorTransProxy.java @@ -14,7 +14,6 @@ import android.util.Log; public class TorTransProxy implements TorServiceConstants { private boolean useSystemIpTables = false; - private boolean mBundledFailed = false; private String mSysIptables = null; private TorService mTorService = null; @@ -35,7 +34,7 @@ public class TorTransProxy implements TorServiceConstants { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()); useSystemIpTables = prefs.getBoolean(TorConstants.PREF_USE_SYSTEM_IPTABLES, false); - if (useSystemIpTables || mBundledFailed) + if (useSystemIpTables) { ipTablesPath = findSystemIPTables(); } @@ -45,19 +44,6 @@ public class TorTransProxy implements TorServiceConstants { 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; @@ -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 - File fileIpt = new File("/system/bin/iptables"); + File fileIpt = new File("/system/xbin/iptables"); if (fileIpt.exists()) mSysIptables = fileIpt.getAbsolutePath(); else { - fileIpt = new File("/system/xbin/iptables"); + fileIpt = new File("/system/bin/iptables"); if (fileIpt.exists()) mSysIptables = fileIpt.getAbsolutePath(); @@ -201,7 +187,7 @@ public class TorTransProxy implements TorServiceConstants { return code; } */ - + /* public int testOwnerModule(Context context, String ipTablesPath) throws Exception { @@ -245,6 +231,7 @@ public class TorTransProxy implements TorServiceConstants { return code; } + */ public int setTransparentProxyingByApp (Context context, ArrayList apps) throws Exception { diff --git a/src/org/torproject/android/wizard/Permissions.java b/src/org/torproject/android/wizard/Permissions.java index b93ba198..91e93db5 100644 --- a/src/org/torproject/android/wizard/Permissions.java +++ b/src/org/torproject/android/wizard/Permissions.java @@ -2,10 +2,7 @@ package org.torproject.android.wizard; import org.torproject.android.R; import org.torproject.android.TorConstants; -import org.torproject.android.R.drawable; -import org.torproject.android.R.id; -import org.torproject.android.R.layout; -import org.torproject.android.R.string; +import org.torproject.android.service.Root; import org.torproject.android.service.TorService; import org.torproject.android.service.TorServiceUtils; import org.torproject.android.service.TorTransProxy; @@ -22,8 +19,8 @@ import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; -import android.widget.ImageView; import android.widget.CompoundButton.OnCheckedChangeListener; +import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; @@ -69,7 +66,7 @@ public class Permissions extends Activity implements TorConstants { private void stepThree(){ - boolean isRootPossible = TorServiceUtils.isRootPossible(); + boolean isRootPossible = new Root().isDeviceRooted(); if (isRootPossible) { @@ -150,9 +147,8 @@ public class Permissions extends Activity implements TorConstants { if (!hasRoot) { - - hasRoot = TorServiceUtils.isRootPossible(); - + hasRoot = new Root().isDeviceRooted(); + Editor pEdit = prefs.edit(); pEdit.putBoolean(PREF_HAS_ROOT,hasRoot); pEdit.commit(); @@ -162,7 +158,9 @@ public class Permissions extends Activity implements TorConstants { if (hasRoot) { try { + /* TorTransProxy ttProxy = new TorTransProxy(); + int resp = ttProxy.testOwnerModule(context,ttProxy.getIpTablesPath(context)); if (resp != 0) @@ -173,6 +171,7 @@ public class Permissions extends Activity implements TorConstants { Log.i(TorService.TAG,"ERROR: IPTables OWNER module not available"); stepFour(); } + */ } catch (Exception e) {