fixes #12411 and #12412 enables DNS and transport by default

with new Orbot settings to enable user to easily change/disable
This commit is contained in:
Nathan Freitas 2014-06-17 15:42:54 -04:00
parent fc608d364f
commit b6715b4d3c
5 changed files with 84 additions and 22 deletions

View File

@ -258,8 +258,18 @@
<string name="updating_settings_in_tor_service">updating settings in Tor service</string> <string name="updating_settings_in_tor_service">updating settings in Tor service</string>
<string name="pref_socks_title">Tor SOCKS</string> <string name="pref_socks_title">Tor SOCKS</string>
<string name="pref_socks_summary">IP and Port that Tor offers its SOCKS proxy on (default: 9050)</string> <string name="pref_socks_summary">Port that Tor offers its SOCKS proxy on (default: 9050 or 0 to disable)</string>
<string name="pref_socks_dialog">SOCKS Config (ip:port)</string> <string name="pref_socks_dialog">SOCKS Port Config</string>
<string name="pref_transport_title">Tor TransProxy Port</string>
<string name="pref_transport_summary">Port that Tor offers its Transparent Proxy on (default: 9040 or 0 to disable)</string>
<string name="pref_transport_dialog">TransProxy Port Config</string>
<string name="pref_dnsport_title">Tor DNS Port</string>
<string name="pref_dnsport_summary">Port that Tor offers its DNS on (default: 5400 or 0 to disable)</string>
<string name="pref_dnsport_dialog">DNS Port Config</string>
<string name="pref_torrc_title">Torrc Custom Config</string> <string name="pref_torrc_title">Torrc Custom Config</string>
<string name="pref_torrc_summary">EXPERTS ONLY: enter direct torrc config lines</string> <string name="pref_torrc_summary">EXPERTS ONLY: enter direct torrc config lines</string>

View File

@ -202,6 +202,20 @@ android:title="@string/pref_socks_title"
android:summary="@string/pref_socks_summary" android:summary="@string/pref_socks_summary"
android:dialogTitle="@string/pref_socks_dialog" android:dialogTitle="@string/pref_socks_dialog"
android:defaultValue="9050" android:defaultValue="9050"
/>
<EditTextPreference android:key="pref_transport"
android:title="@string/pref_transport_title"
android:summary="@string/pref_transport_summary"
android:dialogTitle="@string/pref_transport_dialog"
android:defaultValue="9040"
/>
<EditTextPreference android:key="pref_dnsport"
android:title="@string/pref_dnsport_title"
android:summary="@string/pref_dnsport_summary"
android:dialogTitle="@string/pref_dnsport_dialog"
android:defaultValue="5400"
/> />
<EditTextPreference android:key="pref_custom_torrc" <EditTextPreference android:key="pref_custom_torrc"

View File

@ -659,17 +659,22 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{ {
mTransProxy = new TorTransProxy(this, fileXtables); mTransProxy = new TorTransProxy(this, fileXtables);
} }
logMessage ("Transparent Proxying: updating Tor settings...");
mBinder.updateConfiguration("TransPort","9040",false); SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
mBinder.updateConfiguration("DNSPort","5400",false); String transProxy = prefs.getString("pref_transport", TorServiceConstants.TOR_TRANSPROXY_PORT_DEFAULT+"");
mBinder.updateConfiguration("VirtualAddrNetwork","10.192.0.0/10",false); String dnsPort = prefs.getString("pref_dnsport", TorServiceConstants.TOR_TRANSPROXY_PORT_DEFAULT+"");
mBinder.updateConfiguration("AutomapHostsOnResolve","1",false);
mBinder.saveConfiguration(); if (transProxy.indexOf(':')!=-1) //we just want the port for this
transProxy = transProxy.split(":")[1];
if (dnsPort.indexOf(':')!=-1) //we just want the port for this
dnsPort = dnsPort.split(":")[1];
mTransProxy.setTransProxyPort(Integer.parseInt(transProxy));
mTransProxy.setDNSPort(Integer.parseInt(dnsPort));
//TODO: Find a nice place for the next (commented) line //TODO: Find a nice place for the next (commented) line
@ -1781,6 +1786,12 @@ public class TorService extends Service implements TorServiceConstants, TorConst
enableSocks (socksConfig,false); enableSocks (socksConfig,false);
String transPort = prefs.getString("pref_transport", TorServiceConstants.TOR_TRANSPROXY_PORT_DEFAULT+"");
String dnsPort = prefs.getString("pref_dnsport", TorServiceConstants.TOR_DNS_PORT_DEFAULT+"");
enableTransProxyAndDNSPorts(transPort, dnsPort);
boolean useBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_ENABLED, false); boolean useBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_ENABLED, false);
//boolean autoUpdateBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_UPDATED, false); //boolean autoUpdateBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_UPDATED, false);
@ -2041,6 +2052,19 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
private void enableTransProxyAndDNSPorts (String transPort, String dnsPort) throws RemoteException
{
logMessage ("Transparent Proxying: enabling port...");
mBinder.updateConfiguration("TransPort",transPort,false);
mBinder.updateConfiguration("DNSPort",dnsPort,false);
mBinder.updateConfiguration("VirtualAddrNetwork","10.192.0.0/10",false);
mBinder.updateConfiguration("AutomapHostsOnResolve","1",false);
mBinder.saveConfiguration();
}
private void blockPlaintextPorts (String portList) throws RemoteException private void blockPlaintextPorts (String portList) throws RemoteException
{ {

View File

@ -54,9 +54,9 @@ public interface TorServiceConstants {
//what is says! //what is says!
public final static String IP_LOCALHOST = "127.0.0.1"; public final static String IP_LOCALHOST = "127.0.0.1";
public final static int UPDATE_TIMEOUT = 1000; public final static int UPDATE_TIMEOUT = 1000;
public final static int TOR_TRANSPROXY_PORT = 9040; public final static int TOR_TRANSPROXY_PORT_DEFAULT = 9040;
public final static int STANDARD_DNS_PORT = 53; public final static int STANDARD_DNS_PORT = 53;
public final static int TOR_DNS_PORT = 5400; public final static int TOR_DNS_PORT_DEFAULT = 5400;
//path to check Tor against //path to check Tor against
public final static String URL_TOR_CHECK = "https://check.torproject.org"; public final static String URL_TOR_CHECK = "https://check.torproject.org";

View File

@ -23,10 +23,24 @@ public class TorTransProxy implements TorServiceConstants {
private final static String ALLOW_LOCAL = " ! -o lo ! -d 127.0.0.1 ! -s 127.0.0.1 "; private final static String ALLOW_LOCAL = " ! -o lo ! -d 127.0.0.1 ! -s 127.0.0.1 ";
private int mTransProxyPort = TorServiceConstants.TOR_TRANSPROXY_PORT_DEFAULT;
private int mDNSPort = TorServiceConstants.TOR_DNS_PORT_DEFAULT;
public TorTransProxy (TorService torService, File fileXTables) public TorTransProxy (TorService torService, File fileXTables)
{ {
mTorService = torService; mTorService = torService;
mFileXtables = fileXTables; mFileXtables = fileXTables;
}
public void setTransProxyPort (int transProxyPort)
{
mTransProxyPort = transProxyPort;
}
public void setDNSPort (int dnsPort)
{
mDNSPort = dnsPort;
} }
public String getIpTablesPath (Context context) public String getIpTablesPath (Context context)
@ -383,7 +397,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append(tApp.getUid()); script.append(tApp.getUid());
script.append(" -m tcp --syn"); script.append(" -m tcp --syn");
script.append(" -j REDIRECT --to-ports "); script.append(" -j REDIRECT --to-ports ");
script.append(TOR_TRANSPROXY_PORT); script.append(mTransProxyPort);
executeCommand (shell, script.toString()); executeCommand (shell, script.toString());
script = new StringBuilder(); script = new StringBuilder();
@ -398,7 +412,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append(" -m udp --dport "); script.append(" -m udp --dport ");
script.append(STANDARD_DNS_PORT); script.append(STANDARD_DNS_PORT);
script.append(" -j REDIRECT --to-ports "); script.append(" -j REDIRECT --to-ports ");
script.append(TOR_DNS_PORT); script.append(mDNSPort);
executeCommand (shell, script.toString()); executeCommand (shell, script.toString());
script = new StringBuilder(); script = new StringBuilder();
@ -454,7 +468,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append(" -t nat -A PREROUTING -i "); script.append(" -t nat -A PREROUTING -i ");
script.append(hwinterfaces[i]); script.append(hwinterfaces[i]);
script.append(" -p udp --dport 53 -j REDIRECT --to-ports "); script.append(" -p udp --dport 53 -j REDIRECT --to-ports ");
script.append(TOR_DNS_PORT); script.append(mDNSPort);
executeCommand (shell, script.toString()); executeCommand (shell, script.toString());
script = new StringBuilder(); script = new StringBuilder();
@ -465,7 +479,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append(" -t nat -A PREROUTING -i "); script.append(" -t nat -A PREROUTING -i ");
script.append(hwinterfaces[i]); script.append(hwinterfaces[i]);
script.append(" -p tcp -j REDIRECT --to-ports "); script.append(" -p tcp -j REDIRECT --to-ports ");
script.append(TOR_TRANSPROXY_PORT); script.append(mTransProxyPort);
lastExit = executeCommand (shell, script.toString()); lastExit = executeCommand (shell, script.toString());
script = new StringBuilder(); script = new StringBuilder();
@ -642,7 +656,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append(torUid); script.append(torUid);
script.append(" -m tcp --syn"); script.append(" -m tcp --syn");
script.append(" -j REDIRECT --to-ports "); script.append(" -j REDIRECT --to-ports ");
script.append(TOR_TRANSPROXY_PORT); script.append(mTransProxyPort);
executeCommand (shell, script.toString()); executeCommand (shell, script.toString());
script = new StringBuilder(); script = new StringBuilder();
@ -658,7 +672,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append(" -m udp --dport "); script.append(" -m udp --dport ");
script.append(STANDARD_DNS_PORT); script.append(STANDARD_DNS_PORT);
script.append(" -j REDIRECT --to-ports "); script.append(" -j REDIRECT --to-ports ");
script.append(TOR_DNS_PORT); script.append(mDNSPort);
executeCommand (shell, script.toString()); executeCommand (shell, script.toString());
script = new StringBuilder(); script = new StringBuilder();
@ -699,7 +713,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append(" -A ").append(srcChainName); script.append(" -A ").append(srcChainName);
script.append(" -p tcp"); script.append(" -p tcp");
script.append(" -m tcp"); script.append(" -m tcp");
script.append(" --dport ").append(TOR_TRANSPROXY_PORT); script.append(" --dport ").append(mTransProxyPort);
script.append(" -j ACCEPT"); script.append(" -j ACCEPT");
executeCommand (shell, script.toString()); executeCommand (shell, script.toString());
@ -735,7 +749,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append(" -A ").append(srcChainName); script.append(" -A ").append(srcChainName);
script.append(" -p udp"); script.append(" -p udp");
script.append(" -m udp"); script.append(" -m udp");
script.append(" --dport ").append(TOR_DNS_PORT); script.append(" --dport ").append(mDNSPort);
script.append(" -j ACCEPT"); script.append(" -j ACCEPT");
executeCommand (shell, script.toString()); executeCommand (shell, script.toString());
@ -747,7 +761,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append(" -A ").append(srcChainName); script.append(" -A ").append(srcChainName);
script.append(" -p udp"); script.append(" -p udp");
script.append(" -m udp"); script.append(" -m udp");
script.append(" --dport ").append(TOR_DNS_PORT); script.append(" --dport ").append(mDNSPort);
script.append(" -j ACCEPT"); script.append(" -j ACCEPT");
executeCommand (shell, script.toString()); executeCommand (shell, script.toString());