diff options
Diffstat (limited to 'app/src/main/java')
8 files changed, 40 insertions, 207 deletions
diff --git a/app/src/main/java/de/blinkt/openvpn/core/ConnectionStatus.java b/app/src/main/java/de/blinkt/openvpn/core/ConnectionStatus.java index 3e6d23f7..8ee46d77 100644 --- a/app/src/main/java/de/blinkt/openvpn/core/ConnectionStatus.java +++ b/app/src/main/java/de/blinkt/openvpn/core/ConnectionStatus.java @@ -21,7 +21,8 @@ public enum ConnectionStatus implements Parcelable { LEVEL_START, LEVEL_AUTH_FAILED, LEVEL_WAITING_FOR_USER_INPUT, - LEVEL_BLOCKING, // used for Bitmask's VoidVPN + LEVEL_BLOCKING, // used for Bitmask's VoidVPN + LEVEL_STOPPING, UNKNOWN_LEVEL; @Override diff --git a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java index 11bc4da3..55e9cfe9 100644 --- a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java +++ b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java @@ -7,12 +7,8 @@ package de.blinkt.openvpn.core; import android.Manifest.permission; import android.annotation.TargetApi; -import android.app.Activity; import android.app.Notification; -import android.app.NotificationManager; -import android.app.PendingIntent; import android.app.UiModeManager; -import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; @@ -20,17 +16,14 @@ import android.content.pm.ShortcutManager; import android.content.res.Configuration; import android.content.res.Resources; import android.net.ConnectivityManager; -import android.net.Uri; import android.net.VpnService; import android.os.Build; -import android.os.Bundle; import android.os.Handler; import android.os.Handler.Callback; import android.os.IBinder; import android.os.Message; import android.os.ParcelFileDescriptor; import android.os.RemoteException; -import android.support.annotation.NonNull; import android.support.annotation.RequiresApi; import android.system.OsConstants; import android.text.TextUtils; @@ -39,7 +32,6 @@ import android.widget.Toast; import java.io.IOException; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.net.Inet6Address; import java.net.InetAddress; import java.net.UnknownHostException; @@ -47,8 +39,6 @@ import java.util.Collection; import java.util.Locale; import java.util.Vector; -import de.blinkt.openvpn.LaunchVPN; -import se.leap.bitmaskclient.R; import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.core.VpnStatus.ByteCountListener; import de.blinkt.openvpn.core.VpnStatus.StateListener; @@ -248,10 +238,14 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac @Override public boolean stopVPN(boolean replaceConnection) throws RemoteException { - if (getManagement() != null) - return getManagement().stopVPN(replaceConnection); - else - return false; + if (getManagement() != null && getManagement().stopVPN(replaceConnection)) { + if (!replaceConnection) { + VpnStatus.updateStateString("NOPROCESS", "VPN STOPPED", R.string.state_noprocess, ConnectionStatus.LEVEL_NOTCONNECTED); + } + return true; + } else { + return false; + } } /** diff --git a/app/src/main/java/de/blinkt/openvpn/core/VpnStatus.java b/app/src/main/java/de/blinkt/openvpn/core/VpnStatus.java index 0fae6183..d52ebac1 100644 --- a/app/src/main/java/de/blinkt/openvpn/core/VpnStatus.java +++ b/app/src/main/java/de/blinkt/openvpn/core/VpnStatus.java @@ -212,7 +212,6 @@ public class VpnStatus { } public interface StateListener { - String STATE_CONNECTRETRY = "CONNECTRETRY"; void updateState(String state, String logmessage, int localizedResId, ConnectionStatus level); void setConnectedVPN(String uuid); @@ -328,22 +327,29 @@ public class VpnStatus { String[] connected = {"CONNECTED"}; String[] notconnected = {"DISCONNECTED", "EXITING"}; + /** + * ignore incoming connection/reconnecting states if vpn is about to shut down + */ for (String x : noreplyet) - if (state.equals(x)) + if (state.equals(x) && !mLaststate.equals("STOPPING")) return ConnectionStatus.LEVEL_CONNECTING_NO_SERVER_REPLY_YET; for (String x : reply) - if (state.equals(x)) + if (state.equals(x) && !mLaststate.equals("STOPPING")) return ConnectionStatus.LEVEL_CONNECTING_SERVER_REPLIED; for (String x : connected) - if (state.equals(x)) + if (state.equals(x) && !mLaststate.equals("STOPPING")) return ConnectionStatus.LEVEL_CONNECTED; for (String x : notconnected) if (state.equals(x)) return ConnectionStatus.LEVEL_NOTCONNECTED; + if (mLaststate.equals("STOPPING")) { + return ConnectionStatus.LEVEL_STOPPING; + } + return ConnectionStatus.UNKNOWN_LEVEL; } @@ -377,6 +383,11 @@ public class VpnStatus { return; } + if (mLaststate.equals("STOPPING") && !state.equals("DISCONNECTED") && !state.equals("EXITING") && !state.equals("NOPROCESS")) { + newLogItem(new LogItem((LogLevel.DEBUG), String.format("Ignoring OpenVPN Status while exiting (%s->%s)", mLastLevel.toString(), level.toString()))); + return; + } + mLaststate = state; mLaststatemsg = msg; mLastStateresid = resid; diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index a535b0cb..2af455f8 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -350,7 +350,7 @@ public class EipFragment extends Fragment implements Observer { eipStatus = (EipStatus) observable; Activity activity = getActivity(); if (activity != null) { - activity.runOnUiThread(() -> handleNewState()); + activity.runOnUiThread(this::handleNewState); } else { Log.e("EipFragment", "activity is null"); } diff --git a/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java b/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java index f17fe28e..d9a6121b 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java @@ -25,6 +25,7 @@ import se.leap.bitmaskclient.utils.PreferenceHelper; import static android.app.Activity.RESULT_CANCELED; import static android.content.Intent.CATEGORY_DEFAULT; import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_CONNECTING_NO_SERVER_REPLY_YET; +import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_NOTCONNECTED; import static se.leap.bitmaskclient.Constants.BROADCAST_EIP_EVENT; import static se.leap.bitmaskclient.Constants.BROADCAST_GATEWAY_SETUP_OBSERVER_EVENT; import static se.leap.bitmaskclient.Constants.BROADCAST_PROVIDER_API_EVENT; @@ -101,8 +102,6 @@ class EipSetupObserver extends BroadcastReceiver implements VpnStatus.StateListe @Override public void onReceive(Context context, Intent intent) { - Log.d(TAG, "received Broadcast"); - String action = intent.getAction(); if (action == null) { return; @@ -124,8 +123,6 @@ class EipSetupObserver extends BroadcastReceiver implements VpnStatus.StateListe } private void handleProviderApiEvent(Intent intent) { - - int resultCode = intent.getIntExtra(BROADCAST_RESULT_CODE, RESULT_CANCELED); Bundle resultData = intent.getParcelableExtra(BROADCAST_RESULT_KEY); if (resultData == null) { @@ -145,24 +142,23 @@ class EipSetupObserver extends BroadcastReceiver implements VpnStatus.StateListe case CORRECTLY_UPDATED_INVALID_VPN_CERTIFICATE: provider = resultData.getParcelable(PROVIDER_KEY); ProviderObservable.getInstance().updateProvider(provider); + PreferenceHelper.storeProviderInPreferences(preferences, provider); EipCommand.startVPN(context.getApplicationContext(), true); break; default: break; } - - for (EipSetupListener listener : listeners) { listener.handleProviderApiEvent(intent); } - } private void handleEipEvent(Intent intent) { int resultCode = intent.getIntExtra(BROADCAST_RESULT_CODE, RESULT_CANCELED); - String eipRequest = intent.getStringExtra(EIP_REQUEST); + Bundle result = intent.getBundleExtra(BROADCAST_RESULT_KEY); + String eipRequest = result.getString(EIP_REQUEST); if (eipRequest == null) { return; } @@ -174,10 +170,6 @@ class EipSetupObserver extends BroadcastReceiver implements VpnStatus.StateListe finishGatewaySetup(false); } break; - case EIP_ACTION_STOP: - //setup was manually cancelled - finishGatewaySetup(false); - break; default: break; } @@ -232,9 +224,10 @@ class EipSetupObserver extends BroadcastReceiver implements VpnStatus.StateListe return; } - Log.d(TAG, "trying gateway: " + setupVpnProfile.getName()); - - if ("CONNECTRETRY".equals(state) && LEVEL_CONNECTING_NO_SERVER_REPLY_YET.equals(level)) { + if (ConnectionStatus.LEVEL_STOPPING == level) { + finishGatewaySetup(false); + } else if ("CONNECTRETRY".equals(state) && LEVEL_CONNECTING_NO_SERVER_REPLY_YET.equals(level)) { + Log.d(TAG, "trying gateway: " + setupVpnProfile.getName()); if (TIMEOUT.equals(logmessage)) { Log.e(TAG, "Timeout reached! Try next gateway!"); VpnStatus.logError("Timeout reached! Try next gateway!"); @@ -243,7 +236,7 @@ class EipSetupObserver extends BroadcastReceiver implements VpnStatus.StateListe } int current = reconnectTry.get(); reconnectTry.set(current + 1); - } else if ("NOPROCESS".equals(state) && ConnectionStatus.LEVEL_NOTCONNECTED == level) { + } else if ("NOPROCESS".equals(state) && LEVEL_NOTCONNECTED == level) { //?? } else if ("CONNECTED".equals(state)) { //saveLastProfile(context.getApplicationContext(), setupVpnProfile.getUUIDString()); diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java index 4226d70f..6cf6b67b 100644 --- a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java @@ -25,15 +25,12 @@ import android.support.annotation.IntDef; import android.support.annotation.Nullable; import android.util.Log; -import java.io.File; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import de.blinkt.openvpn.core.Preferences; import de.blinkt.openvpn.core.VpnStatus; import se.leap.bitmaskclient.eip.EipCommand; import se.leap.bitmaskclient.userstatus.User; -import se.leap.bitmaskclient.utils.PreferenceHelper; import static se.leap.bitmaskclient.Constants.APP_ACTION_CONFIGURE_ALWAYS_ON_PROFILE; import static se.leap.bitmaskclient.Constants.EIP_RESTART_ON_BOOT; @@ -100,9 +97,6 @@ public class StartActivity extends Activity{ VpnStatus.initLogCache(getApplicationContext().getCacheDir()); User.init(getString(R.string.default_username)); - fakeSetup(); - - prepareEIP(); } @@ -234,145 +228,4 @@ public class StartActivity extends Activity{ finish(); } - private void fakeSetup() { - PreferenceHelper.putString(this, "Constants.EIP_DEFINITION.riseup.net", getRiseupEipJson()); - PreferenceHelper.putString(this, "Constants.EIP_DEFINITION", getRiseupEipJson()); - SharedPreferences prefs = Preferences.getDefaultSharedPreferences(this); - SharedPreferences.Editor prefsedit = prefs.edit(); - prefsedit.remove("lastConnectedProfile").commit(); - File f = new File(this.getCacheDir().getAbsolutePath() + "/android.conf"); - if (f.exists()) { - Log.d(TAG, "android.conf exists -> delete:" + f.delete()); - } - - File filesDirectory = new File(this.getFilesDir().getAbsolutePath()); - if (filesDirectory.exists() && filesDirectory.isDirectory()) { - File[] filesInDirectory = filesDirectory.listFiles(); - for (File file : filesInDirectory) { - Log.d(TAG, "delete profile: " + file.getName() + ": "+ file.delete()); - - } - } else Log.d(TAG, "file folder doesn't exist"); - - - Log.d(TAG, "faked eipjson: " + PreferenceHelper.getString(this, "Constants.EIP_DEFINITION", "")); - Log.d(TAG, "lastConnectedProfile is emty: " + (prefs.getString("lastConnectedProfile", null) == null)); - } - - private String getRiseupEipJson() { - return "{\n" + - " \"gateways\":[\n" + - " {\n" + - " \"capabilities\":{\n" + - " \"adblock\":false,\n" + - " \"filter_dns\":false,\n" + - " \"limited\":false,\n" + - " \"ports\":[\n" + - " \"443\"\n" + - " ],\n" + - " \"protocols\":[\n" + - " \"tcp\"\n" + - " ],\n" + - " \"transport\":[\n" + - " \"openvpn\"\n" + - " ],\n" + - " \"user_ips\":false\n" + - " },\n" + - " \"host\":\"garza.riseup.net\",\n" + - " \"ip_address\":\"198.252.153.28\",\n" + - " \"location\":\"seattle\"\n" + - " },\n" + - " {\n" + - " \"capabilities\":{\n" + - " \"adblock\":false,\n" + - " \"filter_dns\":false,\n" + - " \"limited\":false,\n" + - " \"ports\":[\n" + - " \"443\"\n" + - " ],\n" + - " \"protocols\":[\n" + - " \"tcp\"\n" + - " ],\n" + - " \"transport\":[\n" + - " \"openvpn\"\n" + - " ],\n" + - " \"user_ips\":false\n" + - " },\n" + - " \"host\":\"no.giraffe.riseup.net\",\n" + - " \"ip_address\":\"37.218.242.212\",\n" + - " \"location\":\"amsterdam\"\n" + - " },\n" + - " {\n" + - " \"capabilities\":{\n" + - " \"adblock\":false,\n" + - " \"filter_dns\":false,\n" + - " \"limited\":false,\n" + - " \"ports\":[\n" + - " \"443\"\n" + - " ],\n" + - " \"protocols\":[\n" + - " \"tcp\"\n" + - " ],\n" + - " \"transport\":[\n" + - " \"openvpn\"\n" + - " ],\n" + - " \"user_ips\":false\n" + - " },\n" + - " \"host\":\"no.tenca.riseup.net\",\n" + - " \"ip_address\":\"5.79.86.181\",\n" + - " \"location\":\"amsterdam\"\n" + - " },\n" + - " {\n" + - " \"capabilities\":{\n" + - " \"adblock\":false,\n" + - " \"filter_dns\":false,\n" + - " \"limited\":false,\n" + - " \"ports\":[\n" + - " \"443\"\n" + - " ],\n" + - " \"protocols\":[\n" + - " \"tcp\"\n" + - " ],\n" + - " \"transport\":[\n" + - " \"openvpn\"\n" + - " ],\n" + - " \"user_ips\":false\n" + - " },\n" + - " \"host\":\"yal.riseup.net\",\n" + - " \"ip_address\":\"199.58.81.145\",\n" + - " \"location\":\"montreal\"\n" + - " }\n" + - " ],\n" + - " \"locations\":{\n" + - " \"amsterdam\":{\n" + - " \"country_code\":\"NL\",\n" + - " \"hemisphere\":\"N\",\n" + - " \"name\":\"Amsterdam\",\n" + - " \"timezone\":\"+2\"\n" + - " },\n" + - " \"montreal\":{\n" + - " \"country_code\":\"CA\",\n" + - " \"hemisphere\":\"N\",\n" + - " \"name\":\"Montreal\",\n" + - " \"timezone\":\"-5\"\n" + - " },\n" + - " \"seattle\":{\n" + - " \"country_code\":\"US\",\n" + - " \"hemisphere\":\"N\",\n" + - " \"name\":\"Seattle\",\n" + - " \"timezone\":\"-7\"\n" + - " }\n" + - " },\n" + - " \"openvpn_configuration\":{\n" + - " \"auth\":\"SHA1\",\n" + - " \"cipher\":\"AES-128-CBC\",\n" + - " \"keepalive\":\"10 30\",\n" + - " \"tls-cipher\":\"DHE-RSA-AES128-SHA\",\n" + - " \"tun-ipv6\":true\n" + - " },\n" + - " \"serial\":1,\n" + - " \"version\":1\n" + - "}"; - } - } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java index 0e6d9b95..29e2199f 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -43,12 +43,13 @@ import java.util.Observer; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; -import de.blinkt.openvpn.LaunchVPN; +import de.blinkt.openvpn.core.ConnectionStatus; import de.blinkt.openvpn.core.IOpenVPNServiceInternal; import de.blinkt.openvpn.core.OpenVPNService; import de.blinkt.openvpn.core.ProfileManager; import de.blinkt.openvpn.core.VpnStatus; import se.leap.bitmaskclient.OnBootReceiver; +import se.leap.bitmaskclient.R; import static android.app.Activity.RESULT_CANCELED; import static android.app.Activity.RESULT_OK; @@ -175,7 +176,6 @@ public final class EIP extends JobIntentService implements Observer { } } - /** * Initiates an EIP connection by selecting a gateway and preparing and sending an * Intent to {@link de.blinkt.openvpn.LaunchVPN}. @@ -216,13 +216,10 @@ public final class EIP extends JobIntentService implements Observer { * The {@link OnBootReceiver} will care if there is no profile. */ private void startEIPAlwaysOnVpn() { - Log.d(TAG, "startEIPAlwaysOnVpn vpn"); - GatewaysManager gatewaysManager = gatewaysFromPreferences(); Gateway gateway = gatewaysManager.select(0); if (gateway != null && gateway.getProfile() != null) { - Log.d(TAG, "startEIPAlwaysOnVpn eip launch closest gateway."); launchActiveGateway(gateway, 0); } else { Log.d(TAG, "startEIPAlwaysOnVpn no active profile available!"); @@ -245,18 +242,9 @@ public final class EIP extends JobIntentService implements Observer { * @param gateway to connect to */ private void launchActiveGateway(@NonNull Gateway gateway, int nClosestGateway) { - /*Intent gatewaySetupWatcherIntent = new Intent(BROADCAST_GATEWAY_SETUP_OBSERVER_EVENT); - gatewaySetupWatcherIntent.putExtra(EIP_REQUEST, ) - gatewaySetupWatcherIntent.putExtra(LaunchVPN.EXTRA_TEMP_VPN_PROFILE, gateway.getProfile());*/ - - - Intent intent = new Intent(BROADCAST_GATEWAY_SETUP_OBSERVER_EVENT); //new Intent(this, LaunchVPN.class); - //intent.setAction(Intent.ACTION_MAIN); - //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - //intent.putExtra(LaunchVPN.EXTRA_HIDELOG, true); + Intent intent = new Intent(BROADCAST_GATEWAY_SETUP_OBSERVER_EVENT); intent.putExtra(EXTRA_TEMP_VPN_PROFILE, gateway.getProfile()); intent.putExtra(Gateway.KEY_N_CLOSEST_GATEWAY, nClosestGateway); - //startActivity(intent); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); } @@ -267,6 +255,7 @@ public final class EIP extends JobIntentService implements Observer { * terminates EIP if currently connected or connecting */ private void stopEIP() { + VpnStatus.updateStateString("STOPPING", "STOPPING VPN", R.string.state_exiting, ConnectionStatus.LEVEL_STOPPING); int resultCode = stop() ? RESULT_OK : RESULT_CANCELED; tellToReceiverOrBroadcast(EIP_ACTION_STOP, resultCode); } @@ -295,14 +284,6 @@ public final class EIP extends JobIntentService implements Observer { } /** - * Updates the eip.json. It containes information about the vpn service of a provider such as - * available gateways, supported protocols and open ports. - */ - private void updateEipJson() { - - } - - /** * read VPN certificate from preferences and check it * broadcast result */ @@ -409,7 +390,6 @@ public final class EIP extends JobIntentService implements Observer { startService(stopVoidVpnIntent); } - /** * creates a OpenVpnServiceConnection if necessary * then terminates OpenVPN diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java index 861f5fd3..20154ac1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java @@ -115,6 +115,7 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { break; case LEVEL_AUTH_FAILED: case LEVEL_NOTCONNECTED: + case LEVEL_STOPPING: currentEipLevel = EipLevel.DISCONNECTED; break; case LEVEL_NONETWORK: |