summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-12-15 16:22:58 +0100
committerParménides GV <parmegv@sdf.org>2014-12-15 16:22:58 +0100
commit18fef7c99aa36b3e5622b3865f36d78d0879e92d (patch)
tree7a04fc87318d5008bbc1f1ac145ebb505bb5238c /app/src/main/java
parent56fe0400b8983ce57112ed5a0f993985a87741c0 (diff)
parent33c5958a18599267820f73b151d8161d83f93d88 (diff)
Merge branch 'research/Test-on-Android-5-#6543' into develop
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/de/blinkt/openvpn/VpnProfile.java38
-rw-r--r--app/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java8
-rw-r--r--app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java1
-rw-r--r--app/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java7
-rw-r--r--app/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java151
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java72
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java35
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/Constants.java1
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIP.java28
9 files changed, 190 insertions, 151 deletions
diff --git a/app/src/main/java/de/blinkt/openvpn/VpnProfile.java b/app/src/main/java/de/blinkt/openvpn/VpnProfile.java
index 65214c4f..fb2ba90d 100644
--- a/app/src/main/java/de/blinkt/openvpn/VpnProfile.java
+++ b/app/src/main/java/de/blinkt/openvpn/VpnProfile.java
@@ -45,7 +45,6 @@ import java.util.Collection;
import java.util.Locale;
import java.util.UUID;
import java.util.Vector;
-import java.util.concurrent.Future;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
@@ -54,6 +53,7 @@ import javax.crypto.NoSuchPaddingException;
import de.blinkt.openvpn.core.NativeUtils;
import de.blinkt.openvpn.core.OpenVPNService;
+import de.blinkt.openvpn.core.VPNLaunchHelper;
import de.blinkt.openvpn.core.VpnStatus;
import de.blinkt.openvpn.core.X509Utils;
@@ -68,11 +68,8 @@ public class VpnProfile implements Serializable {
public static final String EXTRA_PROFILEUUID = "de.blinkt.openvpn.profileUUID";
public static final String INLINE_TAG = "[[INLINE]]";
public static final String DISPLAYNAME_TAG = "[[NAME]]";
- private static final String MININONPIEVPN = "nopievpn";
- private static final String MINIPIEVPN = "pievpn";
private static final long serialVersionUID = 7085688938959334563L;
- private static final String OVPNCONFIGFILE = "android.conf";
public static final int MAXLOGLEVEL = 4;
public static final int CURRENT_PROFILE_VERSION = 2;
public static final int DEFAULT_MSSFIX_SIZE = 1450;
@@ -164,20 +161,6 @@ public class VpnProfile implements Serializable {
mProfileVersion = CURRENT_PROFILE_VERSION;
}
- public static String getMiniVPNExecutableName()
- {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
- return VpnProfile.MINIPIEVPN;
- else
- return VpnProfile.MININONPIEVPN;
- }
-
- public static String[] replacePieWithNoPie(String[] mArgv)
- {
- mArgv[0] = mArgv[0].replace(MINIPIEVPN, MININONPIEVPN);
- return mArgv;
- }
-
public static String openVpnEscape(String unescaped) {
if (unescaped == null)
return null;
@@ -576,19 +559,6 @@ public class VpnProfile implements Serializable {
return parts[0] + " " + netmask;
}
- private String[] buildOpenvpnArgv(File cacheDir) {
- Vector<String> args = new Vector<String>();
-
- // Add fixed paramenters
- //args.add("/data/data/de.blinkt.openvpn/lib/openvpn");
- args.add(cacheDir.getAbsolutePath() + "/" + getMiniVPNExecutableName());
-
- args.add("--config");
- args.add(cacheDir.getAbsolutePath() + "/" + OVPNCONFIGFILE);
-
-
- return args.toArray(new String[args.size()]);
- }
@@ -603,7 +573,7 @@ public class VpnProfile implements Serializable {
try {
- FileWriter cfg = new FileWriter(context.getCacheDir().getAbsolutePath() + "/" + OVPNCONFIGFILE);
+ FileWriter cfg = new FileWriter(VPNLaunchHelper.getConfigFilePath(context));
cfg.write(getConfigFile(context, false));
cfg.flush();
cfg.close();
@@ -618,7 +588,7 @@ public class VpnProfile implements Serializable {
String prefix = context.getPackageName();
Intent intent = new Intent(context, OpenVPNService.class);
- intent.putExtra(prefix + ".ARGV", buildOpenvpnArgv(context.getCacheDir()));
+ intent.putExtra(prefix + ".ARGV", VPNLaunchHelper.buildOpenvpnArgv(context));
intent.putExtra(prefix + ".profileUUID", mUuid.toString());
ApplicationInfo info = context.getApplicationInfo();
@@ -648,7 +618,7 @@ public class VpnProfile implements Serializable {
public static boolean isEmbedded(String data) {
if (data==null)
return false;
- if(data.startsWith(INLINE_TAG) || data.startsWith(DISPLAYNAME_TAG))
+ if (data.startsWith(INLINE_TAG) || data.startsWith(DISPLAYNAME_TAG))
return true;
else
return false;
diff --git a/app/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java b/app/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java
index e6b73a48..4940d5d6 100644
--- a/app/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java
+++ b/app/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java
@@ -17,7 +17,7 @@ import de.blinkt.openvpn.core.ProfileManager;
/**
* Created by arne on 13.10.13.
*/
-public class DisconnectVPN extends Activity implements DialogInterface.OnClickListener{
+public class DisconnectVPN extends Activity implements DialogInterface.OnClickListener, DialogInterface.OnCancelListener {
protected OpenVPNService mService;
private ServiceConnection mConnection = new ServiceConnection() {
@@ -71,6 +71,7 @@ public class DisconnectVPN extends Activity implements DialogInterface.OnClickLi
builder.setMessage(R.string.cancel_connection_query);
builder.setNegativeButton(android.R.string.no, this);
builder.setPositiveButton(android.R.string.yes,this);
+ builder.setOnCancelListener(this);
builder.show();
}
@@ -84,4 +85,9 @@ public class DisconnectVPN extends Activity implements DialogInterface.OnClickLi
}
finish();
}
+
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ finish();
+ }
}
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 ada065ba..d9830955 100644
--- a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
+++ b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
@@ -719,6 +719,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
public void updateState(String state, String logmessage, int resid, ConnectionStatus level) {
// If the process is not running, ignore any state,
// Notification should be invisible in this state
+
doSendBroadcast(state, level);
if (mProcessThread == null && !mNotificationAlwaysVisible)
return;
diff --git a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java
index e3c60854..e36a5b8a 100644
--- a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java
+++ b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java
@@ -5,6 +5,7 @@
package de.blinkt.openvpn.core;
+import android.annotation.SuppressLint;
import android.util.Log;
import java.io.BufferedReader;
@@ -30,6 +31,7 @@ import de.blinkt.openvpn.core.VpnStatus.LogItem;
public class OpenVPNThread implements Runnable {
private static final String DUMP_PATH_STRING = "Dump path: ";
+ @SuppressLint("SdCardPath")
private static final String BROKEN_PIE_SUPPORT = "/data/data/de.blinkt.openvpn/cache/pievpn[1]: syntax error:";
private static final String TAG = "OpenVPN";
public static final int M_FATAL = (1 << 4);
@@ -78,7 +80,8 @@ public class OpenVPNThread implements Runnable {
if( exitvalue != 0) {
VpnStatus.logError("Process exited with exit value " + exitvalue);
if (mBrokenPie) {
- String[] noPieArgv = VpnProfile.replacePieWithNoPie(mArgv);
+ /* This will probably fail since the NoPIE binary is probably not written */
+ String[] noPieArgv = VPNLaunchHelper.replacePieWithNoPie(mArgv);
// We are already noPIE, nothing to gain
if (!noPieArgv.equals(mArgv)) {
@@ -190,7 +193,7 @@ public class OpenVPNThread implements Runnable {
private String genLibraryPath(String[] argv, ProcessBuilder pb) {
// Hack until I find a good way to get the real library path
- String applibpath = argv[0].replace("/cache/" + VpnProfile.getMiniVPNExecutableName() , "/lib");
+ String applibpath = argv[0].replaceFirst("/cache/.*$" , "/lib");
String lbpath = pb.environment().get("LD_LIBRARY_PATH");
if(lbpath==null)
diff --git a/app/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java b/app/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
index 40f9742b..208aa359 100644
--- a/app/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
+++ b/app/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
@@ -5,70 +5,122 @@
package de.blinkt.openvpn.core;
+import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.ApplicationInfo;
import android.os.Build;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Vector;
import se.leap.bitmaskclient.R;
import de.blinkt.openvpn.VpnProfile;
public class VPNLaunchHelper {
- static private boolean writeMiniVPN(Context context) {
- File mvpnout = new File(context.getCacheDir(),VpnProfile.getMiniVPNExecutableName());
- if (mvpnout.exists() && mvpnout.canExecute())
- return true;
-
- IOException e2 = null;
-
- try {
- InputStream mvpn;
-
- try {
- mvpn = context.getAssets().open(VpnProfile.getMiniVPNExecutableName() + "." + Build.CPU_ABI);
- }
- catch (IOException errabi) {
- VpnStatus.logInfo("Failed getting assets for archicture " + Build.CPU_ABI);
- e2=errabi;
- mvpn = context.getAssets().open(VpnProfile.getMiniVPNExecutableName() + "." + Build.CPU_ABI2);
-
- }
-
-
- FileOutputStream fout = new FileOutputStream(mvpnout);
-
- byte buf[]= new byte[4096];
-
- int lenread = mvpn.read(buf);
- while(lenread> 0) {
- fout.write(buf, 0, lenread);
- lenread = mvpn.read(buf);
- }
- fout.close();
-
- if(!mvpnout.setExecutable(true)) {
- VpnStatus.logError("Failed to make OpenVPN executable");
- return false;
- }
-
-
- return true;
- } catch (IOException e) {
- if(e2!=null)
- VpnStatus.logException(e2);
- VpnStatus.logException(e);
-
- return false;
- }
+ private static final String MININONPIEVPN = "nopievpn";
+ private static final String MINIPIEVPN = "pievpn";
+ private static final String OVPNCONFIGFILE = "android.conf";
+
+
+
+ static private String writeMiniVPN(Context context) {
+ String[] abis;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
+ abis = getSupportedAbisLollipop();
+ else
+ abis = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
+
+ for (String abi: abis) {
+
+ File mvpnout = new File(context.getCacheDir(), getMiniVPNExecutableName() + "." + abi);
+ if ((mvpnout.exists() && mvpnout.canExecute()) || writeMiniVPNBinary(context, abi, mvpnout)) {
+ return mvpnout.getPath();
+ }
+ }
+
+ return null;
}
+
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ private static String[] getSupportedAbisLollipop() {
+ return Build.SUPPORTED_ABIS;
+ }
+
+ private static String getMiniVPNExecutableName()
+ {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
+ return MINIPIEVPN;
+ else
+ return MININONPIEVPN;
+ }
+
+
+ public static String[] replacePieWithNoPie(String[] mArgv)
+ {
+ mArgv[0] = mArgv[0].replace(MINIPIEVPN, MININONPIEVPN);
+ return mArgv;
+ }
+
+
+ public static String[] buildOpenvpnArgv(Context c) {
+ Vector<String> args = new Vector<String>();
+
+ // Add fixed paramenters
+ //args.add("/data/data/de.blinkt.openvpn/lib/openvpn");
+ args.add(writeMiniVPN(c));
+
+ args.add("--config");
+ args.add(c.getCacheDir().getAbsolutePath() + "/" + OVPNCONFIGFILE);
+
+
+ return args.toArray(new String[args.size()]);
+ }
+
+ private static boolean writeMiniVPNBinary(Context context, String abi, File mvpnout) {
+ try {
+ InputStream mvpn;
+
+ try {
+ mvpn = context.getAssets().open(getMiniVPNExecutableName() + "." + abi);
+ }
+ catch (IOException errabi) {
+ VpnStatus.logInfo("Failed getting assets for archicture " + abi);
+ return false;
+ }
+
+
+ FileOutputStream fout = new FileOutputStream(mvpnout);
+
+ byte buf[]= new byte[4096];
+
+ int lenread = mvpn.read(buf);
+ while(lenread> 0) {
+ fout.write(buf, 0, lenread);
+ lenread = mvpn.read(buf);
+ }
+ fout.close();
+
+ if(!mvpnout.setExecutable(true)) {
+ VpnStatus.logError("Failed to make OpenVPN executable");
+ return false;
+ }
+
+
+ return true;
+ } catch (IOException e) {
+ VpnStatus.logException(e);
+ return false;
+ }
+
+ }
public static void startOpenVpn(VpnProfile startprofile, Context context) {
- if(!writeMiniVPN(context)) {
+ if(writeMiniVPN(context)==null) {
VpnStatus.logError("Error writing minivpn binary");
return;
}
@@ -80,4 +132,9 @@ public class VPNLaunchHelper {
context.startService(startVPN);
}
+
+ public static String getConfigFilePath(Context context) {
+ return context.getCacheDir().getAbsolutePath() + "/" + OVPNCONFIGFILE;
+ }
+
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index 3ecf5e52..862086eb 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -16,6 +16,7 @@
*/
package se.leap.bitmaskclient;
+import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DialogFragment;
@@ -34,6 +35,7 @@ import android.view.MenuItem;
import android.widget.ProgressBar;
import android.widget.TextView;
+import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
import org.json.JSONObject;
@@ -48,7 +50,7 @@ import se.leap.bitmaskclient.eip.EIP;
import se.leap.bitmaskclient.eip.EipStatus;
/**
- * The main user facing Activity of LEAP Android, consisting of status, controls,
+ * The main user facing Activity of Bitmask Android, consisting of status, controls,
* and access to preferences.
*
* @author Sean Leonard <meanderingcode@aetherislands.net>
@@ -81,7 +83,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
public ProviderAPIResultReceiver providerAPI_result_receiver;
@Override
- protected void onSaveInstanceState(Bundle outState) {
+ protected void onSaveInstanceState(@NotNull Bundle outState) {
if(provider != null)
outState.putParcelable(Provider.KEY, provider);
super.onSaveInstanceState(outState);
@@ -99,24 +101,36 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
fragment_manager = new FragmentManagerEnhanced(getFragmentManager());
handleVersion();
- if(savedInstanceState != null)
- provider = savedInstanceState.getParcelable(Provider.KEY);
- if(provider == null && preferences.getBoolean(Constants.PROVIDER_CONFIGURED, false))
- try {
- provider = new Provider(new URL(preferences.getString(Provider.MAIN_URL, "")));
- provider.define(new JSONObject(preferences.getString(Provider.KEY, "")));
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (JSONException e) {
- e.printStackTrace();
- }
-
+ provider = getSavedProvider(savedInstanceState);
if (provider == null || provider.getName().isEmpty())
startActivityForResult(new Intent(this,ConfigurationWizard.class),CONFIGURE_LEAP);
else
buildDashboard(getIntent().getBooleanExtra(ON_BOOT, false));
}
+ private Provider getSavedProvider(Bundle savedInstanceState) {
+ Provider provider = null;
+ if(savedInstanceState != null)
+ provider = savedInstanceState.getParcelable(Provider.KEY);
+ else if(preferences.getBoolean(Constants.PROVIDER_CONFIGURED, false))
+ provider = getSavedProviderFromSharedPreferences();
+
+ return provider;
+ }
+
+ private Provider getSavedProviderFromSharedPreferences() {
+ Provider provider = null;
+ try {
+ provider = new Provider(new URL(preferences.getString(Provider.MAIN_URL, "")));
+ provider.define(new JSONObject(preferences.getString(Provider.KEY, "")));
+ } catch (MalformedURLException | JSONException e) {
+ e.printStackTrace();
+ }
+
+ return provider;
+ }
+
+
private void handleVersion() {
try {
int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
@@ -140,13 +154,12 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
}
}
+ @SuppressLint("CommitPrefEdits")
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
Log.d(TAG, "onActivityResult: requestCode = " + requestCode);
if ( requestCode == CONFIGURE_LEAP || requestCode == SWITCH_PROVIDER) {
- // It should be equivalent: if ( (requestCode == CONFIGURE_LEAP) || (data!= null && data.hasExtra(STOP_FIRST))) {
if ( resultCode == RESULT_OK ) {
- preferences.edit().putInt(Constants.PARSED_SERIAL, 0).apply();
preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).apply();
updateEipService();
@@ -205,7 +218,6 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
ButterKnife.inject(this);
provider_name.setText(provider.getDomain());
-
if ( provider.hasEIP()){
fragment_manager.removePreviousFragment(EipServiceFragment.TAG);
@@ -412,16 +424,16 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
@Override
public void onReceiveResult(int resultCode, Bundle resultData) {
Log.d(TAG, "onReceiveResult");
- if(resultCode == ProviderAPI.SRP_REGISTRATION_SUCCESSFUL) {
+ if(resultCode == ProviderAPI.SUCCESSFUL_SIGNUP) {
String username = resultData.getString(SessionDialog.USERNAME);
String password = resultData.getString(SessionDialog.PASSWORD);
logIn(username, password);
- } else if(resultCode == ProviderAPI.SRP_REGISTRATION_FAILED) {
+ } else if(resultCode == ProviderAPI.FAILED_SIGNUP) {
changeStatusMessage(resultCode);
hideProgressBar();
signUpDialog(resultData);
- } else if(resultCode == ProviderAPI.SRP_AUTHENTICATION_SUCCESSFUL) {
+ } else if(resultCode == ProviderAPI.SUCCESSFUL_LOGIN) {
changeStatusMessage(resultCode);
hideProgressBar();
@@ -431,12 +443,12 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).apply();
downloadAuthedUserCertificate();
- } else if(resultCode == ProviderAPI.SRP_AUTHENTICATION_FAILED) {
+ } else if(resultCode == ProviderAPI.FAILED_LOGIN) {
changeStatusMessage(resultCode);
hideProgressBar();
logInDialog(resultData);
- } else if(resultCode == ProviderAPI.LOGOUT_SUCCESSFUL) {
+ } else if(resultCode == ProviderAPI.SUCCESSFUL_LOGOUT) {
changeStatusMessage(resultCode);
hideProgressBar();
@@ -477,7 +489,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
}
}
};
- updateEIP.putExtra(Constants.RECEIVER_TAG, receiver);
+ //updateEIP.putExtra(Constants.RECEIVER_TAG, receiver);
startService(updateEIP);
}
@@ -491,11 +503,11 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
if (resultCode == Activity.RESULT_OK){
switch(previous_result_code){
- case ProviderAPI.SRP_AUTHENTICATION_SUCCESSFUL: eip_fragment.status_message.setText(R.string.succesful_authentication_message); break;
- case ProviderAPI.SRP_AUTHENTICATION_FAILED: eip_fragment.status_message.setText(R.string.authentication_failed_message); break;
+ case ProviderAPI.SUCCESSFUL_LOGIN: eip_fragment.status_message.setText(R.string.succesful_authentication_message); break;
+ case ProviderAPI.FAILED_LOGIN: eip_fragment.status_message.setText(R.string.authentication_failed_message); break;
case ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE: eip_fragment.status_message.setText(R.string.authed_secured_status); break;
case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE: eip_fragment.status_message.setText(R.string.incorrectly_downloaded_certificate_message); break;
- case ProviderAPI.LOGOUT_SUCCESSFUL: eip_fragment.status_message.setText(R.string.logged_out_message); break;
+ case ProviderAPI.SUCCESSFUL_LOGOUT: eip_fragment.status_message.setText(R.string.logged_out_message); break;
case ProviderAPI.LOGOUT_FAILED: eip_fragment.status_message.setText(R.string.log_out_failed_message); break;
}
@@ -504,12 +516,12 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
switch(previous_result_code){
- case ProviderAPI.SRP_AUTHENTICATION_SUCCESSFUL: eip_fragment.status_message.setText(R.string.succesful_authentication_message); break;
- case ProviderAPI.SRP_AUTHENTICATION_FAILED: eip_fragment.status_message.setText(R.string.authentication_failed_message); break;
- case ProviderAPI.SRP_REGISTRATION_FAILED: eip_fragment.status_message.setText(R.string.registration_failed_message); break;
+ case ProviderAPI.SUCCESSFUL_LOGIN: eip_fragment.status_message.setText(R.string.succesful_authentication_message); break;
+ case ProviderAPI.FAILED_LOGIN: eip_fragment.status_message.setText(R.string.authentication_failed_message); break;
+ case ProviderAPI.FAILED_SIGNUP: eip_fragment.status_message.setText(R.string.registration_failed_message); break;
case ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE: break;
case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE: eip_fragment.status_message.setText(R.string.incorrectly_downloaded_certificate_message); break;
- case ProviderAPI.LOGOUT_SUCCESSFUL: eip_fragment.status_message.setText(R.string.logged_out_message); break;
+ case ProviderAPI.SUCCESSFUL_LOGOUT: eip_fragment.status_message.setText(R.string.logged_out_message); break;
case ProviderAPI.LOGOUT_FAILED: eip_fragment.status_message.setText(R.string.log_out_failed_message); break;
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java
index 904aa31d..1b40c94c 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java
@@ -47,6 +47,7 @@ public class EipServiceFragment extends Fragment implements Observer {
private static Activity parent_activity;
private static EIPReceiver mEIPReceiver;
private static EipStatus eip_status;
+ private boolean is_starting_to_connect;
@Override
public void onAttach(Activity activity) {
@@ -139,7 +140,7 @@ public class EipServiceFragment extends Fragment implements Observer {
private boolean canStartEIP() {
boolean certificateExists = !Dashboard.preferences.getString(Constants.CERTIFICATE, "").isEmpty();
boolean isAllowedAnon = Dashboard.preferences.getBoolean(Constants.ALLOWED_ANON, false);
- return (isAllowedAnon || certificateExists) && !eip_status.isConnected();
+ return (isAllowedAnon || certificateExists) && !eip_status.isConnected() && !eip_status.isConnecting();
}
private boolean canLogInToStartEIP() {
@@ -178,6 +179,7 @@ public class EipServiceFragment extends Fragment implements Observer {
}
public void startEipFromScratch() {
+ is_starting_to_connect = true;
progress_bar.setVisibility(View.VISIBLE);
eip_switch.setVisibility(View.VISIBLE);
String status = parent_activity.getString(R.string.eip_status_start_pending);
@@ -230,18 +232,19 @@ public class EipServiceFragment extends Fragment implements Observer {
Log.d(TAG, "handleNewState: " + eip_status.toString());
if(eip_status.wantsToDisconnect())
setDisconnectedUI();
+ else if(eip_status.isConnecting() || is_starting_to_connect)
+ setInProgressUI(eip_status);
else if (eip_status.isConnected())
setConnectedUI();
else if (eip_status.isDisconnected() && !eip_status.isConnecting())
setDisconnectedUI();
- else
- setInProgressUI(eip_status);
}
private void setConnectedUI() {
hideProgressBar();
Log.d(TAG, "setConnectedUi? " + eip_status.isConnected());
adjustSwitch();
+ is_starting_to_connect = false;
status_message.setText(parent_activity.getString(R.string.eip_state_connected));
}
@@ -252,14 +255,14 @@ public class EipServiceFragment extends Fragment implements Observer {
}
private void adjustSwitch() {
- if(eip_status.isConnected() || eip_status.isConnecting()) {
- Log.d(TAG, "adjustSwitch, isConnected || isConnecting, is checked? " + eip_switch.isChecked());
+ if(eip_status.isConnected() || eip_status.isConnecting() || is_starting_to_connect) {
+ Log.d(TAG, "adjustSwitch, isConnected || isConnecting, is checked");
if(!eip_switch.isChecked()) {
eip_switch.setChecked(true);
}
} else {
Log.d(TAG, "adjustSwitch, !isConnected && !isConnecting? " + eip_status.toString());
-
+
if(eip_switch.isChecked()) {
eip_switch.setChecked(false);
}
@@ -272,22 +275,17 @@ public class EipServiceFragment extends Fragment implements Observer {
String prefix = parent_activity.getString(localizedResId);
status_message.setText(prefix + " " + logmessage);
+ is_starting_to_connect = false;
adjustSwitch();
}
- protected void setStatusMessage(String status) {
- if(status_message == null)
- status_message = (TextView) parent_activity.findViewById(R.id.status_message);
- status_message.setText(status);
- }
-
private void hideProgressBar() {
if(progress_bar != null)
progress_bar.setVisibility(View.GONE);
}
protected class EIPReceiver extends ResultReceiver {
-
+
protected EIPReceiver(Handler handler){
super(handler);
}
@@ -295,17 +293,14 @@ public class EipServiceFragment extends Fragment implements Observer {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);
-
+
String request = resultData.getString(Constants.REQUEST_TAG);
if (request.equals(Constants.ACTION_START_EIP)) {
switch (resultCode){
case Activity.RESULT_OK:
- Log.d(TAG, "Action start eip = Result OK");
- progress_bar.setVisibility(View.VISIBLE);
break;
case Activity.RESULT_CANCELED:
- progress_bar.setVisibility(View.GONE);
break;
}
} else if (request.equals(Constants.ACTION_STOP_EIP)) {
@@ -336,13 +331,13 @@ public class EipServiceFragment extends Fragment implements Observer {
status_message.setText(getString(R.string.updating_certificate_message));
if(LeapSRPSession.getToken().isEmpty() && !Dashboard.preferences.getBoolean(Constants.ALLOWED_ANON, false)) {
dashboard.logInDialog(Bundle.EMPTY);
- } else {
+ } else {
Intent provider_API_command = new Intent(parent_activity, ProviderAPI.class);
if(dashboard.providerAPI_result_receiver == null) {
dashboard.providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler());
dashboard.providerAPI_result_receiver.setReceiver(dashboard);
}
-
+
provider_API_command.setAction(ProviderAPI.DOWNLOAD_CERTIFICATE);
provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, dashboard.providerAPI_result_receiver);
parent_activity.startService(provider_API_command);
@@ -352,7 +347,7 @@ public class EipServiceFragment extends Fragment implements Observer {
}
}
}
-
+
public static EIPReceiver getReceiver() {
return mEIPReceiver;
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java b/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java
index 01a83d5f..12c2e015 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java
@@ -39,7 +39,6 @@ public interface Constants {
public final static String CERTIFICATE = "cert";
public final static String PRIVATE_KEY = TAG + ".PRIVATE_KEY";
public final static String KEY = TAG + ".KEY";
- public final static String PARSED_SERIAL = TAG + ".PARSED_SERIAL";
public final static String RECEIVER_TAG = TAG + ".RECEIVER_TAG";
public final static String REQUEST_TAG = TAG + ".REQUEST_TAG";
public final static String START_BLOCKING_VPN_PROFILE = TAG + ".START_BLOCKING_VPN_PROFILE";
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 4363dd13..0713e521 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
@@ -22,6 +22,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
+import android.os.Handler;
import android.os.ResultReceiver;
import android.util.Log;
@@ -38,7 +39,6 @@ import de.blinkt.openvpn.VpnProfile;
import de.blinkt.openvpn.core.ProfileManager;
import se.leap.bitmaskclient.Dashboard;
import se.leap.bitmaskclient.EipServiceFragment;
-import se.leap.bitmaskclient.Provider;
import static se.leap.bitmaskclient.eip.Constants.ACTION_CHECK_CERT_VALIDITY;
import static se.leap.bitmaskclient.eip.Constants.ACTION_IS_EIP_RUNNING;
@@ -65,20 +65,19 @@ public final class EIP extends IntentService {
public final static String TAG = EIP.class.getSimpleName();
public final static String SERVICE_API_PATH = "config/eip-service.json";
-
public static final int DISCONNECT = 15;
private static Context context;
private static ResultReceiver mReceiver;
private static SharedPreferences preferences;
- private static JSONObject eip_definition = null;
+ private static JSONObject eip_definition;
private static List<Gateway> gateways = new ArrayList<Gateway>();
private static ProfileManager profile_manager;
- private static Gateway activeGateway = null;
+ private static Gateway gateway;
public EIP(){
- super("LEAPEIP");
+ super(TAG);
}
@Override
@@ -117,13 +116,15 @@ public final class EIP extends IntentService {
private void startEIP() {
if(gateways.isEmpty())
updateEIPService();
- GatewaySelector gateway_selector = new GatewaySelector(gateways);
- activeGateway = gateway_selector.select();
- if(activeGateway != null && activeGateway.getProfile() != null) {
+ earlyRoutes();
+
+ GatewaySelector gateway_selector = new GatewaySelector(gateways);
+ gateway = gateway_selector.select();
+ if(gateway != null && gateway.getProfile() != null) {
mReceiver = EipServiceFragment.getReceiver();
launchActiveGateway();
}
- earlyRoutes();
+ tellToReceiver(ACTION_START_EIP, Activity.RESULT_OK);
}
/**
@@ -140,16 +141,11 @@ public final class EIP extends IntentService {
Intent intent = new Intent(this,LaunchVPN.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.putExtra(LaunchVPN.EXTRA_NAME, activeGateway.getProfile().getName() );
+ intent.putExtra(LaunchVPN.EXTRA_NAME, gateway.getProfile().getName());
intent.putExtra(LaunchVPN.EXTRA_HIDELOG, true);
- intent.putExtra(RECEIVER_TAG, mReceiver);
startActivity(intent);
}
-
- /**
- * Disconnects the EIP connection gracefully through the bound service or forcefully
- * if there is no bound service. Sends a message to the requesting ResultReceiver.
- */
+
private void stopEIP() {
EipStatus eip_status = EipStatus.getInstance();
Log.d(TAG, "stopEip(): eip is connected? " + eip_status.isConnected());