commit 397391f0580c4997444bfb520fe13c64fa6c973f Author: n8fr8 nathan@guardianproject.info Date: Tue Jun 4 05:27:22 2019 -0400
remove hardcoded port values, make it all dynamic --- app/src/main/res/xml/preferences.xml | 6 ++-- .../org/torproject/android/service/TorService.java | 39 +++++++++++++++------- .../android/service/TorServiceConstants.java | 19 ++++++----- .../android/service/vpn/OrbotVpnManager.java | 11 +++--- 4 files changed, 45 insertions(+), 30 deletions(-)
diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 1f49d58b..53aa5ecd 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -244,7 +244,7 @@ <PreferenceCategory android:title="Debug">
<EditTextPreference - android:defaultValue="9050" + android:defaultValue="auto" android:dialogTitle="@string/pref_socks_dialog" android:inputType="number" android:key="pref_socks" @@ -252,7 +252,7 @@ android:title="@string/pref_socks_title" />
<EditTextPreference - android:defaultValue="9040" + android:defaultValue="auto" android:dialogTitle="@string/pref_transport_dialog" android:inputType="number" android:key="pref_transport" @@ -260,7 +260,7 @@ android:title="@string/pref_transport_title" />
<EditTextPreference - android:defaultValue="5400" + android:defaultValue="auto" android:dialogTitle="@string/pref_dnsport_dialog" android:inputType="number" android:key="pref_dnsport" diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorService.java b/orbotservice/src/main/java/org/torproject/android/service/TorService.java index 4517a106..9d88aeb9 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/TorService.java +++ b/orbotservice/src/main/java/org/torproject/android/service/TorService.java @@ -9,6 +9,7 @@ package org.torproject.android.service;
import android.annotation.SuppressLint; +import android.app.Application; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; @@ -28,6 +29,7 @@ import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; import android.os.Build; +import android.os.Handler; import android.os.IBinder; import android.os.RemoteException; import android.provider.BaseColumns; @@ -89,8 +91,8 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon private TorControlConnection conn = null; private int mLastProcessId = -1;
- public static int mPortSOCKS = SOCKS_PROXY_PORT_DEFAULT; - public static int mPortHTTP = HTTP_PROXY_PORT_DEFAULT; + public static int mPortSOCKS = -1; + public static int mPortHTTP = -1; public static int mPortDns = TOR_DNS_PORT_DEFAULT; public static int mPortTrans = TOR_TRANSPROXY_PORT_DEFAULT;
@@ -132,6 +134,8 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon private static final Uri HS_CONTENT_URI = Uri.parse("content://org.torproject.android.ui.hiddenservices.providers/hs"); private static final Uri COOKIE_CONTENT_URI = Uri.parse("content://org.torproject.android.ui.hiddenservices.providers.cookie/cookie");
+ private Handler mHandler; + public static final class HiddenService implements BaseColumns { public static final String NAME = "name"; public static final String PORT = "port"; @@ -510,16 +514,18 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
try { + mHandler = new Handler (); + appBinHome = getFilesDir();//getDir(TorServiceConstants.DIRECTORY_TOR_BINARY, Application.MODE_PRIVATE); if (!appBinHome.exists()) appBinHome.mkdirs();
- appCacheHome = getCacheDir();// getDir(TorServiceConstants.DIRECTORY_TOR_DATA,Application.MODE_PRIVATE); + appCacheHome = getDir(DIRECTORY_TOR_DATA, Application.MODE_PRIVATE); if (!appCacheHome.exists()) appCacheHome.mkdirs();
- fileTorRc = new File(appBinHome, TorServiceConstants.TORRC_ASSET_KEY); - fileControlPort = new File(getFilesDir(), "control.txt"); + fileTorRc = new File(appBinHome, TORRC_ASSET_KEY); + fileControlPort = new File(getFilesDir(), TOR_CONTROL_PORT_FILE);
mHSBasePath = new File( getFilesDir().getAbsolutePath(), @@ -682,9 +688,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon extraLines.append("SocksListenAddress 0.0.0.0").append('\n');
- - String httpPortPref = HTTP_PROXY_PORT_DEFAULT + ""; - extraLines.append("HTTPTunnelPort ").append(checkPortOrAuto(httpPortPref)).append('\n'); + extraLines.append("HTTPTunnelPort ").append(checkPortOrAuto(HTTP_PROXY_PORT_DEFAULT)).append('\n');
if(prefs.getBoolean(OrbotConstants.PREF_CONNECTION_PADDING, false)) { @@ -1922,10 +1926,21 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
private void startVPNService () { - Intent intentVpn = new Intent(this,TorVpnService.class); - intentVpn.setAction("start"); - intentVpn.putExtra("torSocks",mPortSOCKS); - startService(intentVpn); + if (mPortSOCKS != -1) { + Intent intentVpn = new Intent(this, TorVpnService.class); + intentVpn.setAction("start"); + intentVpn.putExtra("torSocks", mPortSOCKS); + startService(intentVpn); + } + else + { + mHandler.postDelayed(new Runnable() { + public void run () + { + startVPNService(); + } + },5000); + } }
diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java b/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java index e02c8f81..22a6ea29 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java +++ b/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java @@ -11,8 +11,10 @@ public interface TorServiceConstants { String BROWSER_APP_USERNAME = "info.guardianproject.orfox"; //String DIRECTORY_TOR_BINARY = "bin"; - //String DIRECTORY_TOR_DATA = "data"; - + String DIRECTORY_TOR_DATA = "data"; + + String TOR_CONTROL_PORT_FILE = "control.txt"; + //name of the tor C binary String TOR_ASSET_KEY = "tor"; @@ -51,18 +53,17 @@ public interface TorServiceConstants { int FILE_WRITE_BUFFER_SIZE = 1024;
String IP_LOCALHOST = "127.0.0.1"; - int UPDATE_TIMEOUT = 1000; +// int UPDATE_TIMEOUT = 1000; int TOR_TRANSPROXY_PORT_DEFAULT = 9040; - int STANDARD_DNS_PORT = 53; +// int STANDARD_DNS_PORT = 53; int TOR_DNS_PORT_DEFAULT = 5400; - String TOR_VPN_DNS_LISTEN_ADDRESS = "127.0.0.1"; +// String TOR_VPN_DNS_LISTEN_ADDRESS = "127.0.0.1"; - int CONTROL_PORT_DEFAULT = 9051; - int HTTP_PROXY_PORT_DEFAULT = 8118; // like Privoxy! - int SOCKS_PROXY_PORT_DEFAULT = 9050; +// int CONTROL_PORT_DEFAULT = 9051; + String HTTP_PROXY_PORT_DEFAULT = "auto"; // like Privoxy! + String SOCKS_PROXY_PORT_DEFAULT = "auto";
- //path to check Tor against String URL_TOR_CHECK = "https://check.torproject.org";
diff --git a/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java b/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java index 2db02389..e7675001 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java +++ b/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java @@ -62,8 +62,8 @@ public class OrbotVpnManager implements Handler.Callback { private String mSessionName = "OrbotVPN"; private ParcelFileDescriptor mInterface;
- private int mTorSocks = TorServiceConstants.SOCKS_PROXY_PORT_DEFAULT; - + private int mTorSocks = -1; + public static int sSocksProxyServerPort = -1; public static String sSocksProxyLocalhost = null; private ProxyServer mSocksProxyServer; @@ -110,8 +110,8 @@ public class OrbotVpnManager implements Handler.Callback { if (mThreadVPN == null || (!mThreadVPN.isAlive())) { Log.d(TAG,"starting OrbotVPNService service!"); - - mTorSocks = intent.getIntExtra("torSocks", TorServiceConstants.SOCKS_PROXY_PORT_DEFAULT); + + mTorSocks = intent.getIntExtra("torSocks", -1); if (!mIsLollipop) { @@ -303,8 +303,7 @@ public class OrbotVpnManager implements Handler.Callback { final String dummyDNS = "1.1.1.1"; //this is intercepted by the tun2socks library, but we must put in a valid DNS to start final String defaultRoute = "0.0.0.0"; - final String localSocks = localhost + ':' - + String.valueOf(mTorSocks); + final String localSocks = localhost + ':' + mTorSocks; final String localDNS = virtualGateway + ':' + PDNSD_PORT;
tor-commits@lists.torproject.org