diff --git a/app/src/main/java/com/darkweb/genesissearchengine/pluginManager/orbotPluginManager/orbotManager.java b/app/src/main/java/com/darkweb/genesissearchengine/pluginManager/orbotPluginManager/orbotManager.java index 0ed0c83f..1bfaec8b 100644 --- a/app/src/main/java/com/darkweb/genesissearchengine/pluginManager/orbotPluginManager/orbotManager.java +++ b/app/src/main/java/com/darkweb/genesissearchengine/pluginManager/orbotPluginManager/orbotManager.java @@ -19,6 +19,7 @@ import java.lang.ref.WeakReference; import java.util.Collections; import java.util.List; +import com.darkweb.genesissearchengine.appManager.activityContextManager; import com.darkweb.genesissearchengine.appManager.homeManager.homeController.homeController; import com.darkweb.genesissearchengine.constants.constants; import com.darkweb.genesissearchengine.constants.enums; @@ -26,6 +27,7 @@ import com.darkweb.genesissearchengine.constants.keys; import com.darkweb.genesissearchengine.constants.status; import com.darkweb.genesissearchengine.constants.strings; import com.darkweb.genesissearchengine.eventObserver; +import com.darkweb.genesissearchengine.helperManager.helperMethod; import com.darkweb.genesissearchengine.pluginManager.pluginController; import com.darkweb.genesissearchengine.pluginManager.pluginEnums; @@ -85,15 +87,19 @@ public class orbotManager Intent mServiceIntent = new Intent(mAppContext.get().getApplicationContext(), OrbotService.class); mServiceIntent.setAction(ACTION_START); - mAppContext.get().bindService(mServiceIntent, mServerConn, Context.BIND_AUTO_CREATE); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - mAppContext.get().stopService(mServiceIntent); - mAppContext.get().startForegroundService(mServiceIntent); - } - else - { - mAppContext.get().startService(mServiceIntent); - } + helperMethod.onDelayHandler(activityContextManager.getInstance().getHomeController(), 3000, () -> { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + mAppContext.get().stopService(mServiceIntent); + mAppContext.get().startForegroundService(mServiceIntent); + } + else + { + mAppContext.get().stopService(mServiceIntent); + mAppContext.get().startService(mServiceIntent); + } + mAppContext.get().bindService(mServiceIntent, mServerConn, Context.BIND_AUTO_CREATE); + return null; + }); } diff --git a/orbotmanager.rar b/orbotmanager.rar new file mode 100644 index 00000000..262646fb Binary files /dev/null and b/orbotmanager.rar differ diff --git a/orbotmanager/src/main/java/org/torproject/android/service/OrbotService.java b/orbotmanager/src/main/java/org/torproject/android/service/OrbotService.java index 172b6dd7..664607d2 100644 --- a/orbotmanager/src/main/java/org/torproject/android/service/OrbotService.java +++ b/orbotmanager/src/main/java/org/torproject/android/service/OrbotService.java @@ -1,10 +1,3 @@ -/* Copyright (c) 2009-2011, Nathan Freitas, Orbot / The Guardian Project - https://guardianproject.info/apps/orbot */ -/* See LICENSE for licensing information */ -/* - * Code for iptables binary management taken from DroidWall GPLv3 - * Copyright (C) 2009-2010 Rodrigo Zechin Rosauro - */ - package org.torproject.android.service; import android.annotation.SuppressLint; @@ -30,6 +23,7 @@ import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; import android.net.VpnService; +import android.os.BatteryManager; import android.os.Build; import android.os.Handler; import android.os.HandlerThread; @@ -258,7 +252,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb if (conn != null && orbotLocalConstants.mIsTorInitialized) { Intent intentRefresh = new Intent(CMD_NEWNYM); PendingIntent pendingIntentNewNym = PendingIntent.getBroadcast(this, 0, intentRefresh, PendingIntent.FLAG_UPDATE_CURRENT); - mNotifyBuilder.addAction(R.drawable.ic_stat_starting_tor_logo, getString(R.string.menu_new_identity), pendingIntentNewNym); + mNotifyBuilder.addAction(R.mipmap.ic_stat_tor_logo, getString(R.string.menu_new_identity), pendingIntentNewNym); Intent intentSetting = new Intent(CMD_SETTING); PendingIntent pendingIntentSetting = PendingIntent.getBroadcast(this, 0, intentSetting, PendingIntent.FLAG_UPDATE_CURRENT); @@ -364,16 +358,20 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb private void stopTorAsync() { - Log.i("OrbotService", "stopTor"); + debug("stopTor"); + try { sendCallbackStatus(STATUS_STOPPING); sendCallbackLogMessage(getString(R.string.status_shutting_down)); - if (useIPtObfsMeekProxy()) - IPtProxy.stopObfs4Proxy(); - - if (useIPtSnowflakeProxy()) - IPtProxy.stopSnowflake(); + if (Prefs.bridgesEnabled()) { + if (useIPtObfsMeekProxy()) + IPtProxy.stopObfs4Proxy(); + else if (useIPtSnowflakeProxy()) + IPtProxy.stopSnowflake(); + } + else if (Prefs.beSnowflakeProxy()) + disableSnowflakeProxy(); stopTor(); @@ -389,6 +387,11 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb sendCallbackStatus(STATUS_OFF); } + private void disableSnowflakeProxy () { + IPtProxy.stopSnowflakeProxy(); + logNotice("Snowflake Proxy mode DISABLED"); + } + private void stopTorOnError(String message) { stopTorAsync(); showToolbarNotification( @@ -411,19 +414,14 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb public static void loadCdnFronts (Context context) { if (mFronts == null) { mFronts = new HashMap<>(); - try { BufferedReader reader = new BufferedReader(new InputStreamReader(context.getAssets().open("fronts"))); String line; while ((line = reader.readLine())!=null) { String[] front = line.split(" "); - - //add some code to test the connection here - mFronts.put(front[0],front[1]); } } catch (IOException e) { - Log.i("sad","asd"); e.printStackTrace(); } } @@ -433,16 +431,11 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb return mFronts.get(service); } - private void startSnowflakeClient() { - //this is using the current, default Tor snowflake infrastructure String target = getCdnFront("snowflake-target"); String front = getCdnFront("snowflake-front"); String stunServer = getCdnFront("snowflake-stun"); - - IPtProxy.startSnowflake(stunServer, target, front, - null, true, false, true, 3); - + IPtProxy.startSnowflake(stunServer, target, front,null, true, false, true, 3); } /* @@ -843,7 +836,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb startTorService(); - if (Prefs.hostOnionServicesEnabled()) { + if (Prefs.hostOnionServicesEnabled()) { try { updateLegacyV2OnionNames(); } catch (SecurityException se) { @@ -943,8 +936,8 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb private synchronized void startTorService() throws Exception { updateTorConfigCustom(TorService.getDefaultsTorrc(this), "DNSPort 0\n" + - "TransPort 0\n" + - "DisableNetwork 1\n"); + "TransPort 0\n" + + "DisableNetwork 1\n"); File fileTorrcCustom = updateTorrcCustomFile(); if ((!fileTorrcCustom.exists()) || (!fileTorrcCustom.canRead())) @@ -982,8 +975,8 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb events.add(TorControlCommands.EVENT_INFO_MSG); } - conn.setEvents(events); + initControlConnection(); logNotice("SUCCESS added control port event handler"); } catch (InterruptedException | IOException e) { e.printStackTrace(); @@ -1225,7 +1218,6 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb int e=0; private void sendCallbackLogMessage(String logMessage) { - if(logMessage.contains("Bootstrapped 100%")){ orbotLocalConstants.mIsTorInitialized = true; } @@ -1827,14 +1819,24 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb if (!TextUtils.isEmpty(action)) { if (action.equals(ACTION_START) || action.equals(ACTION_START_ON_BOOT)) { - if (useIPtObfsMeekProxy()) - IPtProxy.startObfs4Proxy("DEBUG", true, false); + if (Prefs.bridgesEnabled()) { + if (useIPtObfsMeekProxy()) + IPtProxy.startObfs4Proxy("DEBUG", false, false); + else if (useIPtSnowflakeProxy()) + startSnowflakeClient(); + } else if (Prefs.beSnowflakeProxy()) { - if (useIPtSnowflakeProxy()) - startSnowflakeClient(); + if (Prefs.limitSnowflakeProxying()) + { + if (isChargingAndWifi(OrbotService.this)) + { + enableSnowflakeProxy(); + } - if (Prefs.beSnowflakeProxy()) - runSnowflakeProxy(); + } + else + enableSnowflakeProxy(); + } startTor(); replyWithStatus(mIntent); @@ -1854,7 +1856,8 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb if (mPortSOCKS != -1 && mPortHTTP != -1) sendCallbackPorts(mPortSOCKS, mPortHTTP, mPortDns, mPortTrans); } - + } else if (action.equals(ACTION_STOP)) { + stopTorAsync(); } else if (action.equals(ACTION_START_VPN)) { if (mVpnManager != null && (!mVpnManager.isStarted())) { //start VPN here @@ -1875,14 +1878,9 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb replyWithStatus(mIntent); } else if (action.equals(TorControlCommands.SIGNAL_RELOAD)) { requestTorRereadConfig(); - } - else if (action.equals(CMD_NEWNYM)) { - newIdentity(); - } - else if (action.equals(CMD_SETTING)) { - onSettingRegister(); - } - else if (action.equals(CMD_ACTIVE)) { + } else if (action.equals(TorControlCommands.SIGNAL_NEWNYM)) { + newIdentity(); + } else if (action.equals(CMD_ACTIVE)) { sendSignalActive(); } else if (action.equals(CMD_SET_EXIT)) { setExitNode(mIntent.getStringExtra("exit")); @@ -1893,6 +1891,19 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb } } + private void enableSnowflakeProxy () { + int capacity = 1; + String broker = "https://snowflake-broker.bamsoftware.com/"; + String relay = "wss://snowflake.bamsoftware.com/"; + String stun = "stun:stun.stunprotocol.org:3478"; + String logFile = null; + boolean keepLocalAddresses = true; + boolean unsafeLogging = false; + IPtProxy.startSnowflakeProxy(capacity, broker, relay, stun, logFile, keepLocalAddresses, unsafeLogging); + + logNotice("Snowflake Proxy mode ENABLED"); + } + public void disableNotification(){ if(mNotificationManager!=null){ mNotificationManager.cancel(NOTIFY_ID); @@ -1925,6 +1936,20 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb } } + public static boolean isChargingAndWifi(Context context) { + Intent intent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); + int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); + boolean isCharging = plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS; + + ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + + boolean isUnmetered = cm.getActiveNetworkInfo() != null + && cm.getActiveNetworkInfo().isConnected() + && (!cm.isActiveNetworkMetered()); + + return isCharging && isUnmetered; + } + private class ActionBroadcastReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { switch (intent.getAction()) { diff --git a/orbotmanager/src/main/java/org/torproject/android/service/TorEventHandler.java b/orbotmanager/src/main/java/org/torproject/android/service/TorEventHandler.java index 5340732b..3fcbb17b 100644 --- a/orbotmanager/src/main/java/org/torproject/android/service/TorEventHandler.java +++ b/orbotmanager/src/main/java/org/torproject/android/service/TorEventHandler.java @@ -6,7 +6,6 @@ import net.freehaven.tor.control.EventHandler; import org.torproject.android.service.util.ExternalIPFetcher; import org.torproject.android.service.util.Prefs; -import org.torproject.android.service.wrapper.orbotLocalConstants; import java.util.HashMap; import java.util.List; @@ -86,7 +85,7 @@ public class TorEventHandler implements EventHandler, TorServiceConstants { int iconId = R.drawable.ic_stat_starting_tor_logo; - if (read > 0 || written > 0 || OrbotService.getServiceObject().getConnectivity()) + if (read > 0 || written > 0) iconId = R.mipmap.ic_stat_tor_logo; String sb = OrbotService.formatBandwidthCount(mService, read) + " \u2193" + " / " + @@ -110,9 +109,8 @@ public class TorEventHandler implements EventHandler, TorServiceConstants { public void circuitStatus(String status, String circID, String path) { /* once the first circuit is complete, then announce that Orbot is on*/ - if (mService.getCurrentStatus() == STATUS_STARTING && TextUtils.equals(status, "BUILT")){ + if (mService.getCurrentStatus() == STATUS_STARTING && TextUtils.equals(status, "BUILT")) mService.sendCallbackStatus(STATUS_ON); - } if (Prefs.useDebugLogging()) { StringBuilder sb = new StringBuilder(); diff --git a/orbotmanager/src/main/java/org/torproject/android/service/util/ExternalIPFetcher.java b/orbotmanager/src/main/java/org/torproject/android/service/util/ExternalIPFetcher.java index 0a9e5ad3..957e1e65 100644 --- a/orbotmanager/src/main/java/org/torproject/android/service/util/ExternalIPFetcher.java +++ b/orbotmanager/src/main/java/org/torproject/android/service/util/ExternalIPFetcher.java @@ -4,7 +4,6 @@ import org.json.JSONArray; import org.json.JSONObject; import org.torproject.android.service.OrbotService; import org.torproject.android.service.TorEventHandler; -import org.torproject.android.service.wrapper.orbotLocalConstants; import java.io.BufferedReader; import java.io.InputStream; @@ -19,7 +18,7 @@ public class ExternalIPFetcher implements Runnable { private final static String ONIONOO_BASE_URL = "https://onionoo.torproject.org/details?fields=country_name,as_name,or_addresses&lookup="; private OrbotService mService; private TorEventHandler.Node mNode; - private int mLocalHttpProxyPort = orbotLocalConstants.mHTTPPort; + private int mLocalHttpProxyPort = 8118; public ExternalIPFetcher(OrbotService service, TorEventHandler.Node node, int localProxyPort) { mService = service; diff --git a/orbotmanager/src/main/java/org/torproject/android/service/util/Prefs.java b/orbotmanager/src/main/java/org/torproject/android/service/util/Prefs.java index f68ac98f..eaec24e5 100644 --- a/orbotmanager/src/main/java/org/torproject/android/service/util/Prefs.java +++ b/orbotmanager/src/main/java/org/torproject/android/service/util/Prefs.java @@ -2,8 +2,8 @@ package org.torproject.android.service.util; import android.content.Context; import android.content.SharedPreferences; + import org.torproject.android.service.OrbotConstants; -import org.torproject.android.service.wrapper.orbotLocalConstants; import java.util.Locale; @@ -21,6 +21,10 @@ public class Prefs { private final static String PREF_USE_VPN = "pref_vpn"; private final static String PREF_EXIT_NODES = "pref_exit_nodes"; private final static String PREF_BE_A_SNOWFLAKE = "pref_be_a_snowflake"; + private final static String PREF_BE_A_SNOWFLAKE_LIMIT = "pref_be_a_snowflake_limit"; + + private final static String PREF_HOST_ONION_SERVICES = "pref_host_onionservices"; + private static SharedPreferences prefs; @@ -37,16 +41,20 @@ public class Prefs { prefs.edit().putString(key, value).apply(); } + public static boolean hostOnionServicesEnabled () { + return prefs.getBoolean(PREF_HOST_ONION_SERVICES, true); + } + + public static void putHostOnionServicesEnabled(boolean value) { + putBoolean(PREF_HOST_ONION_SERVICES, value); + } + public static boolean bridgesEnabled() { //if phone is in Farsi, enable bridges by default boolean bridgesEnabledDefault = Locale.getDefault().getLanguage().equals("fa"); return prefs.getBoolean(PREF_BRIDGES_ENABLED, bridgesEnabledDefault); } - public static boolean hostOnionServicesEnabled(){ - return false; - } - public static void putBridgesEnabled(boolean value) { putBoolean(PREF_BRIDGES_ENABLED, value); } @@ -55,24 +63,6 @@ public class Prefs { String defaultBridgeType = "obfs4"; if (Locale.getDefault().getLanguage().equals("fa")) defaultBridgeType = "meek"; //if Farsi, use meek as the default bridge type - if(orbotLocalConstants.mIsManualBridge){ - if(!orbotLocalConstants.mManualBridgeType.equals("")){ - defaultBridgeType = orbotLocalConstants.mManualBridgeType; - putString(PREF_BRIDGES_LIST, defaultBridgeType); - return defaultBridgeType; - } - }else { - if(orbotLocalConstants.mBridges.equals("obfs4")){ - defaultBridgeType = "obfs4"; - putString(PREF_BRIDGES_LIST, defaultBridgeType); - return defaultBridgeType; - }else if(orbotLocalConstants.mBridges.equals("meek")){ - defaultBridgeType = "meek"; - putString(PREF_BRIDGES_LIST, defaultBridgeType); - return defaultBridgeType; - } - } - return prefs.getString(PREF_BRIDGES_LIST, defaultBridgeType); } @@ -92,6 +82,10 @@ public class Prefs { putBoolean(PREF_BE_A_SNOWFLAKE,beSnowflakeProxy); } + public static boolean limitSnowflakeProxying () { + return prefs.getBoolean(PREF_BE_A_SNOWFLAKE_LIMIT,true); + } + public static void setDefaultLocale(String value) { putString(PREF_DEFAULT_LOCALE, value); } @@ -101,7 +95,7 @@ public class Prefs { } public static boolean useDebugLogging() { - return false;//prefs.getBoolean(PREF_ENABLE_LOGGING, false); + return prefs.getBoolean(PREF_ENABLE_LOGGING, false); } public static boolean persistNotifications() { @@ -143,4 +137,4 @@ public class Prefs { public static SharedPreferences getSharedPrefs(Context context) { return context.getSharedPreferences(OrbotConstants.PREF_TOR_SHARED_PREFS, Context.MODE_MULTI_PROCESS); } -} \ No newline at end of file +} diff --git a/orbotmanager/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java b/orbotmanager/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java index 66538b04..7e991ace 100644 --- a/orbotmanager/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java +++ b/orbotmanager/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java @@ -45,9 +45,11 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; +import java.io.PrintWriter; import java.net.InetAddress; import java.util.ArrayList; import java.util.concurrent.TimeoutException; @@ -55,6 +57,8 @@ import java.util.concurrent.TimeoutException; import static org.torproject.android.service.TorServiceConstants.ACTION_START; import static org.torproject.android.service.TorServiceConstants.ACTION_START_VPN; import static org.torproject.android.service.TorServiceConstants.ACTION_STOP_VPN; +import static org.torproject.android.service.TorServiceConstants.TOR_DNS_PORT_DEFAULT; +import static org.torproject.android.service.TorServiceConstants.TOR_TRANSPROXY_PORT_DEFAULT; public class OrbotVpnManager implements Handler.Callback { private static final String TAG = "OrbotVpnService"; @@ -83,7 +87,8 @@ public class OrbotVpnManager implements Handler.Callback { } public static File makePdnsdConf(Context context, File fileDir, String torDnsHost, int torDnsPort, String pdnsdHost, int pdnsdPort) throws IOException { - String conf = String.format(context.getString(R.string.pdnsd_conf), torDnsHost, torDnsPort, fileDir.getCanonicalPath(), pdnsdHost, pdnsdPort); + String conf = String.format(context.getString(R.string.pdnsd_conf), + torDnsHost, torDnsPort, fileDir.getAbsolutePath(), pdnsdHost, pdnsdPort); Log.d(TAG, "pdsnd conf:" + conf); @@ -93,9 +98,8 @@ public class OrbotVpnManager implements Handler.Callback { fPid.delete(); } - FileOutputStream fos = new FileOutputStream(fPid, false); - PrintStream ps = new PrintStream(fos); - ps.print(conf); + PrintWriter ps = new PrintWriter(new FileWriter(fPid, false)); + ps.write(conf); ps.close(); File cache = new File(fileDir, "pdnsd.cache"); @@ -140,8 +144,8 @@ public class OrbotVpnManager implements Handler.Callback { } else if (action.equals(TorServiceConstants.LOCAL_ACTION_PORTS)) { Log.d(TAG, "setting VPN ports"); - int torSocks = intent.getIntExtra(OrbotService.EXTRA_SOCKS_PROXY_PORT, -1); - int torDns = intent.getIntExtra(OrbotService.EXTRA_DNS_PORT, -1); + int torSocks = intent.getIntExtra(OrbotService.EXTRA_SOCKS_PROXY_PORT, TOR_TRANSPROXY_PORT_DEFAULT); + int torDns = intent.getIntExtra(OrbotService.EXTRA_DNS_PORT, TOR_DNS_PORT_DEFAULT); //if running, we need to restart if ((torSocks != mTorSocks || torDns != mTorDns)) { diff --git a/orbotmanager/src/main/java/org/torproject/android/service/vpn/Tun2Socks.java b/orbotmanager/src/main/java/org/torproject/android/service/vpn/Tun2Socks.java index 8eda5954..461a5a8d 100644 --- a/orbotmanager/src/main/java/org/torproject/android/service/vpn/Tun2Socks.java +++ b/orbotmanager/src/main/java/org/torproject/android/service/vpn/Tun2Socks.java @@ -50,7 +50,7 @@ public class Tun2Socks { private static HashMap mAppUidBlacklist = new HashMap<>(); static { - //System.loadLibrary("tun2socks"); + System.loadLibrary("tun2socks"); } public static void init() { diff --git a/orbotmanager/src/main/jni/Android.mk b/orbotmanager/src/main/jni/Android.mk index 10accb58..123954ff 100644 --- a/orbotmanager/src/main/jni/Android.mk +++ b/orbotmanager/src/main/jni/Android.mk @@ -29,8 +29,8 @@ LOCAL_MODULE := pdnsd LOCAL_SRC_FILES := $(PDNSD_SOURCES:$(LOCAL_PATH)/%=%) LOCAL_CFLAGS := -Wall -O2 -I$(LOCAL_PATH)/pdnsd -DHAVE_STPCPY - include $(BUILD_EXECUTABLE) +##include $(BUILD_SHARED_LIBRARY) ######################################################## ## libancillary diff --git a/orbotmanager/src/main/jniLibs b/orbotmanager/src/main/jniLibs new file mode 100644 index 00000000..4dc6caa6 --- /dev/null +++ b/orbotmanager/src/main/jniLibs @@ -0,0 +1 @@ +libs \ No newline at end of file