fixes geoip settings, and other small server config changes

This commit is contained in:
Nathan Freitas 2011-10-28 00:29:57 -04:00
parent e86e1d92f2
commit a2d41e4f79
5 changed files with 67 additions and 104 deletions

View File

@ -13,6 +13,7 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import org.torproject.android.R; import org.torproject.android.R;
import org.torproject.android.TorConstants;
import android.content.Context; import android.content.Context;
import android.util.Log; import android.util.Log;
@ -34,43 +35,34 @@ public class TorBinaryInstaller implements TorServiceConstants {
/* /*
* Extract the Tor binary from the APK file using ZIP * Extract the Tor binary from the APK file using ZIP
*/ */
public boolean installFromRaw () public boolean installFromRaw () throws IOException
{ {
boolean result = false;
InputStream is;
try
{
InputStream is;
is = context.getResources().openRawResource(R.raw.toraa);
streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, false);
is = context.getResources().openRawResource(R.raw.torab); is = context.getResources().openRawResource(R.raw.toraa);
streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, true); streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, false);
is = context.getResources().openRawResource(R.raw.torac);
streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, true);
is = context.getResources().openRawResource(R.raw.torad);
streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, true);
is = context.getResources().openRawResource(R.raw.torrc);
streamToFile(is,installFolder, TORRC_ASSET_KEY, false);
is = context.getResources().openRawResource(R.raw.privoxy); is = context.getResources().openRawResource(R.raw.torab);
streamToFile(is,installFolder, PRIVOXY_ASSET_KEY, false); streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, true);
is = context.getResources().openRawResource(R.raw.privoxy_config); is = context.getResources().openRawResource(R.raw.torac);
streamToFile(is,installFolder, PRIVOXYCONFIG_ASSET_KEY, false); streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, true);
is = context.getResources().openRawResource(R.raw.torad);
streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, true);
is = context.getResources().openRawResource(R.raw.torrc);
streamToFile(is,installFolder, TORRC_ASSET_KEY, false);
} is = context.getResources().openRawResource(R.raw.privoxy);
catch (IOException ioe) streamToFile(is,installFolder, PRIVOXY_ASSET_KEY, false);
{
Log.e(TAG, "unable to install tor binaries from raw", ioe); is = context.getResources().openRawResource(R.raw.privoxy_config);
return false; streamToFile(is,installFolder, PRIVOXYCONFIG_ASSET_KEY, false);
}
is = context.getResources().openRawResource(R.raw.geoip);
streamToFile(is,installFolder, GEOIP_ASSET_KEY, false);
return true; return true;
} }
@ -132,7 +124,7 @@ public class TorBinaryInstaller implements TorServiceConstants {
} catch (IOException ex) { } catch (IOException ex) {
Log.e(TAG, "error copying binary", ex); Log.e(TorConstants.TAG, "error copying binary", ex);
} }
} }

View File

@ -17,12 +17,12 @@ import net.freehaven.tor.control.ConfigEntry;
import net.freehaven.tor.control.EventHandler; import net.freehaven.tor.control.EventHandler;
import net.freehaven.tor.control.TorControlConnection; import net.freehaven.tor.control.TorControlConnection;
import org.torproject.android.AppManager;
import org.torproject.android.Orbot; import org.torproject.android.Orbot;
import org.torproject.android.ProcessSettingsAsyncTask;
import org.torproject.android.R; import org.torproject.android.R;
import org.torproject.android.TorConstants; import org.torproject.android.TorConstants;
import org.torproject.android.Utils; import org.torproject.android.Utils;
import org.torproject.android.settings.AppManager;
import org.torproject.android.settings.ProcessSettingsAsyncTask;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Notification; import android.app.Notification;
@ -40,7 +40,7 @@ import android.os.RemoteException;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
public class TorService extends Service implements TorServiceConstants, Runnable, EventHandler public class TorService extends Service implements TorServiceConstants, TorConstants, Runnable, EventHandler
{ {
public static boolean ENABLE_DEBUG_LOG = false; public static boolean ENABLE_DEBUG_LOG = false;
@ -516,24 +516,14 @@ public class TorService extends Service implements TorServiceConstants, Runnable
private boolean setupTransProxy (boolean activate) throws Exception private boolean setupTransProxy (boolean activate) throws Exception
{ {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean hasRoot;
boolean hasRoot = prefs.getBoolean(PREF_HAS_ROOT,false);
if (prefs.contains("has_root"))
{
hasRoot = prefs.getBoolean("has_root",false);
}
else
{
hasRoot = TorServiceUtils.checkRootAccess();
Editor pEdit = prefs.edit();
pEdit.putBoolean("has_root",hasRoot);
pEdit.commit();
}
if (!hasRoot) if (!hasRoot)
return false; {
if (activate) }
else if (activate)
{ {
boolean enableTransparentProxy = prefs.getBoolean("pref_transparent", false); boolean enableTransparentProxy = prefs.getBoolean("pref_transparent", false);
@ -748,7 +738,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
{ {
logNotice( "Connecting to control port: " + TOR_CONTROL_PORT); logNotice( "Connecting to control port: " + TOR_CONTROL_PORT);
String baseMessage = getString(R.string.tor_process_connecting); String baseMessage = getString(R.string.tor_process_starting);
sendCallbackStatusMessage(baseMessage); sendCallbackStatusMessage(baseMessage);
torConnSocket = new Socket(IP_LOCALHOST, TOR_CONTROL_PORT); torConnSocket = new Socket(IP_LOCALHOST, TOR_CONTROL_PORT);
@ -756,7 +746,6 @@ public class TorService extends Service implements TorServiceConstants, Runnable
// conn.authenticate(new byte[0]); // See section 3.2 // conn.authenticate(new byte[0]); // See section 3.2
sendCallbackStatusMessage(getString(R.string.tor_process_connecting_step2));
logNotice( "SUCCESS connected to control port"); logNotice( "SUCCESS connected to control port");
@ -772,7 +761,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
logNotice( "SUCCESS authenticated to control port"); logNotice( "SUCCESS authenticated to control port");
sendCallbackStatusMessage(getString(R.string.tor_process_connecting_step2) + getString(R.string.tor_process_connecting_step3)); sendCallbackStatusMessage(getString(R.string.tor_process_starting) + ' ' + getString(R.string.tor_process_complete));
addEventHandler(); addEventHandler();
@ -785,7 +774,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
conn = null; conn = null;
Log.d(TAG,"Attempt: Error connecting to control port: " + ce.getLocalizedMessage(),ce); Log.d(TAG,"Attempt: Error connecting to control port: " + ce.getLocalizedMessage(),ce);
sendCallbackStatusMessage(getString(R.string.tor_process_connecting_step4)); sendCallbackStatusMessage(getString(R.string.tor_process_waiting));
Thread.sleep(1000); Thread.sleep(1000);
@ -910,14 +899,14 @@ public class TorService extends Service implements TorServiceConstants, Runnable
if (msg.indexOf(TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE)!=-1) if (msg.indexOf(TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE)!=-1)
{ {
currentStatus = STATUS_ON; currentStatus = STATUS_ON;
showToolbarNotification (getString(R.string.status_activated),NOTIFY_ID,R.drawable.tornotificationon);
getHiddenServiceHostname (); getHiddenServiceHostname ();
} }
showToolbarNotification (getString(R.string.status_activated),NOTIFY_ID,R.drawable.tornotificationon);
sendCallbackStatusMessage (msg); sendCallbackStatusMessage (msg);
@ -1273,7 +1262,6 @@ public class TorService extends Service implements TorServiceConstants, Runnable
private boolean applyPreferences () throws RemoteException private boolean applyPreferences () throws RemoteException
{ {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
ENABLE_DEBUG_LOG = prefs.getBoolean("pref_enable_logging",false); ENABLE_DEBUG_LOG = prefs.getBoolean("pref_enable_logging",false);
@ -1284,9 +1272,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
//boolean autoUpdateBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_UPDATED, false); //boolean autoUpdateBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_UPDATED, false);
boolean becomeRelay = prefs.getBoolean(TorConstants.PREF_OR, false); boolean becomeRelay = prefs.getBoolean(TorConstants.PREF_OR, false);
boolean ReachableAddresses = prefs.getBoolean(TorConstants.PREF_REACHABLE_ADDRESSES,false); boolean ReachableAddresses = prefs.getBoolean(TorConstants.PREF_REACHABLE_ADDRESSES,false);
boolean enableHiddenServices = prefs.getBoolean("pref_hs_enable", false); boolean enableHiddenServices = prefs.getBoolean("pref_hs_enable", false);
boolean enableStrictNodes = prefs.getBoolean("pref_strict_nodes", false); boolean enableStrictNodes = prefs.getBoolean("pref_strict_nodes", false);
@ -1294,6 +1280,18 @@ public class TorService extends Service implements TorServiceConstants, Runnable
String exitNodes = prefs.getString("pref_exit_nodes", null); String exitNodes = prefs.getString("pref_exit_nodes", null);
String excludeNodes = prefs.getString("pref_exclude_nodes", null); String excludeNodes = prefs.getString("pref_exclude_nodes", null);
String proxyType = prefs.getString("pref_proxy_type", null);
if (proxyType != null)
{
String proxyHost = prefs.getString("pref_proxy_host", null);
String proxyPort = prefs.getString("pref_proxy_port", null);
if (proxyHost != null && proxyPort != null)
{
mBinder.updateConfiguration(proxyType + "Proxy", proxyHost + ':' + proxyPort, false);
}
}
if (currentStatus == STATUS_ON) if (currentStatus == STATUS_ON)
{ {
//reset iptables rules in active mode //reset iptables rules in active mode
@ -1308,6 +1306,8 @@ public class TorService extends Service implements TorServiceConstants, Runnable
} }
} }
File fileGeoIP = new File(appBinHome,"geoip");
mBinder.updateConfiguration("GeoIPFile", fileGeoIP.getAbsolutePath(), false);
mBinder.updateConfiguration("EntryNodes", entranceNodes, false); mBinder.updateConfiguration("EntryNodes", entranceNodes, false);
mBinder.updateConfiguration("ExitNodes", exitNodes, false); mBinder.updateConfiguration("ExitNodes", exitNodes, false);
mBinder.updateConfiguration("ExcludeNodes", excludeNodes, false); mBinder.updateConfiguration("ExcludeNodes", excludeNodes, false);

View File

@ -4,11 +4,9 @@ package org.torproject.android.service;
public interface TorServiceConstants { public interface TorServiceConstants {
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";
public final static String ASSETS_BASE = "assets/";
//home directory of Android application //home directory of Android application
@ -27,7 +25,10 @@ public interface TorServiceConstants {
//privoxy.config //privoxy.config
public final static String PRIVOXYCONFIG_ASSET_KEY = "privoxy.config"; public final static String PRIVOXYCONFIG_ASSET_KEY = "privoxy.config";
//geoip data file asset key
public final static String GEOIP_ASSET_KEY = "geoip";
//various console cmds //various console cmds
public final static String SHELL_CMD_CHMOD = "chmod"; public final static String SHELL_CMD_CHMOD = "chmod";
public final static String SHELL_CMD_KILL = "kill -9"; public final static String SHELL_CMD_KILL = "kill -9";

View File

@ -9,47 +9,15 @@ import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.torproject.android.TorConstants;
import android.util.Log; import android.util.Log;
public class TorServiceUtils implements TorServiceConstants { public class TorServiceUtils implements TorServiceConstants {
/**
* Check if we have root access
* @return boolean true if we have root
*/
/*
public static boolean checkRootAccess() {
public static boolean isRootPossible()
StringBuilder log = new StringBuilder(); {
try {
// Run an empty script just to check root access
String[] cmd = {"exit 0"};
int exitCode = TorServiceUtils.doShellCommand(cmd, log, true, true);
if (exitCode == 0) {
return true;
}
} catch (IOException e) {
//this means that there is no root to be had (normally) so we won't log anything
TorService.logException("Error checking for root access",e);
}
catch (Exception e) {
TorService.logException("Error checking for root access",e);
//this means that there is no root to be had (normally)
}
TorService.logMessage("Could not acquire root permissions");
return false;
}
*/
public static boolean checkRootAccess(){
StringBuilder log = new StringBuilder(); StringBuilder log = new StringBuilder();
@ -79,6 +47,8 @@ public class TorServiceUtils implements TorServiceConstants {
} }
TorService.logMessage("Could not acquire root permissions"); TorService.logMessage("Could not acquire root permissions");
return false; return false;
} }
@ -102,7 +72,7 @@ public class TorServiceUtils implements TorServiceConstants {
} }
catch (Exception e2) catch (Exception e2)
{ {
Log.w(TAG,"Unable to get proc id for: " + command,e2); Log.w(TorConstants.TAG,"Unable to get proc id for: " + command,e2);
} }
} }

View File

@ -2,16 +2,16 @@ package org.torproject.android.service;
import java.io.File; import java.io.File;
import org.torproject.android.TorifiedApp; import org.torproject.android.TorConstants;
import org.torproject.android.settings.TorifiedApp;
import android.content.Context; import android.content.Context;
import android.util.Log; import android.util.Log;
public class TorTransProxy implements TorServiceConstants { public class TorTransProxy implements TorServiceConstants {
private final static String TAG = TorServiceConstants.TAG; private final static String TAG = TorConstants.TAG;
public static int purgeIptables(Context context) throws Exception { public static int purgeIptables(Context context) throws Exception {