[or-cvs] r22802: {projects} found and fixed major bug in per-app trans proxing - list of (in projects/android/trunk/Orbot/src/org/torproject/android: . service)
Nathan Freitas
nathan at freitas.net
Wed Aug 4 10:16:38 UTC 2010
Author: n8fr8
Date: 2010-08-04 10:16:38 +0000 (Wed, 04 Aug 2010)
New Revision: 22802
Modified:
projects/android/trunk/Orbot/src/org/torproject/android/AppManager.java
projects/android/trunk/Orbot/src/org/torproject/android/Orbot.java
projects/android/trunk/Orbot/src/org/torproject/android/SettingsPreferences.java
projects/android/trunk/Orbot/src/org/torproject/android/service/ITorService.aidl
projects/android/trunk/Orbot/src/org/torproject/android/service/TorService.java
projects/android/trunk/Orbot/src/org/torproject/android/service/TorTransProxy.java
Log:
found and fixed major bug in per-app trans proxing - list of apps was being cached and iptables rules were not properly updated as the user changed the selection in the list
Modified: projects/android/trunk/Orbot/src/org/torproject/android/AppManager.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/AppManager.java 2010-08-04 10:04:02 UTC (rev 22801)
+++ projects/android/trunk/Orbot/src/org/torproject/android/AppManager.java 2010-08-04 10:16:38 UTC (rev 22802)
@@ -17,6 +17,7 @@
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
@@ -145,11 +146,9 @@
public static TorifiedApp[] getApps (Context context)
{
- if (apps != null)
- return apps;
-
- final SharedPreferences prefs = context.getSharedPreferences(PREFS_KEY, 0);
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+
String tordAppString = prefs.getString(PREFS_KEY_TORIFIED, "");
String[] tordApps;
@@ -205,13 +204,15 @@
}
- public static void saveAppSettings (Context context)
+ public void saveAppSettings (Context context)
{
if (apps == null)
return;
- final SharedPreferences prefs = context.getSharedPreferences(PREFS_KEY, 0);
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
+ // final SharedPreferences prefs = context.getSharedPreferences(PREFS_KEY, 0);
+
StringBuilder tordApps = new StringBuilder();
for (int i = 0; i < apps.length; i++)
Modified: projects/android/trunk/Orbot/src/org/torproject/android/Orbot.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/Orbot.java 2010-08-04 10:04:02 UTC (rev 22801)
+++ projects/android/trunk/Orbot/src/org/torproject/android/Orbot.java 2010-08-04 10:16:38 UTC (rev 22802)
@@ -256,15 +256,6 @@
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancelAll();
- if (mService != null)
- {
- try {
- processSettings();
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mOrbot);
@@ -281,7 +272,13 @@
showHelp();
}
+ else
+ {
+
+
+
+ }
}
@@ -332,7 +329,7 @@
lblStatus = (TextView)findViewById(R.id.lblStatus);
imgStatus = (ImageView)findViewById(R.id.imgStatus);
- //updateStatus("");
+ updateStatus("");
}
/*
@@ -379,19 +376,25 @@
{
- startActivity(new Intent(this, SettingsPreferences.class));
-
-
+ startActivityForResult(new Intent(this, SettingsPreferences.class), 1);
}
- /*
- * Read in the Preferences and write then to the .torrc file
- */
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+
+ if (requestCode == 1)
+ {
+ try {
+ processSettings();
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+ }
-
-
private void processSettings () throws RemoteException
{
@@ -408,6 +411,7 @@
boolean enableTransparentProxy = prefs.getBoolean(PREF_TRANSPARENT, false);
+ mService.updateTransProxy();
String bridgeList = prefs.getString(PREF_BRIDGES_LIST,"");
@@ -490,6 +494,7 @@
}
+
private void showAlert(String title, String msg)
{
@@ -510,13 +515,7 @@
if (mService != null)
torStatus = mService.getStatus();
-
- if (this.currentView == R.layout.layout_log)
- {
- txtMessageLog.append(torServiceMsg);
- txtMessageLog.append("\n");
-
- }
+
if (imgStatus != null)
{
@@ -526,8 +525,9 @@
imgStatus.setImageResource(R.drawable.toron);
imgStatus.clearAnimation();
- lblStatus.setText(getString(R.string.status_activated));
+ String lblMsg = getString(R.string.status_activated) + ": " + torServiceMsg;
+ lblStatus.setText(lblMsg);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mOrbot);
@@ -545,17 +545,9 @@
showAlert(getString(R.string.status_activated),getString(R.string.connect_first_time));
}
+
+
- /*
- if (progressDialog != null)
- {
-
- progressDialog.cancel();
- progressDialog.hide();
- progressDialog = null;
-
-
- }*/
}
else if (torStatus == STATUS_CONNECTING)
@@ -563,34 +555,7 @@
imgStatus.setImageResource(R.drawable.torstarting);
-
- /*
- if (imgStatus.getAnimation()==null)
- {
-
- imgStatus.setAnimation(AnimationUtils.loadAnimation(this, R.anim.starting));
- imgStatus.getAnimation().setRepeatMode(Animation.INFINITE);
-
- imgStatus.getAnimation().setRepeatCount(Animation.INFINITE);
- }*/
-
- /*
- if (progressDialog == null)
- {
- progressDialog = new ProgressDialog(this);
- progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
- progressDialog.setCancelable(true);
- progressDialog.setMessage(getString(R.string.status_starting_up));
- progressDialog.show();
-
- progressDialog.setProgress(10);
-
- }
-
- progressDialog.setMessage(torServiceMsg);
- */
-
lblStatus.setText(torServiceMsg);
@@ -617,20 +582,13 @@
{
- /*
- if (progressDialog != null)
- {
-
- progressDialog.cancel();
- progressDialog.hide();
- progressDialog = null;
- }
- */
imgStatus.clearAnimation();
imgStatus.setImageResource(R.drawable.toroff);
lblStatus.setText(getString(R.string.status_disabled));
+
+
}
}
@@ -653,7 +611,6 @@
Message msg = mHandler.obtainMessage(ENABLE_TOR_MSG);
mHandler.sendMessage(msg);
- // updateStatus("");
}
private void stopTor () throws RemoteException
@@ -663,7 +620,6 @@
Message msg = mHandler.obtainMessage(DISABLE_TOR_MSG);
mHandler.sendMessage(msg);
- //updateStatus("");
}
Modified: projects/android/trunk/Orbot/src/org/torproject/android/SettingsPreferences.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/SettingsPreferences.java 2010-08-04 10:04:02 UTC (rev 22801)
+++ projects/android/trunk/Orbot/src/org/torproject/android/SettingsPreferences.java 2010-08-04 10:16:38 UTC (rev 22802)
@@ -89,6 +89,7 @@
{
startActivity(new Intent(this, AppManager.class));
}
+ /*
else if (preference == prefWebProxy)
{
Intent intent = new Intent();
@@ -99,7 +100,7 @@
startActivity(intent);
- }
+ }*/
else
{
prefcBTransProxyAll.setEnabled(prefCBTransProxy.isChecked());
Modified: projects/android/trunk/Orbot/src/org/torproject/android/service/ITorService.aidl
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/service/ITorService.aidl 2010-08-04 10:04:02 UTC (rev 22801)
+++ projects/android/trunk/Orbot/src/org/torproject/android/service/ITorService.aidl 2010-08-04 10:16:38 UTC (rev 22802)
@@ -27,6 +27,12 @@
**/
void setProfile(int profile);
+ /**
+ * Update trans proxying
+ **/
+ boolean updateTransProxy ();
+
+
/**
* Set configuration
**/
Modified: projects/android/trunk/Orbot/src/org/torproject/android/service/TorService.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/service/TorService.java 2010-08-04 10:04:02 UTC (rev 22801)
+++ projects/android/trunk/Orbot/src/org/torproject/android/service/TorService.java 2010-08-04 10:16:38 UTC (rev 22802)
@@ -943,6 +943,14 @@
}
+ public boolean updateTransProxy ()
+ {
+
+ //turn on
+
+ return setupTransProxy(currentStatus == STATUS_ON);
+ }
+
public String getConfiguration (String name)
{
try
@@ -1160,10 +1168,10 @@
}
- private void setupTransProxy (boolean enabled)
+ private boolean setupTransProxy (boolean enabled)
{
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplication());
boolean enableTransparentProxy = prefs.getBoolean("pref_transparent", false);
boolean transProxyAll = prefs.getBoolean("pref_transparent_all", false);
@@ -1186,10 +1194,14 @@
logNotice ("TorTransProxy enabled: " + success);
+ return true;
+
} catch (Exception e) {
logNotice("WARNING: Error configuring transparenty proxying: " + e.getMessage());
Log.w(TAG, "error refreshing iptables: err=" + e.getMessage(), e);
+
+ return false;
}
}
@@ -1206,5 +1218,7 @@
TorTransProxy.purgeIptables();
}
}
+
+ return true;
}
}
Modified: projects/android/trunk/Orbot/src/org/torproject/android/service/TorTransProxy.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/service/TorTransProxy.java 2010-08-04 10:04:02 UTC (rev 22801)
+++ projects/android/trunk/Orbot/src/org/torproject/android/service/TorTransProxy.java 2010-08-04 10:16:38 UTC (rev 22802)
@@ -53,6 +53,7 @@
private static String findBaseDir ()
{
+ /*
String[] cmds = {"/system/bin/iptables -t nat --list"};
StringBuilder res = new StringBuilder();
@@ -69,8 +70,10 @@
} catch (Exception e) {
return BASE_DIR;
- }
+ }*/
+ return "/system/bin/";
+
}
public static int setDNSProxying () throws Exception
@@ -139,6 +142,15 @@
final StringBuilder script = new StringBuilder();
+ //first we have to flush old settings
+ script.append(baseDir);
+ script.append(CMD_NAT_FLUSH);
+ script.append(" || exit\n");
+
+ script.append(baseDir);
+ script.append(CMD_FILTER_FLUSH);
+ script.append(" || exit\n");
+
StringBuilder res = new StringBuilder();
int code = -1;
@@ -156,6 +168,8 @@
Log.i(TAG,"enabling transproxy for app: " + apps[i].getUsername() + "(" + apps[i].getUid() + ")");
+
+
//TCP
script.append(baseDir);
script.append("iptables -t nat");
@@ -173,12 +187,14 @@
script.append(" --dport 53 -j REDIRECT --to-ports 5400"); //drop all UDP packets as Tor won't handle them
script.append(" || exit\n");
+ /*
script.append(baseDir);
script.append("iptables -t nat");
script.append(" -A OUTPUT -m owner --uid-owner ");
script.append(apps[i].getUid());
script.append(" -j DROP"); //drop all other packets as Tor won't handle them
script.append(" || exit\n");
+ */
/*
More information about the tor-commits
mailing list