commit 1d45a3d28d548bac4b562df18fee4eef92688119 Author: n8fr8 nathan@guardianproject.info Date: Tue Sep 10 00:22:38 2019 -0400
update APT Pluggable Transport library to 1.0.7 - this should fix one issue with installing the correct ofbs4proxy binary - also small changes to ensure no lock states and reduce log noise --- orbotservice/build.gradle | 8 +- .../android/service/TorEventHandler.java | 102 ++++++------- .../org/torproject/android/service/TorService.java | 166 ++++++++++----------- .../android/service/util/CustomNativeLoader.java | 4 +- .../android/service/vpn/OrbotVpnManager.java | 2 +- 5 files changed, 134 insertions(+), 148 deletions(-)
diff --git a/orbotservice/build.gradle b/orbotservice/build.gradle index bf3dc863..b2e3418c 100644 --- a/orbotservice/build.gradle +++ b/orbotservice/build.gradle @@ -14,7 +14,7 @@ android { minSdkVersion 16 targetSdkVersion 29 versionCode 16111000 - versionName '16.1.1-BETA-2-tor-0.4.0.4-rc-orbotservice' + versionName '16.1.1-BETA-2-tor-0.4.1-5-rc-orbotservice' archivesBaseName = "OrbotService-$versionName"
} @@ -37,9 +37,9 @@ android {
dependencies {
- implementation 'org.torproject:tor-android-binary:0.4.0.4-rc' - implementation 'info.pluggabletransports.aptds:apt-dispatch-library:1.0.6' - implementation 'info.pluggabletransports.aptds:apt-meek-obfs4-legacy:1.0.6' + implementation 'org.torproject:tor-android-binary:0.4.1.5-rc' + implementation 'info.pluggabletransports.aptds:apt-dispatch-library:1.0.7' + implementation 'info.pluggabletransports.aptds:apt-meek-obfs4-legacy:1.0.7' implementation 'info.pluggabletransports.aptds:jsocksAndroid:1.0.4'
implementation 'com.android.support:appcompat-v7:28.0.0' diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorEventHandler.java b/orbotservice/src/main/java/org/torproject/android/service/TorEventHandler.java index 15ec4bc0..ae2841d9 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/TorEventHandler.java +++ b/orbotservice/src/main/java/org/torproject/android/service/TorEventHandler.java @@ -160,69 +160,65 @@ public class TorEventHandler implements EventHandler, TorServiceConstants { if (mService.getCurrentStatus() == STATUS_STARTING && TextUtils.equals(status, "BUILT")) mService.sendCallbackStatus(STATUS_ON);
- StringBuilder sb = new StringBuilder(); - sb.append("Circuit ("); - sb.append((circID)); - sb.append(") "); - sb.append(status); - sb.append(": "); - - StringTokenizer st = new StringTokenizer(path,","); - Node node = null; - - while (st.hasMoreTokens()) - { - String nodePath = st.nextToken(); - node = new Node(); + if (Prefs.useDebugLogging()) { + StringBuilder sb = new StringBuilder(); + sb.append("Circuit ("); + sb.append((circID)); + sb.append(") "); + sb.append(status); + sb.append(": "); + + StringTokenizer st = new StringTokenizer(path, ","); + Node node = null; + + while (st.hasMoreTokens()) { + String nodePath = st.nextToken(); + node = new Node(); + + String[] nodeParts; + + if (nodePath.contains("=")) + nodeParts = nodePath.split("="); + else + nodeParts = nodePath.split("~"); + + if (nodeParts.length == 1) { + node.id = nodeParts[0].substring(1); + node.name = node.id; + } else if (nodeParts.length == 2) { + node.id = nodeParts[0].substring(1); + node.name = nodeParts[1]; + }
- String[] nodeParts; + node.status = status;
- if (nodePath.contains("=")) - nodeParts = nodePath.split("="); - else - nodeParts = nodePath.split("~"); + sb.append(node.name);
- if (nodeParts.length == 1) - { - node.id = nodeParts[0].substring(1); - node.name = node.id; + if (st.hasMoreTokens()) + sb.append(" > "); } - else if (nodeParts.length == 2) - { - node.id = nodeParts[0].substring(1); - node.name = nodeParts[1]; - }
- node.status = status; + if (Prefs.useDebugLogging()) + mService.debug(sb.toString()); + else if (status.equals("BUILT")) + mService.logNotice(sb.toString()); + else if (status.equals("CLOSED")) + mService.logNotice(sb.toString());
- sb.append(node.name); + if (Prefs.expandedNotifications()) { + //get IP from last nodename + if (status.equals("BUILT")) {
- if (st.hasMoreTokens()) - sb.append (" > "); - } - - if (Prefs.useDebugLogging()) - mService.debug(sb.toString()); - else if(status.equals("BUILT")) - mService.logNotice(sb.toString()); - else if (status.equals("CLOSED")) - mService.logNotice(sb.toString()); - - if (Prefs.expandedNotifications()) - { - //get IP from last nodename - if(status.equals("BUILT")){ - - // if (node.ipAddress == null) - // mService.exec(new ExternalIPFetcher(node)); + // if (node.ipAddress == null) + // mService.exec(new ExternalIPFetcher(node));
- hmBuiltNodes.put(circID, node); - } + hmBuiltNodes.put(circID, node); + }
- if (status.equals("CLOSED")) - { - hmBuiltNodes.remove(circID); + if (status.equals("CLOSED")) { + hmBuiltNodes.remove(circID);
+ } } }
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 5b047143..a566b6d4 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/TorService.java +++ b/orbotservice/src/main/java/org/torproject/android/service/TorService.java @@ -91,7 +91,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon public final static String BINARY_TOR_VERSION = org.torproject.android.binary.TorServiceConstants.BINARY_TOR_VERSION; private String mCurrentStatus = STATUS_OFF;
- private final static int CONTROL_SOCKET_TIMEOUT = 0; + private final static int CONTROL_SOCKET_TIMEOUT = 60000;
private TorControlConnection conn = null; private int mLastProcessId = -1; @@ -108,8 +108,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon private ArrayList<String> configBuffer = null; private ArrayList<String> resetBuffer = null;
- private boolean isTorUpgradeAndConfigComplete = false; - private File fileControlPort;
private boolean mConnectivity = true; @@ -371,12 +369,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
public void run() {
- while (!isTorUpgradeAndConfigComplete) - { - try { Thread.sleep (500);} - catch (Exception e){} - } - String action = mIntent.getAction();
if (action != null) { @@ -602,6 +594,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon fileObfsclient = new TransportManager() { @Override public void startTransportSync(TransportListener transportListener) { + } }.installTransport(this, OBFSCLIENT_ASSET_KEY);
@@ -619,8 +612,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon }
private boolean torUpgradeAndConfig() throws IOException, TimeoutException { - if (isTorUpgradeAndConfigComplete) - return true;
SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext()); String version = prefs.getString(PREF_BINARY_TOR_VERSION_INSTALLED,null); @@ -639,8 +630,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon if (!fileTorRc.exists()) return false;
- isTorUpgradeAndConfigComplete = true; - return true; }
@@ -732,8 +721,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon { extraLines.append("Log debug syslog").append('\n'); extraLines.append("Log info syslog").append('\n'); - extraLines.append("SafeLogging 0").append('\n'); - + extraLines.append("SafeLogging 0").append('\n'); }
extraLines = processSettingsImpl(extraLines); @@ -851,7 +839,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
// make sure there are no stray daemons running -// killAllDaemons(); + killAllDaemons();
SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext()); String version = prefs.getString(PREF_BINARY_TOR_VERSION_INSTALLED,null); @@ -859,8 +847,8 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
sendCallbackStatus(STATUS_STARTING); showToolbarNotification(getString(R.string.status_starting_up),NOTIFY_ID,R.drawable.ic_stat_tor); - sendCallbackLogMessage(getString(R.string.status_starting_up)); - logNotice(getString(R.string.status_starting_up)); + //sendCallbackLogMessage(getString(R.string.status_starting_up)); + //logNotice(getString(R.string.status_starting_up)); ArrayList<String> customEnv = new ArrayList<String>(); @@ -874,56 +862,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
if (success) { - // if (mPortHTTP != -1) - // runPolipoShellCmd(); - - // Tor is running, update new .onion names at db - ContentResolver mCR = getApplicationContext().getContentResolver(); - Cursor hidden_services = mCR.query(HS_CONTENT_URI, hsProjection, null, null, null); - if(hidden_services != null) { - try { - while (hidden_services.moveToNext()) { - String HSDomain = hidden_services.getString(hidden_services.getColumnIndex(HiddenService.DOMAIN)); - Integer HSLocalPort = hidden_services.getInt(hidden_services.getColumnIndex(HiddenService.PORT)); - Integer HSAuthCookie = hidden_services.getInt(hidden_services.getColumnIndex(HiddenService.AUTH_COOKIE)); - String HSAuthCookieValue = hidden_services.getString(hidden_services.getColumnIndex(HiddenService.AUTH_COOKIE_VALUE)); - - // Update only new domains or restored from backup with auth cookie - if ((HSDomain == null || HSDomain.length() < 1) || (HSAuthCookie == 1 && (HSAuthCookieValue == null || HSAuthCookieValue.length() < 1))) { - String hsDirPath = new File(mHSBasePath.getAbsolutePath(), "hs" + HSLocalPort).getCanonicalPath(); - File file = new File(hsDirPath, "hostname"); - - if (file.exists()) { - ContentValues fields = new ContentValues(); - - try { - String onionHostname = Utils.readString(new FileInputStream(file)).trim(); - if (HSAuthCookie == 1) { - String[] aux = onionHostname.split(" "); - onionHostname = aux[0]; - fields.put(HiddenService.AUTH_COOKIE_VALUE, aux[1]); - } - fields.put(HiddenService.DOMAIN, onionHostname); - mCR.update(HS_CONTENT_URI, fields, "port=" + HSLocalPort, null); - } catch (FileNotFoundException e) { - logException("unable to read onion hostname file", e); - showToolbarNotification(getString(R.string.unable_to_read_hidden_service_name), HS_NOTIFY_ID, R.drawable.ic_stat_notifyerr); - } - } else { - showToolbarNotification(getString(R.string.unable_to_read_hidden_service_name), HS_NOTIFY_ID, R.drawable.ic_stat_notifyerr); - - } - } - } - - } catch (NumberFormatException e) { - Log.e(OrbotConstants.TAG, "error parsing hsport", e); - } catch (Exception e) { - Log.e(OrbotConstants.TAG, "error starting share server", e); - } - - hidden_services.close(); - } + updateOnionNames (); }
} catch (Exception e) { @@ -936,6 +875,57 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon } }
+ private void updateOnionNames () + { + // Tor is running, update new .onion names at db + ContentResolver mCR = getApplicationContext().getContentResolver(); + Cursor hidden_services = mCR.query(HS_CONTENT_URI, hsProjection, null, null, null); + if(hidden_services != null) { + try { + while (hidden_services.moveToNext()) { + String HSDomain = hidden_services.getString(hidden_services.getColumnIndex(HiddenService.DOMAIN)); + Integer HSLocalPort = hidden_services.getInt(hidden_services.getColumnIndex(HiddenService.PORT)); + Integer HSAuthCookie = hidden_services.getInt(hidden_services.getColumnIndex(HiddenService.AUTH_COOKIE)); + String HSAuthCookieValue = hidden_services.getString(hidden_services.getColumnIndex(HiddenService.AUTH_COOKIE_VALUE)); + + // Update only new domains or restored from backup with auth cookie + if ((HSDomain == null || HSDomain.length() < 1) || (HSAuthCookie == 1 && (HSAuthCookieValue == null || HSAuthCookieValue.length() < 1))) { + String hsDirPath = new File(mHSBasePath.getAbsolutePath(), "hs" + HSLocalPort).getCanonicalPath(); + File file = new File(hsDirPath, "hostname"); + + if (file.exists()) { + ContentValues fields = new ContentValues(); + + try { + String onionHostname = Utils.readString(new FileInputStream(file)).trim(); + if (HSAuthCookie == 1) { + String[] aux = onionHostname.split(" "); + onionHostname = aux[0]; + fields.put(HiddenService.AUTH_COOKIE_VALUE, aux[1]); + } + fields.put(HiddenService.DOMAIN, onionHostname); + mCR.update(HS_CONTENT_URI, fields, "port=" + HSLocalPort, null); + } catch (FileNotFoundException e) { + logException("unable to read onion hostname file", e); + showToolbarNotification(getString(R.string.unable_to_read_hidden_service_name), HS_NOTIFY_ID, R.drawable.ic_stat_notifyerr); + } + } else { + showToolbarNotification(getString(R.string.unable_to_read_hidden_service_name), HS_NOTIFY_ID, R.drawable.ic_stat_notifyerr); + + } + } + } + + } catch (NumberFormatException e) { + Log.e(OrbotConstants.TAG, "error parsing hsport", e); + } catch (Exception e) { + Log.e(OrbotConstants.TAG, "error starting share server", e); + } + + hidden_services.close(); + } + } + private boolean runTorShellCmd() throws Exception { boolean result = true; @@ -943,7 +933,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon File fileTorrcCustom = updateTorrcCustomFile();
//make sure Tor exists and we can execute it - if ((!fileTor.exists()) || (!fileTor.canExecute())) + if (fileTor == null || (!fileTor.exists()) || (!fileTor.canExecute())) return false;
if ((!fileTorRc.exists()) || (!fileTorRc.canRead()) ) @@ -1052,7 +1042,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon torConnSocket.setSoTimeout(CONTROL_SOCKET_TIMEOUT);
conn = new TorControlConnection(torConnSocket); - conn.launchThread(false);//is daemon + conn.launchThread(true);//is daemon
break; } @@ -1089,9 +1079,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon logNotice( "SUCCESS - authenticated to control port.");
sendCallbackLogMessage(getString(R.string.tor_process_starting) + ' ' + getString(R.string.tor_process_complete)); - - addEventHandler(); - + String torProcId = conn.getInfo("process/pid");
String confSocks = conn.getInfo("net/listeners/socks"); @@ -1127,6 +1115,8 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
sendCallbackPorts(mPortSOCKS, mPortHTTP, mPortDns, mPortTrans);
+ addEventHandler(); + return Integer.parseInt(torProcId);
} @@ -1189,7 +1179,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon return result; }
- public synchronized void addEventHandler () throws Exception + public void addEventHandler () throws Exception { // We extend NullEventHandler so that we don't need to provide empty // implementations for all the events we don't care about. @@ -1199,9 +1189,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon conn.setEventHandler(mEventHandler);
conn.setEvents(Arrays.asList(new String[]{ - "ORCONN", "CIRC", "NOTICE", "WARN", "ERR","BW"})); - // conn.setEvents(Arrays.asList(new String[]{ - // "DEBUG", "INFO", "NOTICE", "WARN", "ERR"})); + "ORCONN", "CIRC", "NOTICE", "WARN", "ERR","BW"}));
logNotice( "SUCCESS added control port event handler"); } @@ -1625,34 +1613,34 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon //check if any PT bridges are needed if (obfs3Bridges) extraLines.append("ClientTransportPlugin obfs3 exec ") - .append(fileObfsclient.getCanonicalPath()).append('\n'); + .append(fileObfsclient.getAbsolutePath()).append('\n');
if (obfs4Bridges) extraLines.append("ClientTransportPlugin obfs4 exec ") - .append(fileObfsclient.getCanonicalPath()).append('\n'); + .append(fileObfsclient.getAbsolutePath()).append('\n');
if (meekBridges) extraLines.append("ClientTransportPlugin meek_lite exec " + fileObfsclient.getCanonicalPath()).append('\n');
if (bridgeList != null && bridgeList.length() > 5) //longer then 1 = some real values here { - String[] bridgeListLines = bridgeList.split("\n"); + String[] bridgeListLines = bridgeList.trim().split("\n"); +
+ int bridgeIdx = (int)Math.round(Math.random()*((double)bridgeListLines.length)); + String bridgeLine = bridgeListLines[bridgeIdx]; + extraLines.append("Bridge "); + extraLines.append(bridgeLine); + extraLines.append("\n"); + /** for (String bridgeConfigLine : bridgeListLines) { if (!TextUtils.isEmpty(bridgeConfigLine)) { extraLines.append("Bridge "); - extraLines.append(bridgeConfigLine); - - /** - StringTokenizer st = new StringTokenizer(bridgeConfigLine, " "); - while (st.hasMoreTokens()) - extraLines.append(st.nextToken()).append(' '); - **/ + extraLines.append(bridgeConfigLine.trim()); extraLines.append("\n"); - }
- } + }**/
} else {
diff --git a/orbotservice/src/main/java/org/torproject/android/service/util/CustomNativeLoader.java b/orbotservice/src/main/java/org/torproject/android/service/util/CustomNativeLoader.java index e44340b4..24a994d5 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/util/CustomNativeLoader.java +++ b/orbotservice/src/main/java/org/torproject/android/service/util/CustomNativeLoader.java @@ -26,7 +26,9 @@ public class CustomNativeLoader { zipFile = new ZipFile(context.getApplicationInfo().sourceDir); ZipEntry entry = zipFile.getEntry("lib/" + arch + "/" + libname + ".so"); if (entry == null) { - throw new Exception("Unable to find file in apk:" + "lib/" + arch + "/" + libname); + entry = zipFile.getEntry("jni/" + arch + "/" + libname + ".so"); + if (entry == null) + throw new Exception("Unable to find file in apk:" + "lib/" + arch + "/" + libname); }
//how we wrap this in another stream because the native .so is zipped itself 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 03ad79c2..98de7bbb 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 @@ -341,7 +341,7 @@ public class OrbotVpnManager implements Handler.Callback {
//start PDNSD daemon pointing to actual DNS int pdnsdPort = 8091; - startDNS(filePdnsd.getCanonicalPath(), localhost,mTorDns, virtualGateway, pdnsdPort); + startDNS(filePdnsd.getCanonicalPath(), localhost,mTorDns, virtualGateway, pdnsdPort); final boolean localDnsTransparentProxy = true;
Tun2Socks.Start(mService, mInterface, VPN_MTU, virtualIP, virtualNetMask, localSocks , virtualGateway + ":" + pdnsdPort , localDnsTransparentProxy);