alpha-1.0.3 RC1: cleaned up unnecessary log output; improved iptables handling for transproxy

svn:r23154
This commit is contained in:
Nathan Freitas 2010-09-09 20:39:52 +00:00
parent 5a824a7aa5
commit 9258248a31
18 changed files with 201 additions and 244 deletions

View File

@ -1,15 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.torproject.android" android:versionName="0.2.2.14-orbot-alpha-1.0.2" android:versionCode="8"> package="org.torproject.android" android:versionName="0.2.2.14-orbot-alpha-1.0.3" android:versionCode="9">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon" android:label="@string/app_name"> <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<activity android:name=".Orbot" <activity android:name=".Orbot"
android:theme="@android:style/Theme.NoTitleBar" android:theme="@android:style/Theme.NoTitleBar">
>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
@ -34,7 +33,8 @@
<activity android:name=".AppManager" android:label="@string/app_name"/> <activity android:name=".AppManager" android:label="@string/app_name"/>
<activity android:name=".WizardActivity" android:label="@string/app_name"/> <activity android:name=".WizardActivity" android:label="@string/app_name"/>
<service android:name=".service.TorService" android:process=":remote"> <!-- <service android:name=".service.TorService" android:process=":remote"> -->
<service android:name=".service.TorService">
<intent-filter> <intent-filter>
<action android:name="org.torproject.android.service.ITorService" /> <action android:name="org.torproject.android.service.ITorService" />
<action android:name="org.torproject.android.service.TOR_SERVICE" /> <action android:name="org.torproject.android.service.TOR_SERVICE" />

View File

@ -1,5 +1,18 @@
NOTE: Specific #s below correspond to Trac tickets logged and maintained at https://trac.torproject.org/projects/tor/ NOTE: Specific #s below correspond to Trac tickets logged and maintained at https://trac.torproject.org/projects/tor/
1.0.3
- fixed spanish language issues with settings screen
- cleaned up logging, and moved most of it to debug output only
- small changes to iptables, transproxy settings to handle iptables 1.3 and 1.4 variations
1.0.2
- added "check" yes/no dialog prompt
- debugged iptables/transprox settings on Android 1.6 and 2.2
- added proxy settings help screen and fixed processSettings() NPE
1.0.1
- found and fixed major bug in per-app trans proxying; list of apps was being cached and iptables rules were not properly updated as the user changed the selection in the list
1.0.0 - 2010-08-10 1.0.0 - 2010-08-10
- Added "Proxy Settings" help screen - Added "Proxy Settings" help screen
- Handle potential null pointers on process settings where service not yet active - Handle potential null pointers on process settings where service not yet active

View File

@ -2,7 +2,6 @@ SocksPort 9050
SocksListenAddress 127.0.0.1 SocksListenAddress 127.0.0.1
SafeSocks 1 SafeSocks 1
Log notice stdout Log notice stdout
##Log debug syslog
DataDirectory /data/data/org.torproject.android/data DataDirectory /data/data/org.torproject.android/data
ControlPort 9051 ControlPort 9051
CookieAuthentication 1 CookieAuthentication 1

View File

@ -32,8 +32,9 @@
android:layout_toLeftOf="@+id/radioModeImage" android:layout_toLeftOf="@+id/radioModeImage"
android:textColor="#333333" /> android:textColor="#333333" />
</RelativeLayout> </RelativeLayout>
<ScrollView android:orientation="vertical" <ScrollView android:orientation="vertical"
android:layout_height="fill_parent" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="@+id/logScrollView" android:layout_width="fill_parent" android:id="@+id/logScrollView"
xmlns:android="http://schemas.android.com/apk/res/android"> xmlns:android="http://schemas.android.com/apk/res/android">
@ -45,8 +46,8 @@
android:textSize="12px" android:textSize="12px"
android:background="#A0222222" android:background="#A0222222"
/> />
</ScrollView> </ScrollView>
</LinearLayout> </LinearLayout>

View File

@ -35,6 +35,9 @@
<string name="button_close">Close</string> <string name="button_close">Close</string>
<string name="button_about">About</string> <string name="button_about">About</string>
<string name="button_clear_log">Clear Log</string>
<string name="help_text_1">Orbot requires different configuration depending on the Android operating system version it is used on. <string name="help_text_1">Orbot requires different configuration depending on the Android operating system version it is used on.
Please visit https://www.torproject.org/docs/android.html for the latest information.</string> Please visit https://www.torproject.org/docs/android.html for the latest information.</string>

View File

@ -1,76 +0,0 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="Transparent Proxying">
<CheckBoxPreference
android:defaultValue="false"
android:key="pref_transparent"
android:title="Transparent Proxying"
android:summary="Root Devices Only: Per App Torification"
android:enabled="true"/>
</PreferenceCategory>
<PreferenceCategory android:title="Bridges">
<CheckBoxPreference android:defaultValue="false"
android:title="Use Bridges" android:key="pref_bridges_enabled"
android:summary="Enable alternate entrance nodes into the Tor Network"></CheckBoxPreference>
<!-- 5/8/2010 NF: Arma says this doesn't actually work, so commenting out for now
<CheckBoxPreference android:defaultValue="false"
android:title="Update from Authority" android:key="pref_bridges_update"
android:summary="Modify bridge list automatically"></CheckBoxPreference>
-->
<EditTextPreference android:key="pref_bridges_list"
android:title="Bridges"
android:summary="IP address and port of bridges"
android:dialogTitle="Enter Bridge Addresses"
/>
</PreferenceCategory>
<PreferenceCategory android:title="Relays">
<CheckBoxPreference android:key="pref_or"
android:defaultValue="false"
android:title="Relaying"
android:summary="Enable your device to be a non-exit relay"
android:enabled="true"
/>
<EditTextPreference android:key="pref_or_port"
android:defaultValue="9001"
android:title="Relay Port"
android:summary="Listening port for your Tor relay"
android:dialogTitle="Enter OR port"
/>
<EditTextPreference android:key="pref_or_nickname"
android:defaultValue="Orbot"
android:title="Relay nickname"
android:summary="The nickname for your Tor relay"
android:dialogTitle="Enter a custom relay nickname"
/>
</PreferenceCategory>
<PreferenceCategory android:title="ReachableAddresses">
<CheckBoxPreference
android:key="pref_reachable_addresses"
android:defaultValue="false"
android:title="ReachableAddresses"
android:summary="Run as a client behind a firewall with restrictive policies"
android:enabled="true"></CheckBoxPreference>
<EditTextPreference
android:key="pref_reachable_addresses_ports"
android:defaultValue="*:80,*:443"
android:title="Reachable ports"
android:summary="Ports reachable behind a restrictive firewall"
android:dialogTitle="Enter ports"
/>
</PreferenceCategory>
</PreferenceScreen>

View File

@ -140,7 +140,7 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
//Log.i(getClass().getName(),"Exiting Preferences"); //Log.d(getClass().getName(),"Exiting Preferences");
} }

View File

@ -306,8 +306,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
setResult(RESULT_OK, nResult); setResult(RESULT_OK, nResult);
} catch (RemoteException e) { } catch (RemoteException e) {
// TODO Auto-generated catch block Log.e(TAG, "error accessing hidden service", e);
e.printStackTrace();
} }
@ -478,6 +477,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
txtMessageLog.setClickable(true); txtMessageLog.setClickable(true);
txtMessageLog.setText(logBuffer.toString()); txtMessageLog.setText(logBuffer.toString());
} }
@ -684,7 +684,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
String onionHostname = Utils.readString(new FileInputStream(file)); String onionHostname = Utils.readString(new FileInputStream(file));
return onionHostname.trim(); return onionHostname.trim();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.i(TAG, "unable to read onion hostname file",e); Log.d(TAG, "unable to read onion hostname file",e);
return null; return null;
} }
} }
@ -820,6 +820,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
Message msg = mHandler.obtainMessage(ENABLE_TOR_MSG); Message msg = mHandler.obtainMessage(ENABLE_TOR_MSG);
mHandler.sendMessage(msg); mHandler.sendMessage(msg);
logBuffer = new StringBuffer();
} }
private void stopTor () throws RemoteException private void stopTor () throws RemoteException
@ -862,7 +863,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
} }
catch (Exception e) catch (Exception e)
{ {
Log.i(TAG,"error onclick",e); Log.d(TAG,"error onclick",e);
} }
return super.onTouchEvent(event); return super.onTouchEvent(event);
@ -900,7 +901,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
} }
catch (Exception e) catch (Exception e)
{ {
Log.i(TAG,"error onclick",e); Log.d(TAG,"error onclick",e);
} }
// } // }
@ -954,7 +955,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
logBuffer.append('\n'); logBuffer.append('\n');
if (torServiceMsg.length() > 0 && torServiceMsg.charAt(0)!='>') if (torServiceMsg.length() > 0)
updateStatus(torServiceMsg); updateStatus(torServiceMsg);
break; break;
@ -965,6 +966,10 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
logBuffer.append(torLogMsg); logBuffer.append(torLogMsg);
logBuffer.append('\n'); logBuffer.append('\n');
if (txtMessageLog != null)
{
txtMessageLog.append(torLogMsg + '\n');
}
break; break;
case ENABLE_TOR_MSG: case ENABLE_TOR_MSG:
@ -1017,7 +1022,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
// do anything with it; we can count on soon being // do anything with it; we can count on soon being
// disconnected (and then reconnected if it can be restarted) // disconnected (and then reconnected if it can be restarted)
// so there is no need to do anything here. // so there is no need to do anything here.
Log.i(TAG,"error registering callback to service",e); Log.d(TAG,"error registering callback to service",e);
} }

View File

@ -78,7 +78,7 @@ public class SettingsPreferences
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
//Log.i(getClass().getName(),"Exiting Preferences"); //Log.d(getClass().getName(),"Exiting Preferences");
} }
@Override @Override

View File

@ -84,7 +84,7 @@ public class Utils {
return true; return true;
} catch (IOException e) { } catch (IOException e) {
// Log.i(TAG, "error writing file: " + path, e); // Log.d(TAG, "error writing file: " + path, e);
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }

View File

@ -60,8 +60,6 @@ import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams; import org.apache.http.params.HttpParams;
import android.util.Log;
/** /**
@ -255,8 +253,6 @@ public class ModSSLSocketFactory implements LayeredSocketFactory {
this.socketfactory = SSLSocketFactory.getSocketFactory(); this.socketfactory = SSLSocketFactory.getSocketFactory();
//this.nameResolver = null; //this.nameResolver = null;
//Log.i("TOR_SERVICE","ModSSLSocketFactory: proxied via " + host + ":" + port);
this.mSocksSocketFactory = new SocksSocketFactory("127.0.0.1",9050); this.mSocksSocketFactory = new SocksSocketFactory("127.0.0.1",9050);
} }
@ -325,16 +321,11 @@ public class ModSSLSocketFactory implements LayeredSocketFactory {
}*/ }*/
Log.i("TOR_SERVICE","connecting socks factory");
Socket sSocket = mSocksSocketFactory.connectSocket(underlying, host, port, localAddress, localPort, params); Socket sSocket = mSocksSocketFactory.connectSocket(underlying, host, port, localAddress, localPort, params);
Log.i("TOR_SERVICE","creating SSL Socket");
// SSLSocket sslsock = (SSLSocket) socketfactory.connectSocket(sSocket, host, port, localAddress, localPort, params); // SSLSocket sslsock = (SSLSocket) socketfactory.connectSocket(sSocket, host, port, localAddress, localPort, params);
SSLSocket sslsock = (SSLSocket)socketfactory.createSocket(sSocket, host, port, true); SSLSocket sslsock = (SSLSocket)socketfactory.createSocket(sSocket, host, port, true);
Log.i("TOR_SERVICE","created SSL Socket!");
if ((localAddress != null) || (localPort > 0)) { if ((localAddress != null) || (localPort > 0)) {
// we need to bind explicitly // we need to bind explicitly
@ -343,8 +334,6 @@ public class ModSSLSocketFactory implements LayeredSocketFactory {
InetSocketAddress isa = InetSocketAddress isa =
new InetSocketAddress(localAddress, localPort); new InetSocketAddress(localAddress, localPort);
Log.i("TOR_SERVICE","binding SSL Socket!");
sslsock.bind(isa); sslsock.bind(isa);
} }

View File

@ -47,9 +47,9 @@ private static final int BUF_SIZE = 1024;
ss = new SocksSocket(host, port); ss = new SocksSocket(host, port);
out = ss.getOutputStream(); out = ss.getOutputStream();
in = ss.getInputStream(); in = ss.getInputStream();
Log.i(getClass().getName(),"Connected..."); Log.d(getClass().getName(),"Connected...");
Log.i(getClass().getName(),"TO: "+host+":"+port); Log.d(getClass().getName(),"TO: "+host+":"+port);
Log.i(getClass().getName(),"ViaProxy: "+ss.getLocalAddress().getHostAddress() Log.d(getClass().getName(),"ViaProxy: "+ss.getLocalAddress().getHostAddress()
+":"+ss.getLocalPort()); +":"+ss.getLocalPort());
} }

View File

@ -65,7 +65,7 @@ public class SocksSocketFactory implements SocketFactory {
sProxy = new Socks5Proxy(proxyaddress, proxyport); sProxy = new Socks5Proxy(proxyaddress, proxyport);
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
Log.i("TOR_SERVICE","SocksSF couldn't connect",e); Log.d("TOR_SERVICE","SocksSF couldn't connect",e);
} }
sProxy.resolveAddrLocally(false); sProxy.resolveAddrLocally(false);
@ -77,7 +77,7 @@ public class SocksSocketFactory implements SocketFactory {
InetAddress localAddress, int localPort, HttpParams params) throws IOException, InetAddress localAddress, int localPort, HttpParams params) throws IOException,
UnknownHostException, ConnectTimeoutException { UnknownHostException, ConnectTimeoutException {
Log.i("TOR_SERVICE","SocksSocketFactory: connectSocket: " + host + ":" + port); Log.d("TOR_SERVICE","SocksSocketFactory: connectSocket: " + host + ":" + port);
if (host == null) { if (host == null) {
throw new IllegalArgumentException("Target host may not be null."); throw new IllegalArgumentException("Target host may not be null.");

View File

@ -33,10 +33,10 @@ public class TorBinaryInstaller implements TorServiceConstants {
{ {
boolean torBinaryExists = new File(installPath + TOR_BINARY_ASSET_KEY).exists(); boolean torBinaryExists = new File(installPath + TOR_BINARY_ASSET_KEY).exists();
Log.i(TAG,"Tor binary exists=" + torBinaryExists); Log.d(TAG,"Tor binary exists=" + torBinaryExists);
boolean privoxyBinaryExists = new File(installPath + PRIVOXY_ASSET_KEY).exists(); boolean privoxyBinaryExists = new File(installPath + PRIVOXY_ASSET_KEY).exists();
Log.i(TAG,"Privoxy binary exists=" + privoxyBinaryExists); Log.d(TAG,"Privoxy binary exists=" + privoxyBinaryExists);
if (!(torBinaryExists && privoxyBinaryExists) || force) if (!(torBinaryExists && privoxyBinaryExists) || force)
installFromZip (); installFromZip ();
@ -72,12 +72,12 @@ public class TorBinaryInstaller implements TorServiceConstants {
zip.close(); zip.close();
Log.i(TAG,"SUCCESS: unzipped tor, privoxy, iptables binaries from apk"); Log.d(TAG,"SUCCESS: unzipped tor, privoxy, iptables binaries from apk");
} }
catch (IOException ioe) catch (IOException ioe)
{ {
Log.i(TAG,"FAIL: unable to unzip binaries from apk",ioe); Log.d(TAG,"FAIL: unable to unzip binaries from apk",ioe);
} }
} }
@ -108,7 +108,7 @@ public class TorBinaryInstaller implements TorServiceConstants {
{ {
Log.i(TAG,"Error opening output file " + targetFilename,e); Log.d(TAG,"Error opening output file " + targetFilename,e);
return; return;
} }
@ -135,7 +135,7 @@ public class TorBinaryInstaller implements TorServiceConstants {
{ {
Log.i(TAG,"Error writing output file '" + targetFilename + "': " + e.toString()); Log.d(TAG,"Error writing output file '" + targetFilename + "': " + e.toString());
return; return;

View File

@ -51,6 +51,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
private ArrayList<String> configBuffer = null; private ArrayList<String> configBuffer = null;
private boolean isBound = false;
private String appHome = null; private String appHome = null;
private String torBinaryPath = null; private String torBinaryPath = null;
@ -60,7 +61,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
Log.i(TAG,"TorService: onCreate"); Log.d(TAG,"TorService: onCreate");
} }
@ -72,9 +73,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable
if (procId != -1) if (procId != -1)
{ {
Log.i(TAG,"Found existing Tor process"); Log.d(TAG,"Found existing Tor process");
sendCallbackMessage ("found existing Tor process..."); sendCallbackLogMessage ("found existing Tor process...");
try { try {
currentStatus = STATUS_CONNECTING; currentStatus = STATUS_CONNECTING;
@ -87,12 +88,12 @@ public class TorService extends Service implements TorServiceConstants, Runnable
return true; return true;
} catch (RuntimeException e) { } catch (RuntimeException e) {
Log.i(TAG,"Unable to connect to existing Tor instance,",e); Log.d(TAG,"Unable to connect to existing Tor instance,",e);
currentStatus = STATUS_OFF; currentStatus = STATUS_OFF;
this.stopTor(); this.stopTor();
} catch (Exception e) { } catch (Exception e) {
Log.i(TAG,"Unable to connect to existing Tor instance,",e); Log.d(TAG,"Unable to connect to existing Tor instance,",e);
currentStatus = STATUS_OFF; currentStatus = STATUS_OFF;
this.stopTor(); this.stopTor();
@ -110,7 +111,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
public void onLowMemory() { public void onLowMemory() {
super.onLowMemory(); super.onLowMemory();
Log.i(TAG, "Low Memory Called"); Log.d(TAG, "Low Memory Called");
} }
@ -120,8 +121,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable
*/ */
public boolean onUnbind(Intent intent) { public boolean onUnbind(Intent intent) {
Log.i(TAG, "onUnbind Called: " + intent.getAction()); Log.d(TAG, "onUnbind Called: " + intent.getAction());
isBound = false;
return super.onUnbind(intent); return super.onUnbind(intent);
@ -138,6 +140,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
private void showToolbarNotification (String notifyMsg, int icon) private void showToolbarNotification (String notifyMsg, int icon)
{ {
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
@ -168,7 +171,8 @@ public class TorService extends Service implements TorServiceConstants, Runnable
public void onRebind(Intent intent) { public void onRebind(Intent intent) {
super.onRebind(intent); super.onRebind(intent);
Log.i(TAG,"on rebind"); isBound = true;
} }
@ -196,7 +200,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
{ {
currentStatus = STATUS_OFF; currentStatus = STATUS_OFF;
this.showToolbarNotification(getString(R.string.status_disabled), R.drawable.tornotification); this.showToolbarNotification(getString(R.string.status_disabled), R.drawable.tornotification);
Log.i(TAG,"Unable to start Tor: " + e.getMessage(),e); Log.d(TAG,"Unable to start Tor: " + e.getMessage(),e);
} }
} }
} }
@ -210,7 +214,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
mCallbacks.kill(); mCallbacks.kill();
Log.i(TAG,"onDestroy called"); Log.d(TAG,"onDestroy called");
stopTor(); stopTor();
} }
@ -220,7 +224,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
currentStatus = STATUS_OFF; currentStatus = STATUS_OFF;
sendCallbackMessage("Web proxy shutdown"); sendCallbackLogMessage("Web proxy shutdown");
try try
{ {
@ -230,15 +234,15 @@ public class TorService extends Service implements TorServiceConstants, Runnable
showToolbarNotification (getString(R.string.status_disabled),R.drawable.tornotificationoff); showToolbarNotification (getString(R.string.status_disabled),R.drawable.tornotificationoff);
sendCallbackMessage(getString(R.string.status_disabled)); sendCallbackStatusMessage(getString(R.string.status_disabled));
setupTransProxy(false); setupTransProxy(false);
} }
catch (Exception e) catch (Exception e)
{ {
Log.i(TAG, "An error occured stopping Tor",e); Log.d(TAG, "An error occured stopping Tor",e);
logNotice("An error occured stopping Tor: " + e.getMessage()); logNotice("An error occured stopping Tor: " + e.getMessage());
sendCallbackMessage("Something bad happened. Check the log"); sendCallbackStatusMessage("Something bad happened. Check the log");
} }
} }
@ -262,7 +266,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
} }
catch (Exception e) catch (Exception e)
{ {
Log.i(TAG,"Unable to reload configuration",e); Log.d(TAG,"Unable to reload configuration",e);
} }
} }
@ -276,7 +280,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
// conn.shutdownTor(arg0) // conn.shutdownTor(arg0)
conn.signal("SHUTDOWN"); conn.signal("SHUTDOWN");
} catch (Exception e) { } catch (Exception e) {
Log.i(TAG,"error shutting down Tor via connection",e); Log.d(TAG,"error shutting down Tor via connection",e);
} }
conn = null; conn = null;
} }
@ -301,7 +305,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
while (procId != -1) while (procId != -1)
{ {
Log.i(TAG,"Found Privoxy PID=" + procId + " - killing now..."); Log.d(TAG,"Found Privoxy PID=" + procId + " - killing now...");
String[] cmd = { SHELL_CMD_KILL + ' ' + procId + "" }; String[] cmd = { SHELL_CMD_KILL + ' ' + procId + "" };
TorServiceUtils.doShellCommand(cmd,log, false, false); TorServiceUtils.doShellCommand(cmd,log, false, false);
@ -314,9 +318,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable
private void logNotice (String msg) private void logNotice (String msg)
{ {
Log.i(TAG, msg); Log.d(TAG, msg);
sendCallbackMessage('>' + msg); sendCallbackLogMessage(msg);
} }
@ -330,7 +334,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
int MAX_TRIES = 10; int MAX_TRIES = 10;
String buildPath = apkBase + TOR_APP_USERNAME + APK_EXT; String buildPath = apkBase + TOR_APP_USERNAME + APK_EXT;
Log.i(TAG, "Checking APK location: " + buildPath); Log.d(TAG, "Checking APK location: " + buildPath);
File fileApk = new File(buildPath); File fileApk = new File(buildPath);
@ -342,7 +346,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
buildPath = apkBase + TOR_APP_USERNAME + '-' + i + APK_EXT; buildPath = apkBase + TOR_APP_USERNAME + '-' + i + APK_EXT;
fileApk = new File(buildPath); fileApk = new File(buildPath);
Log.i(TAG, "Checking APK location: " + buildPath); Log.d(TAG, "Checking APK location: " + buildPath);
if (fileApk.exists()) if (fileApk.exists())
return fileApk.getAbsolutePath(); return fileApk.getAbsolutePath();
@ -354,7 +358,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
buildPath = apkBaseExt + pkgFile; buildPath = apkBaseExt + pkgFile;
fileApk = new File(buildPath); fileApk = new File(buildPath);
Log.i(TAG, "Checking external storage APK location: " + buildPath); Log.d(TAG, "Checking external storage APK location: " + buildPath);
if (fileApk.exists()) if (fileApk.exists())
return fileApk.getAbsolutePath(); return fileApk.getAbsolutePath();
@ -364,7 +368,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
buildPath = apkBaseExt + '-' + i + pkgFile; buildPath = apkBaseExt + '-' + i + pkgFile;
fileApk = new File(buildPath); fileApk = new File(buildPath);
Log.i(TAG, "Checking external storage APK location: " + buildPath); Log.d(TAG, "Checking external storage APK location: " + buildPath);
if (fileApk.exists()) if (fileApk.exists())
return fileApk.getAbsolutePath(); return fileApk.getAbsolutePath();
@ -376,19 +380,18 @@ public class TorService extends Service implements TorServiceConstants, Runnable
private boolean checkTorBinaries () throws Exception private boolean checkTorBinaries () throws Exception
{ {
//android.os.Debug.waitForDebugger();
Log.i(TAG,"checking Tor binaries"); Log.d(TAG,"checking Tor binaries");
//appHome = getApplicationContext().getFilesDir().getAbsolutePath(); //appHome = getApplicationContext().getFilesDir().getAbsolutePath();
appHome = "/data/data/" + TOR_APP_USERNAME + "/"; appHome = "/data/data/" + TOR_APP_USERNAME + "/";
Log.i(TAG,"appHome=" + appHome); Log.d(TAG,"appHome=" + appHome);
String apkPath = findAPK(); String apkPath = findAPK();
Log.i(TAG,"found apk at: " + apkPath); Log.d(TAG,"found apk at: " + apkPath);
boolean apkExists = new File(apkPath).exists(); boolean apkExists = new File(apkPath).exists();
@ -427,7 +430,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
logNotice(getString(R.string.status_install_fail)); logNotice(getString(R.string.status_install_fail));
sendCallbackMessage(getString(R.string.status_install_fail)); sendCallbackStatusMessage(getString(R.string.status_install_fail));
return false; return false;
} }
@ -458,16 +461,13 @@ public class TorService extends Service implements TorServiceConstants, Runnable
public void initTor () throws Exception public void initTor () throws Exception
{ {
// android.os.Debug.waitForDebugger();
currentStatus = STATUS_CONNECTING; currentStatus = STATUS_CONNECTING;
logNotice(getString(R.string.status_starting_up)); logNotice(getString(R.string.status_starting_up));
sendCallbackMessage(getString(R.string.status_starting_up)); sendCallbackStatusMessage(getString(R.string.status_starting_up));
killTorProcess (); killTorProcess ();
@ -484,8 +484,8 @@ public class TorService extends Service implements TorServiceConstants, Runnable
} catch (Exception e) { } catch (Exception e) {
currentStatus = STATUS_OFF; currentStatus = STATUS_OFF;
Log.i(TAG,"Unable to start Privoxy: " + e.getMessage(),e); Log.d(TAG,"Unable to start Privoxy: " + e.getMessage(),e);
sendCallbackMessage("Unable to start Privoxy: " + e.getMessage()); sendCallbackLogMessage("Unable to start Privoxy: " + e.getMessage());
} }
} }
@ -501,8 +501,8 @@ public class TorService extends Service implements TorServiceConstants, Runnable
setupTransProxy(true); setupTransProxy(true);
} catch (Exception e) { } catch (Exception e) {
Log.i(TAG,"Unable to start Tor: " + e.getMessage(),e); Log.d(TAG,"Unable to start Tor: " + e.getMessage(),e);
sendCallbackMessage("Unable to start Tor: " + e.getMessage()); sendCallbackStatusMessage("Unable to start Tor: " + e.getMessage());
stopTor(); stopTor();
} }
} }
@ -513,15 +513,18 @@ public class TorService extends Service implements TorServiceConstants, Runnable
private void runTorShellCmd() throws Exception private void runTorShellCmd() throws Exception
{ {
StringBuilder log = new StringBuilder(); StringBuilder log = new StringBuilder();
Log.i(TAG,"Starting tor process");
String torrcPath = appHome + TORRC_ASSET_KEY; String torrcPath = appHome + TORRC_ASSET_KEY;
String[] torCmd = {torBinaryPath + " -f " + torrcPath + " || exit\n"}; String[] torCmd = {torBinaryPath + " -f " + torrcPath + " || exit\n"};
TorServiceUtils.doShellCommand(torCmd, log, false, false); TorServiceUtils.doShellCommand(torCmd, log, false, false);
Log.d(TAG,"Starting tor process: " + torCmd[0]);
Thread.sleep(1000); Thread.sleep(1000);
int procId = TorServiceUtils.findProcessId(torBinaryPath); int procId = TorServiceUtils.findProcessId(torBinaryPath);
@ -538,9 +541,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable
if (procId == -1) if (procId == -1)
{ {
sendCallbackMessage("Couldn't start Tor process...\n" + log.toString()); sendCallbackStatusMessage("Couldn't start Tor process...\n" + log.toString());
Thread.sleep(1000); Thread.sleep(1000);
sendCallbackMessage(getString(R.string.status_starting_up)); sendCallbackStatusMessage(getString(R.string.status_starting_up));
Thread.sleep(3000); Thread.sleep(3000);
attempts++; attempts++;
} }
@ -566,7 +569,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
private void runPrivoxyShellCmd () throws Exception private void runPrivoxyShellCmd () throws Exception
{ {
Log.i(TAG,"Starting privoxy process"); Log.d(TAG,"Starting privoxy process");
int privoxyProcId = TorServiceUtils.findProcessId(privoxyPath); int privoxyProcId = TorServiceUtils.findProcessId(privoxyPath);
@ -602,7 +605,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
logNotice(log.toString()); logNotice(log.toString());
} }
sendCallbackMessage("Privoxy is running on port: " + PORT_HTTP); sendCallbackLogMessage("Privoxy is running on port: " + PORT_HTTP);
Thread.sleep(100); Thread.sleep(100);
logNotice("Privoxy process id=" + privoxyProcId); logNotice("Privoxy process id=" + privoxyProcId);
@ -628,18 +631,18 @@ public class TorService extends Service implements TorServiceConstants, Runnable
{ {
try try
{ {
Log.i(TAG,"Connecting to control port: " + TOR_CONTROL_PORT); Log.d(TAG,"Connecting to control port: " + TOR_CONTROL_PORT);
String baseMessage = getString(R.string.tor_process_connecting); String baseMessage = getString(R.string.tor_process_connecting);
sendCallbackMessage(baseMessage); sendCallbackStatusMessage(baseMessage);
Socket s = new Socket(IP_LOCALHOST, TOR_CONTROL_PORT); Socket s = new Socket(IP_LOCALHOST, TOR_CONTROL_PORT);
conn = TorControlConnection.getConnection(s); conn = TorControlConnection.getConnection(s);
// conn.authenticate(new byte[0]); // See section 3.2 // conn.authenticate(new byte[0]); // See section 3.2
sendCallbackMessage(getString(R.string.tor_process_connecting_step2)); sendCallbackStatusMessage(getString(R.string.tor_process_connecting_step2));
Log.i(TAG,"SUCCESS connected to control port"); Log.d(TAG,"SUCCESS connected to control port");
String torAuthCookie = appHome + "data/control_auth_cookie"; String torAuthCookie = appHome + "data/control_auth_cookie";
@ -648,9 +651,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable
new FileInputStream(new File(torAuthCookie)).read(cookie); new FileInputStream(new File(torAuthCookie)).read(cookie);
conn.authenticate(cookie); conn.authenticate(cookie);
Log.i(TAG,"SUCCESS authenticated to control port"); Log.d(TAG,"SUCCESS authenticated to control port");
sendCallbackMessage(getString(R.string.tor_process_connecting_step2) + getString(R.string.tor_process_connecting_step3)); sendCallbackStatusMessage(getString(R.string.tor_process_connecting_step2) + getString(R.string.tor_process_connecting_step3));
addEventHandler(); addEventHandler();
@ -662,9 +665,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable
catch (Exception ce) catch (Exception ce)
{ {
conn = null; conn = null;
Log.i(TAG,"Attempt: Error connecting to control port: " + ce.getLocalizedMessage(),ce); Log.d(TAG,"Attempt: Error connecting to control port: " + ce.getLocalizedMessage(),ce);
sendCallbackMessage(getString(R.string.tor_process_connecting_step4)); sendCallbackStatusMessage(getString(R.string.tor_process_connecting_step4));
Thread.sleep(1000); Thread.sleep(1000);
@ -695,20 +698,20 @@ public class TorService extends Service implements TorServiceConstants, Runnable
// "status/bootstrap-phase", "status","version"})); // "status/bootstrap-phase", "status","version"}));
String bsPhase = conn.getInfo("status/bootstrap-phase"); String bsPhase = conn.getInfo("status/bootstrap-phase");
Log.i(TAG, "bootstrap-phase: " + bsPhase); Log.d(TAG, "bootstrap-phase: " + bsPhase);
} }
else else
{ {
// String status = conn.getInfo("status/circuit-established"); // String status = conn.getInfo("status/circuit-established");
// Log.i(TAG, "status/circuit-established=" + status); // Log.d(TAG, "status/circuit-established=" + status);
} }
} }
} }
catch (Exception e) catch (Exception e)
{ {
Log.i(TAG, "Unable to get Tor status from control port"); Log.d(TAG, "Unable to get Tor status from control port");
currentStatus = STATUS_UNAVAILABLE; currentStatus = STATUS_UNAVAILABLE;
} }
@ -720,7 +723,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
// We extend NullEventHandler so that we don't need to provide empty // We extend NullEventHandler so that we don't need to provide empty
// implementations for all the events we don't care about. // implementations for all the events we don't care about.
// ... // ...
Log.i(TAG,"adding control port event handler"); Log.d(TAG,"adding control port event handler");
conn.setEventHandler(this); conn.setEventHandler(this);
@ -729,7 +732,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
// conn.setEvents(Arrays.asList(new String[]{ // conn.setEvents(Arrays.asList(new String[]{
// "DEBUG", "INFO", "NOTICE", "WARN", "ERR"})); // "DEBUG", "INFO", "NOTICE", "WARN", "ERR"}));
Log.i(TAG,"SUCCESS added control port event handler"); Log.d(TAG,"SUCCESS added control port event handler");
@ -762,7 +765,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
if (profile == PROFILE_ON) if (profile == PROFILE_ON)
{ {
currentStatus = STATUS_CONNECTING; currentStatus = STATUS_CONNECTING;
sendCallbackMessage ("starting..."); sendCallbackStatusMessage ("starting...");
new Thread(_torInstance).start(); new Thread(_torInstance).start();
@ -770,7 +773,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
else else
{ {
currentStatus = STATUS_OFF; currentStatus = STATUS_OFF;
sendCallbackMessage ("shutting down..."); sendCallbackStatusMessage ("shutting down...");
_torInstance.stopTor(); _torInstance.stopTor();
@ -781,7 +784,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
public void message(String severity, String msg) { public void message(String severity, String msg) {
Log.i(TAG, "[Tor Control Port] " + severity + ": " + msg); Log.d(TAG, "[Tor Control Port] " + severity + ": " + msg);
if (msg.indexOf(TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE)!=-1) if (msg.indexOf(TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE)!=-1)
{ {
@ -790,8 +793,8 @@ public class TorService extends Service implements TorServiceConstants, Runnable
} }
sendCallbackMessage (msg); sendCallbackStatusMessage (msg);
} }
private void showAlert(String title, String msg) private void showAlert(String title, String msg)
@ -849,7 +852,6 @@ public class TorService extends Service implements TorServiceConstants, Runnable
} }
public void bandwidthUsed(long read, long written) { public void bandwidthUsed(long read, long written) {
sendCallbackMessage ("bandwidth used: read=" + read + " written=" + written);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("Bandwidth used: "); sb.append("Bandwidth used: ");
@ -864,6 +866,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
public void circuitStatus(String status, String circID, String path) { public void circuitStatus(String status, String circID, String path) {
/*
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("Circuit ("); sb.append("Circuit (");
sb.append((circID)); sb.append((circID));
@ -873,7 +876,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
sb.append(path); sb.append(path);
logNotice(sb.toString()); logNotice(sb.toString());
*/
} }
@ -894,7 +897,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
} }
catch (Exception e) catch (Exception e)
{ {
Log.i(TAG,"Unable to check for Tor binaries",e); Log.d(TAG,"Unable to check for Tor binaries",e);
return null; return null;
} }
} }
@ -948,7 +951,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
} }
catch (Exception e) catch (Exception e)
{ {
Log.i(TAG, "error enabling transproxy",e); Log.d(TAG, "error enabling transproxy",e);
return false; return false;
} }
@ -1045,8 +1048,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable
private ArrayList<String> callbackBuffer = new ArrayList<String>(); private ArrayList<String> callbackBuffer = new ArrayList<String>();
private void sendCallbackMessage (String newStatus) private void sendCallbackStatusMessage (String newStatus)
{ {
sendCallbackLogMessage (newStatus); //we want everything to go to the log!
// Broadcast to all clients the new value. // Broadcast to all clients the new value.
final int N = mCallbacks.beginBroadcast(); final int N = mCallbacks.beginBroadcast();
@ -1082,6 +1086,43 @@ public class TorService extends Service implements TorServiceConstants, Runnable
mCallbacks.finishBroadcast(); mCallbacks.finishBroadcast();
} }
private void sendCallbackLogMessage (String logMessage)
{
// Broadcast to all clients the new value.
final int N = mCallbacks.beginBroadcast();
callbackBuffer.add(logMessage);
if (N > 0)
{
Iterator<String> it = callbackBuffer.iterator();
String status = null;
while (it.hasNext())
{
status = it.next();
for (int i=0; i<N; i++) {
try {
mCallbacks.getBroadcastItem(i).logMessage(status);
} catch (RemoteException e) {
// The RemoteCallbackList will take care of removing
// the dead object for us.
}
}
}
callbackBuffer.clear();
}
mCallbacks.finishBroadcast();
}
private void applyPreferences () throws RemoteException private void applyPreferences () throws RemoteException
{ {

View File

@ -4,7 +4,7 @@ package org.torproject.android.service;
public interface TorServiceConstants { public interface TorServiceConstants {
public final static String TAG = "TOR_SERVICE"; public final static String TAG = "ORBOT";
public final static String TOR_APP_USERNAME = "org.torproject.android"; public final static String TOR_APP_USERNAME = "org.torproject.android";

View File

@ -5,26 +5,13 @@ package org.torproject.android.service;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.torproject.android.TorifiedApp;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.util.Log; import android.util.Log;
public class TorServiceUtils implements TorServiceConstants { public class TorServiceUtils implements TorServiceConstants {
private final static String PREFS_KEY = "OrbotPrefs";
private final static String PREFS_KEY_TORIFIED = "PrefTord";
public static int findProcessId(String command) public static int findProcessId(String command)
{ {
@ -125,7 +112,7 @@ public class TorServiceUtils implements TorServiceConstants {
public static int doShellCommand(String[] cmds, StringBuilder log, boolean runAsRoot, boolean waitFor) throws Exception public static int doShellCommand(String[] cmds, StringBuilder log, boolean runAsRoot, boolean waitFor) throws Exception
{ {
Log.i(TAG,"executing shell cmds: " + cmds[0] + "; runAsRoot=" + runAsRoot); Log.d(TAG,"executing shell cmds: " + cmds[0] + "; runAsRoot=" + runAsRoot);
Process proc = null; Process proc = null;
@ -176,7 +163,7 @@ public class TorServiceUtils implements TorServiceConstants {
log.append(exitCode); log.append(exitCode);
log.append("\n"); log.append("\n");
Log.i(TAG,"command process exit value: " + exitCode); Log.d(TAG,"command process exit value: " + exitCode);
} }

View File

@ -1,7 +1,5 @@
package org.torproject.android.service; package org.torproject.android.service;
import java.io.File;
import org.torproject.android.TorifiedApp; import org.torproject.android.TorifiedApp;
import android.content.Context; import android.content.Context;
@ -9,17 +7,19 @@ import android.util.Log;
public class TorTransProxy { public class TorTransProxy {
private final static String TAG = "TorTransProxy"; private final static String TAG = TorServiceConstants.TAG;
private static String BASE_DIR = "/data/data/" + TorServiceConstants.TOR_APP_USERNAME + "/";
//private static String BASE_DIR = "/data/data/" + TorServiceConstants.TOR_APP_USERNAME + "/";
/*
private final static String CMD_NAT_FLUSH = "iptables -t nat -F || exit\n"; private final static String CMD_NAT_FLUSH = "iptables -t nat -F || exit\n";
private final static String CMD_FILTER_FLUSH = "iptables -t filter -F || exit\n"; private final static String CMD_FILTER_FLUSH = "iptables -t filter -F || exit\n";
private final static String CMD_DNS_PROXYING_ADD = "iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to 127.0.0.1:5400 || exit\n"; private final static String CMD_DNS_PROXYING_ADD = "iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to 127.0.0.1:5400 || exit\n";
private final static String IPTABLES_ADD = " -A "; private final static String IPTABLES_ADD = " -A ";
*/
//private final static String CMD_DNS_PROXYING_DELETE = "iptables -t nat -D PREROUTING -p udp --dport 53 -j DNAT --to 127.0.0.1:5400 || exit\n"; //private final static String CMD_DNS_PROXYING_DELETE = "iptables -t nat -D PREROUTING -p udp --dport 53 -j DNAT --to 127.0.0.1:5400 || exit\n";
// - just calling a system wide flush of iptables rules // - just calling a system wide flush of iptables rules
@ -65,7 +65,10 @@ public class TorTransProxy {
// Run an empty script just to check root access // Run an empty script just to check root access
String[] cmd = {"iptables -v"}; String[] cmd = {"iptables -v"};
int exitCode = TorServiceUtils.doShellCommand(cmd, log, true, true); int code = TorServiceUtils.doShellCommand(cmd, log, true, true);
String msg = log.toString();
Log.d(TAG,cmd[0] + ";errCode=" + code + ";resp=" + msg);
String out = log.toString(); String out = log.toString();
if (out.indexOf(" v")!=-1) if (out.indexOf(" v")!=-1)
@ -86,8 +89,11 @@ public class TorTransProxy {
return null; return null;
} }
private static String findBaseDir () private static String findBaseDir ()
{ {
return ""; //just blank for now
/* /*
String[] cmds = {"/system/bin/iptables -t nat --list"}; String[] cmds = {"/system/bin/iptables -t nat --list"};
StringBuilder res = new StringBuilder(); StringBuilder res = new StringBuilder();
@ -105,12 +111,14 @@ public class TorTransProxy {
} catch (Exception e) { } catch (Exception e) {
return BASE_DIR; return BASE_DIR;
}*/ }
return ""; return "";
*/
} }
/* /*
public static int setDNSProxying () throws Exception public static int setDNSProxying () throws Exception
{ {
@ -149,7 +157,6 @@ public class TorTransProxy {
String baseDir = findBaseDir(); String baseDir = findBaseDir();
final StringBuilder script = new StringBuilder(); final StringBuilder script = new StringBuilder();
StringBuilder res = new StringBuilder(); StringBuilder res = new StringBuilder();
@ -170,13 +177,10 @@ public class TorTransProxy {
} }
String[] cmd = {script.toString()}; String[] cmd = {script.toString()};
Log.i(TAG, cmd[0]); code = TorServiceUtils.doShellCommand(cmd, res, true, true);
code = TorServiceUtils.doShellCommand(cmd, res, true, true);
String msg = res.toString(); String msg = res.toString();
Log.i(TAG, msg); Log.d(TAG,cmd[0] + ";errCode=" + code + ";resp=" + msg);
return code; return code;
@ -208,11 +212,13 @@ public class TorTransProxy {
public static int setTransparentProxyingByApp(Context context, TorifiedApp[] apps, boolean forceAll) throws Exception public static int setTransparentProxyingByApp(Context context, TorifiedApp[] apps, boolean forceAll) throws Exception
{ {
android.os.Debug.waitForDebugger();
String baseDir = findBaseDir(); String baseDir = findBaseDir();
String iptablesVersion = getIPTablesVersion(); String iptablesVersion = getIPTablesVersion();
Log.i(TAG, "iptables version: " + iptablesVersion); Log.d(TAG, "iptables version: " + iptablesVersion);
boolean ipTablesOld = false; boolean ipTablesOld = false;
if (iptablesVersion != null && iptablesVersion.startsWith("1.3")){ if (iptablesVersion != null && iptablesVersion.startsWith("1.3")){
@ -239,38 +245,33 @@ public class TorTransProxy {
} }
String[] cmdFlush = {script.toString()}; String[] cmdFlush = {script.toString()};
Log.i(TAG, cmdFlush[0]);
code = TorServiceUtils.doShellCommand(cmdFlush, res, true, true); code = TorServiceUtils.doShellCommand(cmdFlush, res, true, true);
//String msg = res.toString(); //get stdout from command
String msg = res.toString();
Log.i(TAG, msg);
script = new StringBuilder(); script = new StringBuilder();
//build up array of shell cmds to execute under one root context
for (int i = 0; i < apps.length; i++) for (int i = 0; i < apps.length; i++)
{ {
if (forceAll || apps[i].isTorified()) if (forceAll || apps[i].isTorified()) //if "Tor Everything" on or app is set to true
{ {
if (apps[i].getUsername().equals(TorServiceConstants.TOR_APP_USERNAME)) if (apps[i].getUsername().equals(TorServiceConstants.TOR_APP_USERNAME))
{ {
Log.i(TAG,"detected Orbot app - will not transproxy"); //should never trans proxy the Orbot app (and Tor or Privoxy) itself
continue; continue;
} }
Log.i(TAG,"enabling transproxy for app: " + apps[i].getUsername() + "(" + apps[i].getUid() + ")"); Log.d(TAG,"enabling transproxy for app: " + apps[i].getUsername() + "(" + apps[i].getUid() + ")");
//TCP //TCP
script.append(baseDir); script.append(baseDir);
script.append("iptables -t nat"); script.append("iptables -t nat");
script.append(" -A OUTPUT -p tcp --syn"); script.append(" -A OUTPUT -p tcp");
script.append(" -m owner --uid-owner "); script.append(" -m owner --uid-owner ");
script.append(apps[i].getUid()); script.append(apps[i].getUid());
script.append(" -m tcp "); script.append(" -m tcp --syn");
if (ipTablesOld) if (ipTablesOld)
script.append(" -j DNAT --to 127.0.0.1:9040"); script.append(" -j DNAT --to 127.0.0.1:9040");
@ -284,15 +285,15 @@ public class TorTransProxy {
script.append("iptables -t nat"); script.append("iptables -t nat");
script.append(" -A OUTPUT -p udp -m owner --uid-owner "); script.append(" -A OUTPUT -p udp -m owner --uid-owner ");
script.append(apps[i].getUid()); script.append(apps[i].getUid());
script.append(" -m udp --dport 53"); script.append(" --dport 53"); //drop all UDP packets as Tor won't handle them
if (ipTablesOld) if (ipTablesOld)
script.append(" -j DNAT --to 127.0.0.1:5400"); script.append(" -j DNAT --to 127.0.0.1:9040");
else else
script.append(" -j REDIRECT --to-ports 5400"); script.append(" -j REDIRECT --to-ports 9040");
script.append(" || exit\n"); script.append(" || exit\n");
//EVERYTHING ELSE UDP - DROP! //EVERYTHING ELSE UDP - DROP!
if (!ipTablesOld) //for some reason this doesn't work on iptables 1.3.7 if (!ipTablesOld) //for some reason this doesn't work on iptables 1.3.7
{ {
@ -309,14 +310,10 @@ public class TorTransProxy {
} }
String[] cmdAdd = {script.toString()}; String[] cmdAdd = {script.toString()};
Log.i(TAG, cmdAdd[0]);
code = TorServiceUtils.doShellCommand(cmdAdd, res, true, true); code = TorServiceUtils.doShellCommand(cmdAdd, res, true, true);
String msg = res.toString();
msg = res.toString(); Log.d(TAG,cmdAdd[0] + ";errCode=" + code + ";resp=" + msg);
Log.i(TAG, msg);
return code; return code;
} }
@ -334,7 +331,7 @@ public class TorTransProxy {
for (int i = 0; i < ports.length; i++) for (int i = 0; i < ports.length; i++)
{ {
Log.i(TAG,"enabling transproxy for port: " + ports[i]); Log.d(TAG,"enabling transproxy for port: " + ports[i]);
//TCP //TCP
@ -358,14 +355,12 @@ public class TorTransProxy {
StringBuilder res = new StringBuilder(); StringBuilder res = new StringBuilder();
String[] cmd = {script.toString()}; String[] cmd = {script.toString()};
Log.i(TAG, cmd[0]);
code = TorServiceUtils.doShellCommand(cmd, res, true, true); code = TorServiceUtils.doShellCommand(cmd, res, true, true);
String msg = res.toString();
Log.d(TAG,cmd[0] + ";errCode=" + code + ";resp=" + msg);
String msg = res.toString();
Log.e(TAG, msg);
} catch (Exception e) { } catch (Exception e) {
Log.w(TAG, "error refreshing iptables: " + e); Log.w(TAG, "error refreshing iptables: " + e);
} }