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
svn:r22802
This commit is contained in:
parent
0bc5f8f640
commit
2b814e1eaa
|
@ -17,6 +17,7 @@ import android.content.pm.ApplicationInfo;
|
|||
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,10 +146,8 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
|
|||
|
||||
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,12 +204,14 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
|
|||
}
|
||||
|
||||
|
||||
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();
|
||||
|
||||
|
|
|
@ -256,15 +256,6 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
|
|||
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 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
|
|||
|
||||
showHelp();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -332,7 +329,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
|
|||
lblStatus = (TextView)findViewById(R.id.lblStatus);
|
||||
imgStatus = (ImageView)findViewById(R.id.imgStatus);
|
||||
|
||||
//updateStatus("");
|
||||
updateStatus("");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -379,19 +376,25 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
|
|||
{
|
||||
|
||||
|
||||
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 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
|
|||
|
||||
boolean enableTransparentProxy = prefs.getBoolean(PREF_TRANSPARENT, false);
|
||||
|
||||
mService.updateTransProxy();
|
||||
|
||||
String bridgeList = prefs.getString(PREF_BRIDGES_LIST,"");
|
||||
|
||||
|
@ -490,6 +494,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
|
|||
|
||||
}
|
||||
|
||||
|
||||
private void showAlert(String title, String msg)
|
||||
{
|
||||
|
||||
|
@ -510,13 +515,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
|
|||
|
||||
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 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
|
|||
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 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
|
|||
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,33 +555,6 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
|
|||
|
||||
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 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
|
|||
{
|
||||
|
||||
|
||||
/*
|
||||
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 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
|
|||
Message msg = mHandler.obtainMessage(ENABLE_TOR_MSG);
|
||||
mHandler.sendMessage(msg);
|
||||
|
||||
// updateStatus("");
|
||||
}
|
||||
|
||||
private void stopTor () throws RemoteException
|
||||
|
@ -663,7 +620,6 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
|
|||
Message msg = mHandler.obtainMessage(DISABLE_TOR_MSG);
|
||||
mHandler.sendMessage(msg);
|
||||
|
||||
//updateStatus("");
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -89,6 +89,7 @@ public class SettingsPreferences
|
|||
{
|
||||
startActivity(new Intent(this, AppManager.class));
|
||||
}
|
||||
/*
|
||||
else if (preference == prefWebProxy)
|
||||
{
|
||||
Intent intent = new Intent();
|
||||
|
@ -99,7 +100,7 @@ public class SettingsPreferences
|
|||
startActivity(intent);
|
||||
|
||||
|
||||
}
|
||||
}*/
|
||||
else
|
||||
{
|
||||
prefcBTransProxyAll.setEnabled(prefCBTransProxy.isChecked());
|
||||
|
|
|
@ -27,6 +27,12 @@ interface ITorService {
|
|||
**/
|
||||
void setProfile(int profile);
|
||||
|
||||
/**
|
||||
* Update trans proxying
|
||||
**/
|
||||
boolean updateTransProxy ();
|
||||
|
||||
|
||||
/**
|
||||
* Set configuration
|
||||
**/
|
||||
|
|
|
@ -943,6 +943,14 @@ public class TorService extends Service implements TorServiceConstants, Runnable
|
|||
|
||||
}
|
||||
|
||||
public boolean updateTransProxy ()
|
||||
{
|
||||
|
||||
//turn on
|
||||
|
||||
return setupTransProxy(currentStatus == STATUS_ON);
|
||||
}
|
||||
|
||||
public String getConfiguration (String name)
|
||||
{
|
||||
try
|
||||
|
@ -1160,10 +1168,10 @@ public class TorService extends Service implements TorServiceConstants, Runnable
|
|||
}
|
||||
|
||||
|
||||
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 @@ public class TorService extends Service implements TorServiceConstants, Runnable
|
|||
|
||||
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 @@ public class TorService extends Service implements TorServiceConstants, Runnable
|
|||
TorTransProxy.purgeIptables();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ public class TorTransProxy {
|
|||
|
||||
private static String findBaseDir ()
|
||||
{
|
||||
/*
|
||||
String[] cmds = {"/system/bin/iptables -t nat --list"};
|
||||
StringBuilder res = new StringBuilder();
|
||||
|
||||
|
@ -69,7 +70,9 @@ public class TorTransProxy {
|
|||
|
||||
} catch (Exception e) {
|
||||
return BASE_DIR;
|
||||
}
|
||||
}*/
|
||||
|
||||
return "/system/bin/";
|
||||
|
||||
|
||||
}
|
||||
|
@ -139,6 +142,15 @@ public class TorTransProxy {
|
|||
|
||||
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 @@ public class TorTransProxy {
|
|||
|
||||
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 @@ public class TorTransProxy {
|
|||
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");
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue