summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java81
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java92
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java7
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/Constants.java50
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIP.java (renamed from app/src/main/java/se/leap/bitmaskclient/EIP.java)96
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java (renamed from app/src/main/java/se/leap/bitmaskclient/VoidVpnLauncher.java)4
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java (renamed from app/src/main/java/se/leap/bitmaskclient/VoidVpnService.java)7
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java (renamed from app/src/main/java/se/leap/bitmaskclient/VpnConfigGenerator.java)9
8 files changed, 161 insertions, 185 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index 364a79af..473cd5ec 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -14,38 +14,21 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
- package se.leap.bitmaskclient;
+package se.leap.bitmaskclient;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import se.leap.bitmaskclient.R;
-import se.leap.bitmaskclient.ProviderAPIResultReceiver.Receiver;
-import se.leap.bitmaskclient.FragmentManagerEnhanced;
-import se.leap.bitmaskclient.SignUpDialog;
+import se.leap.bitmaskclient.*;
+import se.leap.bitmaskclient.eip.*;
import de.blinkt.openvpn.activities.LogWindow;
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.DialogFragment;
-import android.app.FragmentTransaction;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.SharedPreferences;
+import android.app.*;
+import android.content.*;
import android.content.pm.PackageManager.NameNotFoundException;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.ResultReceiver;
+import android.os.*;
import android.util.Log;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ProgressBar;
-import android.widget.TextView;
-import android.widget.Toast;
+import android.view.*;
+import android.widget.*;
+import org.json.*;
/**
* The main user facing Activity of LEAP Android, consisting of status, controls,
@@ -54,7 +37,7 @@ import android.widget.Toast;
* @author Sean Leonard <meanderingcode@aetherislands.net>
* @author parmegv
*/
-public class Dashboard extends Activity implements LogInDialog.LogInDialogInterface, SignUpDialog.SignUpDialogInterface, Receiver {
+public class Dashboard extends Activity implements LogInDialog.LogInDialogInterface, SignUpDialog.SignUpDialogInterface, ProviderAPIResultReceiver.Receiver {
protected static final int CONFIGURE_LEAP = 0;
protected static final int SWITCH_PROVIDER = 1;
@@ -95,7 +78,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
fragment_manager = new FragmentManagerEnhanced(getFragmentManager());
handleVersion();
- authed_eip = preferences.getBoolean(EIP.AUTHED_EIP, false);
+ authed_eip = preferences.getBoolean(Constants.AUTHED_EIP, false);
if (preferences.getString(Provider.KEY, "").isEmpty())
startActivityForResult(new Intent(this,ConfigurationWizard.class),CONFIGURE_LEAP);
else
@@ -113,9 +96,9 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
switch(versionCode) {
case 91: // 0.6.0 without Bug #5999
case 101: // 0.8.0
- if(!preferences.getString(EIP.KEY, "").isEmpty()) {
+ if(!preferences.getString(Constants.KEY, "").isEmpty()) {
Intent rebuildVpnProfiles = new Intent(getApplicationContext(), EIP.class);
- rebuildVpnProfiles.setAction(EIP.ACTION_REBUILD_PROFILES);
+ rebuildVpnProfiles.setAction(Constants.ACTION_REBUILD_PROFILES);
startService(rebuildVpnProfiles);
}
break;
@@ -139,23 +122,21 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
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(EIP.PARSED_SERIAL, 0).commit();
- preferences.edit().putBoolean(EIP.AUTHED_EIP, authed_eip).commit();
-
+ preferences.edit().putInt(Constants.PARSED_SERIAL, 0).commit();
+ preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).commit();
Intent updateEIP = new Intent(getApplicationContext(), EIP.class);
- updateEIP.setAction(EIP.ACTION_UPDATE_EIP_SERVICE);
+ updateEIP.setAction(Constants.ACTION_UPDATE_EIP_SERVICE);
startService(updateEIP);
-
buildDashboard(false);
invalidateOptionsMenu();
if(data != null && data.hasExtra(LogInDialog.TAG)) {
View view = ((ViewGroup)findViewById(android.R.id.content)).getChildAt(0);
logInDialog(Bundle.EMPTY);
}
- } else if(resultCode == RESULT_CANCELED && (data == null || data.hasExtra(ACTION_QUIT))) {
- finish();
- } else
- configErrorDialog();
+ } else if(resultCode == RESULT_CANCELED && (data == null || data.hasExtra(ACTION_QUIT))) {
+ finish();
+ } else
+ configErrorDialog();
}
}
@@ -227,7 +208,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE);
boolean authed_eip = !LeapSRPSession.getToken().isEmpty();
boolean allow_registered_eip = service_description.getBoolean(Provider.ALLOW_REGISTRATION);
- preferences.edit().putBoolean(EIP.ALLOWED_REGISTERED, allow_registered_eip);
+ preferences.edit().putBoolean(Constants.ALLOWED_REGISTERED, allow_registered_eip);
if(allow_registered_eip) {
if(authed_eip) {
@@ -268,7 +249,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
return true;
case R.id.switch_provider:
if (Provider.getInstance().hasEIP()){
- if (preferences.getBoolean(EIP.AUTHED_EIP, false)){
+ if (preferences.getBoolean(Constants.AUTHED_EIP, false)){
logOut();
}
eipStop();
@@ -426,7 +407,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
invalidateOptionsMenu();
authed_eip = true;
- preferences.edit().putBoolean(EIP.AUTHED_EIP, authed_eip).commit();
+ preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).commit();
downloadAuthedUserCertificate();
} else if(resultCode == ProviderAPI.SRP_AUTHENTICATION_FAILED) {
@@ -441,7 +422,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
invalidateOptionsMenu();
authed_eip = false;
- preferences.edit().putBoolean(EIP.AUTHED_EIP, authed_eip).commit();
+ preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).commit();
} else if(resultCode == ProviderAPI.LOGOUT_FAILED) {
changeStatusMessage(resultCode);
@@ -457,7 +438,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
ResultReceiver eip_receiver = new ResultReceiver(new Handler()){
protected void onReceiveResult(int resultCode, Bundle resultData){
super.onReceiveResult(resultCode, resultData);
- String request = resultData.getString(EIP.REQUEST_TAG);
+ String request = resultData.getString(Constants.REQUEST_TAG);
if (resultCode == Activity.RESULT_OK){
if(authed_eip)
eipStart();
@@ -466,8 +447,8 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
}
}
};
- updateEIP.putExtra(EIP.RECEIVER_TAG, eip_receiver);
- updateEIP.setAction(EIP.ACTION_UPDATE_EIP_SERVICE);
+ updateEIP.putExtra(Constants.RECEIVER_TAG, eip_receiver);
+ updateEIP.setAction(Constants.ACTION_UPDATE_EIP_SERVICE);
startService(updateEIP);
} else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) {
changeStatusMessage(resultCode);
@@ -481,9 +462,9 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
ResultReceiver eip_status_receiver = new ResultReceiver(new Handler()){
protected void onReceiveResult(int resultCode, Bundle resultData){
super.onReceiveResult(resultCode, resultData);
- String request = resultData.getString(EIP.REQUEST_TAG);
+ String request = resultData.getString(Constants.REQUEST_TAG);
if(eipStatus == null) eipStatus = (TextView) findViewById(R.id.eipStatus);
- if (request.equalsIgnoreCase(EIP.ACTION_IS_EIP_RUNNING)){
+ if (request.equalsIgnoreCase(Constants.ACTION_IS_EIP_RUNNING)){
if (resultCode == Activity.RESULT_OK){
switch(previous_result_code){
@@ -544,8 +525,8 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
private void eipIsRunning(ResultReceiver eip_receiver){
// TODO validate "action"...how do we get the list of intent-filters for a class via Android API?
Intent eip_intent = new Intent(this, EIP.class);
- eip_intent.setAction(EIP.ACTION_IS_EIP_RUNNING);
- eip_intent.putExtra(EIP.RECEIVER_TAG, eip_receiver);
+ eip_intent.setAction(Constants.ACTION_IS_EIP_RUNNING);
+ eip_intent.putExtra(Constants.RECEIVER_TAG, eip_receiver);
startService(eip_intent);
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java
index 6d223dd6..f35a3cfa 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java
@@ -3,34 +3,18 @@ package se.leap.bitmaskclient;
import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.ProviderAPIResultReceiver;
import se.leap.bitmaskclient.ProviderAPIResultReceiver.Receiver;
-import se.leap.bitmaskclient.Dashboard;
-
-import de.blinkt.openvpn.activities.LogWindow;
-import de.blinkt.openvpn.core.VpnStatus;
-import de.blinkt.openvpn.core.VpnStatus.ConnectionStatus;
-import de.blinkt.openvpn.core.VpnStatus.StateListener;
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Fragment;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.ResultReceiver;
+import se.leap.bitmaskclient.eip.*;
+
+import de.blinkt.openvpn.activities.*;
+import de.blinkt.openvpn.core.*;
+import android.app.*;
+import android.content.*;
+import android.os.*;
import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup;
-import android.widget.CompoundButton.OnCheckedChangeListener;
-import android.widget.CompoundButton;
-import android.widget.ProgressBar;
-import android.widget.RelativeLayout;
-import android.widget.Switch;
-import android.widget.TextView;
-
-public class EipServiceFragment extends Fragment implements StateListener, OnCheckedChangeListener {
+import android.view.*;
+import android.widget.*;
+
+public class EipServiceFragment extends Fragment implements VpnStatus.StateListener, CompoundButton.OnCheckedChangeListener {
protected static final String IS_EIP_PENDING = "is_eip_pending";
public static final String START_ON_BOOT = "start on boot";
@@ -85,8 +69,8 @@ public class EipServiceFragment extends Fragment implements StateListener, OnChe
super.onResume();
VpnStatus.addStateListener(this);
-
- eipCommand(EIP.ACTION_CHECK_CERT_VALIDITY);
+
+ eipCommand(Constants.ACTION_CHECK_CERT_VALIDITY);
}
@Override
@@ -139,13 +123,13 @@ public class EipServiceFragment extends Fragment implements StateListener, OnChe
}
private boolean canStartEIP() {
- boolean certificateExists = !Dashboard.preferences.getString(EIP.CERTIFICATE, "").isEmpty();
- boolean isAllowedAnon = Dashboard.preferences.getBoolean(EIP.ALLOWED_ANON, false);
+ boolean certificateExists = !Dashboard.preferences.getString(Constants.CERTIFICATE, "").isEmpty();
+ boolean isAllowedAnon = Dashboard.preferences.getBoolean(Constants.ALLOWED_ANON, false);
return (isAllowedAnon || certificateExists) && !EIP.mIsStarting && !EIP.isConnected();
}
private boolean canLogInToStartEIP() {
- boolean isAllowedRegistered = Dashboard.preferences.getBoolean(EIP.ALLOWED_REGISTERED, false);
+ boolean isAllowedRegistered = Dashboard.preferences.getBoolean(Constants.ALLOWED_REGISTERED, false);
boolean isLoggedIn = !LeapSRPSession.getToken().isEmpty();
Log.d(TAG, "Allow registered? " + isAllowedRegistered);
Log.d(TAG, "Is logged in? " + isLoggedIn);
@@ -192,7 +176,7 @@ public class EipServiceFragment extends Fragment implements StateListener, OnChe
eipSwitch.setChecked(true);
saveEipStatus();
}
- eipCommand(EIP.ACTION_START_EIP);
+ eipCommand(Constants.ACTION_START_EIP);
}
protected void stopEIP() {
@@ -203,7 +187,7 @@ public class EipServiceFragment extends Fragment implements StateListener, OnChe
String status = getResources().getString(R.string.eip_state_not_connected);
setEipStatus(status);
- eipCommand(EIP.ACTION_STOP_EIP);
+ eipCommand(Constants.ACTION_STOP_EIP);
}
/**
@@ -216,16 +200,16 @@ public class EipServiceFragment extends Fragment implements StateListener, OnChe
// TODO validate "action"...how do we get the list of intent-filters for a class via Android API?
Intent vpn_intent = new Intent(getActivity().getApplicationContext(), EIP.class);
vpn_intent.setAction(action);
- vpn_intent.putExtra(EIP.RECEIVER_TAG, mEIPReceiver);
+ vpn_intent.putExtra(Constants.RECEIVER_TAG, mEIPReceiver);
getActivity().startService(vpn_intent);
}
@Override
- public void updateState(final String state, final String logmessage, final int localizedResId, final ConnectionStatus level) {
+ public void updateState(final String state, final String logmessage, final int localizedResId, final VpnStatus.ConnectionStatus level) {
boolean isNewLevel = EIP.lastConnectionStatusLevel != level;
- boolean justDecidedOnDisconnect = EIP.lastConnectionStatusLevel == ConnectionStatus.UNKNOWN_LEVEL;
+ boolean justDecidedOnDisconnect = EIP.lastConnectionStatusLevel == VpnStatus.ConnectionStatus.UNKNOWN_LEVEL;
Log.d(TAG, "update state with level " + level);
- if(!justDecidedOnDisconnect && (isNewLevel || level == ConnectionStatus.LEVEL_CONNECTED)) {
+ if(!justDecidedOnDisconnect && (isNewLevel || level == VpnStatus.ConnectionStatus.LEVEL_CONNECTED)) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
@@ -233,28 +217,28 @@ public class EipServiceFragment extends Fragment implements StateListener, OnChe
handleNewState(state, logmessage, localizedResId, level);
}
});
- } else if(justDecidedOnDisconnect && level == ConnectionStatus.LEVEL_CONNECTED) {
- EIP.lastConnectionStatusLevel = ConnectionStatus.LEVEL_NOTCONNECTED;
+ } else if(justDecidedOnDisconnect && level == VpnStatus.ConnectionStatus.LEVEL_CONNECTED) {
+ EIP.lastConnectionStatusLevel = VpnStatus.ConnectionStatus.LEVEL_NOTCONNECTED;
updateState(state, logmessage, localizedResId, level);
} // else if(isNewLevel || level == ConnectionStatus.LEVEL_AUTH_FAILED)
// handleNewState(state, logmessage, localizedResId, level);
}
- private void handleNewState(final String state, final String logmessage, final int localizedResId, final ConnectionStatus level) {
- if (level == ConnectionStatus.LEVEL_CONNECTED)
+ private void handleNewState(final String state, final String logmessage, final int localizedResId, final VpnStatus.ConnectionStatus level) {
+ if (level == VpnStatus.ConnectionStatus.LEVEL_CONNECTED)
setConnectedUI();
else if (isDisconnectedLevel(level) && !EIP.mIsStarting)
setDisconnectedUI();
- else if (level == ConnectionStatus.LEVEL_CONNECTING_NO_SERVER_REPLY_YET)
+ else if (level == VpnStatus.ConnectionStatus.LEVEL_CONNECTING_NO_SERVER_REPLY_YET)
setNoServerReplyUI(localizedResId, logmessage);
- else if (level == ConnectionStatus.LEVEL_CONNECTING_SERVER_REPLIED)
+ else if (level == VpnStatus.ConnectionStatus.LEVEL_CONNECTING_SERVER_REPLIED)
setServerReplyUI(state, localizedResId, logmessage);
- // else if (level == ConnectionStatus.LEVEL_AUTH_FAILED)
+ // else if (level == VpnStatus.ConnectionStatus.LEVEL_AUTH_FAILED)
// handleSwitchOn();
}
- private boolean isDisconnectedLevel(final ConnectionStatus level) {
- return level == ConnectionStatus.LEVEL_NOTCONNECTED || level == ConnectionStatus.LEVEL_AUTH_FAILED;
+ private boolean isDisconnectedLevel(final VpnStatus.ConnectionStatus level) {
+ return level == VpnStatus.ConnectionStatus.LEVEL_NOTCONNECTED || level == VpnStatus.ConnectionStatus.LEVEL_AUTH_FAILED;
}
private void setConnectedUI() {
@@ -331,10 +315,10 @@ public class EipServiceFragment extends Fragment implements StateListener, OnChe
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);
- String request = resultData.getString(EIP.REQUEST_TAG);
+ String request = resultData.getString(Constants.REQUEST_TAG);
boolean checked = false;
- if (request == EIP.ACTION_IS_EIP_RUNNING) {
+ if (request == Constants.ACTION_IS_EIP_RUNNING) {
switch (resultCode){
case Activity.RESULT_OK:
checked = true;
@@ -343,7 +327,7 @@ public class EipServiceFragment extends Fragment implements StateListener, OnChe
checked = false;
break;
}
- } else if (request == EIP.ACTION_START_EIP) {
+ } else if (request == Constants.ACTION_START_EIP) {
switch (resultCode){
case Activity.RESULT_OK:
Log.d(TAG, "Action start eip = Result OK");
@@ -356,7 +340,7 @@ public class EipServiceFragment extends Fragment implements StateListener, OnChe
eipFragment.findViewById(R.id.eipProgress).setVisibility(View.GONE);
break;
}
- } else if (request == EIP.ACTION_STOP_EIP) {
+ } else if (request == Constants.ACTION_STOP_EIP) {
switch (resultCode){
case Activity.RESULT_OK:
checked = false;
@@ -365,7 +349,7 @@ public class EipServiceFragment extends Fragment implements StateListener, OnChe
checked = true;
break;
}
- } else if (request == EIP.EIP_NOTIFICATION) {
+ } else if (request == Constants.EIP_NOTIFICATION) {
switch (resultCode){
case Activity.RESULT_OK:
checked = true;
@@ -374,7 +358,7 @@ public class EipServiceFragment extends Fragment implements StateListener, OnChe
checked = false;
break;
}
- } else if (request == EIP.ACTION_CHECK_CERT_VALIDITY) {
+ } else if (request == Constants.ACTION_CHECK_CERT_VALIDITY) {
checked = eipSwitch.isChecked();
switch (resultCode) {
@@ -387,7 +371,7 @@ public class EipServiceFragment extends Fragment implements StateListener, OnChe
String status = getResources().getString(R.string.updating_certificate_message);
setEipStatus(status);
- if(LeapSRPSession.getToken().isEmpty() && !Dashboard.preferences.getBoolean(EIP.ALLOWED_ANON, false)) {
+ if(LeapSRPSession.getToken().isEmpty() && !Dashboard.preferences.getBoolean(Constants.ALLOWED_ANON, false)) {
dashboard.logInDialog(Bundle.EMPTY);
} else {
diff --git a/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java b/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java
index eb196d46..74f89ab8 100644
--- a/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java
+++ b/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java
@@ -1,10 +1,9 @@
package se.leap.bitmaskclient;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
+import android.content.*;
import android.util.Log;
+import se.leap.bitmaskclient.eip.Constants;
public class OnBootReceiver extends BroadcastReceiver {
@@ -14,7 +13,7 @@ public class OnBootReceiver extends BroadcastReceiver {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
if (!context.getSharedPreferences(Dashboard.SHARED_PREFERENCES, Context.MODE_PRIVATE).getString(Provider.KEY, "").isEmpty() && context.getSharedPreferences(Dashboard.SHARED_PREFERENCES, Context.MODE_PRIVATE).getBoolean(Dashboard.START_ON_BOOT, false)) {
Intent dashboard_intent = new Intent(context, Dashboard.class);
- dashboard_intent.setAction(EIP.ACTION_START_EIP);
+ dashboard_intent.setAction(Constants.ACTION_START_EIP);
dashboard_intent.putExtra(Dashboard.ON_BOOT, true);
dashboard_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(dashboard_intent);
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java b/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java
new file mode 100644
index 00000000..719fff6d
--- /dev/null
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java
@@ -0,0 +1,50 @@
+/**
+ * Copyright (c) 2013 LEAP Encryption Access Project and contributers
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package se.leap.bitmaskclient.eip;
+
+/**
+ *
+ * Constants for intent passing, shared preferences
+ *
+ * @author Parménides GV <parmegv@sdf.org>
+ *
+ */
+public interface Constants {
+
+ public final static String TAG = Constants.class.getSimpleName();
+
+ public final static String AUTHED_EIP = TAG + ".AUTHED_EIP";
+ public final static String ACTION_CHECK_CERT_VALIDITY = TAG + ".CHECK_CERT_VALIDITY";
+ public final static String ACTION_START_EIP = TAG + ".START_EIP";
+ public final static String ACTION_STOP_EIP = TAG + ".STOP_EIP";
+ public final static String ACTION_UPDATE_EIP_SERVICE = TAG + ".UPDATE_EIP_SERVICE";
+ public final static String ACTION_IS_EIP_RUNNING = TAG + ".IS_RUNNING";
+ public final static String ACTION_REBUILD_PROFILES = TAG + ".REBUILD_PROFILES";
+ public final static String EIP_NOTIFICATION = TAG + ".EIP_NOTIFICATION";
+ public final static String STATUS = TAG + ".STATUS";
+ public final static String DATE_FROM_CERTIFICATE = TAG + ".DATE_FROM_CERTIFICATE";
+ public final static String ALLOWED_ANON = TAG + ".ALLOW_ANONYMOUS";
+ public final static String ALLOWED_REGISTERED = TAG + ".ALLOW_REGISTRATION";
+ public final static String CERTIFICATE = TAG + ".CERTIFICATE";
+ 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.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
index 2f06def3..b668ce64 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
@@ -14,47 +14,24 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package se.leap.bitmaskclient;
-
-import android.app.Activity;
-import android.app.IntentService;
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.os.Bundle;
-import android.os.ResultReceiver;
+package se.leap.bitmaskclient.eip;
+
+import android.app.*;
+import android.content.*;
+import android.os.*;
import android.util.Log;
-import de.blinkt.openvpn.LaunchVPN;
-import de.blinkt.openvpn.VpnProfile;
-import de.blinkt.openvpn.activities.DisconnectVPN;
-import de.blinkt.openvpn.core.ConfigParser;
-import de.blinkt.openvpn.core.ConfigParser.ConfigParseError;
-import de.blinkt.openvpn.core.ProfileManager;
-import de.blinkt.openvpn.core.VpnStatus.ConnectionStatus;
-import java.io.IOException;
-import java.io.StringReader;
-import java.security.cert.CertificateExpiredException;
-import java.security.cert.CertificateNotYetValidException;
-import java.security.cert.X509Certificate;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.NoSuchElementException;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.Vector;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-import se.leap.bitmaskclient.Dashboard;
-import se.leap.bitmaskclient.Provider;
-import se.leap.bitmaskclient.R;
+import java.io.*;
+import java.security.cert.*;
+import java.text.*;
+import java.util.*;
+import org.json.*;
+
+import de.blinkt.openvpn.*;
+import de.blinkt.openvpn.activities.*;
+import de.blinkt.openvpn.core.*;
+import se.leap.bitmaskclient.*;
+
+import static se.leap.bitmaskclient.eip.Constants.*;
/**
* EIP is the abstract base class for interacting with and managing the Encrypted
@@ -67,27 +44,11 @@ import se.leap.bitmaskclient.R;
* @author Parménides GV <parmegv@sdf.org>
*/
public final class EIP extends IntentService {
-
- public final static String AUTHED_EIP = "authed eip";
- public final static String ACTION_CHECK_CERT_VALIDITY = "se.leap.bitmaskclient.CHECK_CERT_VALIDITY";
- public final static String ACTION_START_EIP = "se.leap.bitmaskclient.START_EIP";
- public final static String ACTION_STOP_EIP = "se.leap.bitmaskclient.STOP_EIP";
- public final static String ACTION_UPDATE_EIP_SERVICE = "se.leap.bitmaskclient.UPDATE_EIP_SERVICE";
- public final static String ACTION_IS_EIP_RUNNING = "se.leap.bitmaskclient.IS_RUNNING";
- public final static String ACTION_REBUILD_PROFILES = "se.leap.bitmaskclient.REBUILD_PROFILES";
- public final static String EIP_NOTIFICATION = "EIP_NOTIFICATION";
- public final static String STATUS = "eip status";
- public final static String DATE_FROM_CERTIFICATE = "date from certificate";
- public final static String ALLOWED_ANON = "allow_anonymous";
- public final static String ALLOWED_REGISTERED = "allow_registration";
- public final static String CERTIFICATE = "cert";
- public final static String PRIVATE_KEY = "private_key";
- public final static String KEY = "eip";
- public final static String PARSED_SERIAL = "eip_parsed_serial";
- public final static String SERVICE_API_PATH = "config/eip-service.json";
- public final static String RECEIVER_TAG = "receiverTag";
- public final static String REQUEST_TAG = "requestTag";
+
public final static String TAG = EIP.class.getSimpleName();
+
+ public final static String SERVICE_API_PATH = "config/eip-service.json";
+
private static SharedPreferences preferences;
private static Context context;
@@ -98,11 +59,12 @@ public final class EIP extends IntentService {
private static OVPNGateway activeGateway = null;
- protected static ConnectionStatus lastConnectionStatusLevel;
- protected static boolean mIsDisconnecting = false;
- protected static boolean mIsStarting = false;
+ public static VpnStatus.ConnectionStatus lastConnectionStatusLevel;
+ public static boolean mIsDisconnecting = false;
+ public static boolean mIsStarting = false;
public static SimpleDateFormat certificate_date_format = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
+
public EIP(){
super("LEAPEIP");
}
@@ -277,7 +239,7 @@ public final class EIP extends IntentService {
disconnect_vpn.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(disconnect_vpn);
mIsDisconnecting = true;
- lastConnectionStatusLevel = ConnectionStatus.UNKNOWN_LEVEL; // Wait for the decision of the user
+ lastConnectionStatusLevel = VpnStatus.ConnectionStatus.UNKNOWN_LEVEL; // Wait for the decision of the user
Log.d(TAG, "mIsDisconnecting = true");
}
@@ -307,8 +269,8 @@ public final class EIP extends IntentService {
tellToReceiver(ACTION_IS_EIP_RUNNING, resultCode);
}
- protected static boolean isConnected() {
- return lastConnectionStatusLevel != null && lastConnectionStatusLevel.equals(ConnectionStatus.LEVEL_CONNECTED) && !mIsDisconnecting;
+ public static boolean isConnected() {
+ return lastConnectionStatusLevel != null && lastConnectionStatusLevel.equals(VpnStatus.ConnectionStatus.LEVEL_CONNECTED) && !mIsDisconnecting;
}
/**
@@ -499,7 +461,7 @@ public final class EIP extends IntentService {
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
- } catch (ConfigParseError e) {
+ } catch (ConfigParser.ConfigParseError e) {
// FIXME We didn't get a VpnProfile! Error handling! and log level
Log.v(TAG,"Error creating VPNProfile");
e.printStackTrace();
diff --git a/app/src/main/java/se/leap/bitmaskclient/VoidVpnLauncher.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java
index 3b286fbf..9814c167 100644
--- a/app/src/main/java/se/leap/bitmaskclient/VoidVpnLauncher.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java
@@ -1,4 +1,4 @@
-package se.leap.bitmaskclient;
+package se.leap.bitmaskclient.eip;
import android.app.Activity;
import android.content.Intent;
@@ -28,7 +28,7 @@ public class VoidVpnLauncher extends Activity {
if(requestCode == VPN_USER_PERMISSION) {
if(resultCode == RESULT_OK) {
Intent void_vpn_service = new Intent(getApplicationContext(), VoidVpnService.class);
- void_vpn_service.setAction(VoidVpnService.START_BLOCKING_VPN_PROFILE);
+ void_vpn_service.setAction(Constants.START_BLOCKING_VPN_PROFILE);
startService(void_vpn_service);
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
index 7b597554..224e3bd4 100644
--- a/app/src/main/java/se/leap/bitmaskclient/VoidVpnService.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
@@ -1,19 +1,20 @@
-package se.leap.bitmaskclient;
+package se.leap.bitmaskclient.eip;
import android.content.Intent;
import android.os.Process;
import android.net.VpnService;
import android.util.Log;
+import static se.leap.bitmaskclient.eip.Constants.*;
+
public class VoidVpnService extends VpnService {
- static final String START_BLOCKING_VPN_PROFILE = "se.leap.bitmaskclient.START_BLOCKING_VPN_PROFILE";
static final String TAG = VoidVpnService.class.getSimpleName();
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
String action = intent.getAction();
- if (action == START_BLOCKING_VPN_PROFILE) {
+ if (action == Constants.START_BLOCKING_VPN_PROFILE) {
new Thread(new Runnable() {
public void run() {
Builder builder = new Builder();
diff --git a/app/src/main/java/se/leap/bitmaskclient/VpnConfigGenerator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java
index ef049a3c..8e36f53c 100644
--- a/app/src/main/java/se/leap/bitmaskclient/VpnConfigGenerator.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package se.leap.bitmaskclient;
+package se.leap.bitmaskclient.eip;
import android.content.SharedPreferences;
import android.util.Log;
@@ -24,8 +24,7 @@ import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONException;
-import se.leap.bitmaskclient.Provider;
-import se.leap.bitmaskclient.EIP;
+import se.leap.bitmaskclient.*;
public class VpnConfigGenerator {
@@ -121,14 +120,14 @@ public class VpnConfigGenerator {
String key =
"<key>"
+ new_line
- + preferences.getString(EIP.PRIVATE_KEY, "")
+ + preferences.getString(Constants.PRIVATE_KEY, "")
+ new_line
+ "</key>";
String openvpn_cert =
"<cert>"
+ new_line
- + preferences.getString(EIP.CERTIFICATE, "")
+ + preferences.getString(Constants.CERTIFICATE, "")
+ new_line
+ "</cert>";