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"?>
<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" />
<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"
android:theme="@android:style/Theme.NoTitleBar"
>
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
@ -34,7 +33,8 @@
<activity android:name=".AppManager" 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>
<action android:name="org.torproject.android.service.ITorService" />
<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/
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
- Added "Proxy Settings" help screen
- 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
SafeSocks 1
Log notice stdout
##Log debug syslog
DataDirectory /data/data/org.torproject.android/data
ControlPort 9051
CookieAuthentication 1

View File

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

View File

@ -35,6 +35,9 @@
<string name="button_close">Close</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.
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() {
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);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e(TAG, "error accessing hidden service", e);
}
@ -478,6 +477,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
txtMessageLog.setClickable(true);
txtMessageLog.setText(logBuffer.toString());
}
@ -684,7 +684,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
String onionHostname = Utils.readString(new FileInputStream(file));
return onionHostname.trim();
} 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;
}
}
@ -820,6 +820,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
Message msg = mHandler.obtainMessage(ENABLE_TOR_MSG);
mHandler.sendMessage(msg);
logBuffer = new StringBuffer();
}
private void stopTor () throws RemoteException
@ -862,7 +863,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
}
catch (Exception e)
{
Log.i(TAG,"error onclick",e);
Log.d(TAG,"error onclick",e);
}
return super.onTouchEvent(event);
@ -900,7 +901,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
}
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');
if (torServiceMsg.length() > 0 && torServiceMsg.charAt(0)!='>')
if (torServiceMsg.length() > 0)
updateStatus(torServiceMsg);
break;
@ -965,6 +966,10 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
logBuffer.append(torLogMsg);
logBuffer.append('\n');
if (txtMessageLog != null)
{
txtMessageLog.append(torLogMsg + '\n');
}
break;
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
// disconnected (and then reconnected if it can be restarted)
// 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() {
super.onStop();
//Log.i(getClass().getName(),"Exiting Preferences");
//Log.d(getClass().getName(),"Exiting Preferences");
}
@Override

View File

@ -84,7 +84,7 @@ public class Utils {
return true;
} catch (IOException e) {
// Log.i(TAG, "error writing file: " + path, e);
// Log.d(TAG, "error writing file: " + path, e);
e.printStackTrace();
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.HttpParams;
import android.util.Log;
/**
@ -255,8 +253,6 @@ public class ModSSLSocketFactory implements LayeredSocketFactory {
this.socketfactory = SSLSocketFactory.getSocketFactory();
//this.nameResolver = null;
//Log.i("TOR_SERVICE","ModSSLSocketFactory: proxied via " + host + ":" + port);
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);
Log.i("TOR_SERVICE","creating SSL Socket");
// SSLSocket sslsock = (SSLSocket) socketfactory.connectSocket(sSocket, host, port, localAddress, localPort, params);
SSLSocket sslsock = (SSLSocket)socketfactory.createSocket(sSocket, host, port, true);
Log.i("TOR_SERVICE","created SSL Socket!");
if ((localAddress != null) || (localPort > 0)) {
// we need to bind explicitly
@ -343,8 +334,6 @@ public class ModSSLSocketFactory implements LayeredSocketFactory {
InetSocketAddress isa =
new InetSocketAddress(localAddress, localPort);
Log.i("TOR_SERVICE","binding SSL Socket!");
sslsock.bind(isa);
}

View File

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

View File

@ -65,7 +65,7 @@ public class SocksSocketFactory implements SocketFactory {
sProxy = new Socks5Proxy(proxyaddress, proxyport);
} catch (UnknownHostException e) {
// 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);
@ -77,7 +77,7 @@ public class SocksSocketFactory implements SocketFactory {
InetAddress localAddress, int localPort, HttpParams params) throws IOException,
UnknownHostException, ConnectTimeoutException {
Log.i("TOR_SERVICE","SocksSocketFactory: connectSocket: " + host + ":" + port);
Log.d("TOR_SERVICE","SocksSocketFactory: connectSocket: " + host + ":" + port);
if (host == 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();
Log.i(TAG,"Tor binary exists=" + torBinaryExists);
Log.d(TAG,"Tor binary exists=" + torBinaryExists);
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)
installFromZip ();
@ -72,12 +72,12 @@ public class TorBinaryInstaller implements TorServiceConstants {
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)
{
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;
}
@ -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;

View File

@ -51,6 +51,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
private ArrayList<String> configBuffer = null;
private boolean isBound = false;
private String appHome = null;
private String torBinaryPath = null;
@ -60,7 +61,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
public void 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)
{
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 {
currentStatus = STATUS_CONNECTING;
@ -87,12 +88,12 @@ public class TorService extends Service implements TorServiceConstants, Runnable
return true;
} 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;
this.stopTor();
} 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;
this.stopTor();
@ -110,7 +111,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
public void 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) {
Log.i(TAG, "onUnbind Called: " + intent.getAction());
Log.d(TAG, "onUnbind Called: " + intent.getAction());
isBound = false;
return super.onUnbind(intent);
@ -138,6 +140,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
private void showToolbarNotification (String notifyMsg, int icon)
{
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
@ -168,7 +171,8 @@ public class TorService extends Service implements TorServiceConstants, Runnable
public void onRebind(Intent 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;
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();
Log.i(TAG,"onDestroy called");
Log.d(TAG,"onDestroy called");
stopTor();
}
@ -220,7 +224,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
currentStatus = STATUS_OFF;
sendCallbackMessage("Web proxy shutdown");
sendCallbackLogMessage("Web proxy shutdown");
try
{
@ -230,15 +234,15 @@ public class TorService extends Service implements TorServiceConstants, Runnable
showToolbarNotification (getString(R.string.status_disabled),R.drawable.tornotificationoff);
sendCallbackMessage(getString(R.string.status_disabled));
sendCallbackStatusMessage(getString(R.string.status_disabled));
setupTransProxy(false);
}
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());
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)
{
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.signal("SHUTDOWN");
} 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;
}
@ -301,7 +305,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
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 + "" };
TorServiceUtils.doShellCommand(cmd,log, false, false);
@ -314,9 +318,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable
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;
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);
@ -342,7 +346,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
buildPath = apkBase + TOR_APP_USERNAME + '-' + i + APK_EXT;
fileApk = new File(buildPath);
Log.i(TAG, "Checking APK location: " + buildPath);
Log.d(TAG, "Checking APK location: " + buildPath);
if (fileApk.exists())
return fileApk.getAbsolutePath();
@ -354,7 +358,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
buildPath = apkBaseExt + pkgFile;
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())
return fileApk.getAbsolutePath();
@ -364,7 +368,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
buildPath = apkBaseExt + '-' + i + pkgFile;
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())
return fileApk.getAbsolutePath();
@ -376,19 +380,18 @@ public class TorService extends Service implements TorServiceConstants, Runnable
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 = "/data/data/" + TOR_APP_USERNAME + "/";
Log.i(TAG,"appHome=" + appHome);
Log.d(TAG,"appHome=" + appHome);
String apkPath = findAPK();
Log.i(TAG,"found apk at: " + apkPath);
Log.d(TAG,"found apk at: " + apkPath);
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));
sendCallbackMessage(getString(R.string.status_install_fail));
sendCallbackStatusMessage(getString(R.string.status_install_fail));
return false;
}
@ -458,16 +461,13 @@ public class TorService extends Service implements TorServiceConstants, Runnable
public void initTor () throws Exception
{
// android.os.Debug.waitForDebugger();
currentStatus = STATUS_CONNECTING;
logNotice(getString(R.string.status_starting_up));
sendCallbackMessage(getString(R.string.status_starting_up));
sendCallbackStatusMessage(getString(R.string.status_starting_up));
killTorProcess ();
@ -484,8 +484,8 @@ public class TorService extends Service implements TorServiceConstants, Runnable
} catch (Exception e) {
currentStatus = STATUS_OFF;
Log.i(TAG,"Unable to start Privoxy: " + e.getMessage(),e);
sendCallbackMessage("Unable to start Privoxy: " + e.getMessage());
Log.d(TAG,"Unable to start Privoxy: " + e.getMessage(),e);
sendCallbackLogMessage("Unable to start Privoxy: " + e.getMessage());
}
}
@ -501,8 +501,8 @@ public class TorService extends Service implements TorServiceConstants, Runnable
setupTransProxy(true);
} catch (Exception e) {
Log.i(TAG,"Unable to start Tor: " + e.getMessage(),e);
sendCallbackMessage("Unable to start Tor: " + e.getMessage());
Log.d(TAG,"Unable to start Tor: " + e.getMessage(),e);
sendCallbackStatusMessage("Unable to start Tor: " + e.getMessage());
stopTor();
}
}
@ -513,15 +513,18 @@ public class TorService extends Service implements TorServiceConstants, Runnable
private void runTorShellCmd() throws Exception
{
StringBuilder log = new StringBuilder();
Log.i(TAG,"Starting tor process");
String torrcPath = appHome + TORRC_ASSET_KEY;
String[] torCmd = {torBinaryPath + " -f " + torrcPath + " || exit\n"};
TorServiceUtils.doShellCommand(torCmd, log, false, false);
Log.d(TAG,"Starting tor process: " + torCmd[0]);
Thread.sleep(1000);
int procId = TorServiceUtils.findProcessId(torBinaryPath);
@ -538,9 +541,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable
if (procId == -1)
{
sendCallbackMessage("Couldn't start Tor process...\n" + log.toString());
sendCallbackStatusMessage("Couldn't start Tor process...\n" + log.toString());
Thread.sleep(1000);
sendCallbackMessage(getString(R.string.status_starting_up));
sendCallbackStatusMessage(getString(R.string.status_starting_up));
Thread.sleep(3000);
attempts++;
}
@ -566,7 +569,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
private void runPrivoxyShellCmd () throws Exception
{
Log.i(TAG,"Starting privoxy process");
Log.d(TAG,"Starting privoxy process");
int privoxyProcId = TorServiceUtils.findProcessId(privoxyPath);
@ -602,7 +605,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
logNotice(log.toString());
}
sendCallbackMessage("Privoxy is running on port: " + PORT_HTTP);
sendCallbackLogMessage("Privoxy is running on port: " + PORT_HTTP);
Thread.sleep(100);
logNotice("Privoxy process id=" + privoxyProcId);
@ -628,18 +631,18 @@ public class TorService extends Service implements TorServiceConstants, Runnable
{
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);
sendCallbackMessage(baseMessage);
sendCallbackStatusMessage(baseMessage);
Socket s = new Socket(IP_LOCALHOST, TOR_CONTROL_PORT);
conn = TorControlConnection.getConnection(s);
// 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";
@ -648,9 +651,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable
new FileInputStream(new File(torAuthCookie)).read(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();
@ -662,9 +665,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable
catch (Exception ce)
{
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);
@ -695,20 +698,20 @@ public class TorService extends Service implements TorServiceConstants, Runnable
// "status/bootstrap-phase", "status","version"}));
String bsPhase = conn.getInfo("status/bootstrap-phase");
Log.i(TAG, "bootstrap-phase: " + bsPhase);
Log.d(TAG, "bootstrap-phase: " + bsPhase);
}
else
{
// String status = conn.getInfo("status/circuit-established");
// Log.i(TAG, "status/circuit-established=" + status);
// Log.d(TAG, "status/circuit-established=" + status);
}
}
}
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;
}
@ -720,7 +723,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
// We extend NullEventHandler so that we don't need to provide empty
// 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);
@ -729,7 +732,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
// conn.setEvents(Arrays.asList(new String[]{
// "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)
{
currentStatus = STATUS_CONNECTING;
sendCallbackMessage ("starting...");
sendCallbackStatusMessage ("starting...");
new Thread(_torInstance).start();
@ -770,7 +773,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
else
{
currentStatus = STATUS_OFF;
sendCallbackMessage ("shutting down...");
sendCallbackStatusMessage ("shutting down...");
_torInstance.stopTor();
@ -781,7 +784,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
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)
{
@ -790,8 +793,8 @@ public class TorService extends Service implements TorServiceConstants, Runnable
}
sendCallbackMessage (msg);
sendCallbackStatusMessage (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) {
sendCallbackMessage ("bandwidth used: read=" + read + " written=" + written);
StringBuilder sb = new StringBuilder();
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) {
/*
StringBuilder sb = new StringBuilder();
sb.append("Circuit (");
sb.append((circID));
@ -873,7 +876,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
sb.append(path);
logNotice(sb.toString());
*/
}
@ -894,7 +897,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
}
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;
}
}
@ -948,7 +951,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
}
catch (Exception e)
{
Log.i(TAG, "error enabling transproxy",e);
Log.d(TAG, "error enabling transproxy",e);
return false;
}
@ -1045,8 +1048,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable
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.
final int N = mCallbacks.beginBroadcast();
@ -1082,6 +1086,43 @@ public class TorService extends Service implements TorServiceConstants, Runnable
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
{

View File

@ -4,7 +4,7 @@ package org.torproject.android.service;
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";

View File

@ -5,26 +5,13 @@ package org.torproject.android.service;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
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;
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)
{
@ -125,7 +112,7 @@ public class TorServiceUtils implements TorServiceConstants {
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;
@ -176,7 +163,7 @@ public class TorServiceUtils implements TorServiceConstants {
log.append(exitCode);
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;
import java.io.File;
import org.torproject.android.TorifiedApp;
import android.content.Context;
@ -9,17 +7,19 @@ import android.util.Log;
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_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 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";
// - 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
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();
if (out.indexOf(" v")!=-1)
@ -86,8 +89,11 @@ public class TorTransProxy {
return null;
}
private static String findBaseDir ()
{
return ""; //just blank for now
/*
String[] cmds = {"/system/bin/iptables -t nat --list"};
StringBuilder res = new StringBuilder();
@ -105,12 +111,14 @@ public class TorTransProxy {
} catch (Exception e) {
return BASE_DIR;
}*/
}
return "";
*/
}
/*
public static int setDNSProxying () throws Exception
{
@ -149,7 +157,6 @@ public class TorTransProxy {
String baseDir = findBaseDir();
final StringBuilder script = new StringBuilder();
StringBuilder res = new StringBuilder();
@ -170,13 +177,10 @@ public class TorTransProxy {
}
String[] cmd = {script.toString()};
Log.i(TAG, cmd[0]);
code = TorServiceUtils.doShellCommand(cmd, res, true, true);
String[] cmd = {script.toString()};
code = TorServiceUtils.doShellCommand(cmd, res, true, true);
String msg = res.toString();
Log.i(TAG, msg);
Log.d(TAG,cmd[0] + ";errCode=" + code + ";resp=" + msg);
return code;
@ -208,11 +212,13 @@ public class TorTransProxy {
public static int setTransparentProxyingByApp(Context context, TorifiedApp[] apps, boolean forceAll) throws Exception
{
android.os.Debug.waitForDebugger();
String baseDir = findBaseDir();
String iptablesVersion = getIPTablesVersion();
Log.i(TAG, "iptables version: " + iptablesVersion);
Log.d(TAG, "iptables version: " + iptablesVersion);
boolean ipTablesOld = false;
if (iptablesVersion != null && iptablesVersion.startsWith("1.3")){
@ -239,38 +245,33 @@ public class TorTransProxy {
}
String[] cmdFlush = {script.toString()};
Log.i(TAG, cmdFlush[0]);
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();
//build up array of shell cmds to execute under one root context
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))
{
Log.i(TAG,"detected Orbot app - will not transproxy");
//should never trans proxy the Orbot app (and Tor or Privoxy) itself
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
script.append(baseDir);
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(apps[i].getUid());
script.append(" -m tcp ");
script.append(" -m tcp --syn");
if (ipTablesOld)
script.append(" -j DNAT --to 127.0.0.1:9040");
@ -284,15 +285,15 @@ public class TorTransProxy {
script.append("iptables -t nat");
script.append(" -A OUTPUT -p udp -m owner --uid-owner ");
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)
script.append(" -j DNAT --to 127.0.0.1:5400");
script.append(" -j DNAT --to 127.0.0.1:9040");
else
script.append(" -j REDIRECT --to-ports 5400");
script.append(" -j REDIRECT --to-ports 9040");
script.append(" || exit\n");
//EVERYTHING ELSE UDP - DROP!
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()};
Log.i(TAG, cmdAdd[0]);
String[] cmdAdd = {script.toString()};
code = TorServiceUtils.doShellCommand(cmdAdd, res, true, true);
msg = res.toString();
Log.i(TAG, msg);
String msg = res.toString();
Log.d(TAG,cmdAdd[0] + ";errCode=" + code + ";resp=" + msg);
return code;
}
@ -334,7 +331,7 @@ public class TorTransProxy {
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
@ -358,14 +355,12 @@ public class TorTransProxy {
StringBuilder res = new StringBuilder();
String[] cmd = {script.toString()};
Log.i(TAG, cmd[0]);
String[] cmd = {script.toString()};
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) {
Log.w(TAG, "error refreshing iptables: " + e);
}