From 767bb8de42b9529b60858fc43e07b1d050ccd785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Mon, 9 Mar 2015 12:05:32 +0100 Subject: Eip status disconnects void vpn when disconnecting. --- app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'app/src/main') 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 4ac3bd6a..f3f6e16f 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java @@ -50,9 +50,11 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { current_status.setLocalizedResId(localizedResId); current_status.setLevel(level); current_status.setChanged(); - if(isConnected() || isDisconnected()) + if(isConnected() || isDisconnected()) { setConnectedOrDisconnected(); - else if(isConnecting()) + if(isDisconnected()) + VoidVpnService.stop(); + } else if(isConnecting()) setConnecting(); Log.d(TAG, "update state with level " + level); current_status.notifyObservers(); -- cgit v1.2.3 From 767f2982ec62e071396226415f5abda2fb6cb3f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Mon, 9 Mar 2015 12:15:09 +0100 Subject: Extracted a new method, refactoring. --- .../main/java/se/leap/bitmaskclient/eip/EipStatus.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'app/src/main') 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 f3f6e16f..c6735130 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java @@ -44,12 +44,7 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { @Override public void updateState(final String state, final String logmessage, final int localizedResId, final VpnStatus.ConnectionStatus level) { - current_status = getInstance(); - current_status.setState(state); - current_status.setLogMessage(logmessage); - current_status.setLocalizedResId(localizedResId); - current_status.setLevel(level); - current_status.setChanged(); + updateStatus(state, logmessage, localizedResId, level); if(isConnected() || isDisconnected()) { setConnectedOrDisconnected(); if(isDisconnected()) @@ -57,7 +52,15 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { } else if(isConnecting()) setConnecting(); Log.d(TAG, "update state with level " + level); - current_status.notifyObservers(); + } + + private void updateStatus(final String state, final String logmessage, final int localizedResId, final VpnStatus.ConnectionStatus level) { + current_status = getInstance(); + current_status.setState(state); + current_status.setLogMessage(logmessage); + current_status.setLocalizedResId(localizedResId); + current_status.setLevel(level); + current_status.setChanged(); } public boolean wantsToDisconnect() { -- cgit v1.2.3 From 6e245043236476b0d440732a729a47304dddce96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Mon, 9 Mar 2015 14:58:33 +0100 Subject: Just say it's authenticated, nothing about certificates --- app/src/main/java/se/leap/bitmaskclient/Dashboard.java | 1 - app/src/main/res/values/strings.xml | 2 -- 2 files changed, 3 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index 6d368e11..a4197eaf 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -422,7 +422,6 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn switch(previous_result_code){ case ProviderAPI.SUCCESSFUL_LOGIN: setStatusMessage(R.string.succesful_authentication_message); break; case ProviderAPI.FAILED_LOGIN: setStatusMessage(R.string.authentication_failed_message); break; - case ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE: setStatusMessage(R.string.authed_secured_status); break; case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE: setStatusMessage(R.string.incorrectly_downloaded_certificate_message); break; case ProviderAPI.SUCCESSFUL_LOGOUT: setStatusMessage(R.string.logged_out_message); break; case ProviderAPI.LOGOUT_FAILED: setStatusMessage(R.string.log_out_failed_message); break; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1608f487..709d92b5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -16,8 +16,6 @@ Provider: No provider configured Status unknown. - Connection secure using an anonymous certificate. - Connection secure using your own certificate. Encrypted Internet Select a service provider Add new Provider -- cgit v1.2.3 From 49f906005c2d80dab2751d4e6beff100e99586c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Tue, 10 Mar 2015 10:08:46 +0100 Subject: Logged in == leapsrpsession has a token --- app/src/main/java/se/leap/bitmaskclient/Dashboard.java | 15 +++------------ .../main/java/se/leap/bitmaskclient/LeapSRPSession.java | 6 +++++- .../main/java/se/leap/bitmaskclient/eip/Constants.java | 1 - 3 files changed, 8 insertions(+), 14 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index a4197eaf..4fe51939 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -63,7 +63,6 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn EipFragment eip_fragment; private Provider provider; - private static boolean authed_eip; public ProviderAPIResultReceiver providerAPI_result_receiver; private boolean switching_provider; @@ -148,7 +147,6 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn sessionDialog(Bundle.EMPTY); } - preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).apply(); } else if (resultCode == RESULT_CANCELED && data.hasExtra(ACTION_QUIT)) { finish(); } else @@ -222,12 +220,11 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn if(!provider_json_string.isEmpty()) { provider_json = new JSONObject(provider_json_string); 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(Constants.ALLOWED_REGISTERED, allow_registered_eip).apply(); if(allow_registered_eip) { - if(authed_eip) { + if(LeapSRPSession.loggedIn()) { menu.findItem(R.id.login_button).setVisible(false); menu.findItem(R.id.logout_button).setVisible(true); } else { @@ -265,7 +262,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn return true; case R.id.switch_provider: switching_provider = true; - if (preferences.getBoolean(Constants.AUTHED_EIP, false)) logOut(); + if (LeapSRPSession.loggedIn()) logOut(); else switchProvider(); return true; case R.id.login_button: @@ -299,7 +296,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn } protected void downloadVpnCertificate() { - boolean is_authenticated = !LeapSRPSession.getToken().isEmpty(); + boolean is_authenticated = LeapSRPSession.loggedIn(); boolean allowed_anon = preferences.getBoolean(Constants.ALLOWED_ANON, false); if(allowed_anon || is_authenticated) providerApiCommand(Bundle.EMPTY, R.string.downloading_certificate_message, ProviderAPI.DOWNLOAD_CERTIFICATE); @@ -373,18 +370,12 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn updateViewHidingProgressBar(resultCode); sessionDialog(resultData); } else if(resultCode == ProviderAPI.SUCCESSFUL_LOGIN) { - authed_eip = true; - preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).apply(); - updateViewHidingProgressBar(resultCode); downloadVpnCertificate(); } else if(resultCode == ProviderAPI.FAILED_LOGIN) { updateViewHidingProgressBar(resultCode); sessionDialog(resultData); } else if(resultCode == ProviderAPI.SUCCESSFUL_LOGOUT) { - authed_eip = false; - preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).apply(); - updateViewHidingProgressBar(resultCode); if(switching_provider) switchProvider(); } else if(resultCode == ProviderAPI.LOGOUT_FAILED) { diff --git a/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java b/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java index 989dc395..09855baf 100644 --- a/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java +++ b/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - package se.leap.bitmaskclient; +package se.leap.bitmaskclient; import org.jboss.security.srp.SRPParameters; @@ -331,6 +331,10 @@ public class LeapSRPSession { return token; } + protected static boolean loggedIn() { + return !token.isEmpty(); + } + /** * @return a new SHA-256 digest. */ 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 12c2e015..f7206927 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java @@ -27,7 +27,6 @@ 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"; -- cgit v1.2.3 From 8a53bf0c88498059751693695775788874714fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Tue, 10 Mar 2015 11:44:00 +0100 Subject: Point to the log if an error occurrs while connecting --- app/src/main/java/se/leap/bitmaskclient/EipFragment.java | 6 +++++- app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java | 12 +++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index 588b137b..3023442a 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -262,7 +262,11 @@ public class EipFragment extends Fragment implements Observer { private void setDisconnectedUI(){ hideProgressBar(); adjustSwitch(); - status_message.setText(dashboard.getString(R.string.eip_state_not_connected)); + String last_log_message = eip_status.getLastLogMessage(dashboard.getApplicationContext()); + if(last_log_message.contains("error") || last_log_message.contains("ERROR")) + status_message.setText("An error occurred." + "\n" + "Please take a look at the log, from the menu"); + else + status_message.setText(dashboard.getString(R.string.eip_state_not_connected)); } private void adjustSwitch() { 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 c6735130..14158696 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java @@ -16,11 +16,12 @@ */ package se.leap.bitmaskclient.eip; -import android.util.Log; +import android.util.*; +import android.content.*; -import java.util.Observable; +import java.util.*; -import de.blinkt.openvpn.core.VpnStatus; +import de.blinkt.openvpn.core.*; public class EipStatus extends Observable implements VpnStatus.StateListener { public static String TAG = EipStatus.class.getSimpleName(); @@ -135,6 +136,11 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { EipStatus.level = level; } + public String getLastLogMessage(Context context) { + VpnStatus.LogItem[] log = VpnStatus.getlogbuffer(); + return log[log.length-1].getString(context); + } + @Override public String toString() { return "State: " + state + " Level: " + level.toString(); -- cgit v1.2.3 From 9732f263b3ea9af0c9610fa9b3f3010481a39e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 12 Mar 2015 11:47:28 +0100 Subject: Just show the log if an error occurred. --- .../main/java/se/leap/bitmaskclient/Dashboard.java | 19 ++++-- .../java/se/leap/bitmaskclient/EipFragment.java | 77 ++++++++++++---------- 2 files changed, 54 insertions(+), 42 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index 4fe51939..04385ddd 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -249,16 +249,12 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn @Override public boolean onOptionsItemSelected(MenuItem item){ - Intent intent; switch (item.getItemId()){ case R.id.about_leap: - intent = new Intent(this, AboutActivity.class); - startActivity(intent); + showAbout(); return true; case R.id.log_window: - Intent startLW = new Intent(getAppContext(), LogWindow.class); - startLW.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); - startActivity(startLW); + showLog(); return true; case R.id.switch_provider: switching_provider = true; @@ -279,6 +275,17 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn } } + public void showAbout() { + Intent intent = new Intent(this, AboutActivity.class); + startActivity(intent); + } + + public void showLog() { + Intent startLW = new Intent(getAppContext(), LogWindow.class); + //startLW.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + startActivity(startLW); + } + @Override public void signUp(String username, String password) { Bundle parameters = bundleParameters(username, password); diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index 3023442a..680f21e1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -1,32 +1,33 @@ +/** + * 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 . + */ package se.leap.bitmaskclient; -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 android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ProgressBar; -import android.widget.Switch; -import android.widget.TextView; - -import java.util.Observable; -import java.util.Observer; - -import butterknife.ButterKnife; -import butterknife.InjectView; -import butterknife.OnCheckedChanged; -import de.blinkt.openvpn.activities.DisconnectVPN; -import se.leap.bitmaskclient.eip.Constants; -import se.leap.bitmaskclient.eip.EIP; -import se.leap.bitmaskclient.eip.EipStatus; -import se.leap.bitmaskclient.eip.VoidVpnService; +import android.app.*; +import android.content.*; +import android.os.*; +import android.util.*; +import android.view.*; +import android.widget.*; + +import java.util.*; + +import butterknife.*; +import de.blinkt.openvpn.activities.*; +import se.leap.bitmaskclient.eip.*; public class EipFragment extends Fragment implements Observer { @@ -193,6 +194,10 @@ public class EipFragment extends Fragment implements Observer { private void stopEIP() { if(eip_status.isConnecting()) VoidVpnService.stop(); + disconnect(); + } + + private void disconnect() { Intent disconnect_vpn = new Intent(dashboard, DisconnectVPN.class); dashboard.startActivityForResult(disconnect_vpn, EIP.DISCONNECT); eip_status.setDisconnecting(); @@ -201,8 +206,8 @@ public class EipFragment extends Fragment implements Observer { protected void askToStopEIP() { hideProgressBar(); - String status = dashboard.getString(R.string.eip_state_not_connected); - status_message.setText(status); + String message = dashboard.getString(R.string.eip_state_not_connected); + status_message.setText(message); eipCommand(Constants.ACTION_STOP_EIP); } @@ -240,11 +245,10 @@ public class EipFragment extends Fragment implements Observer { } private void handleNewState(EipStatus eip_status) { - 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.isConnecting() || is_starting_to_connect) + setInProgressUI(eip_status); else if (eip_status.isConnected()) setConnectedUI(); else if (eip_status.isDisconnected() && !eip_status.isConnecting()) @@ -263,10 +267,11 @@ public class EipFragment extends Fragment implements Observer { hideProgressBar(); adjustSwitch(); String last_log_message = eip_status.getLastLogMessage(dashboard.getApplicationContext()); - if(last_log_message.contains("error") || last_log_message.contains("ERROR")) - status_message.setText("An error occurred." + "\n" + "Please take a look at the log, from the menu"); - else - status_message.setText(dashboard.getString(R.string.eip_state_not_connected)); + if((last_log_message.contains("error") || last_log_message.contains("ERROR")) + && !status_message.getText().toString().equalsIgnoreCase(dashboard.getString(R.string.eip_state_not_connected))){ + dashboard.showLog(); + } + status_message.setText(dashboard.getString(R.string.eip_state_not_connected)); } private void adjustSwitch() { -- cgit v1.2.3 From 4d0e03dc3e836418e8fc240e81e2a4d9ebc445a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 12 Mar 2015 11:57:23 +0100 Subject: Failed log out message a bit explained. Now that I fixed the internal inconsistencies of checking if the user is logged in, if this error happens it should be caused by the provider or the network itself. So I tell the user. --- app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/src/main') diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 709d92b5..37969cda 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -58,7 +58,7 @@ Signing up Logging out from this session. Logged out. - Didn\'t log out. + Didn\'t log out. Try later, it may be a problem in the network or in the provider. Authentication succeeded. Authentication failed. Registration failed. -- cgit v1.2.3 From f62c2c0ef907744814b48a56d08a83a6fbe1bed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 12 Mar 2015 12:01:34 +0100 Subject: Suggest to wipe data if logging out fails repeatedly. --- app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/src/main') diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 37969cda..032602cb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -58,7 +58,7 @@ Signing up Logging out from this session. Logged out. - Didn\'t log out. Try later, it may be a problem in the network or in the provider. + Didn\'t log out. Try later, it may be a problem in the network or in the provider. If the problem persists, then wipe Bitmask data from the Android settings Authentication succeeded. Authentication failed. Registration failed. -- cgit v1.2.3 From 06b98e2c28f93f2294f3e6f88ba3812e8b8751e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 12 Mar 2015 13:50:10 +0100 Subject: Show progress bar if connecting. --- app/src/main/java/se/leap/bitmaskclient/EipFragment.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index 680f21e1..6dbdf961 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -294,16 +294,22 @@ public class EipFragment extends Fragment implements Observer { String logmessage = eip_status.getLogMessage(); String prefix = dashboard.getString(localizedResId); + showProgressBar(); status_message.setText(prefix + " " + logmessage); is_starting_to_connect = false; adjustSwitch(); } private void updatingCertificateUI() { - progress_bar.setVisibility(View.VISIBLE); + showProgressBar(); status_message.setText(getString(R.string.updating_certificate_message)); } + private void showProgressBar() { + if(progress_bar != null) + progress_bar.setVisibility(View.VISIBLE); + } + private void hideProgressBar() { if(progress_bar != null) progress_bar.setVisibility(View.GONE); -- cgit v1.2.3 From 6738a3f17cb38febfa1c698d6b420aed9e17ad74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Fri, 13 Mar 2015 14:22:25 +0100 Subject: Show user session status separately. Switching orientation doesn't hide that information, now we have two places to avoid it. --- .../main/java/se/leap/bitmaskclient/Dashboard.java | 179 ++++++++++++--------- .../java/se/leap/bitmaskclient/EipFragment.java | 22 +-- .../java/se/leap/bitmaskclient/LeapSRPSession.java | 3 +- .../main/java/se/leap/bitmaskclient/Provider.java | 8 + app/src/main/java/se/leap/bitmaskclient/User.java | 41 +++++ .../se/leap/bitmaskclient/UserSessionStatus.java | 65 ++++++++ .../se/leap/bitmaskclient/eip/VoidVpnService.java | 3 +- app/src/main/res/layout/dashboard.xml | 15 +- 8 files changed, 240 insertions(+), 96 deletions(-) create mode 100644 app/src/main/java/se/leap/bitmaskclient/User.java create mode 100644 app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index 04385ddd..c6ac2477 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -28,6 +28,7 @@ import android.widget.*; import org.jetbrains.annotations.NotNull; import org.json.*; import java.net.*; +import java.util.*; import butterknife.*; import de.blinkt.openvpn.activities.*; @@ -40,7 +41,7 @@ import se.leap.bitmaskclient.eip.*; * @author Sean Leonard * @author parmegv */ -public class Dashboard extends Activity implements SessionDialog.SessionDialogInterface, ProviderAPIResultReceiver.Receiver { +public class Dashboard extends Activity implements SessionDialog.SessionDialogInterface, ProviderAPIResultReceiver.Receiver, Observer { protected static final int CONFIGURE_LEAP = 0; protected static final int SWITCH_PROVIDER = 1; @@ -60,46 +61,63 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn @InjectView(R.id.providerName) TextView provider_name; + @InjectView(R.id.user_session_status) + TextView user_session_status_text_view; EipFragment eip_fragment; private Provider provider; + private UserSessionStatus user_session_status; public ProviderAPIResultReceiver providerAPI_result_receiver; private boolean switching_provider; @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - app = this; + super.onCreate(savedInstanceState); - PRNGFixes.apply(); + app = this; + user_session_status = UserSessionStatus.getInstance(); + user_session_status.addObserver(this); - preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); - fragment_manager = new FragmentManagerEnhanced(getFragmentManager()); - handleVersion(); + PRNGFixes.apply(); - provider = getSavedProvider(savedInstanceState); + preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); + fragment_manager = new FragmentManagerEnhanced(getFragmentManager()); + handleVersion(); + + restoreProvider(savedInstanceState); if (provider == null || provider.getName().isEmpty()) - startActivityForResult(new Intent(this,ConfigurationWizard.class),CONFIGURE_LEAP); - else - buildDashboard(getIntent().getBooleanExtra(ON_BOOT, false)); + startActivityForResult(new Intent(this,ConfigurationWizard.class),CONFIGURE_LEAP); + else { + buildDashboard(getIntent().getBooleanExtra(ON_BOOT, false)); + restoreSessionStatus(savedInstanceState); + } + } + + private void restoreProvider(Bundle savedInstanceState) { + if (savedInstanceState != null) { + if(savedInstanceState.containsKey(Provider.KEY)) + provider = savedInstanceState.getParcelable(Provider.KEY); + if(provider == null && preferences.getBoolean(Constants.PROVIDER_CONFIGURED, false)) + provider = getSavedProviderFromSharedPreferences(); + } + } + + private void restoreSessionStatus(Bundle savedInstanceState) { + if (savedInstanceState != null) + if(savedInstanceState.containsKey(UserSessionStatus.TAG)) { + UserSessionStatus.SessionStatus status = (UserSessionStatus.SessionStatus) savedInstanceState.getSerializable(UserSessionStatus.TAG); + user_session_status.updateStatus(status); + } } @Override protected void onSaveInstanceState(@NotNull Bundle outState) { if(provider != null) outState.putParcelable(Provider.KEY, provider); - super.onSaveInstanceState(outState); - } + if(user_session_status_text_view != null && user_session_status_text_view.getVisibility() == TextView.VISIBLE) + outState.putSerializable(UserSessionStatus.TAG, user_session_status.sessionStatus()); - 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; + super.onSaveInstanceState(outState); } private Provider getSavedProviderFromSharedPreferences() { @@ -107,9 +125,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn 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) { + } catch (MalformedURLException | JSONException e) { e.printStackTrace(); } @@ -136,8 +152,8 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn @Override protected void onActivityResult(int requestCode, int resultCode, Intent data){ - if ( requestCode == CONFIGURE_LEAP || requestCode == SWITCH_PROVIDER) { - if ( resultCode == RESULT_OK && data.hasExtra(Provider.KEY)) { + if ( requestCode == CONFIGURE_LEAP || requestCode == SWITCH_PROVIDER) { + if ( resultCode == RESULT_OK && data.hasExtra(Provider.KEY)) { provider = data.getParcelableExtra(Provider.KEY); providerToPreferences(provider); @@ -147,13 +163,13 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn sessionDialog(Bundle.EMPTY); } - } else if (resultCode == RESULT_CANCELED && data.hasExtra(ACTION_QUIT)) { + } else if (resultCode == RESULT_CANCELED && data.hasExtra(ACTION_QUIT)) { finish(); - } else - configErrorDialog(); - } else if(requestCode == EIP.DISCONNECT) { - EipStatus.getInstance().setConnectedOrDisconnected(); - } + } else + configErrorDialog(); + } else if(requestCode == EIP.DISCONNECT) { + EipStatus.getInstance().setConnectedOrDisconnected(); + } } @SuppressLint("CommitPrefEdits") @@ -190,55 +206,39 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn * service dependent UI elements to include. */ private void buildDashboard(boolean hide_and_turn_on_eip) { - setContentView(R.layout.dashboard); + setContentView(R.layout.dashboard); ButterKnife.inject(this); - provider_name.setText(provider.getDomain()); - if ( provider.hasEIP()){ + provider_name.setText(provider.getDomain()); + if ( provider.hasEIP()){ fragment_manager.removePreviousFragment(EipFragment.TAG); eip_fragment = new EipFragment(); - if (hide_and_turn_on_eip) { - preferences.edit().remove(Dashboard.START_ON_BOOT).apply(); - Bundle arguments = new Bundle(); - arguments.putBoolean(EipFragment.START_ON_BOOT, true); + if (hide_and_turn_on_eip) { + preferences.edit().remove(Dashboard.START_ON_BOOT).apply(); + Bundle arguments = new Bundle(); + arguments.putBoolean(EipFragment.START_ON_BOOT, true); if(eip_fragment != null) eip_fragment.setArguments(arguments); - } + } fragment_manager.replace(R.id.servicesCollection, eip_fragment, EipFragment.TAG); - if (hide_and_turn_on_eip) { - onBackPressed(); - } - } + if (hide_and_turn_on_eip) { + onBackPressed(); + } + } + handleNewUserSessionStatus(user_session_status); } @Override public boolean onPrepareOptionsMenu(Menu menu) { - JSONObject provider_json; - try { - String provider_json_string = preferences.getString(Provider.KEY, ""); - if(!provider_json_string.isEmpty()) { - provider_json = new JSONObject(provider_json_string); - JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); - boolean allow_registered_eip = service_description.getBoolean(Provider.ALLOW_REGISTRATION); - preferences.edit().putBoolean(Constants.ALLOWED_REGISTERED, allow_registered_eip).apply(); - - if(allow_registered_eip) { - if(LeapSRPSession.loggedIn()) { - menu.findItem(R.id.login_button).setVisible(false); - menu.findItem(R.id.logout_button).setVisible(true); - } else { - menu.findItem(R.id.login_button).setVisible(true); - menu.findItem(R.id.logout_button).setVisible(false); - } - menu.findItem(R.id.signup_button).setVisible(true); - } - } - } catch (JSONException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return true; + if(provider.allowsRegistration()) { + menu.findItem(R.id.signup_button).setVisible(true); + + boolean logged_in = User.loggedIn(); + menu.findItem(R.id.login_button).setVisible(!logged_in); + menu.findItem(R.id.logout_button).setVisible(logged_in); + } + return true; } @Override @@ -282,25 +282,50 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn public void showLog() { Intent startLW = new Intent(getAppContext(), LogWindow.class); - //startLW.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(startLW); } @Override public void signUp(String username, String password) { - Bundle parameters = bundleParameters(username, password); - providerApiCommand(parameters, R.string.signingup_message, ProviderAPI.SRP_REGISTER); + User.setUserName(username); + Bundle parameters = bundlePassword(password); + providerApiCommand(parameters, R.string.signingup_message, ProviderAPI.SIGN_UP); } @Override public void logIn(String username, String password) { - Bundle parameters = bundleParameters(username, password); - providerApiCommand(parameters, R.string.authenticating_message, ProviderAPI.SRP_AUTH); + User.setUserName(username); + Bundle parameters = bundlePassword(password); + providerApiCommand(parameters, R.string.authenticating_message, ProviderAPI.LOG_IN); } public void logOut() { providerApiCommand(Bundle.EMPTY, R.string.logout_message, ProviderAPI.LOG_OUT); } + + @Override + public void update (Observable observable, Object data) { + if(observable instanceof UserSessionStatus) { + UserSessionStatus status = (UserSessionStatus) observable; + handleNewUserSessionStatus(status); + } + } + + private void handleNewUserSessionStatus(UserSessionStatus status) { + user_session_status = status; + if(provider.allowsRegistration()) + changeSessionStatusMessage(user_session_status.toString()); + } + + private void changeSessionStatusMessage(final String message) { + Log.d(TAG, message); + runOnUiThread(new Runnable() { + @Override + public void run() { + user_session_status_text_view.setText(message); + } + }); + } protected void downloadVpnCertificate() { boolean is_authenticated = LeapSRPSession.loggedIn(); @@ -312,10 +337,8 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn } - private Bundle bundleParameters(String username, String password) { + private Bundle bundlePassword(String password) { Bundle parameters = new Bundle(); - if(!username.isEmpty()) - parameters.putString(SessionDialog.USERNAME, username); if(!password.isEmpty()) parameters.putString(SessionDialog.PASSWORD, password); return parameters; diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index 6dbdf961..e152df46 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -23,6 +23,8 @@ import android.util.*; import android.view.*; import android.widget.*; +import org.jetbrains.annotations.NotNull; + import java.util.*; import butterknife.*; @@ -80,18 +82,20 @@ public class EipFragment extends Fragment implements Observer { Bundle arguments = getArguments(); if(arguments != null && arguments.containsKey(START_ON_BOOT) && arguments.getBoolean(START_ON_BOOT)) startEipFromScratch(); + if(savedInstanceState != null) restoreState(savedInstanceState); - if (savedInstanceState != null) { - status_message.setText(savedInstanceState.getString(STATUS_MESSAGE)); - if(savedInstanceState.getBoolean(IS_PENDING)) - eip_status.setConnecting(); - else if(savedInstanceState.getBoolean(IS_CONNECTED)) { - eip_status.setConnectedOrDisconnected(); - } - } return view; } + private void restoreState(@NotNull Bundle savedInstanceState) { + if(savedInstanceState.getBoolean(IS_PENDING)) + eip_status.setConnecting(); + else if(savedInstanceState.getBoolean(IS_CONNECTED)) + eip_status.setConnectedOrDisconnected(); + else + status_message.setText(savedInstanceState.getString(STATUS_MESSAGE)); + } + @Override public void onResume() { super.onResume(); @@ -103,14 +107,12 @@ public class EipFragment extends Fragment implements Observer { public void onSaveInstanceState(Bundle outState) { outState.putBoolean(IS_PENDING, eip_status.isConnecting()); outState.putBoolean(IS_CONNECTED, eip_status.isConnected()); - Log.d(TAG, "status message onSaveInstanceState = " + status_message.getText().toString()); outState.putString(STATUS_MESSAGE, status_message.getText().toString()); super.onSaveInstanceState(outState); } protected void saveStatus() { boolean is_on = eip_switch.isChecked(); - Log.d(TAG, "saveStatus: is_on = " + is_on); Dashboard.preferences.edit().putBoolean(Dashboard.START_ON_BOOT, is_on).commit(); } diff --git a/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java b/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java index 09855baf..49c115ae 100644 --- a/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java +++ b/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java @@ -44,7 +44,8 @@ public class LeapSRPSession { final public static String TOKEN = "token"; final public static String AUTHORIZATION_HEADER= "Authorization"; final public static String TAG= "Leap SRP session class tag"; - + + private User user; private SRPParameters params; private String username; private String password; diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java index d7ff6633..ef25c5d2 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Provider.java +++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java @@ -172,6 +172,14 @@ public final class Provider implements Parcelable { return false; } + public boolean allowsRegistration() { + try { + return definition.getJSONObject(Provider.SERVICE).getBoolean(Provider.ALLOW_REGISTRATION); + } catch (JSONException e) { + return false; + } + } + @Override public int describeContents() { return 0; diff --git a/app/src/main/java/se/leap/bitmaskclient/User.java b/app/src/main/java/se/leap/bitmaskclient/User.java new file mode 100644 index 00000000..e05a0573 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/User.java @@ -0,0 +1,41 @@ +/** + * 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 . + */ +package se.leap.bitmaskclient; + +public class User { + private static String user_name = "The user"; + private static User user; + + public static User getInstance() { + if(user == null) { + user = new User(); + } + return user; + } + + public static void setUserName(String user_name) { + User.user_name = user_name; + } + + private User() { } + + public static String userName() { return user_name; } + + public static boolean loggedIn() { + return LeapSRPSession.loggedIn(); + } +} diff --git a/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java b/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java new file mode 100644 index 00000000..bab57d04 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java @@ -0,0 +1,65 @@ +/** + * 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 . + */ +package se.leap.bitmaskclient; + +import android.os.*; + +import java.util.*; + +public class UserSessionStatus extends Observable { + public static String TAG = UserSessionStatus.class.getSimpleName(); + private static UserSessionStatus current_status; + + public enum SessionStatus { + LOGGED_IN, + LOGGED_OUT, + NOT_LOGGED_IN, + DIDNT_LOG_OUT, + LOGGING_IN, + LOGGING_OUT + } + + private static SessionStatus session_status = SessionStatus.NOT_LOGGED_IN; + + public static UserSessionStatus getInstance() { + if(current_status == null) { + current_status = new UserSessionStatus(); + } + return current_status; + } + + private UserSessionStatus() { } + + private void sessionStatus(SessionStatus session_status) { + this.session_status = session_status; + } + + public SessionStatus sessionStatus() { return session_status; } + + public static void updateStatus(SessionStatus session_status) { + current_status = getInstance(); + current_status.sessionStatus(session_status); + current_status.setChanged(); + current_status.notifyObservers(); + } + + @Override + public String toString() { + return User.userName() + " is " + + session_status.toString().toLowerCase().replaceAll("_", " "); + } +} diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java index 0c773208..0a707ab1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java @@ -42,7 +42,8 @@ public class VoidVpnService extends VpnService { public static boolean stop() { try { - fd.close(); + if(fd != null) + fd.close(); return true; } catch (IOException | NullPointerException e) { android.util.Log.d(TAG, "VoidVpnService didn't stop"); diff --git a/app/src/main/res/layout/dashboard.xml b/app/src/main/res/layout/dashboard.xml index 67a1122f..4a9dd502 100644 --- a/app/src/main/res/layout/dashboard.xml +++ b/app/src/main/res/layout/dashboard.xml @@ -16,7 +16,6 @@ android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:ellipsize="marquee" - android:fadingEdge="horizontal" android:singleLine="true" android:text="@string/provider_label" android:textAppearance="?android:attr/textAppearanceMedium" /> @@ -28,18 +27,22 @@ android:textSize="28sp" android:layout_marginLeft="10dp" android:ellipsize="marquee" - android:fadingEdge="horizontal" android:singleLine="true" android:text="@string/provider_label_none" android:textAppearance="?android:attr/textAppearanceMedium" /> - + android:layout_height="wrap_content" + android:textSize="18sp" + android:layout_marginLeft="10dp" + android:ellipsize="marquee" + android:singleLine="true" + android:textAppearance="?android:attr/textAppearanceMedium" + /> Date: Fri, 13 Mar 2015 14:56:27 +0100 Subject: Progress spinning bar for user session status Copy changes to xlarge layout. --- .../main/java/se/leap/bitmaskclient/Dashboard.java | 35 ++++++++++++++++++---- .../se/leap/bitmaskclient/UserSessionStatus.java | 5 ++++ app/src/main/res/layout-xlarge/dashboard.xml | 22 ++++++++++++++ app/src/main/res/layout/dashboard.xml | 32 +++++++++++++------- 4 files changed, 77 insertions(+), 17 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index c6ac2477..28eb739c 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -63,6 +63,8 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn TextView provider_name; @InjectView(R.id.user_session_status) TextView user_session_status_text_view; + @InjectView(R.id.user_session_status_progress) + ProgressBar user_session_status_progress_bar; EipFragment eip_fragment; private Provider provider; @@ -313,12 +315,16 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn private void handleNewUserSessionStatus(UserSessionStatus status) { user_session_status = status; - if(provider.allowsRegistration()) + if(provider.allowsRegistration()) { + if(user_session_status.inProgress()) + showUserSessionProgressBar(); + else + hideUserSessionProgressBar(); changeSessionStatusMessage(user_session_status.toString()); + } } private void changeSessionStatusMessage(final String message) { - Log.d(TAG, message); runOnUiThread(new Runnable() { @Override public void run() { @@ -327,6 +333,24 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn }); } + private void showUserSessionProgressBar() { + runOnUiThread(new Runnable() { + @Override + public void run() { + user_session_status_progress_bar.setVisibility(ProgressBar.VISIBLE); + } + }); + } + + private void hideUserSessionProgressBar() { + runOnUiThread(new Runnable() { + @Override + public void run() { + user_session_status_progress_bar.setVisibility(ProgressBar.GONE); + } + }); + } + protected void downloadVpnCertificate() { boolean is_authenticated = LeapSRPSession.loggedIn(); boolean allowed_anon = preferences.getBoolean(Constants.ALLOWED_ANON, false); @@ -428,12 +452,11 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn } private void updateViewHidingProgressBar(int resultCode) { - changeStatusMessage(resultCode); - hideProgressBar(); + changeEipStatusMessage(resultCode); invalidateOptionsMenu(); } - private void changeStatusMessage(final int previous_result_code) { + private void changeEipStatusMessage(final int previous_result_code) { ResultReceiver status_receiver = new ResultReceiver(new Handler()){ protected void onReceiveResult(int resultCode, Bundle resultData){ super.onReceiveResult(resultCode, resultData); @@ -480,7 +503,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn startService(intent); } - private void hideProgressBar() { + private void hideEipProgressBar() { if(eip_fragment != null) { eip_fragment.progress_bar.setProgress(0); eip_fragment.progress_bar.setVisibility(ProgressBar.GONE); diff --git a/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java b/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java index bab57d04..f533819b 100644 --- a/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java @@ -49,6 +49,11 @@ public class UserSessionStatus extends Observable { } public SessionStatus sessionStatus() { return session_status; } + + public boolean inProgress() { + return session_status == SessionStatus.LOGGING_IN + || session_status == SessionStatus.LOGGING_OUT; + } public static void updateStatus(SessionStatus session_status) { current_status = getInstance(); diff --git a/app/src/main/res/layout-xlarge/dashboard.xml b/app/src/main/res/layout-xlarge/dashboard.xml index bd644e1e..268bd3f9 100644 --- a/app/src/main/res/layout-xlarge/dashboard.xml +++ b/app/src/main/res/layout-xlarge/dashboard.xml @@ -52,6 +52,28 @@ + + + + + - - + + + + + Date: Fri, 13 Mar 2015 15:19:20 +0100 Subject: Say nothing about user sessions in eip status. --- .../main/java/se/leap/bitmaskclient/Dashboard.java | 71 ++-------------------- .../java/se/leap/bitmaskclient/EipFragment.java | 7 ++- app/src/main/java/se/leap/bitmaskclient/User.java | 2 +- 3 files changed, 13 insertions(+), 67 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index 28eb739c..74a87e63 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -182,7 +182,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn } private void configErrorDialog() { - AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getAppContext()); + AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getContext()); alertBuilder.setTitle(getResources().getString(R.string.setup_error_title)); alertBuilder .setMessage(getResources().getString(R.string.setup_error_text)) @@ -190,7 +190,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn .setPositiveButton(getResources().getString(R.string.setup_error_configure_button), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - startActivityForResult(new Intent(getAppContext(),ConfigurationWizard.class),CONFIGURE_LEAP); + startActivityForResult(new Intent(getContext(),ConfigurationWizard.class),CONFIGURE_LEAP); } }) .setNegativeButton(getResources().getString(R.string.setup_error_close_button), new DialogInterface.OnClickListener() { @@ -283,7 +283,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn } public void showLog() { - Intent startLW = new Intent(getAppContext(), LogWindow.class); + Intent startLW = new Intent(getContext(), LogWindow.class); startActivity(startLW); } @@ -321,6 +321,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn else hideUserSessionProgressBar(); changeSessionStatusMessage(user_session_status.toString()); + invalidateOptionsMenu(); } } @@ -421,26 +422,20 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn String password = resultData.getString(SessionDialog.PASSWORD); logIn(username, password); } else if(resultCode == ProviderAPI.FAILED_SIGNUP) { - updateViewHidingProgressBar(resultCode); sessionDialog(resultData); } else if(resultCode == ProviderAPI.SUCCESSFUL_LOGIN) { - updateViewHidingProgressBar(resultCode); downloadVpnCertificate(); } else if(resultCode == ProviderAPI.FAILED_LOGIN) { - updateViewHidingProgressBar(resultCode); sessionDialog(resultData); } else if(resultCode == ProviderAPI.SUCCESSFUL_LOGOUT) { - updateViewHidingProgressBar(resultCode); if(switching_provider) switchProvider(); } else if(resultCode == ProviderAPI.LOGOUT_FAILED) { - updateViewHidingProgressBar(resultCode); setResult(RESULT_CANCELED); } else if(resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) { - updateViewHidingProgressBar(resultCode); eip_fragment.updateEipService(); + eip_fragment.handleNewVpnCertificate(); setResult(RESULT_OK); } else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) { - updateViewHidingProgressBar(resultCode); setResult(RESULT_CANCELED); } else if(resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_EIP_SERVICE) { @@ -451,66 +446,12 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn } } - private void updateViewHidingProgressBar(int resultCode) { - changeEipStatusMessage(resultCode); - invalidateOptionsMenu(); - } - - private void changeEipStatusMessage(final int previous_result_code) { - ResultReceiver status_receiver = new ResultReceiver(new Handler()){ - protected void onReceiveResult(int resultCode, Bundle resultData){ - super.onReceiveResult(resultCode, resultData); - String request = resultData.getString(Constants.REQUEST_TAG); - if (request.equalsIgnoreCase(Constants.ACTION_IS_EIP_RUNNING)){ - if (resultCode == Activity.RESULT_OK){ - switch(previous_result_code){ - case ProviderAPI.SUCCESSFUL_LOGIN: setStatusMessage(R.string.succesful_authentication_message); break; - case ProviderAPI.FAILED_LOGIN: setStatusMessage(R.string.authentication_failed_message); break; - case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE: setStatusMessage(R.string.incorrectly_downloaded_certificate_message); break; - case ProviderAPI.SUCCESSFUL_LOGOUT: setStatusMessage(R.string.logged_out_message); break; - case ProviderAPI.LOGOUT_FAILED: setStatusMessage(R.string.log_out_failed_message); break; - - } - } - else if(resultCode == Activity.RESULT_CANCELED){ - switch(previous_result_code){ - case ProviderAPI.SUCCESSFUL_LOGIN: setStatusMessage(R.string.succesful_authentication_message); break; - case ProviderAPI.FAILED_LOGIN: setStatusMessage(R.string.authentication_failed_message); break; - case ProviderAPI.FAILED_SIGNUP: setStatusMessage(R.string.registration_failed_message); break; - case ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE: break; - case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE: setStatusMessage(R.string.incorrectly_downloaded_certificate_message); break; - case ProviderAPI.SUCCESSFUL_LOGOUT: setStatusMessage(R.string.logged_out_message); break; - case ProviderAPI.LOGOUT_FAILED: setStatusMessage(R.string.log_out_failed_message); break; - } - } - } - - } - }; - eipIsRunning(status_receiver); - } - private void setStatusMessage(int string_resId) { if(eip_fragment != null && eip_fragment.status_message != null) eip_fragment.status_message.setText(string_resId); } - 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 intent = new Intent(this, EIP.class); - intent.setAction(Constants.ACTION_IS_EIP_RUNNING); - intent.putExtra(Constants.RECEIVER_TAG, eip_receiver); - startService(intent); - } - - private void hideEipProgressBar() { - if(eip_fragment != null) { - eip_fragment.progress_bar.setProgress(0); - eip_fragment.progress_bar.setVisibility(ProgressBar.GONE); - } - } - - public static Context getAppContext() { + public static Context getContext() { return app; } diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index e152df46..2057a80b 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -116,6 +116,10 @@ public class EipFragment extends Fragment implements Observer { Dashboard.preferences.edit().putBoolean(Dashboard.START_ON_BOOT, is_on).commit(); } + void handleNewVpnCertificate() { + handleSwitch(!eip_switch.isEnabled()); + } + @OnCheckedChanged(R.id.eipSwitch) void handleSwitch(boolean isChecked) { if(isChecked) @@ -156,7 +160,8 @@ public class EipFragment extends Fragment implements Observer { askPendingStartCancellation(); } else if(eip_status.isConnected()) { askToStopEIP(); - } + } else + setDisconnectedUI(); } private void askPendingStartCancellation() { diff --git a/app/src/main/java/se/leap/bitmaskclient/User.java b/app/src/main/java/se/leap/bitmaskclient/User.java index e05a0573..6e20c165 100644 --- a/app/src/main/java/se/leap/bitmaskclient/User.java +++ b/app/src/main/java/se/leap/bitmaskclient/User.java @@ -17,7 +17,7 @@ package se.leap.bitmaskclient; public class User { - private static String user_name = "The user"; + private static String user_name = "You"; private static User user; public static User getInstance() { -- cgit v1.2.3 From 429295bd6ee5f2caa57c287e74392c80aed25f20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Fri, 13 Mar 2015 15:28:59 +0100 Subject: If a provider fails to be configured, go back to CW. --- app/src/main/res/values/strings.xml | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/src/main') diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 032602cb..897223ad 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -71,4 +71,6 @@ No "Not running! Connection not secure!" Connection Secure. + It seems there is a problem with the provider. + Please try another provider, or contact yours. -- cgit v1.2.3 From b9120adba28b5d691375ece5a919357e54e86a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Fri, 13 Mar 2015 15:44:24 +0100 Subject: Restore provider from sharedconfs if necessary --- app/src/main/java/se/leap/bitmaskclient/Dashboard.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index 74a87e63..face6ced 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -99,9 +99,9 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn if (savedInstanceState != null) { if(savedInstanceState.containsKey(Provider.KEY)) provider = savedInstanceState.getParcelable(Provider.KEY); - if(provider == null && preferences.getBoolean(Constants.PROVIDER_CONFIGURED, false)) - provider = getSavedProviderFromSharedPreferences(); } + if(provider == null && preferences.getBoolean(Constants.PROVIDER_CONFIGURED, false)) + provider = getSavedProviderFromSharedPreferences(); } private void restoreSessionStatus(Bundle savedInstanceState) { -- cgit v1.2.3 From 3a7b9c1c746bd26b4e689814c3a4ec6b3141a76a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Fri, 13 Mar 2015 15:57:43 +0100 Subject: 0.9.3 RC1 --- app/src/main/AndroidManifest.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e11b57ef..2bd630ee 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,8 +17,8 @@ + android:versionCode="117" + android:versionName="0.9.3" > -- cgit v1.2.3 From bb2a944265da15eeba35106f2e2bcda288855527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 19 Mar 2015 15:07:55 +0100 Subject: Show browser warning on disconnect. Also reindent some code. --- .../main/java/se/leap/bitmaskclient/Dashboard.java | 2 +- .../java/se/leap/bitmaskclient/EipFragment.java | 428 +++++++++++---------- .../leap/bitmaskclient/eip/VpnConfigGenerator.java | 144 +++---- app/src/main/res/values/strings.xml | 1 + 4 files changed, 298 insertions(+), 277 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index face6ced..a8f6e110 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -407,7 +407,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn } private void switchProvider() { - if (provider.hasEIP()) eip_fragment.askToStopEIP(); + if (provider.hasEIP()) eip_fragment.stopEipIfPossible(); preferences.edit().clear().apply(); switching_provider = false; diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index 2057a80b..5e5b76b2 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -1,6 +1,6 @@ /** * 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 @@ -32,7 +32,7 @@ import de.blinkt.openvpn.activities.*; import se.leap.bitmaskclient.eip.*; public class EipFragment extends Fragment implements Observer { - + public static String TAG = EipFragment.class.getSimpleName(); protected static final String IS_PENDING = TAG + ".is_pending"; @@ -55,36 +55,36 @@ public class EipFragment extends Fragment implements Observer { @Override public void onAttach(Activity activity) { - super.onAttach(activity); + super.onAttach(activity); dashboard = (Dashboard) activity; dashboard.providerApiCommand(Bundle.EMPTY, 0, ProviderAPI.DOWNLOAD_EIP_SERVICE); } - + @Override public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - eip_status = EipStatus.getInstance(); - eip_status.addObserver(this); - mEIPReceiver = new EIPReceiver(new Handler()); + super.onCreate(savedInstanceState); + eip_status = EipStatus.getInstance(); + eip_status.addObserver(this); + mEIPReceiver = new EIPReceiver(new Handler()); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.eip_service_fragment, container, false); + View view = inflater.inflate(R.layout.eip_service_fragment, container, false); ButterKnife.inject(this, view); - if (eip_status.isConnecting()) - eip_switch.setVisibility(View.VISIBLE); + if (eip_status.isConnecting()) + eip_switch.setVisibility(View.VISIBLE); - Log.d(TAG, "onCreateView, eip_switch is checked? " + eip_switch.isChecked()); + Log.d(TAG, "onCreateView, eip_switch is checked? " + eip_switch.isChecked()); Bundle arguments = getArguments(); - if(arguments != null && arguments.containsKey(START_ON_BOOT) && arguments.getBoolean(START_ON_BOOT)) - startEipFromScratch(); - if(savedInstanceState != null) restoreState(savedInstanceState); + if(arguments != null && arguments.containsKey(START_ON_BOOT) && arguments.getBoolean(START_ON_BOOT)) + startEipFromScratch(); + if(savedInstanceState != null) restoreState(savedInstanceState); - return view; + return view; } private void restoreState(@NotNull Bundle savedInstanceState) { @@ -98,22 +98,22 @@ public class EipFragment extends Fragment implements Observer { @Override public void onResume() { - super.onResume(); - eipCommand(Constants.ACTION_CHECK_CERT_VALIDITY); - handleNewState(eip_status); + super.onResume(); + eipCommand(Constants.ACTION_CHECK_CERT_VALIDITY); + handleNewState(eip_status); } - + @Override public void onSaveInstanceState(Bundle outState) { - outState.putBoolean(IS_PENDING, eip_status.isConnecting()); - outState.putBoolean(IS_CONNECTED, eip_status.isConnected()); - outState.putString(STATUS_MESSAGE, status_message.getText().toString()); - super.onSaveInstanceState(outState); + outState.putBoolean(IS_PENDING, eip_status.isConnecting()); + outState.putBoolean(IS_CONNECTED, eip_status.isConnected()); + outState.putString(STATUS_MESSAGE, status_message.getText().toString()); + super.onSaveInstanceState(outState); } protected void saveStatus() { - boolean is_on = eip_switch.isChecked(); - Dashboard.preferences.edit().putBoolean(Dashboard.START_ON_BOOT, is_on).commit(); + boolean is_on = eip_switch.isChecked(); + Dashboard.preferences.edit().putBoolean(Dashboard.START_ON_BOOT, is_on).commit(); } void handleNewVpnCertificate() { @@ -122,251 +122,271 @@ public class EipFragment extends Fragment implements Observer { @OnCheckedChanged(R.id.eipSwitch) void handleSwitch(boolean isChecked) { - if(isChecked) - handleSwitchOn(); - else - handleSwitchOff(); - - saveStatus(); + if(isChecked) + handleSwitchOn(); + else + handleSwitchOff(); + + saveStatus(); } private void handleSwitchOn() { - if(canStartEIP()) - startEipFromScratch(); - else if(canLogInToStartEIP()) { - wants_to_connect = true; - Bundle bundle = new Bundle(); - bundle.putBoolean(IS_PENDING, true); - dashboard.sessionDialog(bundle); - } - } - + if(canStartEIP()) + startEipFromScratch(); + else if(canLogInToStartEIP()) { + wants_to_connect = true; + Bundle bundle = new Bundle(); + bundle.putBoolean(IS_PENDING, true); + dashboard.sessionDialog(bundle); + } + } + 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() && !eip_status.isConnecting(); + boolean certificateExists = !Dashboard.preferences.getString(Constants.CERTIFICATE, "").isEmpty(); + boolean isAllowedAnon = Dashboard.preferences.getBoolean(Constants.ALLOWED_ANON, false); + return (isAllowedAnon || certificateExists) && !eip_status.isConnected() && !eip_status.isConnecting(); } - + private boolean canLogInToStartEIP() { - 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); - return isAllowedRegistered && !isLoggedIn && !eip_status.isConnecting() && !eip_status.isConnected(); + 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); + return isAllowedRegistered && !isLoggedIn && !eip_status.isConnecting() && !eip_status.isConnected(); } private void handleSwitchOff() { - if(eip_status.isConnecting()) { - askPendingStartCancellation(); - } else if(eip_status.isConnected()) { - askToStopEIP(); - } else - setDisconnectedUI(); - } - - private void askPendingStartCancellation() { - AlertDialog.Builder alertBuilder = new AlertDialog.Builder(dashboard); - alertBuilder.setTitle(dashboard.getString(R.string.eip_cancel_connect_title)) - .setMessage(dashboard.getString(R.string.eip_cancel_connect_text)) - .setPositiveButton((R.string.yes), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - askToStopEIP(); - } - }) - .setNegativeButton(dashboard.getString(R.string.no), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - eip_switch.setChecked(true); - } - }) - .show(); + if(eip_status.isConnecting()) { + askPendingStartCancellation(); + } else if(eip_status.isConnected()) { + askToStopEIP(); + } else + setDisconnectedUI(); + } + + private void askPendingStartCancellation() { + AlertDialog.Builder alertBuilder = new AlertDialog.Builder(dashboard); + alertBuilder.setTitle(dashboard.getString(R.string.eip_cancel_connect_title)) + .setMessage(dashboard.getString(R.string.eip_cancel_connect_text)) + .setPositiveButton((R.string.yes), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + askToStopEIP(); + } + }) + .setNegativeButton(dashboard.getString(R.string.no), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + eip_switch.setChecked(true); + } + }) + .show(); } public void startEipFromScratch() { wants_to_connect = false; is_starting_to_connect = true; progress_bar.setVisibility(View.VISIBLE); - eip_switch.setVisibility(View.VISIBLE); - String status = dashboard.getString(R.string.eip_status_start_pending); - status_message.setText(status); - - if(!eip_switch.isChecked()) { - eip_switch.setChecked(true); - } + eip_switch.setVisibility(View.VISIBLE); + String status = dashboard.getString(R.string.eip_status_start_pending); + status_message.setText(status); + + if(!eip_switch.isChecked()) { + eip_switch.setChecked(true); + } saveStatus(); - eipCommand(Constants.ACTION_START_EIP); + eipCommand(Constants.ACTION_START_EIP); } - private void stopEIP() { - if(eip_status.isConnecting()) - VoidVpnService.stop(); - disconnect(); + private void stop() { + if(eip_status.isConnecting()) + VoidVpnService.stop(); + disconnect(); } private void disconnect() { - Intent disconnect_vpn = new Intent(dashboard, DisconnectVPN.class); - dashboard.startActivityForResult(disconnect_vpn, EIP.DISCONNECT); - eip_status.setDisconnecting(); + Intent disconnect_vpn = new Intent(dashboard, DisconnectVPN.class); + dashboard.startActivityForResult(disconnect_vpn, EIP.DISCONNECT); + eip_status.setDisconnecting(); } - protected void askToStopEIP() { + protected void stopEipIfPossible() { + hideProgressBar(); - String message = dashboard.getString(R.string.eip_state_not_connected); - status_message.setText(message); + String message = dashboard.getString(R.string.eip_state_not_connected); + status_message.setText(message); + + eipCommand(Constants.ACTION_STOP_EIP); + } - eipCommand(Constants.ACTION_STOP_EIP); + private void askToStopEIP() { + AlertDialog.Builder alertBuilder = new AlertDialog.Builder(dashboard); + alertBuilder.setTitle(dashboard.getString(R.string.eip_cancel_connect_title)) + .setMessage(dashboard.getString(R.string.eip_warning_browser_inconsistency)) + .setPositiveButton((R.string.yes), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + stopEipIfPossible(); + } + }) + .setNegativeButton(dashboard.getString(R.string.no), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + eip_switch.setChecked(true); + } + }) + .show(); } protected void updateEipService() { eipCommand(Constants.ACTION_UPDATE_EIP_SERVICE); } - + /** * Send a command to EIP - * + * * @param action A valid String constant from EIP class representing an Intent * filter for the EIP class */ private void eipCommand(String action){ - // TODO validate "action"...how do we get the list of intent-filters for a class via Android API? - Intent vpn_intent = new Intent(dashboard.getApplicationContext(), EIP.class); - vpn_intent.setAction(action); - vpn_intent.putExtra(Constants.RECEIVER_TAG, mEIPReceiver); - dashboard.startService(vpn_intent); + // TODO validate "action"...how do we get the list of intent-filters for a class via Android API? + Intent vpn_intent = new Intent(dashboard.getApplicationContext(), EIP.class); + vpn_intent.setAction(action); + vpn_intent.putExtra(Constants.RECEIVER_TAG, mEIPReceiver); + dashboard.startService(vpn_intent); } - + @Override public void update (Observable observable, Object data) { - if(observable instanceof EipStatus) { - eip_status = (EipStatus) observable; - final EipStatus eip_status = (EipStatus) observable; - dashboard.runOnUiThread(new Runnable() { - @Override - public void run() { - handleNewState(eip_status); - } - }); - } + if(observable instanceof EipStatus) { + eip_status = (EipStatus) observable; + final EipStatus eip_status = (EipStatus) observable; + dashboard.runOnUiThread(new Runnable() { + @Override + public void run() { + handleNewState(eip_status); + } + }); + } } private void handleNewState(EipStatus eip_status) { - 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(); + 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(); } private void setConnectedUI() { - hideProgressBar(); - Log.d(TAG, "setConnectedUi? " + eip_status.isConnected()); - adjustSwitch(); - is_starting_to_connect = false; - status_message.setText(dashboard.getString(R.string.eip_state_connected)); + hideProgressBar(); + Log.d(TAG, "setConnectedUi? " + eip_status.isConnected()); + adjustSwitch(); + is_starting_to_connect = false; + status_message.setText(dashboard.getString(R.string.eip_state_connected)); } private void setDisconnectedUI(){ - hideProgressBar(); - adjustSwitch(); - String last_log_message = eip_status.getLastLogMessage(dashboard.getApplicationContext()); - if((last_log_message.contains("error") || last_log_message.contains("ERROR")) - && !status_message.getText().toString().equalsIgnoreCase(dashboard.getString(R.string.eip_state_not_connected))){ - dashboard.showLog(); - } + hideProgressBar(); + adjustSwitch(); + String last_log_message = eip_status.getLastLogMessage(dashboard.getApplicationContext()); + if((last_log_message.contains("error") || last_log_message.contains("ERROR")) + && !status_message.getText().toString().equalsIgnoreCase(dashboard.getString(R.string.eip_state_not_connected))){ + dashboard.showLog(); + } status_message.setText(dashboard.getString(R.string.eip_state_not_connected)); } private void adjustSwitch() { - 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_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); - } - } + if(eip_switch.isChecked()) { + eip_switch.setChecked(false); + } + } } private void setInProgressUI(EipStatus eip_status) { - int localizedResId = eip_status.getLocalizedResId(); - String logmessage = eip_status.getLogMessage(); - String prefix = dashboard.getString(localizedResId); + int localizedResId = eip_status.getLocalizedResId(); + String logmessage = eip_status.getLogMessage(); + String prefix = dashboard.getString(localizedResId); - showProgressBar(); - status_message.setText(prefix + " " + logmessage); + showProgressBar(); + status_message.setText(prefix + " " + logmessage); is_starting_to_connect = false; - adjustSwitch(); + adjustSwitch(); } private void updatingCertificateUI() { - showProgressBar(); + showProgressBar(); status_message.setText(getString(R.string.updating_certificate_message)); } private void showProgressBar() { - if(progress_bar != null) - progress_bar.setVisibility(View.VISIBLE); + if(progress_bar != null) + progress_bar.setVisibility(View.VISIBLE); } private void hideProgressBar() { - if(progress_bar != null) - progress_bar.setVisibility(View.GONE); - } - - protected class EIPReceiver extends ResultReceiver { - - protected EIPReceiver(Handler handler){ - super(handler); - } - - @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: - break; - case Activity.RESULT_CANCELED: - - break; - } - } else if (request.equals(Constants.ACTION_STOP_EIP)) { - switch (resultCode){ - case Activity.RESULT_OK: - stopEIP(); - break; - case Activity.RESULT_CANCELED: - break; - } - } else if (request.equals(Constants.EIP_NOTIFICATION)) { - switch (resultCode){ - case Activity.RESULT_OK: - break; - case Activity.RESULT_CANCELED: - break; - } - } else if (request.equals(Constants.ACTION_CHECK_CERT_VALIDITY)) { - switch (resultCode) { - case Activity.RESULT_OK: - break; - case Activity.RESULT_CANCELED: - updatingCertificateUI(); - dashboard.downloadVpnCertificate(); - break; - } - } else if (request.equals(Constants.ACTION_UPDATE_EIP_SERVICE)) { + if(progress_bar != null) + progress_bar.setVisibility(View.GONE); + } + +protected class EIPReceiver extends ResultReceiver { + + protected EIPReceiver(Handler handler){ + super(handler); + } + + @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: + break; + case Activity.RESULT_CANCELED: + + break; + } + } else if (request.equals(Constants.ACTION_STOP_EIP)) { + switch (resultCode){ + case Activity.RESULT_OK: + stop(); + break; + case Activity.RESULT_CANCELED: + break; + } + } else if (request.equals(Constants.EIP_NOTIFICATION)) { + switch (resultCode){ + case Activity.RESULT_OK: + break; + case Activity.RESULT_CANCELED: + break; + } + } else if (request.equals(Constants.ACTION_CHECK_CERT_VALIDITY)) { + switch (resultCode) { + case Activity.RESULT_OK: + break; + case Activity.RESULT_CANCELED: + updatingCertificateUI(); + dashboard.downloadVpnCertificate(); + break; + } + } else if (request.equals(Constants.ACTION_UPDATE_EIP_SERVICE)) { switch (resultCode) { case Activity.RESULT_OK: if(wants_to_connect) @@ -377,11 +397,11 @@ public class EipFragment extends Fragment implements Observer { break; } } - } } +} public static EIPReceiver getReceiver() { - return mEIPReceiver; + return mEIPReceiver; } } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java index 6f260f55..5f5dcabd 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java @@ -1,6 +1,6 @@ /** * 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 @@ -37,79 +37,79 @@ public class VpnConfigGenerator { private final String new_line = System.getProperty("line.separator"); // Platform new line public VpnConfigGenerator(JSONObject general_configuration, JSONObject secrets, JSONObject gateway) { - this.general_configuration = general_configuration; - this.gateway = gateway; + this.general_configuration = general_configuration; + this.gateway = gateway; this.secrets = secrets; } - + public String generate() { - return - generalConfiguration() - + new_line - + gatewayConfiguration() - + new_line - + secretsConfiguration() - + new_line - + androidCustomizations(); + return + generalConfiguration() + + new_line + + gatewayConfiguration() + + new_line + + secretsConfiguration() + + new_line + + androidCustomizations(); } private String generalConfiguration() { - String common_options = ""; - try { - Iterator keys = general_configuration.keys(); - while ( keys.hasNext() ){ - String key = keys.next().toString(); - - common_options += key + " "; - for ( String word : general_configuration.getString(key).split(" ") ) - common_options += word + " "; - common_options += new_line; - - } - } catch (JSONException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - common_options += "client"; - - return common_options; + String common_options = ""; + try { + Iterator keys = general_configuration.keys(); + while ( keys.hasNext() ){ + String key = keys.next().toString(); + + common_options += key + " "; + for (String word : general_configuration.getString(key).split(" ")) + common_options += word + " "; + common_options += new_line; + + } + } catch (JSONException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + common_options += "client"; + + return common_options; } - + private String gatewayConfiguration() { - String remotes = ""; - - String ip_address_keyword = "ip_address"; - String remote_keyword = "remote"; - String ports_keyword = "ports"; - String protocol_keyword = "protocols"; - String capabilities_keyword = "capabilities"; - String udp = "udp"; - - try { - String ip_address = gateway.getString(ip_address_keyword); - JSONObject capabilities = gateway.getJSONObject(capabilities_keyword); - JSONArray ports = capabilities.getJSONArray(ports_keyword); - for (int i=0; iInitiating connection Cancel connection? There is a connection attempt in progress. Do you wish to cancel it? + In order to avoid leaking your personal information, please close your browser and start a private window after disconnecting the Encrypted VPN Internet Access. Thanks. Yes No "Not running! Connection not secure!" -- cgit v1.2.3 From 6dfae9951be275ccf33a05f4980a977b5b634e3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 19 Mar 2015 15:27:28 +0100 Subject: Don't show user session progress in the eip fragment --- app/src/main/java/se/leap/bitmaskclient/Dashboard.java | 6 +++--- app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index a8f6e110..c043821f 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -291,18 +291,18 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn public void signUp(String username, String password) { User.setUserName(username); Bundle parameters = bundlePassword(password); - providerApiCommand(parameters, R.string.signingup_message, ProviderAPI.SIGN_UP); + providerApiCommand(parameters, 0, ProviderAPI.SIGN_UP); } @Override public void logIn(String username, String password) { User.setUserName(username); Bundle parameters = bundlePassword(password); - providerApiCommand(parameters, R.string.authenticating_message, ProviderAPI.LOG_IN); + providerApiCommand(parameters, 0, ProviderAPI.LOG_IN); } public void logOut() { - providerApiCommand(Bundle.EMPTY, R.string.logout_message, ProviderAPI.LOG_OUT); + providerApiCommand(Bundle.EMPTY, 0, ProviderAPI.LOG_OUT); } @Override diff --git a/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java b/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java index f533819b..db432a82 100644 --- a/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java @@ -30,7 +30,8 @@ public class UserSessionStatus extends Observable { NOT_LOGGED_IN, DIDNT_LOG_OUT, LOGGING_IN, - LOGGING_OUT + LOGGING_OUT, + SIGNING_UP } private static SessionStatus session_status = SessionStatus.NOT_LOGGED_IN; -- cgit v1.2.3 From 2c44ba2678c6b3367a119d1e857dd5d5723f7681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 19 Mar 2015 15:56:30 +0100 Subject: Warn riseup users about credentials, as an error in the username field. I haven't still decided how to show that warning, I'm talking to gus about it. This is just the first idea, but the core mechanism is implemented at least. --- app/src/main/java/se/leap/bitmaskclient/Dashboard.java | 2 ++ app/src/main/java/se/leap/bitmaskclient/SessionDialog.java | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index c043821f..14d79bc0 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -426,6 +426,8 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn } else if(resultCode == ProviderAPI.SUCCESSFUL_LOGIN) { downloadVpnCertificate(); } else if(resultCode == ProviderAPI.FAILED_LOGIN) { + if(provider.getName().equalsIgnoreCase("riseup")) + resultData.putBoolean(SessionDialog.ERRORS.CONFUSING_CREDENTIALS.toString(), true); sessionDialog(resultData); } else if(resultCode == ProviderAPI.SUCCESSFUL_LOGOUT) { if(switching_provider) switchProvider(); diff --git a/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java b/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java index 9025564b..e32bca8e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java @@ -48,8 +48,11 @@ public class SessionDialog extends DialogFragment{ final public static String USERNAME = "username"; final public static String PASSWORD = "password"; - final public static String USERNAME_MISSING = "username missing"; - final public static String PASSWORD_INVALID_LENGTH = "password_invalid_length"; + public static enum ERRORS { + USERNAME_MISSING, + PASSWORD_INVALID_LENGTH, + CONFUSING_CREDENTIALS + } @InjectView(R.id.user_message) TextView user_message; @@ -105,13 +108,15 @@ public class SessionDialog extends DialogFragment{ private void setUp(Bundle arguments) { is_eip_pending = arguments.getBoolean(EipFragment.IS_PENDING, false); - if (arguments.containsKey(PASSWORD_INVALID_LENGTH)) + if (arguments.containsKey(ERRORS.PASSWORD_INVALID_LENGTH.toString())) password_field.setError(getString(R.string.error_not_valid_password_user_message)); + else if(arguments.containsKey(ERRORS.CONFUSING_CREDENTIALS.toString())) + username_field.setError("Perhaps you used your non LEAP credentials"); if (arguments.containsKey(USERNAME)) { String username = arguments.getString(USERNAME); username_field.setText(username); } - if (arguments.containsKey(USERNAME_MISSING)) { + if (arguments.containsKey(ERRORS.USERNAME_MISSING.toString())) { username_field.setError(getString(R.string.username_ask)); } if(arguments.containsKey(getString(R.string.user_message))) -- cgit v1.2.3 From d18be7ed1dfc645bd378c2eb0c152f7e0eda42e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 19 Mar 2015 16:56:32 +0100 Subject: Show gus message just for riseup login. --- .../main/java/se/leap/bitmaskclient/Dashboard.java | 34 ++++++++++++---------- .../java/se/leap/bitmaskclient/SessionDialog.java | 13 ++++----- app/src/main/res/values/strings.xml | 3 +- 3 files changed, 25 insertions(+), 25 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index 14d79bc0..7c5e5421 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -1,6 +1,6 @@ /** * 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 @@ -37,7 +37,7 @@ import se.leap.bitmaskclient.eip.*; /** * The main user facing Activity of Bitmask Android, consisting of status, controls, * and access to preferences. - * + * * @author Sean Leonard * @author parmegv */ @@ -202,7 +202,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn }) .show(); } - + /** * Inflates permanent UI elements of the View and contains logic for what * service dependent UI elements to include. @@ -248,7 +248,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn getMenuInflater().inflate(R.menu.client_dashboard, menu); return true; } - + @Override public boolean onOptionsItemSelected(MenuItem item){ switch (item.getItemId()){ @@ -279,7 +279,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn public void showAbout() { Intent intent = new Intent(this, AboutActivity.class); - startActivity(intent); + startActivity(intent); } public void showLog() { @@ -300,11 +300,11 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn Bundle parameters = bundlePassword(password); providerApiCommand(parameters, 0, ProviderAPI.LOG_IN); } - + public void logOut() { providerApiCommand(Bundle.EMPTY, 0, ProviderAPI.LOG_OUT); } - + @Override public void update (Observable observable, Object data) { if(observable instanceof UserSessionStatus) { @@ -374,7 +374,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn eip_fragment.progress_bar.setVisibility(ProgressBar.VISIBLE); setStatusMessage(progressbar_message_resId); } - + Intent command = prepareProviderAPICommand(parameters, providerApi_action); startService(command); } @@ -382,9 +382,9 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn private Intent prepareProviderAPICommand(Bundle parameters, String action) { providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler()); providerAPI_result_receiver.setReceiver(this); - + Intent command = new Intent(this, ProviderAPI.class); - + command.putExtra(ProviderAPI.PARAMETERS, parameters); command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver); command.setAction(action); @@ -394,12 +394,16 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn public void cancelLoginOrSignup() { EipStatus.getInstance().setConnectedOrDisconnected(); } - + public void sessionDialog(Bundle resultData) { - + FragmentTransaction transaction = fragment_manager.removePreviousFragment(SessionDialog.TAG); DialogFragment newFragment = new SessionDialog(); + if(provider.getName().equalsIgnoreCase("riseup")) { + resultData = resultData == Bundle.EMPTY ? new Bundle() : resultData; + resultData.putBoolean(SessionDialog.ERRORS.RISEUP_WARNING.toString(), true); + } if(resultData != null && !resultData.isEmpty()) { newFragment.setArguments(resultData); } @@ -408,7 +412,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn private void switchProvider() { if (provider.hasEIP()) eip_fragment.stopEipIfPossible(); - + preferences.edit().clear().apply(); switching_provider = false; startActivityForResult(new Intent(this, ConfigurationWizard.class), SWITCH_PROVIDER); @@ -426,8 +430,6 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn } else if(resultCode == ProviderAPI.SUCCESSFUL_LOGIN) { downloadVpnCertificate(); } else if(resultCode == ProviderAPI.FAILED_LOGIN) { - if(provider.getName().equalsIgnoreCase("riseup")) - resultData.putBoolean(SessionDialog.ERRORS.CONFUSING_CREDENTIALS.toString(), true); sessionDialog(resultData); } else if(resultCode == ProviderAPI.SUCCESSFUL_LOGOUT) { if(switching_provider) switchProvider(); @@ -456,7 +458,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn public static Context getContext() { return app; } - + @Override public void startActivityForResult(Intent intent, int requestCode) { intent.putExtra(Dashboard.REQUEST_CODE, requestCode); diff --git a/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java b/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java index e32bca8e..91e56330 100644 --- a/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java @@ -26,8 +26,6 @@ import android.view.View; import android.widget.EditText; import android.widget.TextView; -import org.jetbrains.annotations.NotNull; - import butterknife.ButterKnife; import butterknife.InjectView; @@ -51,7 +49,7 @@ public class SessionDialog extends DialogFragment{ public static enum ERRORS { USERNAME_MISSING, PASSWORD_INVALID_LENGTH, - CONFUSING_CREDENTIALS + RISEUP_WARNING } @InjectView(R.id.user_message) @@ -110,9 +108,10 @@ public class SessionDialog extends DialogFragment{ is_eip_pending = arguments.getBoolean(EipFragment.IS_PENDING, false); if (arguments.containsKey(ERRORS.PASSWORD_INVALID_LENGTH.toString())) password_field.setError(getString(R.string.error_not_valid_password_user_message)); - else if(arguments.containsKey(ERRORS.CONFUSING_CREDENTIALS.toString())) - username_field.setError("Perhaps you used your non LEAP credentials"); - if (arguments.containsKey(USERNAME)) { + else if(arguments.containsKey(ERRORS.RISEUP_WARNING.toString())) { + user_message.setVisibility(TextView.VISIBLE); + user_message.setText(R.string.login_riseup_warning); + } if (arguments.containsKey(USERNAME)) { String username = arguments.getString(USERNAME); username_field.setText(username); } @@ -121,7 +120,7 @@ public class SessionDialog extends DialogFragment{ } if(arguments.containsKey(getString(R.string.user_message))) user_message.setText(arguments.getString(getString(R.string.user_message))); - else + else if(user_message.getVisibility() != TextView.VISIBLE) user_message.setVisibility(View.GONE); if(!username_field.getText().toString().isEmpty() && password_field.isFocusable()) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 632bc1f8..d1e33928 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -59,11 +59,10 @@ Logging out from this session. Logged out. Didn\'t log out. Try later, it may be a problem in the network or in the provider. If the problem persists, then wipe Bitmask data from the Android settings + "Riseup users: You need to create a separate account to use the VPN service" Authentication succeeded. Authentication failed. Registration failed. - Your own cert has been correctly downloaded. - Your own cert has incorrectly been downloaded. Initiating connection Cancel connection? There is a connection attempt in progress. Do you wish to cancel it? -- cgit v1.2.3 From 966ac406322f0c6b36b2fe746cd3f738bd0f5a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Fri, 20 Mar 2015 13:22:19 +0100 Subject: Detect error in last 5 lines of the log. --- app/src/main/java/se/leap/bitmaskclient/EipFragment.java | 5 +---- .../main/java/se/leap/bitmaskclient/eip/EipStatus.java | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index 5e5b76b2..ed507de4 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -53,7 +53,6 @@ public class EipFragment extends Fragment implements Observer { private boolean is_starting_to_connect; private boolean wants_to_connect; - @Override public void onAttach(Activity activity) { super.onAttach(activity); @@ -293,12 +292,10 @@ public class EipFragment extends Fragment implements Observer { private void setDisconnectedUI(){ hideProgressBar(); adjustSwitch(); - String last_log_message = eip_status.getLastLogMessage(dashboard.getApplicationContext()); - if((last_log_message.contains("error") || last_log_message.contains("ERROR")) + if(eip_status.errorInLast(5, dashboard.getApplicationContext()) && !status_message.getText().toString().equalsIgnoreCase(dashboard.getString(R.string.eip_state_not_connected))){ dashboard.showLog(); } - status_message.setText(dashboard.getString(R.string.eip_state_not_connected)); } private void adjustSwitch() { 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 14158696..adbbaef3 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java @@ -136,9 +136,19 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { EipStatus.level = level; } - public String getLastLogMessage(Context context) { - VpnStatus.LogItem[] log = VpnStatus.getlogbuffer(); - return log[log.length-1].getString(context); + public boolean errorInLast(int lines, Context context) { + boolean result = false; + String[] error_keywords = {"error", "ERROR", "fatal", "FATAL"}; + + VpnStatus.LogItem[] log = VpnStatus.getlogbuffer(); + String message = ""; + for (int i = 0; i < lines; i++) { + message = log[log.length-1].getString(context); + for(int j = 0; j < error_keywords.length; j++) + if(message.contains(error_keywords[i])) + result = true; + } + return result; } @Override -- cgit v1.2.3 From 7c17d2654d9b6f32580e71e22ea08fca1893aa93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Mon, 23 Mar 2015 14:45:07 +0100 Subject: Ammend. --- .../java/se/leap/bitmaskclient/EipFragment.java | 7 ++-- .../main/java/se/leap/bitmaskclient/eip/EIP.java | 8 +++- .../java/se/leap/bitmaskclient/eip/EipStatus.java | 9 ++-- .../se/leap/bitmaskclient/eip/VoidVpnLauncher.java | 15 +++++-- .../se/leap/bitmaskclient/eip/VoidVpnService.java | 49 ++++++++-------------- .../leap/bitmaskclient/eip/VpnConfigGenerator.java | 3 +- 6 files changed, 46 insertions(+), 45 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index ed507de4..43e0c2aa 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -197,9 +197,9 @@ public class EipFragment extends Fragment implements Observer { eipCommand(Constants.ACTION_START_EIP); } - private void stop() { - if(eip_status.isConnecting()) - VoidVpnService.stop(); + public void stop() { + Intent intent = new Intent(dashboard.getApplicationContext(), VoidVpnService.class); + dashboard.stopService(intent); disconnect(); } @@ -296,6 +296,7 @@ public class EipFragment extends Fragment implements Observer { && !status_message.getText().toString().equalsIgnoreCase(dashboard.getString(R.string.eip_state_not_connected))){ dashboard.showLog(); } + status_message.setText(dashboard.getString(R.string.eip_state_not_connected)); } private void adjustSwitch() { 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 3b72a486..5cac4588 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -126,8 +126,12 @@ public final class EIP extends IntentService { private void stopEIP() { EipStatus eip_status = EipStatus.getInstance(); int result_code = Activity.RESULT_CANCELED; - if(eip_status.isConnected() || eip_status.isConnecting()) - result_code = Activity.RESULT_OK; + if(eip_status.isConnected() || eip_status.isConnecting()) { + Intent intent = new Intent(); + intent.setComponent(VoidVpnLauncher.getService()); + stopService(intent); + result_code = Activity.RESULT_OK; + } tellToReceiver(ACTION_STOP_EIP, result_code); } 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 adbbaef3..3b9dad1c 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java @@ -22,6 +22,7 @@ import android.content.*; import java.util.*; import de.blinkt.openvpn.core.*; +import se.leap.bitmaskclient.EipFragment; public class EipStatus extends Observable implements VpnStatus.StateListener { public static String TAG = EipStatus.class.getSimpleName(); @@ -48,8 +49,6 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { updateStatus(state, logmessage, localizedResId, level); if(isConnected() || isDisconnected()) { setConnectedOrDisconnected(); - if(isDisconnected()) - VoidVpnService.stop(); } else if(isConnecting()) setConnecting(); Log.d(TAG, "update state with level " + level); @@ -142,10 +141,10 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { VpnStatus.LogItem[] log = VpnStatus.getlogbuffer(); String message = ""; - for (int i = 0; i < lines; i++) { - message = log[log.length-1].getString(context); + for (int i = 1; i <= lines && i < log.length; i++) { + message = log[log.length-i].getString(context); for(int j = 0; j < error_keywords.length; j++) - if(message.contains(error_keywords[i])) + if(message.contains(error_keywords[j])) result = true; } return result; diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java index d79d8003..e7ce74d4 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java @@ -1,6 +1,7 @@ package se.leap.bitmaskclient.eip; import android.app.Activity; +import android.content.ComponentName; import android.content.Intent; import android.net.VpnService; import android.os.Bundle; @@ -9,6 +10,8 @@ public class VoidVpnLauncher extends Activity { private static final int VPN_USER_PERMISSION = 71; + private static ComponentName service; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -27,11 +30,17 @@ public class VoidVpnLauncher extends Activity { protected void onActivityResult(int requestCode, int resultCode, Intent data){ if(requestCode == VPN_USER_PERMISSION) { if(resultCode == RESULT_OK) { - Intent void_vpn_service = new Intent(getApplicationContext(), VoidVpnService.class); - void_vpn_service.setAction(Constants.START_BLOCKING_VPN_PROFILE); - startService(void_vpn_service); + Intent intent = new Intent(getApplicationContext(), VoidVpnService.class); + intent.setAction(Constants.START_BLOCKING_VPN_PROFILE); + android.util.Log.d(VoidVpnLauncher.class.getSimpleName(), "VoidVpnService starting from Launcher"); + + service = startService(intent); } } finish(); } + + public static ComponentName getService() { + return service; + } } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java index 0a707ab1..367a9f1d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java @@ -13,42 +13,29 @@ public class VoidVpnService extends VpnService { @Override public int onStartCommand(Intent intent, int flags, int startId) { - String action = intent != null ? intent.getAction() : ""; - if (action == Constants.START_BLOCKING_VPN_PROFILE) { - new Thread(new Runnable() { - public void run() { - Builder builder = new Builder(); - builder.setSession("Blocking until running"); - builder.addAddress("10.42.0.8",16); - builder.addRoute("0.0.0.0", 1); - builder.addRoute("192.168.1.0", 24); - builder.addDnsServer("10.42.0.1"); - try { - fd = builder.establish(); - } catch (Exception e) { - e.printStackTrace(); - } - android.util.Log.d(TAG, "VoidVpnService set up"); - } - }).run(); - } - return 0; - } + String action = intent != null ? intent.getAction() : ""; + if (action == Constants.START_BLOCKING_VPN_PROFILE) { + start(); + } - @Override - public void onRevoke() { - super.onRevoke(); + return 0; } - public static boolean stop() { + protected void start() { + Builder builder = new Builder(); + builder.setSession("Blocking until running"); + builder.addAddress("10.42.0.8", 16); + builder.addRoute("0.0.0.0", 1); + builder.addRoute("192.168.1.0", 24); + builder.addDnsServer("10.42.0.1"); try { - if(fd != null) - fd.close(); - return true; - } catch (IOException | NullPointerException e) { - android.util.Log.d(TAG, "VoidVpnService didn't stop"); + fd = builder.establish(); + if (fd != null) + android.util.Log.d(TAG, "VoidVpnService set up"); + else + android.util.Log.d(TAG, "VoidVpnService failed to set up"); + } catch (Exception e) { e.printStackTrace(); - return false; } } } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java index 5f5dcabd..c29cc180 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java @@ -148,6 +148,7 @@ public class VpnConfigGenerator { + new_line + "persist-tun" + new_line - + "auth-retry nointeract"; + + "auth-retry nointeract" + + "fragment 1400"; } } -- cgit v1.2.3 From ea748b512ecb4eaff6ad7e212d9356a1caf7ed98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Mon, 23 Mar 2015 14:48:12 +0100 Subject: 0.9.3RC2 --- app/src/main/AndroidManifest.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2bd630ee..07315bdd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,8 +17,8 @@ + android:versionCode="118" + android:versionName="0.9.3RC2" > -- cgit v1.2.3 From 92a48eda9956193cfb143875a849ff979e16e4a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Tue, 24 Mar 2015 12:53:51 +0100 Subject: Revert "Ammend." This reverts commit 7c17d2654d9b6f32580e71e22ea08fca1893aa93. --- .../java/se/leap/bitmaskclient/EipFragment.java | 7 ++-- .../main/java/se/leap/bitmaskclient/eip/EIP.java | 8 +--- .../java/se/leap/bitmaskclient/eip/EipStatus.java | 9 ++-- .../se/leap/bitmaskclient/eip/VoidVpnLauncher.java | 15 ++----- .../se/leap/bitmaskclient/eip/VoidVpnService.java | 49 ++++++++++++++-------- .../leap/bitmaskclient/eip/VpnConfigGenerator.java | 3 +- 6 files changed, 45 insertions(+), 46 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index 43e0c2aa..ed507de4 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -197,9 +197,9 @@ public class EipFragment extends Fragment implements Observer { eipCommand(Constants.ACTION_START_EIP); } - public void stop() { - Intent intent = new Intent(dashboard.getApplicationContext(), VoidVpnService.class); - dashboard.stopService(intent); + private void stop() { + if(eip_status.isConnecting()) + VoidVpnService.stop(); disconnect(); } @@ -296,7 +296,6 @@ public class EipFragment extends Fragment implements Observer { && !status_message.getText().toString().equalsIgnoreCase(dashboard.getString(R.string.eip_state_not_connected))){ dashboard.showLog(); } - status_message.setText(dashboard.getString(R.string.eip_state_not_connected)); } private void adjustSwitch() { 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 5cac4588..3b72a486 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -126,12 +126,8 @@ public final class EIP extends IntentService { private void stopEIP() { EipStatus eip_status = EipStatus.getInstance(); int result_code = Activity.RESULT_CANCELED; - if(eip_status.isConnected() || eip_status.isConnecting()) { - Intent intent = new Intent(); - intent.setComponent(VoidVpnLauncher.getService()); - stopService(intent); - result_code = Activity.RESULT_OK; - } + if(eip_status.isConnected() || eip_status.isConnecting()) + result_code = Activity.RESULT_OK; tellToReceiver(ACTION_STOP_EIP, result_code); } 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 3b9dad1c..adbbaef3 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java @@ -22,7 +22,6 @@ import android.content.*; import java.util.*; import de.blinkt.openvpn.core.*; -import se.leap.bitmaskclient.EipFragment; public class EipStatus extends Observable implements VpnStatus.StateListener { public static String TAG = EipStatus.class.getSimpleName(); @@ -49,6 +48,8 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { updateStatus(state, logmessage, localizedResId, level); if(isConnected() || isDisconnected()) { setConnectedOrDisconnected(); + if(isDisconnected()) + VoidVpnService.stop(); } else if(isConnecting()) setConnecting(); Log.d(TAG, "update state with level " + level); @@ -141,10 +142,10 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { VpnStatus.LogItem[] log = VpnStatus.getlogbuffer(); String message = ""; - for (int i = 1; i <= lines && i < log.length; i++) { - message = log[log.length-i].getString(context); + for (int i = 0; i < lines; i++) { + message = log[log.length-1].getString(context); for(int j = 0; j < error_keywords.length; j++) - if(message.contains(error_keywords[j])) + if(message.contains(error_keywords[i])) result = true; } return result; diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java index e7ce74d4..d79d8003 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java @@ -1,7 +1,6 @@ package se.leap.bitmaskclient.eip; import android.app.Activity; -import android.content.ComponentName; import android.content.Intent; import android.net.VpnService; import android.os.Bundle; @@ -10,8 +9,6 @@ public class VoidVpnLauncher extends Activity { private static final int VPN_USER_PERMISSION = 71; - private static ComponentName service; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -30,17 +27,11 @@ public class VoidVpnLauncher extends Activity { protected void onActivityResult(int requestCode, int resultCode, Intent data){ if(requestCode == VPN_USER_PERMISSION) { if(resultCode == RESULT_OK) { - Intent intent = new Intent(getApplicationContext(), VoidVpnService.class); - intent.setAction(Constants.START_BLOCKING_VPN_PROFILE); - android.util.Log.d(VoidVpnLauncher.class.getSimpleName(), "VoidVpnService starting from Launcher"); - - service = startService(intent); + Intent void_vpn_service = new Intent(getApplicationContext(), VoidVpnService.class); + void_vpn_service.setAction(Constants.START_BLOCKING_VPN_PROFILE); + startService(void_vpn_service); } } finish(); } - - public static ComponentName getService() { - return service; - } } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java index 367a9f1d..0a707ab1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java @@ -13,29 +13,42 @@ public class VoidVpnService extends VpnService { @Override public int onStartCommand(Intent intent, int flags, int startId) { - String action = intent != null ? intent.getAction() : ""; - if (action == Constants.START_BLOCKING_VPN_PROFILE) { - start(); - } + String action = intent != null ? intent.getAction() : ""; + if (action == Constants.START_BLOCKING_VPN_PROFILE) { + new Thread(new Runnable() { + public void run() { + Builder builder = new Builder(); + builder.setSession("Blocking until running"); + builder.addAddress("10.42.0.8",16); + builder.addRoute("0.0.0.0", 1); + builder.addRoute("192.168.1.0", 24); + builder.addDnsServer("10.42.0.1"); + try { + fd = builder.establish(); + } catch (Exception e) { + e.printStackTrace(); + } + android.util.Log.d(TAG, "VoidVpnService set up"); + } + }).run(); + } + return 0; + } - return 0; + @Override + public void onRevoke() { + super.onRevoke(); } - protected void start() { - Builder builder = new Builder(); - builder.setSession("Blocking until running"); - builder.addAddress("10.42.0.8", 16); - builder.addRoute("0.0.0.0", 1); - builder.addRoute("192.168.1.0", 24); - builder.addDnsServer("10.42.0.1"); + public static boolean stop() { try { - fd = builder.establish(); - if (fd != null) - android.util.Log.d(TAG, "VoidVpnService set up"); - else - android.util.Log.d(TAG, "VoidVpnService failed to set up"); - } catch (Exception e) { + if(fd != null) + fd.close(); + return true; + } catch (IOException | NullPointerException e) { + android.util.Log.d(TAG, "VoidVpnService didn't stop"); e.printStackTrace(); + return false; } } } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java index c29cc180..5f5dcabd 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java @@ -148,7 +148,6 @@ public class VpnConfigGenerator { + new_line + "persist-tun" + new_line - + "auth-retry nointeract" - + "fragment 1400"; + + "auth-retry nointeract"; } } -- cgit v1.2.3 From 4d1ee9cd65d10161d3e818e99cbd06b93e211277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Tue, 24 Mar 2015 12:58:18 +0100 Subject: Error in last lines fixed. --- app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java | 4 ++-- app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'app/src/main') 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 adbbaef3..f9ddc0d2 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java @@ -143,9 +143,9 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { VpnStatus.LogItem[] log = VpnStatus.getlogbuffer(); String message = ""; for (int i = 0; i < lines; i++) { - message = log[log.length-1].getString(context); + message = log[log.length-i].getString(context); for(int j = 0; j < error_keywords.length; j++) - if(message.contains(error_keywords[i])) + if(message.contains(error_keywords[j])) result = true; } return result; diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java index 5f5dcabd..25c85585 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java @@ -148,6 +148,6 @@ public class VpnConfigGenerator { + new_line + "persist-tun" + new_line - + "auth-retry nointeract"; + + "auth-retry nointeract remove"; } } -- cgit v1.2.3 From 7dba6442fb80cb55fe66f3d9510f71b80cb9e2b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Tue, 24 Mar 2015 13:06:55 +0100 Subject: Show log if an error is reported in last 5 log messages. --- app/src/main/java/se/leap/bitmaskclient/EipFragment.java | 1 + app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java | 2 +- app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index ed507de4..8b532e24 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -296,6 +296,7 @@ public class EipFragment extends Fragment implements Observer { && !status_message.getText().toString().equalsIgnoreCase(dashboard.getString(R.string.eip_state_not_connected))){ dashboard.showLog(); } + status_message.setText(dashboard.getString(R.string.eip_state_not_connected)); } private void adjustSwitch() { 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 f9ddc0d2..17e290b8 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java @@ -142,7 +142,7 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { VpnStatus.LogItem[] log = VpnStatus.getlogbuffer(); String message = ""; - for (int i = 0; i < lines; i++) { + for (int i = 1; i <= lines && log.length > i; i++) { message = log[log.length-i].getString(context); for(int j = 0; j < error_keywords.length; j++) if(message.contains(error_keywords[j])) diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java index 25c85585..5af8b8f1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java @@ -148,6 +148,6 @@ public class VpnConfigGenerator { + new_line + "persist-tun" + new_line - + "auth-retry nointeract remove"; + + "auth-retry nointeract" } } -- cgit v1.2.3 From 4d3e6e733d4f7f0c310642da2c43a35057018bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Tue, 24 Mar 2015 13:12:32 +0100 Subject: Silly typo. --- app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java index 5af8b8f1..5f5dcabd 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java @@ -148,6 +148,6 @@ public class VpnConfigGenerator { + new_line + "persist-tun" + new_line - + "auth-retry nointeract" + + "auth-retry nointeract"; } } -- cgit v1.2.3 From e4eeef39a6219d2abba26af5a588bc51c4f5af5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Tue, 24 Mar 2015 17:40:50 +0100 Subject: 9 out of 10 times, in a row, void vpn is closed. --- .../java/se/leap/bitmaskclient/EipFragment.java | 1 + .../java/se/leap/bitmaskclient/eip/EipStatus.java | 2 -- .../se/leap/bitmaskclient/eip/VoidVpnService.java | 32 ++++++++++++++-------- 3 files changed, 22 insertions(+), 13 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index 8b532e24..ac869b18 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -295,6 +295,7 @@ public class EipFragment extends Fragment implements Observer { if(eip_status.errorInLast(5, dashboard.getApplicationContext()) && !status_message.getText().toString().equalsIgnoreCase(dashboard.getString(R.string.eip_state_not_connected))){ dashboard.showLog(); + VoidVpnService.stop(); } status_message.setText(dashboard.getString(R.string.eip_state_not_connected)); } 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 17e290b8..d1ed0d27 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java @@ -48,8 +48,6 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { updateStatus(state, logmessage, localizedResId, level); if(isConnected() || isDisconnected()) { setConnectedOrDisconnected(); - if(isDisconnected()) - VoidVpnService.stop(); } else if(isConnecting()) setConnecting(); Log.d(TAG, "update state with level " + level); diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java index 0a707ab1..f87f35e2 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java @@ -11,12 +11,14 @@ public class VoidVpnService extends VpnService { static final String TAG = VoidVpnService.class.getSimpleName(); static ParcelFileDescriptor fd; + static Thread thread; + @Override public int onStartCommand(Intent intent, int flags, int startId) { String action = intent != null ? intent.getAction() : ""; if (action == Constants.START_BLOCKING_VPN_PROFILE) { - new Thread(new Runnable() { - public void run() { + thread = new Thread(new Runnable() { + public void run() { Builder builder = new Builder(); builder.setSession("Blocking until running"); builder.addAddress("10.42.0.8",16); @@ -25,30 +27,38 @@ public class VoidVpnService extends VpnService { builder.addDnsServer("10.42.0.1"); try { fd = builder.establish(); + } catch (Exception e) { e.printStackTrace(); } - android.util.Log.d(TAG, "VoidVpnService set up"); + android.util.Log.d(TAG, "VoidVpnService set up: fd = " + fd.toString()); } - }).run(); - } + }); + thread.run(); + } return 0; } @Override public void onRevoke() { super.onRevoke(); + closeFd(); + } + + public static void stop() { + if(thread != null) + thread.interrupt(); + closeFd(); } - public static boolean stop() { + private static void closeFd() { try { - if(fd != null) + if(fd != null) { + android.util.Log.d(TAG, "VoidVpnService closing fd = " + fd.toString()); fd.close(); - return true; - } catch (IOException | NullPointerException e) { - android.util.Log.d(TAG, "VoidVpnService didn't stop"); + } + } catch (IOException e) { e.printStackTrace(); - return false; } } } -- cgit v1.2.3 From 1e300837b2b2188bc682af7b1dfadfa16942725b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Tue, 24 Mar 2015 17:57:20 +0100 Subject: Remove unused imports. Using intellij tool. --- .../main/java/se/leap/bitmaskclient/Dashboard.java | 40 +++++++++++++++------- .../java/se/leap/bitmaskclient/EipFragment.java | 37 ++++++++++++++------ .../main/java/se/leap/bitmaskclient/Provider.java | 4 --- .../se/leap/bitmaskclient/ProviderListAdapter.java | 5 --- .../se/leap/bitmaskclient/ProviderManager.java | 1 - .../se/leap/bitmaskclient/ProviderRenderer.java | 3 -- .../bitmaskclient/ProviderRendererBuilder.java | 6 ---- .../se/leap/bitmaskclient/UserSessionStatus.java | 4 +-- .../main/java/se/leap/bitmaskclient/eip/EIP.java | 35 +++++++++++++------ .../java/se/leap/bitmaskclient/eip/EipStatus.java | 8 ++--- .../java/se/leap/bitmaskclient/eip/Gateway.java | 3 -- .../se/leap/bitmaskclient/eip/GatewaysManager.java | 26 +++++++++----- .../leap/bitmaskclient/eip/VpnConfigGenerator.java | 3 -- 13 files changed, 100 insertions(+), 75 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index 7c5e5421..bfa0e123 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -17,22 +17,38 @@ package se.leap.bitmaskclient; import android.annotation.SuppressLint; -import android.app.*; -import android.content.*; +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.content.pm.PackageManager.NameNotFoundException; -import android.os.*; +import android.os.Bundle; +import android.os.Handler; import android.util.Log; -import android.view.*; -import android.widget.*; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.ProgressBar; +import android.widget.TextView; import org.jetbrains.annotations.NotNull; -import org.json.*; -import java.net.*; -import java.util.*; - -import butterknife.*; -import de.blinkt.openvpn.activities.*; -import se.leap.bitmaskclient.eip.*; +import org.json.JSONException; +import org.json.JSONObject; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Observable; +import java.util.Observer; + +import butterknife.ButterKnife; +import butterknife.InjectView; +import de.blinkt.openvpn.activities.LogWindow; +import se.leap.bitmaskclient.eip.Constants; +import se.leap.bitmaskclient.eip.EIP; +import se.leap.bitmaskclient.eip.EipStatus; /** * The main user facing Activity of Bitmask Android, consisting of status, controls, diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index ac869b18..153d473b 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -16,20 +16,35 @@ */ package se.leap.bitmaskclient; -import android.app.*; -import android.content.*; -import android.os.*; -import android.util.*; -import android.view.*; -import android.widget.*; +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 android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ProgressBar; +import android.widget.Switch; +import android.widget.TextView; import org.jetbrains.annotations.NotNull; -import java.util.*; - -import butterknife.*; -import de.blinkt.openvpn.activities.*; -import se.leap.bitmaskclient.eip.*; +import java.util.Observable; +import java.util.Observer; + +import butterknife.ButterKnife; +import butterknife.InjectView; +import butterknife.OnCheckedChanged; +import de.blinkt.openvpn.activities.DisconnectVPN; +import se.leap.bitmaskclient.eip.Constants; +import se.leap.bitmaskclient.eip.EIP; +import se.leap.bitmaskclient.eip.EipStatus; +import se.leap.bitmaskclient.eip.VoidVpnService; public class EipFragment extends Fragment implements Observer { diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java index ef25c5d2..f2587968 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Provider.java +++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java @@ -16,9 +16,6 @@ */ package se.leap.bitmaskclient; -import android.app.Activity; -import android.content.Context; -import android.content.SharedPreferences; import android.os.Parcel; import android.os.Parcelable; @@ -27,7 +24,6 @@ import org.json.JSONException; import org.json.JSONObject; import java.io.File; -import java.io.Serializable; import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java b/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java index c63e2edb..e7a6a536 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java @@ -1,18 +1,13 @@ package se.leap.bitmaskclient; -import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.TwoLineListItem; import com.pedrogomez.renderers.AdapteeCollection; import com.pedrogomez.renderers.RendererAdapter; import com.pedrogomez.renderers.RendererBuilder; -import java.util.Collection; -import java.util.List; import java.util.Set; public class ProviderListAdapter extends RendererAdapter { diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java b/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java index 69bd7c1e..e0dd0989 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java @@ -10,7 +10,6 @@ import org.json.JSONObject; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java b/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java index 6e194e84..60ef9791 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java @@ -4,15 +4,12 @@ import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; import android.widget.TextView; import com.pedrogomez.renderers.Renderer; import butterknife.ButterKnife; import butterknife.InjectView; -import butterknife.OnItemClick; -import butterknife.OnItemSelected; /** * Created by parmegv on 4/12/14. diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderRendererBuilder.java b/app/src/main/java/se/leap/bitmaskclient/ProviderRendererBuilder.java index 7366e68e..4a4f3901 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderRendererBuilder.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderRendererBuilder.java @@ -1,15 +1,9 @@ package se.leap.bitmaskclient; -import android.content.Context; - import com.pedrogomez.renderers.Renderer; import com.pedrogomez.renderers.RendererBuilder; import java.util.Collection; -import java.util.LinkedList; -import java.util.List; - -import javax.inject.Inject; /** * Created by parmegv on 4/12/14. diff --git a/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java b/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java index db432a82..2779efd0 100644 --- a/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java @@ -16,9 +16,7 @@ */ package se.leap.bitmaskclient; -import android.os.*; - -import java.util.*; +import java.util.Observable; public class UserSessionStatus extends Observable { public static String TAG = UserSessionStatus.class.getSimpleName(); 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 3b72a486..58cd2cee 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -16,17 +16,30 @@ */ package se.leap.bitmaskclient.eip; -import android.app.*; -import android.content.*; -import android.os.*; -import android.util.Log; - -import org.json.*; - -import de.blinkt.openvpn.*; -import se.leap.bitmaskclient.*; - -import static se.leap.bitmaskclient.eip.Constants.*; +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; + +import org.json.JSONException; +import org.json.JSONObject; + +import de.blinkt.openvpn.LaunchVPN; +import se.leap.bitmaskclient.Dashboard; +import se.leap.bitmaskclient.EipFragment; + +import static se.leap.bitmaskclient.eip.Constants.ACTION_CHECK_CERT_VALIDITY; +import static se.leap.bitmaskclient.eip.Constants.ACTION_IS_EIP_RUNNING; +import static se.leap.bitmaskclient.eip.Constants.ACTION_START_EIP; +import static se.leap.bitmaskclient.eip.Constants.ACTION_STOP_EIP; +import static se.leap.bitmaskclient.eip.Constants.ACTION_UPDATE_EIP_SERVICE; +import static se.leap.bitmaskclient.eip.Constants.CERTIFICATE; +import static se.leap.bitmaskclient.eip.Constants.KEY; +import static se.leap.bitmaskclient.eip.Constants.RECEIVER_TAG; +import static se.leap.bitmaskclient.eip.Constants.REQUEST_TAG; /** * EIP is the abstract base class for interacting with and managing the Encrypted 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 d1ed0d27..902ef8da 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java @@ -16,12 +16,12 @@ */ package se.leap.bitmaskclient.eip; -import android.util.*; -import android.content.*; +import android.content.Context; +import android.util.Log; -import java.util.*; +import java.util.Observable; -import de.blinkt.openvpn.core.*; +import de.blinkt.openvpn.core.VpnStatus; public class EipStatus extends Observable implements VpnStatus.StateListener { public static String TAG = EipStatus.class.getSimpleName(); diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java index 0d8a2f7b..bc978684 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java @@ -16,8 +16,6 @@ */ package se.leap.bitmaskclient.eip; -import android.app.Activity; -import android.content.SharedPreferences; import android.util.Log; import com.google.gson.Gson; @@ -30,7 +28,6 @@ import java.io.StringReader; import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.core.ConfigParser; -import se.leap.bitmaskclient.Dashboard; /** * Gateway provides objects defining gateways and their metadata. diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java index 401cd701..d79a599b 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java @@ -16,20 +16,28 @@ */ package se.leap.bitmaskclient.eip; -import android.content.*; +import android.content.Context; +import android.content.SharedPreferences; import android.util.Log; -import com.google.gson.*; -import com.google.gson.reflect.*; +import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; +import com.google.gson.reflect.TypeToken; -import org.json.*; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; -import java.lang.reflect.*; -import java.util.*; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; -import de.blinkt.openvpn.*; -import de.blinkt.openvpn.core.*; -import se.leap.bitmaskclient.*; +import de.blinkt.openvpn.VpnProfile; +import de.blinkt.openvpn.core.Connection; +import de.blinkt.openvpn.core.ProfileManager; +import se.leap.bitmaskclient.Provider; /** * @author parmegv diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java index 5f5dcabd..1fe7df9f 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java @@ -16,9 +16,6 @@ */ package se.leap.bitmaskclient.eip; -import android.content.SharedPreferences; -import android.util.Log; - import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -- cgit v1.2.3 From 26efe3b9b2e1cbfe87f88239e1a3c9264ae1e1db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Tue, 24 Mar 2015 17:59:08 +0100 Subject: Revert "Remove unused imports." This reverts commit 1e300837b2b2188bc682af7b1dfadfa16942725b. I don't want big lists of imports, I like wildcards. --- .../main/java/se/leap/bitmaskclient/Dashboard.java | 40 +++++++--------------- .../java/se/leap/bitmaskclient/EipFragment.java | 37 ++++++-------------- .../main/java/se/leap/bitmaskclient/Provider.java | 4 +++ .../se/leap/bitmaskclient/ProviderListAdapter.java | 5 +++ .../se/leap/bitmaskclient/ProviderManager.java | 1 + .../se/leap/bitmaskclient/ProviderRenderer.java | 3 ++ .../bitmaskclient/ProviderRendererBuilder.java | 6 ++++ .../se/leap/bitmaskclient/UserSessionStatus.java | 4 ++- .../main/java/se/leap/bitmaskclient/eip/EIP.java | 35 ++++++------------- .../java/se/leap/bitmaskclient/eip/EipStatus.java | 8 ++--- .../java/se/leap/bitmaskclient/eip/Gateway.java | 3 ++ .../se/leap/bitmaskclient/eip/GatewaysManager.java | 26 +++++--------- .../leap/bitmaskclient/eip/VpnConfigGenerator.java | 3 ++ 13 files changed, 75 insertions(+), 100 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index bfa0e123..7c5e5421 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -17,38 +17,22 @@ package se.leap.bitmaskclient; import android.annotation.SuppressLint; -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.*; import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; -import android.widget.ProgressBar; -import android.widget.TextView; +import android.view.*; +import android.widget.*; import org.jetbrains.annotations.NotNull; -import org.json.JSONException; -import org.json.JSONObject; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Observable; -import java.util.Observer; - -import butterknife.ButterKnife; -import butterknife.InjectView; -import de.blinkt.openvpn.activities.LogWindow; -import se.leap.bitmaskclient.eip.Constants; -import se.leap.bitmaskclient.eip.EIP; -import se.leap.bitmaskclient.eip.EipStatus; +import org.json.*; +import java.net.*; +import java.util.*; + +import butterknife.*; +import de.blinkt.openvpn.activities.*; +import se.leap.bitmaskclient.eip.*; /** * The main user facing Activity of Bitmask Android, consisting of status, controls, diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index 153d473b..ac869b18 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -16,35 +16,20 @@ */ package se.leap.bitmaskclient; -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 android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ProgressBar; -import android.widget.Switch; -import android.widget.TextView; +import android.app.*; +import android.content.*; +import android.os.*; +import android.util.*; +import android.view.*; +import android.widget.*; import org.jetbrains.annotations.NotNull; -import java.util.Observable; -import java.util.Observer; - -import butterknife.ButterKnife; -import butterknife.InjectView; -import butterknife.OnCheckedChanged; -import de.blinkt.openvpn.activities.DisconnectVPN; -import se.leap.bitmaskclient.eip.Constants; -import se.leap.bitmaskclient.eip.EIP; -import se.leap.bitmaskclient.eip.EipStatus; -import se.leap.bitmaskclient.eip.VoidVpnService; +import java.util.*; + +import butterknife.*; +import de.blinkt.openvpn.activities.*; +import se.leap.bitmaskclient.eip.*; public class EipFragment extends Fragment implements Observer { diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java index f2587968..ef25c5d2 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Provider.java +++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java @@ -16,6 +16,9 @@ */ package se.leap.bitmaskclient; +import android.app.Activity; +import android.content.Context; +import android.content.SharedPreferences; import android.os.Parcel; import android.os.Parcelable; @@ -24,6 +27,7 @@ import org.json.JSONException; import org.json.JSONObject; import java.io.File; +import java.io.Serializable; import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java b/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java index e7a6a536..c63e2edb 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java @@ -1,13 +1,18 @@ package se.leap.bitmaskclient; +import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TwoLineListItem; import com.pedrogomez.renderers.AdapteeCollection; import com.pedrogomez.renderers.RendererAdapter; import com.pedrogomez.renderers.RendererBuilder; +import java.util.Collection; +import java.util.List; import java.util.Set; public class ProviderListAdapter extends RendererAdapter { diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java b/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java index e0dd0989..69bd7c1e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java @@ -10,6 +10,7 @@ import org.json.JSONObject; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java b/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java index 60ef9791..6e194e84 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java @@ -4,12 +4,15 @@ import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.TextView; import com.pedrogomez.renderers.Renderer; import butterknife.ButterKnife; import butterknife.InjectView; +import butterknife.OnItemClick; +import butterknife.OnItemSelected; /** * Created by parmegv on 4/12/14. diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderRendererBuilder.java b/app/src/main/java/se/leap/bitmaskclient/ProviderRendererBuilder.java index 4a4f3901..7366e68e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderRendererBuilder.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderRendererBuilder.java @@ -1,9 +1,15 @@ package se.leap.bitmaskclient; +import android.content.Context; + import com.pedrogomez.renderers.Renderer; import com.pedrogomez.renderers.RendererBuilder; import java.util.Collection; +import java.util.LinkedList; +import java.util.List; + +import javax.inject.Inject; /** * Created by parmegv on 4/12/14. diff --git a/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java b/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java index 2779efd0..db432a82 100644 --- a/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java @@ -16,7 +16,9 @@ */ package se.leap.bitmaskclient; -import java.util.Observable; +import android.os.*; + +import java.util.*; public class UserSessionStatus extends Observable { public static String TAG = UserSessionStatus.class.getSimpleName(); 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 58cd2cee..3b72a486 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -16,30 +16,17 @@ */ package se.leap.bitmaskclient.eip; -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; - -import org.json.JSONException; -import org.json.JSONObject; - -import de.blinkt.openvpn.LaunchVPN; -import se.leap.bitmaskclient.Dashboard; -import se.leap.bitmaskclient.EipFragment; - -import static se.leap.bitmaskclient.eip.Constants.ACTION_CHECK_CERT_VALIDITY; -import static se.leap.bitmaskclient.eip.Constants.ACTION_IS_EIP_RUNNING; -import static se.leap.bitmaskclient.eip.Constants.ACTION_START_EIP; -import static se.leap.bitmaskclient.eip.Constants.ACTION_STOP_EIP; -import static se.leap.bitmaskclient.eip.Constants.ACTION_UPDATE_EIP_SERVICE; -import static se.leap.bitmaskclient.eip.Constants.CERTIFICATE; -import static se.leap.bitmaskclient.eip.Constants.KEY; -import static se.leap.bitmaskclient.eip.Constants.RECEIVER_TAG; -import static se.leap.bitmaskclient.eip.Constants.REQUEST_TAG; +import android.app.*; +import android.content.*; +import android.os.*; +import android.util.Log; + +import org.json.*; + +import de.blinkt.openvpn.*; +import se.leap.bitmaskclient.*; + +import static se.leap.bitmaskclient.eip.Constants.*; /** * EIP is the abstract base class for interacting with and managing the Encrypted 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 902ef8da..d1ed0d27 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java @@ -16,12 +16,12 @@ */ package se.leap.bitmaskclient.eip; -import android.content.Context; -import android.util.Log; +import android.util.*; +import android.content.*; -import java.util.Observable; +import java.util.*; -import de.blinkt.openvpn.core.VpnStatus; +import de.blinkt.openvpn.core.*; public class EipStatus extends Observable implements VpnStatus.StateListener { public static String TAG = EipStatus.class.getSimpleName(); diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java index bc978684..0d8a2f7b 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java @@ -16,6 +16,8 @@ */ package se.leap.bitmaskclient.eip; +import android.app.Activity; +import android.content.SharedPreferences; import android.util.Log; import com.google.gson.Gson; @@ -28,6 +30,7 @@ import java.io.StringReader; import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.core.ConfigParser; +import se.leap.bitmaskclient.Dashboard; /** * Gateway provides objects defining gateways and their metadata. diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java index d79a599b..401cd701 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java @@ -16,28 +16,20 @@ */ package se.leap.bitmaskclient.eip; -import android.content.Context; -import android.content.SharedPreferences; +import android.content.*; import android.util.Log; -import com.google.gson.Gson; -import com.google.gson.JsonSyntaxException; -import com.google.gson.reflect.TypeToken; +import com.google.gson.*; +import com.google.gson.reflect.*; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; +import org.json.*; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; +import java.lang.reflect.*; +import java.util.*; -import de.blinkt.openvpn.VpnProfile; -import de.blinkt.openvpn.core.Connection; -import de.blinkt.openvpn.core.ProfileManager; -import se.leap.bitmaskclient.Provider; +import de.blinkt.openvpn.*; +import de.blinkt.openvpn.core.*; +import se.leap.bitmaskclient.*; /** * @author parmegv diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java index 1fe7df9f..5f5dcabd 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java @@ -16,6 +16,9 @@ */ package se.leap.bitmaskclient.eip; +import android.content.SharedPreferences; +import android.util.Log; + import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -- cgit v1.2.3 From 9bb172e96cfd741e528e692118ee32fc609c6da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Tue, 24 Mar 2015 18:59:27 +0100 Subject: Cleaned imports, use wildcards when appropriate --- .../java/se/leap/bitmaskclient/AboutActivity.java | 10 ++++---- .../java/se/leap/bitmaskclient/ConfigHelper.java | 26 +++++++-------------- .../main/java/se/leap/bitmaskclient/Dashboard.java | 8 +++---- .../leap/bitmaskclient/DownloadFailedDialog.java | 9 +++----- .../java/se/leap/bitmaskclient/EipFragment.java | 2 +- .../bitmaskclient/FragmentManagerEnhanced.java | 4 +--- .../java/se/leap/bitmaskclient/LeapSRPSession.java | 14 +++++------ .../java/se/leap/bitmaskclient/OnBootReceiver.java | 9 +++----- .../main/java/se/leap/bitmaskclient/PRNGFixes.java | 21 ++++------------- .../main/java/se/leap/bitmaskclient/Provider.java | 23 ++++++------------ .../bitmaskclient/ProviderAPIResultReceiver.java | 4 +--- .../se/leap/bitmaskclient/ProviderListAdapter.java | 15 +++--------- .../se/leap/bitmaskclient/ProviderManager.java | 27 ++++++---------------- .../se/leap/bitmaskclient/ProviderRenderer.java | 20 ++++++---------- .../bitmaskclient/ProviderRendererBuilder.java | 12 ++-------- .../java/se/leap/bitmaskclient/SessionDialog.java | 19 ++++++--------- .../main/java/se/leap/bitmaskclient/eip/EIP.java | 1 - .../java/se/leap/bitmaskclient/eip/Gateway.java | 18 +++++---------- .../se/leap/bitmaskclient/eip/GatewaySelector.java | 6 +---- .../se/leap/bitmaskclient/eip/GatewaysManager.java | 2 +- .../se/leap/bitmaskclient/eip/VoidVpnLauncher.java | 8 +++---- .../se/leap/bitmaskclient/eip/VoidVpnService.java | 8 +++---- .../bitmaskclient/eip/VpnCertificateValidator.java | 10 ++++---- .../leap/bitmaskclient/eip/VpnConfigGenerator.java | 13 +++-------- 24 files changed, 93 insertions(+), 196 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/AboutActivity.java b/app/src/main/java/se/leap/bitmaskclient/AboutActivity.java index 6c4e517b..fa79d009 100644 --- a/app/src/main/java/se/leap/bitmaskclient/AboutActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/AboutActivity.java @@ -1,10 +1,10 @@ package se.leap.bitmaskclient; -import android.app.Activity; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager.NameNotFoundException; -import android.os.Bundle; -import android.widget.TextView; +import android.app.*; +import android.content.pm.*; +import android.content.pm.PackageManager.*; +import android.os.*; +import android.widget.*; public class AboutActivity extends Activity { diff --git a/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java b/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java index c0f0b0c3..b20cb1ae 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java @@ -16,26 +16,16 @@ */ package se.leap.bitmaskclient; -import android.util.Base64; +import android.util.*; -import org.json.JSONException; -import org.json.JSONObject; +import org.json.*; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.math.BigInteger; -import java.security.KeyFactory; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; -import java.security.interfaces.RSAPrivateKey; -import java.security.spec.InvalidKeySpecException; -import java.security.spec.PKCS8EncodedKeySpec; +import java.io.*; +import java.math.*; +import java.security.*; +import java.security.cert.*; +import java.security.interfaces.*; +import java.security.spec.*; /** * Stores constants, and implements auxiliary methods used across all LEAP Android classes. diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index 7c5e5421..7e2fa0b5 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -16,16 +16,16 @@ */ package se.leap.bitmaskclient; -import android.annotation.SuppressLint; +import android.annotation.*; import android.app.*; import android.content.*; -import android.content.pm.PackageManager.NameNotFoundException; +import android.content.pm.PackageManager.*; import android.os.*; -import android.util.Log; +import android.util.*; import android.view.*; import android.widget.*; -import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.*; import org.json.*; import java.net.*; import java.util.*; diff --git a/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java b/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java index a44253c6..b26205bb 100644 --- a/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java @@ -16,12 +16,9 @@ */ package se.leap.bitmaskclient; -import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; -import android.app.DialogFragment; -import android.content.DialogInterface; -import android.os.Bundle; +import android.app.*; +import android.content.*; +import android.os.*; /** * Implements a dialog to show why a download failed. diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index ac869b18..a5f3118c 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -23,7 +23,7 @@ import android.util.*; import android.view.*; import android.widget.*; -import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.*; import java.util.*; diff --git a/app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java b/app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java index 49af9274..9975b127 100644 --- a/app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java +++ b/app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java @@ -16,9 +16,7 @@ */ package se.leap.bitmaskclient; -import android.app.Fragment; -import android.app.FragmentManager; -import android.app.FragmentTransaction; +import android.app.*; public class FragmentManagerEnhanced { diff --git a/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java b/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java index 49c115ae..d3085fa3 100644 --- a/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java +++ b/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java @@ -17,14 +17,12 @@ package se.leap.bitmaskclient; -import org.jboss.security.srp.SRPParameters; - -import java.io.UnsupportedEncodingException; -import java.math.BigInteger; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.util.Arrays; +import org.jboss.security.srp.*; + +import java.io.*; +import java.math.*; +import java.security.*; +import java.util.*; /** * Implements all SRP algorithm logic. diff --git a/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java b/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java index 96b87085..806d5602 100644 --- a/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java +++ b/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java @@ -1,12 +1,9 @@ package se.leap.bitmaskclient; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.util.Log; +import android.content.*; +import android.util.*; -import se.leap.bitmaskclient.eip.Constants; +import se.leap.bitmaskclient.eip.*; public class OnBootReceiver extends BroadcastReceiver { diff --git a/app/src/main/java/se/leap/bitmaskclient/PRNGFixes.java b/app/src/main/java/se/leap/bitmaskclient/PRNGFixes.java index a046f01f..33d2971d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/PRNGFixes.java +++ b/app/src/main/java/se/leap/bitmaskclient/PRNGFixes.java @@ -12,24 +12,13 @@ package se.leap.bitmaskclient; * Source: http://android-developers.blogspot.de/2013/08/some-securerandom-thoughts.html */ -import android.os.Build; +import android.os.*; import android.os.Process; -import android.util.Log; - -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.security.NoSuchAlgorithmException; +import android.util.*; + +import java.io.*; +import java.security.*; import java.security.Provider; -import java.security.SecureRandom; -import java.security.SecureRandomSpi; -import java.security.Security; /** * Fixes for the output of the default PRNG having low entropy. diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java index ef25c5d2..f45eccdd 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Provider.java +++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java @@ -16,22 +16,13 @@ */ package se.leap.bitmaskclient; -import android.app.Activity; -import android.content.Context; -import android.content.SharedPreferences; -import android.os.Parcel; -import android.os.Parcelable; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.File; -import java.io.Serializable; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Arrays; -import java.util.Locale; +import android.os.*; + +import org.json.*; + +import java.io.*; +import java.net.*; +import java.util.*; /** * @author Sean Leonard diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderAPIResultReceiver.java b/app/src/main/java/se/leap/bitmaskclient/ProviderAPIResultReceiver.java index 7e4e95d3..4e6333c0 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderAPIResultReceiver.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderAPIResultReceiver.java @@ -16,9 +16,7 @@ */ package se.leap.bitmaskclient; -import android.os.Bundle; -import android.os.Handler; -import android.os.ResultReceiver; +import android.os.*; /** * Implements the ResultReceiver needed by Activities using ProviderAPI to receive the results of its operations. diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java b/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java index c63e2edb..f0103986 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java @@ -1,19 +1,10 @@ package se.leap.bitmaskclient; -import android.content.Context; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.TwoLineListItem; +import android.view.*; -import com.pedrogomez.renderers.AdapteeCollection; -import com.pedrogomez.renderers.RendererAdapter; -import com.pedrogomez.renderers.RendererBuilder; +import com.pedrogomez.renderers.*; -import java.util.Collection; -import java.util.List; -import java.util.Set; +import java.util.*; public class ProviderListAdapter extends RendererAdapter { private static boolean[] hidden = null; diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java b/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java index 69bd7c1e..56b38a29 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java @@ -1,25 +1,12 @@ package se.leap.bitmaskclient; -import android.content.res.AssetManager; - -import com.pedrogomez.renderers.AdapteeCollection; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; +import android.content.res.*; +import com.pedrogomez.renderers.*; +import org.json.*; + +import java.io.*; +import java.net.*; +import java.util.*; /** * Created by parmegv on 4/12/14. diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java b/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java index 6e194e84..4a5d0db1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java @@ -1,18 +1,12 @@ package se.leap.bitmaskclient; -import android.content.Context; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; - -import com.pedrogomez.renderers.Renderer; - -import butterknife.ButterKnife; -import butterknife.InjectView; -import butterknife.OnItemClick; -import butterknife.OnItemSelected; +import android.content.*; +import android.view.*; +import android.widget.*; + +import com.pedrogomez.renderers.*; + +import butterknife.*; /** * Created by parmegv on 4/12/14. diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderRendererBuilder.java b/app/src/main/java/se/leap/bitmaskclient/ProviderRendererBuilder.java index 7366e68e..1b42e349 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderRendererBuilder.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderRendererBuilder.java @@ -1,15 +1,7 @@ package se.leap.bitmaskclient; -import android.content.Context; - -import com.pedrogomez.renderers.Renderer; -import com.pedrogomez.renderers.RendererBuilder; - -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; - -import javax.inject.Inject; +import com.pedrogomez.renderers.*; +import java.util.*; /** * Created by parmegv on 4/12/14. diff --git a/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java b/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java index 91e56330..6346fc36 100644 --- a/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java @@ -16,18 +16,13 @@ */ package se.leap.bitmaskclient; -import android.app.Activity; -import android.app.AlertDialog; -import android.app.DialogFragment; -import android.content.DialogInterface; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.EditText; -import android.widget.TextView; - -import butterknife.ButterKnife; -import butterknife.InjectView; +import android.app.*; +import android.content.*; +import android.os.*; +import android.view.*; +import android.widget.*; + +import butterknife.*; /** * Implements the log in dialog, currently without progress dialog. 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 3b72a486..6335f818 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -19,7 +19,6 @@ package se.leap.bitmaskclient.eip; import android.app.*; import android.content.*; import android.os.*; -import android.util.Log; import org.json.*; diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java index 0d8a2f7b..10ddc0ef 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java @@ -16,21 +16,15 @@ */ package se.leap.bitmaskclient.eip; -import android.app.Activity; -import android.content.SharedPreferences; -import android.util.Log; +import android.util.*; -import com.google.gson.Gson; +import com.google.gson.*; -import org.json.JSONException; -import org.json.JSONObject; +import org.json.*; +import java.io.*; -import java.io.IOException; -import java.io.StringReader; - -import de.blinkt.openvpn.VpnProfile; -import de.blinkt.openvpn.core.ConfigParser; -import se.leap.bitmaskclient.Dashboard; +import de.blinkt.openvpn.*; +import de.blinkt.openvpn.core.*; /** * Gateway provides objects defining gateways and their metadata. diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaySelector.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaySelector.java index 39ae7ca6..11823511 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaySelector.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaySelector.java @@ -1,10 +1,6 @@ package se.leap.bitmaskclient.eip; -import java.util.Calendar; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.TreeMap; +import java.util.*; public class GatewaySelector { List gateways; diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java index 401cd701..af5670f5 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java @@ -17,7 +17,7 @@ package se.leap.bitmaskclient.eip; import android.content.*; -import android.util.Log; +import android.util.*; import com.google.gson.*; import com.google.gson.reflect.*; diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java index d79d8003..39a802c6 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java @@ -1,9 +1,9 @@ package se.leap.bitmaskclient.eip; -import android.app.Activity; -import android.content.Intent; -import android.net.VpnService; -import android.os.Bundle; +import android.app.*; +import android.content.*; +import android.net.*; +import android.os.*; public class VoidVpnLauncher extends Activity { diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java index f87f35e2..e864288a 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java @@ -1,10 +1,10 @@ package se.leap.bitmaskclient.eip; -import android.content.Intent; -import android.net.VpnService; -import android.os.ParcelFileDescriptor; +import android.content.*; +import android.net.*; +import android.os.*; -import java.io.IOException; +import java.io.*; public class VoidVpnService extends VpnService { diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java index 0bbe9db4..27971c3d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java @@ -16,14 +16,12 @@ */ package se.leap.bitmaskclient.eip; -import android.util.Log; +import android.util.*; -import java.security.cert.CertificateExpiredException; -import java.security.cert.CertificateNotYetValidException; -import java.security.cert.X509Certificate; -import java.util.Calendar; +import java.security.cert.*; +import java.util.*; -import se.leap.bitmaskclient.ConfigHelper; +import se.leap.bitmaskclient.*; public class VpnCertificateValidator { public final static String TAG = VpnCertificateValidator.class.getSimpleName(); diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java index 5f5dcabd..8b1bc793 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java @@ -16,16 +16,9 @@ */ package se.leap.bitmaskclient.eip; -import android.content.SharedPreferences; -import android.util.Log; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.Iterator; - -import se.leap.bitmaskclient.Provider; +import org.json.*; +import java.util.*; +import se.leap.bitmaskclient.*; public class VpnConfigGenerator { -- cgit v1.2.3 From b87f082fe0e9c05cf45c56b510a2c4000133b572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Tue, 24 Mar 2015 19:07:43 +0100 Subject: Indent everything with IntelliJ --- .../java/se/leap/bitmaskclient/AboutActivity.java | 38 +- .../java/se/leap/bitmaskclient/ConfigHelper.java | 291 +++++----- .../main/java/se/leap/bitmaskclient/Dashboard.java | 282 +++++----- .../leap/bitmaskclient/DownloadFailedDialog.java | 105 ++-- .../java/se/leap/bitmaskclient/EipFragment.java | 150 ++--- .../bitmaskclient/FragmentManagerEnhanced.java | 32 +- .../java/se/leap/bitmaskclient/LeapSRPSession.java | 613 +++++++++++---------- .../java/se/leap/bitmaskclient/OnBootReceiver.java | 22 +- .../main/java/se/leap/bitmaskclient/PRNGFixes.java | 17 +- .../main/java/se/leap/bitmaskclient/Provider.java | 157 +++--- .../bitmaskclient/ProviderAPIResultReceiver.java | 34 +- .../se/leap/bitmaskclient/ProviderListAdapter.java | 132 ++--- .../se/leap/bitmaskclient/ProviderManager.java | 38 +- .../bitmaskclient/ProviderRendererBuilder.java | 16 +- .../java/se/leap/bitmaskclient/SessionDialog.java | 140 ++--- app/src/main/java/se/leap/bitmaskclient/User.java | 23 +- .../se/leap/bitmaskclient/UserSessionStatus.java | 47 +- .../java/se/leap/bitmaskclient/eip/Constants.java | 6 +- .../main/java/se/leap/bitmaskclient/eip/EIP.java | 150 ++--- .../java/se/leap/bitmaskclient/eip/EipStatus.java | 95 ++-- .../java/se/leap/bitmaskclient/eip/Gateway.java | 100 ++-- .../se/leap/bitmaskclient/eip/GatewaySelector.java | 46 +- .../se/leap/bitmaskclient/eip/GatewaysManager.java | 69 +-- .../se/leap/bitmaskclient/eip/VoidVpnLauncher.java | 36 +- .../se/leap/bitmaskclient/eip/VoidVpnService.java | 48 +- .../bitmaskclient/eip/VpnCertificateValidator.java | 46 +- .../leap/bitmaskclient/eip/VpnConfigGenerator.java | 10 +- 27 files changed, 1388 insertions(+), 1355 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/AboutActivity.java b/app/src/main/java/se/leap/bitmaskclient/AboutActivity.java index fa79d009..ce762fcc 100644 --- a/app/src/main/java/se/leap/bitmaskclient/AboutActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/AboutActivity.java @@ -6,30 +6,30 @@ import android.content.pm.PackageManager.*; import android.os.*; import android.widget.*; -public class AboutActivity extends Activity { - +public class AboutActivity extends Activity { + final public static String TAG = "aboutFragment"; final public static int VIEWED = 0; @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.about); - TextView ver = (TextView) findViewById(R.id.version); - - String version; - String name="Openvpn"; - try { - PackageInfo packageinfo = getPackageManager().getPackageInfo(getPackageName(), 0); - version = packageinfo.versionName; - name = getString(R.string.app); - } catch (NameNotFoundException e) { - version = "error fetching version"; - } - - - ver.setText(getString(R.string.version_info,name,version)); - setResult(VIEWED); + super.onCreate(savedInstanceState); + setContentView(R.layout.about); + TextView ver = (TextView) findViewById(R.id.version); + + String version; + String name = "Openvpn"; + try { + PackageInfo packageinfo = getPackageManager().getPackageInfo(getPackageName(), 0); + version = packageinfo.versionName; + name = getString(R.string.app); + } catch (NameNotFoundException e) { + version = "error fetching version"; + } + + + ver.setText(getString(R.string.version_info, name, version)); + setResult(VIEWED); } } diff --git a/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java b/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java index b20cb1ae..4929f040 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java @@ -1,6 +1,6 @@ /** * 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 @@ -29,156 +29,157 @@ import java.security.spec.*; /** * Stores constants, and implements auxiliary methods used across all LEAP Android classes. - * + * * @author parmegv * @author MeanderingCode - * */ public class ConfigHelper { private static KeyStore keystore_trusted; final public static String NG_1024 = - "eeaf0ab9adb38dd69c33f80afa8fc5e86072618775ff3c0b9ea2314c9c256576d674df7496ea81d3383b4813d692c6e0e0d5d8e250b98be48e495c1d6089dad15dc7d7b46154d6b6ce8ef4ad69b15d4982559b297bcf1885c529f566660e57ec68edbc3c05726cc02fd4cbf4976eaa9afd5138fe8376435b9fc61d2fc0eb06e3"; + "eeaf0ab9adb38dd69c33f80afa8fc5e86072618775ff3c0b9ea2314c9c256576d674df7496ea81d3383b4813d692c6e0e0d5d8e250b98be48e495c1d6089dad15dc7d7b46154d6b6ce8ef4ad69b15d4982559b297bcf1885c529f566660e57ec68edbc3c05726cc02fd4cbf4976eaa9afd5138fe8376435b9fc61d2fc0eb06e3"; final public static BigInteger G = new BigInteger("2"); - - public static boolean checkErroneousDownload(String downloaded_string) { - try { - if(new JSONObject(downloaded_string).has(ProviderAPI.ERRORS) || downloaded_string.isEmpty()) { - return true; - } else { - return false; - } - } catch(JSONException e) { - return false; - } - } - - /** - * Treat the input as the MSB representation of a number, - * and lop off leading zero elements. For efficiency, the - * input is simply returned if no leading zeroes are found. - * - * @param in array to be trimmed - */ - public static byte[] trim(byte[] in) { - if(in.length == 0 || in[0] != 0) - return in; - - int len = in.length; - int i = 1; - while(in[i] == 0 && i < len) - ++i; - byte[] ret = new byte[len - i]; - System.arraycopy(in, i, ret, 0, len - i); - return ret; - } - - public static X509Certificate parseX509CertificateFromString(String certificate_string) { - java.security.cert.Certificate certificate = null; - CertificateFactory cf; - try { - cf = CertificateFactory.getInstance("X.509"); - - certificate_string = certificate_string.replaceFirst("-----BEGIN CERTIFICATE-----", "").replaceFirst("-----END CERTIFICATE-----", "").trim(); - byte[] cert_bytes = Base64.decode(certificate_string, Base64.DEFAULT); - InputStream caInput = new ByteArrayInputStream(cert_bytes); - try { - certificate = cf.generateCertificate(caInput); - System.out.println("ca=" + ((X509Certificate) certificate).getSubjectDN()); - } finally { - caInput.close(); - } - } catch (CertificateException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - return null; - } catch (IllegalArgumentException e) { - return null; - } - - return (X509Certificate) certificate; - } - - protected static RSAPrivateKey parseRsaKeyFromString(String RsaKeyString) { - RSAPrivateKey key = null; - try { - KeyFactory kf = KeyFactory.getInstance("RSA", "BC"); - - RsaKeyString = RsaKeyString.replaceFirst("-----BEGIN RSA PRIVATE KEY-----", "").replaceFirst("-----END RSA PRIVATE KEY-----", ""); - PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec( Base64.decode(RsaKeyString, Base64.DEFAULT) ); - key = (RSAPrivateKey) kf.generatePrivate(keySpec); - } catch (InvalidKeySpecException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - return null; - } catch (NoSuchAlgorithmException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - return null; - } catch (NoSuchProviderException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - return null; - } - - return key; - } - - /** - * Adds a new X509 certificate given its input stream and its provider name - * @param provider used to store the certificate in the keystore - * @param inputStream from which X509 certificate must be generated. - */ - public static void addTrustedCertificate(String provider, InputStream inputStream) { - CertificateFactory cf; - try { - cf = CertificateFactory.getInstance("X.509"); - X509Certificate cert = - (X509Certificate)cf.generateCertificate(inputStream); - keystore_trusted.setCertificateEntry(provider, cert); - } catch (CertificateException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (KeyStoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - /** - * Adds a new X509 certificate given in its string from and using its provider name - * @param provider used to store the certificate in the keystore - * @param certificate - */ - public static void addTrustedCertificate(String provider, String certificate) { - - try { - X509Certificate cert = ConfigHelper.parseX509CertificateFromString(certificate); - if(keystore_trusted == null) { - keystore_trusted = KeyStore.getInstance("BKS"); - keystore_trusted.load(null); - } - keystore_trusted.setCertificateEntry(provider, cert); - } catch (KeyStoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (CertificateException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - /** - * @return class wide keystore - */ - public static KeyStore getKeystore() { - return keystore_trusted; - } + + public static boolean checkErroneousDownload(String downloaded_string) { + try { + if (new JSONObject(downloaded_string).has(ProviderAPI.ERRORS) || downloaded_string.isEmpty()) { + return true; + } else { + return false; + } + } catch (JSONException e) { + return false; + } + } + + /** + * Treat the input as the MSB representation of a number, + * and lop off leading zero elements. For efficiency, the + * input is simply returned if no leading zeroes are found. + * + * @param in array to be trimmed + */ + public static byte[] trim(byte[] in) { + if (in.length == 0 || in[0] != 0) + return in; + + int len = in.length; + int i = 1; + while (in[i] == 0 && i < len) + ++i; + byte[] ret = new byte[len - i]; + System.arraycopy(in, i, ret, 0, len - i); + return ret; + } + + public static X509Certificate parseX509CertificateFromString(String certificate_string) { + java.security.cert.Certificate certificate = null; + CertificateFactory cf; + try { + cf = CertificateFactory.getInstance("X.509"); + + certificate_string = certificate_string.replaceFirst("-----BEGIN CERTIFICATE-----", "").replaceFirst("-----END CERTIFICATE-----", "").trim(); + byte[] cert_bytes = Base64.decode(certificate_string, Base64.DEFAULT); + InputStream caInput = new ByteArrayInputStream(cert_bytes); + try { + certificate = cf.generateCertificate(caInput); + System.out.println("ca=" + ((X509Certificate) certificate).getSubjectDN()); + } finally { + caInput.close(); + } + } catch (CertificateException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + return null; + } catch (IllegalArgumentException e) { + return null; + } + + return (X509Certificate) certificate; + } + + protected static RSAPrivateKey parseRsaKeyFromString(String RsaKeyString) { + RSAPrivateKey key = null; + try { + KeyFactory kf = KeyFactory.getInstance("RSA", "BC"); + + RsaKeyString = RsaKeyString.replaceFirst("-----BEGIN RSA PRIVATE KEY-----", "").replaceFirst("-----END RSA PRIVATE KEY-----", ""); + PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.decode(RsaKeyString, Base64.DEFAULT)); + key = (RSAPrivateKey) kf.generatePrivate(keySpec); + } catch (InvalidKeySpecException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } catch (NoSuchAlgorithmException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } catch (NoSuchProviderException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } + + return key; + } + + /** + * Adds a new X509 certificate given its input stream and its provider name + * + * @param provider used to store the certificate in the keystore + * @param inputStream from which X509 certificate must be generated. + */ + public static void addTrustedCertificate(String provider, InputStream inputStream) { + CertificateFactory cf; + try { + cf = CertificateFactory.getInstance("X.509"); + X509Certificate cert = + (X509Certificate) cf.generateCertificate(inputStream); + keystore_trusted.setCertificateEntry(provider, cert); + } catch (CertificateException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (KeyStoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * Adds a new X509 certificate given in its string from and using its provider name + * + * @param provider used to store the certificate in the keystore + * @param certificate + */ + public static void addTrustedCertificate(String provider, String certificate) { + + try { + X509Certificate cert = ConfigHelper.parseX509CertificateFromString(certificate); + if (keystore_trusted == null) { + keystore_trusted = KeyStore.getInstance("BKS"); + keystore_trusted.load(null); + } + keystore_trusted.setCertificateEntry(provider, cert); + } catch (KeyStoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchAlgorithmException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (CertificateException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * @return class wide keystore + */ + public static KeyStore getKeystore() { + return keystore_trusted; + } } diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index 7e2fa0b5..2e9aa74c 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -27,6 +27,7 @@ import android.widget.*; import org.jetbrains.annotations.*; import org.json.*; + import java.net.*; import java.util.*; @@ -88,7 +89,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn restoreProvider(savedInstanceState); if (provider == null || provider.getName().isEmpty()) - startActivityForResult(new Intent(this,ConfigurationWizard.class),CONFIGURE_LEAP); + startActivityForResult(new Intent(this, ConfigurationWizard.class), CONFIGURE_LEAP); else { buildDashboard(getIntent().getBooleanExtra(ON_BOOT, false)); restoreSessionStatus(savedInstanceState); @@ -97,16 +98,16 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn private void restoreProvider(Bundle savedInstanceState) { if (savedInstanceState != null) { - if(savedInstanceState.containsKey(Provider.KEY)) + if (savedInstanceState.containsKey(Provider.KEY)) provider = savedInstanceState.getParcelable(Provider.KEY); } - if(provider == null && preferences.getBoolean(Constants.PROVIDER_CONFIGURED, false)) + if (provider == null && preferences.getBoolean(Constants.PROVIDER_CONFIGURED, false)) provider = getSavedProviderFromSharedPreferences(); } private void restoreSessionStatus(Bundle savedInstanceState) { if (savedInstanceState != null) - if(savedInstanceState.containsKey(UserSessionStatus.TAG)) { + if (savedInstanceState.containsKey(UserSessionStatus.TAG)) { UserSessionStatus.SessionStatus status = (UserSessionStatus.SessionStatus) savedInstanceState.getSerializable(UserSessionStatus.TAG); user_session_status.updateStatus(status); } @@ -114,9 +115,9 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn @Override protected void onSaveInstanceState(@NotNull Bundle outState) { - if(provider != null) + if (provider != null) outState.putParcelable(Provider.KEY, provider); - if(user_session_status_text_view != null && user_session_status_text_view.getVisibility() == TextView.VISIBLE) + if (user_session_status_text_view != null && user_session_status_text_view.getVisibility() == TextView.VISIBLE) outState.putSerializable(UserSessionStatus.TAG, user_session_status.sessionStatus()); super.onSaveInstanceState(outState); @@ -135,27 +136,27 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn } private void handleVersion() { - try { - int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; - int lastDetectedVersion = preferences.getInt(APP_VERSION, 0); - preferences.edit().putInt(APP_VERSION, versionCode).apply(); - - switch(versionCode) { - case 91: // 0.6.0 without Bug #5999 - case 101: // 0.8.0 - if(!preferences.getString(Constants.KEY, "").isEmpty()) - eip_fragment.updateEipService(); - break; - } - } catch (NameNotFoundException e) { - Log.d(TAG, "Handle version didn't find any " + getPackageName() + " package"); - } + try { + int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; + int lastDetectedVersion = preferences.getInt(APP_VERSION, 0); + preferences.edit().putInt(APP_VERSION, versionCode).apply(); + + switch (versionCode) { + case 91: // 0.6.0 without Bug #5999 + case 101: // 0.8.0 + if (!preferences.getString(Constants.KEY, "").isEmpty()) + eip_fragment.updateEipService(); + break; + } + } catch (NameNotFoundException e) { + Log.d(TAG, "Handle version didn't find any " + getPackageName() + " package"); + } } @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data){ - if ( requestCode == CONFIGURE_LEAP || requestCode == SWITCH_PROVIDER) { - if ( resultCode == RESULT_OK && data.hasExtra(Provider.KEY)) { + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == CONFIGURE_LEAP || requestCode == SWITCH_PROVIDER) { + if (resultCode == RESULT_OK && data.hasExtra(Provider.KEY)) { provider = data.getParcelableExtra(Provider.KEY); providerToPreferences(provider); @@ -169,7 +170,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn finish(); } else configErrorDialog(); - } else if(requestCode == EIP.DISCONNECT) { + } else if (requestCode == EIP.DISCONNECT) { EipStatus.getInstance().setConnectedOrDisconnected(); } } @@ -182,25 +183,25 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn } private void configErrorDialog() { - AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getContext()); - alertBuilder.setTitle(getResources().getString(R.string.setup_error_title)); - alertBuilder - .setMessage(getResources().getString(R.string.setup_error_text)) - .setCancelable(false) - .setPositiveButton(getResources().getString(R.string.setup_error_configure_button), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - startActivityForResult(new Intent(getContext(),ConfigurationWizard.class),CONFIGURE_LEAP); - } - }) - .setNegativeButton(getResources().getString(R.string.setup_error_close_button), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - preferences.edit().remove(Provider.KEY).remove(Constants.PROVIDER_CONFIGURED).apply(); - finish(); - } - }) - .show(); + AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getContext()); + alertBuilder.setTitle(getResources().getString(R.string.setup_error_title)); + alertBuilder + .setMessage(getResources().getString(R.string.setup_error_text)) + .setCancelable(false) + .setPositiveButton(getResources().getString(R.string.setup_error_configure_button), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + startActivityForResult(new Intent(getContext(), ConfigurationWizard.class), CONFIGURE_LEAP); + } + }) + .setNegativeButton(getResources().getString(R.string.setup_error_close_button), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + preferences.edit().remove(Provider.KEY).remove(Constants.PROVIDER_CONFIGURED).apply(); + finish(); + } + }) + .show(); } /** @@ -212,7 +213,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn ButterKnife.inject(this); provider_name.setText(provider.getDomain()); - if ( provider.hasEIP()){ + if (provider.hasEIP()) { fragment_manager.removePreviousFragment(EipFragment.TAG); eip_fragment = new EipFragment(); @@ -220,7 +221,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn preferences.edit().remove(Dashboard.START_ON_BOOT).apply(); Bundle arguments = new Bundle(); arguments.putBoolean(EipFragment.START_ON_BOOT, true); - if(eip_fragment != null) eip_fragment.setArguments(arguments); + if (eip_fragment != null) eip_fragment.setArguments(arguments); } fragment_manager.replace(R.id.servicesCollection, eip_fragment, EipFragment.TAG); @@ -233,7 +234,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn @Override public boolean onPrepareOptionsMenu(Menu menu) { - if(provider.allowsRegistration()) { + if (provider.allowsRegistration()) { menu.findItem(R.id.signup_button).setVisible(true); boolean logged_in = User.loggedIn(); @@ -245,78 +246,78 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn @Override public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.client_dashboard, menu); - return true; + getMenuInflater().inflate(R.menu.client_dashboard, menu); + return true; } @Override - public boolean onOptionsItemSelected(MenuItem item){ - switch (item.getItemId()){ - case R.id.about_leap: - showAbout(); - return true; - case R.id.log_window: - showLog(); - return true; - case R.id.switch_provider: - switching_provider = true; - if (LeapSRPSession.loggedIn()) logOut(); - else switchProvider(); - return true; - case R.id.login_button: - sessionDialog(Bundle.EMPTY); - return true; - case R.id.logout_button: - logOut(); - return true; - case R.id.signup_button: - sessionDialog(Bundle.EMPTY); - return true; - default: - return super.onOptionsItemSelected(item); - } + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.about_leap: + showAbout(); + return true; + case R.id.log_window: + showLog(); + return true; + case R.id.switch_provider: + switching_provider = true; + if (LeapSRPSession.loggedIn()) logOut(); + else switchProvider(); + return true; + case R.id.login_button: + sessionDialog(Bundle.EMPTY); + return true; + case R.id.logout_button: + logOut(); + return true; + case R.id.signup_button: + sessionDialog(Bundle.EMPTY); + return true; + default: + return super.onOptionsItemSelected(item); + } } public void showAbout() { - Intent intent = new Intent(this, AboutActivity.class); - startActivity(intent); + Intent intent = new Intent(this, AboutActivity.class); + startActivity(intent); } public void showLog() { - Intent startLW = new Intent(getContext(), LogWindow.class); - startActivity(startLW); + Intent startLW = new Intent(getContext(), LogWindow.class); + startActivity(startLW); } @Override public void signUp(String username, String password) { User.setUserName(username); - Bundle parameters = bundlePassword(password); - providerApiCommand(parameters, 0, ProviderAPI.SIGN_UP); + Bundle parameters = bundlePassword(password); + providerApiCommand(parameters, 0, ProviderAPI.SIGN_UP); } @Override public void logIn(String username, String password) { User.setUserName(username); - Bundle parameters = bundlePassword(password); - providerApiCommand(parameters, 0, ProviderAPI.LOG_IN); + Bundle parameters = bundlePassword(password); + providerApiCommand(parameters, 0, ProviderAPI.LOG_IN); } public void logOut() { - providerApiCommand(Bundle.EMPTY, 0, ProviderAPI.LOG_OUT); + providerApiCommand(Bundle.EMPTY, 0, ProviderAPI.LOG_OUT); } @Override - public void update (Observable observable, Object data) { - if(observable instanceof UserSessionStatus) { + public void update(Observable observable, Object data) { + if (observable instanceof UserSessionStatus) { UserSessionStatus status = (UserSessionStatus) observable; - handleNewUserSessionStatus(status); + handleNewUserSessionStatus(status); } } private void handleNewUserSessionStatus(UserSessionStatus status) { user_session_status = status; - if(provider.allowsRegistration()) { - if(user_session_status.inProgress()) + if (provider.allowsRegistration()) { + if (user_session_status.inProgress()) showUserSessionProgressBar(); else hideUserSessionProgressBar(); @@ -355,7 +356,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn protected void downloadVpnCertificate() { boolean is_authenticated = LeapSRPSession.loggedIn(); boolean allowed_anon = preferences.getBoolean(Constants.ALLOWED_ANON, false); - if(allowed_anon || is_authenticated) + if (allowed_anon || is_authenticated) providerApiCommand(Bundle.EMPTY, R.string.downloading_certificate_message, ProviderAPI.DOWNLOAD_CERTIFICATE); else sessionDialog(Bundle.EMPTY); @@ -364,50 +365,50 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn private Bundle bundlePassword(String password) { Bundle parameters = new Bundle(); - if(!password.isEmpty()) - parameters.putString(SessionDialog.PASSWORD, password); - return parameters; + if (!password.isEmpty()) + parameters.putString(SessionDialog.PASSWORD, password); + return parameters; } protected void providerApiCommand(Bundle parameters, int progressbar_message_resId, String providerApi_action) { - if(eip_fragment != null && progressbar_message_resId != 0) { + if (eip_fragment != null && progressbar_message_resId != 0) { eip_fragment.progress_bar.setVisibility(ProgressBar.VISIBLE); setStatusMessage(progressbar_message_resId); } - Intent command = prepareProviderAPICommand(parameters, providerApi_action); - startService(command); + Intent command = prepareProviderAPICommand(parameters, providerApi_action); + startService(command); } private Intent prepareProviderAPICommand(Bundle parameters, String action) { - providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler()); - providerAPI_result_receiver.setReceiver(this); + providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler()); + providerAPI_result_receiver.setReceiver(this); - Intent command = new Intent(this, ProviderAPI.class); + Intent command = new Intent(this, ProviderAPI.class); - command.putExtra(ProviderAPI.PARAMETERS, parameters); - command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver); - command.setAction(action); - return command; + command.putExtra(ProviderAPI.PARAMETERS, parameters); + command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver); + command.setAction(action); + return command; } public void cancelLoginOrSignup() { - EipStatus.getInstance().setConnectedOrDisconnected(); + EipStatus.getInstance().setConnectedOrDisconnected(); } public void sessionDialog(Bundle resultData) { - FragmentTransaction transaction = fragment_manager.removePreviousFragment(SessionDialog.TAG); + FragmentTransaction transaction = fragment_manager.removePreviousFragment(SessionDialog.TAG); - DialogFragment newFragment = new SessionDialog(); - if(provider.getName().equalsIgnoreCase("riseup")) { + DialogFragment newFragment = new SessionDialog(); + if (provider.getName().equalsIgnoreCase("riseup")) { resultData = resultData == Bundle.EMPTY ? new Bundle() : resultData; resultData.putBoolean(SessionDialog.ERRORS.RISEUP_WARNING.toString(), true); } - if(resultData != null && !resultData.isEmpty()) { - newFragment.setArguments(resultData); - } - newFragment.show(transaction, SessionDialog.TAG); + if (resultData != null && !resultData.isEmpty()) { + newFragment.setArguments(resultData); + } + newFragment.show(transaction, SessionDialog.TAG); } private void switchProvider() { @@ -420,43 +421,42 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn @Override public void onReceiveResult(int resultCode, Bundle resultData) { - Log.d(TAG, "onReceiveResult"); - if(resultCode == ProviderAPI.SUCCESSFUL_SIGNUP) { - String username = resultData.getString(SessionDialog.USERNAME); - String password = resultData.getString(SessionDialog.PASSWORD); - logIn(username, password); - } else if(resultCode == ProviderAPI.FAILED_SIGNUP) { - sessionDialog(resultData); - } else if(resultCode == ProviderAPI.SUCCESSFUL_LOGIN) { - downloadVpnCertificate(); - } else if(resultCode == ProviderAPI.FAILED_LOGIN) { - sessionDialog(resultData); - } else if(resultCode == ProviderAPI.SUCCESSFUL_LOGOUT) { - if(switching_provider) switchProvider(); - } else if(resultCode == ProviderAPI.LOGOUT_FAILED) { - setResult(RESULT_CANCELED); - } else if(resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) { - eip_fragment.updateEipService(); - eip_fragment.handleNewVpnCertificate(); - setResult(RESULT_OK); - } else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) { - setResult(RESULT_CANCELED); - } - else if(resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_EIP_SERVICE) { - eip_fragment.updateEipService(); - setResult(RESULT_OK); - } else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_EIP_SERVICE) { - setResult(RESULT_CANCELED); - } + Log.d(TAG, "onReceiveResult"); + if (resultCode == ProviderAPI.SUCCESSFUL_SIGNUP) { + String username = resultData.getString(SessionDialog.USERNAME); + String password = resultData.getString(SessionDialog.PASSWORD); + logIn(username, password); + } else if (resultCode == ProviderAPI.FAILED_SIGNUP) { + sessionDialog(resultData); + } else if (resultCode == ProviderAPI.SUCCESSFUL_LOGIN) { + downloadVpnCertificate(); + } else if (resultCode == ProviderAPI.FAILED_LOGIN) { + sessionDialog(resultData); + } else if (resultCode == ProviderAPI.SUCCESSFUL_LOGOUT) { + if (switching_provider) switchProvider(); + } else if (resultCode == ProviderAPI.LOGOUT_FAILED) { + setResult(RESULT_CANCELED); + } else if (resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) { + eip_fragment.updateEipService(); + eip_fragment.handleNewVpnCertificate(); + setResult(RESULT_OK); + } else if (resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) { + setResult(RESULT_CANCELED); + } else if (resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_EIP_SERVICE) { + eip_fragment.updateEipService(); + setResult(RESULT_OK); + } else if (resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_EIP_SERVICE) { + setResult(RESULT_CANCELED); + } } private void setStatusMessage(int string_resId) { - if(eip_fragment != null && eip_fragment.status_message != null) - eip_fragment.status_message.setText(string_resId); + if (eip_fragment != null && eip_fragment.status_message != null) + eip_fragment.status_message.setText(string_resId); } public static Context getContext() { - return app; + return app; } @Override diff --git a/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java b/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java index b26205bb..da32dbd4 100644 --- a/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java @@ -1,6 +1,6 @@ /** * 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 @@ -22,67 +22,68 @@ import android.os.*; /** * Implements a dialog to show why a download failed. - * - * @author parmegv * + * @author parmegv */ public class DownloadFailedDialog extends DialogFragment { - public static String TAG = "downloaded_failed_dialog"; - private String reason_to_fail; - /** - * @return a new instance of this DialogFragment. - */ - public static DialogFragment newInstance(String reason_to_fail) { - DownloadFailedDialog dialog_fragment = new DownloadFailedDialog(); - dialog_fragment.reason_to_fail = reason_to_fail; - return dialog_fragment; - } + public static String TAG = "downloaded_failed_dialog"; + private String reason_to_fail; + + /** + * @return a new instance of this DialogFragment. + */ + public static DialogFragment newInstance(String reason_to_fail) { + DownloadFailedDialog dialog_fragment = new DownloadFailedDialog(); + dialog_fragment.reason_to_fail = reason_to_fail; + return dialog_fragment; + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setMessage(reason_to_fail) + .setPositiveButton(R.string.retry, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dismiss(); + interface_with_ConfigurationWizard.retrySetUpProvider(); + } + }) + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + interface_with_ConfigurationWizard.cancelSettingUpProvider(); + dialog.dismiss(); + } + }); - builder.setMessage(reason_to_fail) - .setPositiveButton(R.string.retry, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dismiss(); - interface_with_ConfigurationWizard.retrySetUpProvider(); - } - }) - .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - interface_with_ConfigurationWizard.cancelSettingUpProvider(); - dialog.dismiss(); - } - }); + // Create the AlertDialog object and return it + return builder.create(); + } - // Create the AlertDialog object and return it - return builder.create(); - } + public interface DownloadFailedDialogInterface { + public void retrySetUpProvider(); - public interface DownloadFailedDialogInterface { - public void retrySetUpProvider(); - public void cancelSettingUpProvider(); - } + public void cancelSettingUpProvider(); + } - DownloadFailedDialogInterface interface_with_ConfigurationWizard; + DownloadFailedDialogInterface interface_with_ConfigurationWizard; - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - try { - interface_with_ConfigurationWizard = (DownloadFailedDialogInterface) activity; - } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() - + " must implement NoticeDialogListener"); - } - } + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + try { + interface_with_ConfigurationWizard = (DownloadFailedDialogInterface) activity; + } catch (ClassCastException e) { + throw new ClassCastException(activity.toString() + + " must implement NoticeDialogListener"); + } + } - @Override - public void onCancel(DialogInterface dialog) { - interface_with_ConfigurationWizard.cancelSettingUpProvider(); - dialog.dismiss(); - } + @Override + public void onCancel(DialogInterface dialog) { + interface_with_ConfigurationWizard.cancelSettingUpProvider(); + dialog.dismiss(); + } } diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index a5f3118c..3ad658f5 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -79,17 +79,17 @@ public class EipFragment extends Fragment implements Observer { Log.d(TAG, "onCreateView, eip_switch is checked? " + eip_switch.isChecked()); Bundle arguments = getArguments(); - if(arguments != null && arguments.containsKey(START_ON_BOOT) && arguments.getBoolean(START_ON_BOOT)) + if (arguments != null && arguments.containsKey(START_ON_BOOT) && arguments.getBoolean(START_ON_BOOT)) startEipFromScratch(); - if(savedInstanceState != null) restoreState(savedInstanceState); + if (savedInstanceState != null) restoreState(savedInstanceState); return view; } private void restoreState(@NotNull Bundle savedInstanceState) { - if(savedInstanceState.getBoolean(IS_PENDING)) + if (savedInstanceState.getBoolean(IS_PENDING)) eip_status.setConnecting(); - else if(savedInstanceState.getBoolean(IS_CONNECTED)) + else if (savedInstanceState.getBoolean(IS_CONNECTED)) eip_status.setConnectedOrDisconnected(); else status_message.setText(savedInstanceState.getString(STATUS_MESSAGE)); @@ -121,7 +121,7 @@ public class EipFragment extends Fragment implements Observer { @OnCheckedChanged(R.id.eipSwitch) void handleSwitch(boolean isChecked) { - if(isChecked) + if (isChecked) handleSwitchOn(); else handleSwitchOff(); @@ -130,9 +130,9 @@ public class EipFragment extends Fragment implements Observer { } private void handleSwitchOn() { - if(canStartEIP()) + if (canStartEIP()) startEipFromScratch(); - else if(canLogInToStartEIP()) { + else if (canLogInToStartEIP()) { wants_to_connect = true; Bundle bundle = new Bundle(); bundle.putBoolean(IS_PENDING, true); @@ -155,9 +155,9 @@ public class EipFragment extends Fragment implements Observer { } private void handleSwitchOff() { - if(eip_status.isConnecting()) { + if (eip_status.isConnecting()) { askPendingStartCancellation(); - } else if(eip_status.isConnected()) { + } else if (eip_status.isConnected()) { askToStopEIP(); } else setDisconnectedUI(); @@ -190,7 +190,7 @@ public class EipFragment extends Fragment implements Observer { String status = dashboard.getString(R.string.eip_status_start_pending); status_message.setText(status); - if(!eip_switch.isChecked()) { + if (!eip_switch.isChecked()) { eip_switch.setChecked(true); } saveStatus(); @@ -198,7 +198,7 @@ public class EipFragment extends Fragment implements Observer { } private void stop() { - if(eip_status.isConnecting()) + if (eip_status.isConnecting()) VoidVpnService.stop(); disconnect(); } @@ -245,10 +245,10 @@ public class EipFragment extends Fragment implements Observer { /** * Send a command to EIP * - * @param action A valid String constant from EIP class representing an Intent - * filter for the EIP class + * @param action A valid String constant from EIP class representing an Intent + * filter for the EIP class */ - private void eipCommand(String action){ + private void eipCommand(String action) { // TODO validate "action"...how do we get the list of intent-filters for a class via Android API? Intent vpn_intent = new Intent(dashboard.getApplicationContext(), EIP.class); vpn_intent.setAction(action); @@ -257,8 +257,8 @@ public class EipFragment extends Fragment implements Observer { } @Override - public void update (Observable observable, Object data) { - if(observable instanceof EipStatus) { + public void update(Observable observable, Object data) { + if (observable instanceof EipStatus) { eip_status = (EipStatus) observable; final EipStatus eip_status = (EipStatus) observable; dashboard.runOnUiThread(new Runnable() { @@ -271,9 +271,9 @@ public class EipFragment extends Fragment implements Observer { } private void handleNewState(EipStatus eip_status) { - if(eip_status.wantsToDisconnect()) + if (eip_status.wantsToDisconnect()) setDisconnectedUI(); - else if(eip_status.isConnecting() || is_starting_to_connect) + else if (eip_status.isConnecting() || is_starting_to_connect) setInProgressUI(eip_status); else if (eip_status.isConnected()) setConnectedUI(); @@ -289,11 +289,11 @@ public class EipFragment extends Fragment implements Observer { status_message.setText(dashboard.getString(R.string.eip_state_connected)); } - private void setDisconnectedUI(){ + private void setDisconnectedUI() { hideProgressBar(); adjustSwitch(); - if(eip_status.errorInLast(5, dashboard.getApplicationContext()) - && !status_message.getText().toString().equalsIgnoreCase(dashboard.getString(R.string.eip_state_not_connected))){ + if (eip_status.errorInLast(5, dashboard.getApplicationContext()) + && !status_message.getText().toString().equalsIgnoreCase(dashboard.getString(R.string.eip_state_not_connected))) { dashboard.showLog(); VoidVpnService.stop(); } @@ -301,15 +301,15 @@ public class EipFragment extends Fragment implements Observer { } private void adjustSwitch() { - if(eip_status.isConnected() || eip_status.isConnecting() || is_starting_to_connect) { + if (eip_status.isConnected() || eip_status.isConnecting() || is_starting_to_connect) { Log.d(TAG, "adjustSwitch, isConnected || isConnecting, is checked"); - if(!eip_switch.isChecked()) { + if (!eip_switch.isChecked()) { eip_switch.setChecked(true); } } else { Log.d(TAG, "adjustSwitch, !isConnected && !isConnecting? " + eip_status.toString()); - if(eip_switch.isChecked()) { + if (eip_switch.isChecked()) { eip_switch.setChecked(false); } } @@ -332,72 +332,72 @@ public class EipFragment extends Fragment implements Observer { } private void showProgressBar() { - if(progress_bar != null) + if (progress_bar != null) progress_bar.setVisibility(View.VISIBLE); } private void hideProgressBar() { - if(progress_bar != null) + if (progress_bar != null) progress_bar.setVisibility(View.GONE); } -protected class EIPReceiver extends ResultReceiver { + protected class EIPReceiver extends ResultReceiver { - protected EIPReceiver(Handler handler){ - super(handler); - } + protected EIPReceiver(Handler handler) { + super(handler); + } - @Override - protected void onReceiveResult(int resultCode, Bundle resultData) { - super.onReceiveResult(resultCode, resultData); + @Override + protected void onReceiveResult(int resultCode, Bundle resultData) { + super.onReceiveResult(resultCode, resultData); - String request = resultData.getString(Constants.REQUEST_TAG); + String request = resultData.getString(Constants.REQUEST_TAG); - if (request.equals(Constants.ACTION_START_EIP)) { - switch (resultCode){ - case Activity.RESULT_OK: - break; - case Activity.RESULT_CANCELED: + if (request.equals(Constants.ACTION_START_EIP)) { + switch (resultCode) { + case Activity.RESULT_OK: + break; + case Activity.RESULT_CANCELED: - break; - } - } else if (request.equals(Constants.ACTION_STOP_EIP)) { - switch (resultCode){ - case Activity.RESULT_OK: - stop(); - break; - case Activity.RESULT_CANCELED: - break; - } - } else if (request.equals(Constants.EIP_NOTIFICATION)) { - switch (resultCode){ - case Activity.RESULT_OK: - break; - case Activity.RESULT_CANCELED: - break; - } - } else if (request.equals(Constants.ACTION_CHECK_CERT_VALIDITY)) { - switch (resultCode) { - case Activity.RESULT_OK: - break; - case Activity.RESULT_CANCELED: - updatingCertificateUI(); - dashboard.downloadVpnCertificate(); - break; - } - } else if (request.equals(Constants.ACTION_UPDATE_EIP_SERVICE)) { - switch (resultCode) { - case Activity.RESULT_OK: - if(wants_to_connect) - startEipFromScratch(); - break; - case Activity.RESULT_CANCELED: - handleNewState(eip_status); - break; + break; + } + } else if (request.equals(Constants.ACTION_STOP_EIP)) { + switch (resultCode) { + case Activity.RESULT_OK: + stop(); + break; + case Activity.RESULT_CANCELED: + break; + } + } else if (request.equals(Constants.EIP_NOTIFICATION)) { + switch (resultCode) { + case Activity.RESULT_OK: + break; + case Activity.RESULT_CANCELED: + break; + } + } else if (request.equals(Constants.ACTION_CHECK_CERT_VALIDITY)) { + switch (resultCode) { + case Activity.RESULT_OK: + break; + case Activity.RESULT_CANCELED: + updatingCertificateUI(); + dashboard.downloadVpnCertificate(); + break; + } + } else if (request.equals(Constants.ACTION_UPDATE_EIP_SERVICE)) { + switch (resultCode) { + case Activity.RESULT_OK: + if (wants_to_connect) + startEipFromScratch(); + break; + case Activity.RESULT_CANCELED: + handleNewState(eip_status); + break; + } } } } -} public static EIPReceiver getReceiver() { diff --git a/app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java b/app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java index 9975b127..8ba7fa34 100644 --- a/app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java +++ b/app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java @@ -1,6 +1,6 @@ /** * 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 @@ -21,26 +21,26 @@ import android.app.*; public class FragmentManagerEnhanced { private FragmentManager generic_fragment_manager; - + public FragmentManagerEnhanced(FragmentManager generic_fragment_manager) { - this.generic_fragment_manager = generic_fragment_manager; + this.generic_fragment_manager = generic_fragment_manager; } - + public FragmentTransaction removePreviousFragment(String tag) { - FragmentTransaction transaction = generic_fragment_manager.beginTransaction(); - Fragment previous_fragment = generic_fragment_manager.findFragmentByTag(tag); - if (previous_fragment != null) { - transaction.remove(previous_fragment); - } - transaction.addToBackStack(null); - - return transaction; + FragmentTransaction transaction = generic_fragment_manager.beginTransaction(); + Fragment previous_fragment = generic_fragment_manager.findFragmentByTag(tag); + if (previous_fragment != null) { + transaction.remove(previous_fragment); + } + transaction.addToBackStack(null); + + return transaction; } public void replace(int containerViewId, Fragment fragment, String tag) { - FragmentTransaction transaction = generic_fragment_manager.beginTransaction(); - - transaction.replace(containerViewId, fragment, tag).commit(); + FragmentTransaction transaction = generic_fragment_manager.beginTransaction(); + + transaction.replace(containerViewId, fragment, tag).commit(); } public FragmentTransaction beginTransaction() { @@ -48,6 +48,6 @@ public class FragmentManagerEnhanced { } public Fragment findFragmentByTag(String tag) { - return generic_fragment_manager.findFragmentByTag(tag); + return generic_fragment_manager.findFragmentByTag(tag); } } diff --git a/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java b/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java index d3085fa3..b961350e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java +++ b/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java @@ -1,6 +1,6 @@ /** * 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 @@ -26,329 +26,336 @@ import java.util.*; /** * Implements all SRP algorithm logic. - * + *

* It's derived from JBoss implementation, with adjustments to make it work with LEAP platform. - * - * @author parmegv * + * @author parmegv */ public class LeapSRPSession { - - private static String token = ""; - - final public static String SALT = "salt"; - final public static String M1 = "M1"; - final public static String M2 = "M2"; - final public static String TOKEN = "token"; - final public static String AUTHORIZATION_HEADER= "Authorization"; - final public static String TAG= "Leap SRP session class tag"; + + private static String token = ""; + + final public static String SALT = "salt"; + final public static String M1 = "M1"; + final public static String M2 = "M2"; + final public static String TOKEN = "token"; + final public static String AUTHORIZATION_HEADER = "Authorization"; + final public static String TAG = "Leap SRP session class tag"; private User user; - private SRPParameters params; - private String username; - private String password; - private BigInteger N; - private byte[] N_bytes; - private BigInteger g; - private BigInteger x; - private BigInteger v; - private BigInteger a; - private BigInteger A; - private byte[] K; - private SecureRandom pseudoRng; - /** The M1 = H(H(N) xor H(g) | H(U) | s | A | B | K) hash */ - private MessageDigest clientHash; - /** The M2 = H(A | M | K) hash */ - private MessageDigest serverHash; - - private static int A_LEN; - - - /** Creates a new SRP server session object from the username, password - verifier, - @param username, the user ID - @param password, the user clear text password - @param params, the SRP parameters for the session - */ - public LeapSRPSession(String username, String password) - { - this(username, password, null); - } - - /** Creates a new SRP server session object from the username, password - verifier, - @param username, the user ID - @param password, the user clear text password - @param params, the SRP parameters for the session - @param abytes, the random exponent used in the A public key - */ - public LeapSRPSession(String username, String password, byte[] abytes) { - - params = new SRPParameters(new BigInteger(ConfigHelper.NG_1024, 16).toByteArray(), ConfigHelper.G.toByteArray(), BigInteger.ZERO.toByteArray(), "SHA-256"); - this.g = new BigInteger(1, params.g); - N_bytes = ConfigHelper.trim(params.N); - this.N = new BigInteger(1, N_bytes); - this.username = username; - this.password = password; - - try { - pseudoRng = SecureRandom.getInstance("SHA1PRNG"); - } catch (NoSuchAlgorithmException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - if( abytes != null ) { - A_LEN = 8*abytes.length; - /* TODO Why did they put this condition? - if( 8*abytes.length != A_LEN ) + private SRPParameters params; + private String username; + private String password; + private BigInteger N; + private byte[] N_bytes; + private BigInteger g; + private BigInteger x; + private BigInteger v; + private BigInteger a; + private BigInteger A; + private byte[] K; + private SecureRandom pseudoRng; + /** + * The M1 = H(H(N) xor H(g) | H(U) | s | A | B | K) hash + */ + private MessageDigest clientHash; + /** + * The M2 = H(A | M | K) hash + */ + private MessageDigest serverHash; + + private static int A_LEN; + + + /** + * Creates a new SRP server session object from the username, password + * verifier, + * + * @param username, the user ID + * @param password, the user clear text password + * @param params, the SRP parameters for the session + */ + public LeapSRPSession(String username, String password) { + this(username, password, null); + } + + /** + * Creates a new SRP server session object from the username, password + * verifier, + * + * @param username, the user ID + * @param password, the user clear text password + * @param params, the SRP parameters for the session + * @param abytes, the random exponent used in the A public key + */ + public LeapSRPSession(String username, String password, byte[] abytes) { + + params = new SRPParameters(new BigInteger(ConfigHelper.NG_1024, 16).toByteArray(), ConfigHelper.G.toByteArray(), BigInteger.ZERO.toByteArray(), "SHA-256"); + this.g = new BigInteger(1, params.g); + N_bytes = ConfigHelper.trim(params.N); + this.N = new BigInteger(1, N_bytes); + this.username = username; + this.password = password; + + try { + pseudoRng = SecureRandom.getInstance("SHA1PRNG"); + } catch (NoSuchAlgorithmException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + if (abytes != null) { + A_LEN = 8 * abytes.length; + /* TODO Why did they put this condition? + if( 8*abytes.length != A_LEN ) throw new IllegalArgumentException("The abytes param must be " +(A_LEN/8)+" in length, abytes.length="+abytes.length); */ - this.a = new BigInteger(abytes); - } - else - A_LEN = 64; - - serverHash = newDigest(); - clientHash = newDigest(); - } - - /** - * Calculates the parameter x of the SRP-6a algorithm. - * @param username - * @param password - * @param salt the salt of the user - * @return x - */ - public byte[] calculatePasswordHash(String username, String password, byte[] salt) - { - //password = password.replaceAll("\\\\", "\\\\\\\\"); - // Calculate x = H(s | H(U | ':' | password)) - MessageDigest x_digest = newDigest(); - // Try to convert the username to a byte[] using ISO-8859-1 - byte[] user = null; - byte[] password_bytes = null; - byte[] colon = {}; - String encoding = "ISO-8859-1"; - try { - user = ConfigHelper.trim(username.getBytes(encoding)); - colon = ConfigHelper.trim(":".getBytes(encoding)); - password_bytes = ConfigHelper.trim(password.getBytes(encoding)); - } - catch(UnsupportedEncodingException e) { - // Use the default platform encoding - user = ConfigHelper.trim(username.getBytes()); - colon = ConfigHelper.trim(":".getBytes()); - password_bytes = ConfigHelper.trim(password.getBytes()); - } - - // Build the hash - x_digest.update(user); - x_digest.update(colon); - x_digest.update(password_bytes); - byte[] h = x_digest.digest(); - - x_digest.reset(); - x_digest.update(salt); - x_digest.update(h); - byte[] x_digest_bytes = x_digest.digest(); - - return x_digest_bytes; - } + this.a = new BigInteger(abytes); + } else + A_LEN = 64; + + serverHash = newDigest(); + clientHash = newDigest(); + } + + /** + * Calculates the parameter x of the SRP-6a algorithm. + * + * @param username + * @param password + * @param salt the salt of the user + * @return x + */ + public byte[] calculatePasswordHash(String username, String password, byte[] salt) { + //password = password.replaceAll("\\\\", "\\\\\\\\"); + // Calculate x = H(s | H(U | ':' | password)) + MessageDigest x_digest = newDigest(); + // Try to convert the username to a byte[] using ISO-8859-1 + byte[] user = null; + byte[] password_bytes = null; + byte[] colon = {}; + String encoding = "ISO-8859-1"; + try { + user = ConfigHelper.trim(username.getBytes(encoding)); + colon = ConfigHelper.trim(":".getBytes(encoding)); + password_bytes = ConfigHelper.trim(password.getBytes(encoding)); + } catch (UnsupportedEncodingException e) { + // Use the default platform encoding + user = ConfigHelper.trim(username.getBytes()); + colon = ConfigHelper.trim(":".getBytes()); + password_bytes = ConfigHelper.trim(password.getBytes()); + } + + // Build the hash + x_digest.update(user); + x_digest.update(colon); + x_digest.update(password_bytes); + byte[] h = x_digest.digest(); + + x_digest.reset(); + x_digest.update(salt); + x_digest.update(h); + byte[] x_digest_bytes = x_digest.digest(); + + return x_digest_bytes; + } public byte[] calculateNewSalt() { - try { - BigInteger salt = new BigInteger(64, SecureRandom.getInstance("SHA1PRNG")); - return ConfigHelper.trim(salt.toByteArray()); - } catch(NoSuchAlgorithmException e) { - e.printStackTrace(); - } - return null; + try { + BigInteger salt = new BigInteger(64, SecureRandom.getInstance("SHA1PRNG")); + return ConfigHelper.trim(salt.toByteArray()); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + return null; } - /** - * Calculates the parameter V of the SRP-6a algorithm. - * @return the value of V - */ + + /** + * Calculates the parameter V of the SRP-6a algorithm. + * + * @return the value of V + */ public BigInteger calculateV(String username, String password, byte[] salt) { - byte[] x_bytes = calculatePasswordHash(username, password, ConfigHelper.trim(salt)); - x = new BigInteger(1, x_bytes); - BigInteger v = g.modPow(x, N); // g^x % N - return v; - } - - /** - * Calculates the trimmed xor from two BigInteger numbers - * @param b1 the positive source to build first BigInteger - * @param b2 the positive source to build second BigInteger - * @param length - * @return - */ - public byte[] xor(byte[] b1, byte[] b2) - { - //TODO Check if length matters in the order, when b2 is smaller than b1 or viceversa - byte[] xor_digest = new BigInteger(1, b1).xor(new BigInteger(1, b2)).toByteArray(); - return ConfigHelper.trim(xor_digest); - } - - /** - * @returns The exponential residue (parameter A) to be sent to the server. - */ - public byte[] exponential() { - byte[] Abytes = null; - if(A == null) { + byte[] x_bytes = calculatePasswordHash(username, password, ConfigHelper.trim(salt)); + x = new BigInteger(1, x_bytes); + BigInteger v = g.modPow(x, N); // g^x % N + return v; + } + + /** + * Calculates the trimmed xor from two BigInteger numbers + * + * @param b1 the positive source to build first BigInteger + * @param b2 the positive source to build second BigInteger + * @param length + * @return + */ + public byte[] xor(byte[] b1, byte[] b2) { + //TODO Check if length matters in the order, when b2 is smaller than b1 or viceversa + byte[] xor_digest = new BigInteger(1, b1).xor(new BigInteger(1, b2)).toByteArray(); + return ConfigHelper.trim(xor_digest); + } + + /** + * @returns The exponential residue (parameter A) to be sent to the server. + */ + public byte[] exponential() { + byte[] Abytes = null; + if (A == null) { /* If the random component of A has not been specified use a random number */ - if( a == null ) { - BigInteger one = BigInteger.ONE; - do { - a = new BigInteger(A_LEN, pseudoRng); - } while(a.compareTo(one) <= 0); - } - A = g.modPow(a, N); - Abytes = ConfigHelper.trim(A.toByteArray()); - } - return Abytes; - } - - /** - * Calculates the parameter M1, to be sent to the SRP server. - * It also updates hashes of client and server for further calculations in other methods. - * It uses a predefined k. - * @param salt_bytes - * @param Bbytes the parameter received from the server, in bytes - * @return the parameter M1 - * @throws NoSuchAlgorithmException - */ + if (a == null) { + BigInteger one = BigInteger.ONE; + do { + a = new BigInteger(A_LEN, pseudoRng); + } while (a.compareTo(one) <= 0); + } + A = g.modPow(a, N); + Abytes = ConfigHelper.trim(A.toByteArray()); + } + return Abytes; + } + + /** + * Calculates the parameter M1, to be sent to the SRP server. + * It also updates hashes of client and server for further calculations in other methods. + * It uses a predefined k. + * + * @param salt_bytes + * @param Bbytes the parameter received from the server, in bytes + * @return the parameter M1 + * @throws NoSuchAlgorithmException + */ public byte[] response(byte[] salt_bytes, byte[] Bbytes) { - // Calculate x = H(s | H(U | ':' | password)) - byte[] M1 = null; - if(new BigInteger(1, Bbytes).mod(new BigInteger(1, N_bytes)) != BigInteger.ZERO) { - this.v = calculateV(username, password, salt_bytes); - // H(N) - byte[] digest_of_n = newDigest().digest(N_bytes); - - // H(g) - byte[] digest_of_g = newDigest().digest(params.g); - - // clientHash = H(N) xor H(g) - byte[] xor_digest = xor(digest_of_n, digest_of_g); - clientHash.update(xor_digest); - - // clientHash = H(N) xor H(g) | H(U) - byte[] username_digest = newDigest().digest(ConfigHelper.trim(username.getBytes())); - username_digest = ConfigHelper.trim(username_digest); - clientHash.update(username_digest); - - // clientHash = H(N) xor H(g) | H(U) | s - clientHash.update(ConfigHelper.trim(salt_bytes)); - - K = null; - - // clientHash = H(N) xor H(g) | H(U) | A - byte[] Abytes = ConfigHelper.trim(A.toByteArray()); - clientHash.update(Abytes); - - // clientHash = H(N) xor H(g) | H(U) | s | A | B - Bbytes = ConfigHelper.trim(Bbytes); - clientHash.update(Bbytes); - - // Calculate S = (B - kg^x) ^ (a + u * x) % N - BigInteger S = calculateS(Bbytes); - byte[] S_bytes = ConfigHelper.trim(S.toByteArray()); - - // K = SessionHash(S) - MessageDigest sessionDigest = newDigest(); - K = ConfigHelper.trim(sessionDigest.digest(S_bytes)); - - // clientHash = H(N) xor H(g) | H(U) | A | B | K - clientHash.update(K); - - M1 = ConfigHelper.trim(clientHash.digest()); - - // serverHash = Astr + M + K - serverHash.update(Abytes); - serverHash.update(M1); - serverHash.update(K); - - } - return M1; - } - - /** - * It calculates the parameter S used by response() to obtain session hash K. - * @param Bbytes the parameter received from the server, in bytes - * @return the parameter S - */ - private BigInteger calculateS(byte[] Bbytes) { - byte[] Abytes = ConfigHelper.trim(A.toByteArray()); - Bbytes = ConfigHelper.trim(Bbytes); - byte[] u_bytes = getU(Abytes, Bbytes); - - BigInteger B = new BigInteger(1, Bbytes); - BigInteger u = new BigInteger(1, u_bytes); - String k_string = "bf66c44a428916cad64aa7c679f3fd897ad4c375e9bbb4cbf2f5de241d618ef0"; - BigInteger k = new BigInteger(k_string, 16); - BigInteger B_minus_v = B.subtract(k.multiply(v)); - BigInteger a_ux = a.add(u.multiply(x)); - BigInteger S = B_minus_v.modPow(a_ux, N); - return S; - } - - /** - * It calculates the parameter u used by calculateS to obtain S. - * @param Abytes the exponential residue sent to the server - * @param Bbytes the parameter received from the server, in bytes - * @return - */ - public byte[] getU(byte[] Abytes, byte[] Bbytes) { - MessageDigest u_digest = newDigest(); - u_digest.update(ConfigHelper.trim(Abytes)); - u_digest.update(ConfigHelper.trim(Bbytes)); - byte[] u_digest_bytes = u_digest.digest(); - return ConfigHelper.trim(new BigInteger(1, u_digest_bytes).toByteArray()); - } - - /** - * @param M2 The server's response to the client's challenge - * @returns True if and only if the server's response was correct. - */ - public boolean verify(byte[] M2) - { - // M2 = H(A | M1 | K) - M2 = ConfigHelper.trim(M2); - byte[] myM2 = ConfigHelper.trim(serverHash.digest()); - boolean valid = Arrays.equals(M2, myM2); - return valid; - } - - protected static void setToken(String token) { - LeapSRPSession.token = token; - } - - protected static String getToken() { - return token; - } + // Calculate x = H(s | H(U | ':' | password)) + byte[] M1 = null; + if (new BigInteger(1, Bbytes).mod(new BigInteger(1, N_bytes)) != BigInteger.ZERO) { + this.v = calculateV(username, password, salt_bytes); + // H(N) + byte[] digest_of_n = newDigest().digest(N_bytes); + + // H(g) + byte[] digest_of_g = newDigest().digest(params.g); + + // clientHash = H(N) xor H(g) + byte[] xor_digest = xor(digest_of_n, digest_of_g); + clientHash.update(xor_digest); + + // clientHash = H(N) xor H(g) | H(U) + byte[] username_digest = newDigest().digest(ConfigHelper.trim(username.getBytes())); + username_digest = ConfigHelper.trim(username_digest); + clientHash.update(username_digest); + + // clientHash = H(N) xor H(g) | H(U) | s + clientHash.update(ConfigHelper.trim(salt_bytes)); + + K = null; + + // clientHash = H(N) xor H(g) | H(U) | A + byte[] Abytes = ConfigHelper.trim(A.toByteArray()); + clientHash.update(Abytes); + + // clientHash = H(N) xor H(g) | H(U) | s | A | B + Bbytes = ConfigHelper.trim(Bbytes); + clientHash.update(Bbytes); + + // Calculate S = (B - kg^x) ^ (a + u * x) % N + BigInteger S = calculateS(Bbytes); + byte[] S_bytes = ConfigHelper.trim(S.toByteArray()); + + // K = SessionHash(S) + MessageDigest sessionDigest = newDigest(); + K = ConfigHelper.trim(sessionDigest.digest(S_bytes)); + + // clientHash = H(N) xor H(g) | H(U) | A | B | K + clientHash.update(K); + + M1 = ConfigHelper.trim(clientHash.digest()); + + // serverHash = Astr + M + K + serverHash.update(Abytes); + serverHash.update(M1); + serverHash.update(K); + + } + return M1; + } + + /** + * It calculates the parameter S used by response() to obtain session hash K. + * + * @param Bbytes the parameter received from the server, in bytes + * @return the parameter S + */ + private BigInteger calculateS(byte[] Bbytes) { + byte[] Abytes = ConfigHelper.trim(A.toByteArray()); + Bbytes = ConfigHelper.trim(Bbytes); + byte[] u_bytes = getU(Abytes, Bbytes); + + BigInteger B = new BigInteger(1, Bbytes); + BigInteger u = new BigInteger(1, u_bytes); + String k_string = "bf66c44a428916cad64aa7c679f3fd897ad4c375e9bbb4cbf2f5de241d618ef0"; + BigInteger k = new BigInteger(k_string, 16); + BigInteger B_minus_v = B.subtract(k.multiply(v)); + BigInteger a_ux = a.add(u.multiply(x)); + BigInteger S = B_minus_v.modPow(a_ux, N); + return S; + } + + /** + * It calculates the parameter u used by calculateS to obtain S. + * + * @param Abytes the exponential residue sent to the server + * @param Bbytes the parameter received from the server, in bytes + * @return + */ + public byte[] getU(byte[] Abytes, byte[] Bbytes) { + MessageDigest u_digest = newDigest(); + u_digest.update(ConfigHelper.trim(Abytes)); + u_digest.update(ConfigHelper.trim(Bbytes)); + byte[] u_digest_bytes = u_digest.digest(); + return ConfigHelper.trim(new BigInteger(1, u_digest_bytes).toByteArray()); + } + + /** + * @param M2 The server's response to the client's challenge + * @returns True if and only if the server's response was correct. + */ + public boolean verify(byte[] M2) { + // M2 = H(A | M1 | K) + M2 = ConfigHelper.trim(M2); + byte[] myM2 = ConfigHelper.trim(serverHash.digest()); + boolean valid = Arrays.equals(M2, myM2); + return valid; + } + + protected static void setToken(String token) { + LeapSRPSession.token = token; + } + + protected static String getToken() { + return token; + } protected static boolean loggedIn() { - return !token.isEmpty(); + return !token.isEmpty(); } - /** - * @return a new SHA-256 digest. - */ - public MessageDigest newDigest() - { - MessageDigest md = null; - try { - md = MessageDigest.getInstance("SHA-256"); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } - return md; - } + /** + * @return a new SHA-256 digest. + */ + public MessageDigest newDigest() { + MessageDigest md = null; + try { + md = MessageDigest.getInstance("SHA-256"); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + return md; + } public byte[] getK() { - return K; + return K; } } diff --git a/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java b/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java index 806d5602..073d727f 100644 --- a/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java +++ b/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java @@ -8,21 +8,21 @@ import se.leap.bitmaskclient.eip.*; public class OnBootReceiver extends BroadcastReceiver { SharedPreferences preferences; - + // Debug: am broadcast -a android.intent.action.BOOT_COMPLETED @Override public void onReceive(Context context, Intent intent) { - preferences = context.getSharedPreferences(Dashboard.SHARED_PREFERENCES, Context.MODE_PRIVATE); - boolean provider_configured = !preferences.getString(Provider.KEY, "").isEmpty(); - boolean start_on_boot = preferences.getBoolean(Dashboard.START_ON_BOOT, false); + preferences = context.getSharedPreferences(Dashboard.SHARED_PREFERENCES, Context.MODE_PRIVATE); + boolean provider_configured = !preferences.getString(Provider.KEY, "").isEmpty(); + boolean start_on_boot = preferences.getBoolean(Dashboard.START_ON_BOOT, false); Log.d("OnBootReceiver", "Provider configured " + String.valueOf(provider_configured)); Log.d("OnBootReceiver", "Start on boot " + String.valueOf(start_on_boot)); - if(provider_configured && start_on_boot) { - Intent dashboard_intent = new Intent(context, Dashboard.class); - 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); - } + if (provider_configured && start_on_boot) { + Intent dashboard_intent = new Intent(context, Dashboard.class); + 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/PRNGFixes.java b/app/src/main/java/se/leap/bitmaskclient/PRNGFixes.java index 33d2971d..9e523751 100644 --- a/app/src/main/java/se/leap/bitmaskclient/PRNGFixes.java +++ b/app/src/main/java/se/leap/bitmaskclient/PRNGFixes.java @@ -22,7 +22,7 @@ import java.security.Provider; /** * Fixes for the output of the default PRNG having low entropy. - * + *

* The fixes need to be applied via {@link #apply()} before any use of Java * Cryptography Architecture primitives. A good place to invoke them is in the * application's {@code onCreate}. @@ -32,10 +32,13 @@ public final class PRNGFixes { private static final int VERSION_CODE_JELLY_BEAN = 16; private static final int VERSION_CODE_JELLY_BEAN_MR2 = 18; private static final byte[] BUILD_FINGERPRINT_AND_DEVICE_SERIAL = - getBuildFingerprintAndDeviceSerial(); + getBuildFingerprintAndDeviceSerial(); - /** Hidden constructor to prevent instantiation. */ - private PRNGFixes() {} + /** + * Hidden constructor to prevent instantiation. + */ + private PRNGFixes() { + } /** * Applies all fixes. @@ -102,7 +105,7 @@ public final class PRNGFixes { if ((secureRandomProviders == null) || (secureRandomProviders.length < 1) || (!LinuxPRNGSecureRandomProvider.class.equals( - secureRandomProviders[0].getClass()))) { + secureRandomProviders[0].getClass()))) { Security.insertProviderAt(new LinuxPRNGSecureRandomProvider(), 1); } @@ -127,7 +130,7 @@ public final class PRNGFixes { rng2.getProvider().getClass())) { throw new SecurityException( "SecureRandom.getInstance(\"SHA1PRNG\") backed by wrong" - + " Provider: " + rng2.getProvider().getClass()); + + " Provider: " + rng2.getProvider().getClass()); } } @@ -141,7 +144,7 @@ public final class PRNGFixes { super("LinuxPRNG", 1.0, "A Linux-specific random number provider that uses" - + " /dev/urandom"); + + " /dev/urandom"); // Although /dev/urandom is not a SHA-1 PRNG, some apps // explicitly request a SHA1PRNG SecureRandom and we thus need to // prevent them from getting the default implementation whose output diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java index f45eccdd..ee06a586 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Provider.java +++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java @@ -1,6 +1,6 @@ /** * 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 @@ -27,46 +27,45 @@ import java.util.*; /** * @author Sean Leonard * @author Parménides GV - * */ public final class Provider implements Parcelable { - private JSONObject definition; // Represents our Provider's provider.json + private JSONObject definition; // Represents our Provider's provider.json private URL main_url; final public static String - API_URL = "api_uri", - API_VERSION = "api_version", - ALLOW_REGISTRATION = "allow_registration", - API_RETURN_SERIAL = "serial", - SERVICE = "service", - KEY = "provider", - CA_CERT = "ca_cert", - CA_CERT_URI = "ca_cert_uri", - CA_CERT_FINGERPRINT = "ca_cert_fingerprint", - NAME = "name", - DESCRIPTION = "description", - DOMAIN = "domain", - MAIN_URL = "main_url", - DOT_JSON_URL = "provider_json_url" - ; - - // Array of what API versions we understand - protected static final String[] API_VERSIONS = {"1"}; // I assume we might encounter arbitrary version "numbers" - // Some API pieces we want to know about - private static final String API_TERM_SERVICES = "services"; - private static final String API_TERM_NAME = "name"; - private static final String API_TERM_DOMAIN = "domain"; - private static final String API_TERM_DEFAULT_LANGUAGE = "default_language"; - protected static final String[] API_EIP_TYPES = {"openvpn"}; - - public Provider(URL main_url) { + API_URL = "api_uri", + API_VERSION = "api_version", + ALLOW_REGISTRATION = "allow_registration", + API_RETURN_SERIAL = "serial", + SERVICE = "service", + KEY = "provider", + CA_CERT = "ca_cert", + CA_CERT_URI = "ca_cert_uri", + CA_CERT_FINGERPRINT = "ca_cert_fingerprint", + NAME = "name", + DESCRIPTION = "description", + DOMAIN = "domain", + MAIN_URL = "main_url", + DOT_JSON_URL = "provider_json_url"; + + // Array of what API versions we understand + protected static final String[] API_VERSIONS = {"1"}; // I assume we might encounter arbitrary version "numbers" + // Some API pieces we want to know about + private static final String API_TERM_SERVICES = "services"; + private static final String API_TERM_NAME = "name"; + private static final String API_TERM_DOMAIN = "domain"; + private static final String API_TERM_DEFAULT_LANGUAGE = "default_language"; + protected static final String[] API_EIP_TYPES = {"openvpn"}; + + public Provider(URL main_url) { this.main_url = main_url; } public Provider(File provider_file) { } + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { public Provider createFromParcel(Parcel in) { @@ -82,7 +81,7 @@ public final class Provider implements Parcelable { try { main_url = new URL(in.readString()); String definition_string = in.readString(); - if(definition_string != null) + if (definition_string != null) definition = new JSONObject((definition_string)); } catch (MalformedURLException e) { e.printStackTrace(); @@ -95,60 +94,62 @@ public final class Provider implements Parcelable { definition = provider_json; } - protected JSONObject definition() { return definition; } + protected JSONObject definition() { + return definition; + } - protected String getDomain(){ - return main_url.getHost(); - } + protected String getDomain() { + return main_url.getHost(); + } protected URL mainUrl() { return main_url; } - - protected String getName(){ - // Should we pass the locale in, or query the system here? - String lang = Locale.getDefault().getLanguage(); - String name = ""; - try { - if(definition != null) - name = definition.getJSONObject(API_TERM_NAME).getString(lang); + + protected String getName() { + // Should we pass the locale in, or query the system here? + String lang = Locale.getDefault().getLanguage(); + String name = ""; + try { + if (definition != null) + name = definition.getJSONObject(API_TERM_NAME).getString(lang); else throw new JSONException("Provider not defined"); - } catch (JSONException e) { - if(main_url != null) { + } catch (JSONException e) { + if (main_url != null) { String host = main_url.getHost(); name = host.substring(0, host.indexOf(".")); } - } - - return name; - } - - protected String getDescription(){ - String lang = Locale.getDefault().getLanguage(); - String desc = null; - try { - desc = definition.getJSONObject("description").getString(lang); - } catch (JSONException e) { - // TODO: handle exception!! - try { - desc = definition.getJSONObject("description").getString( definition.getString("default_language") ); - } catch (JSONException e2) { - // TODO: i can't believe you're doing it again! - } - } - - return desc; - } - - protected boolean hasEIP() { - try { + } + + return name; + } + + protected String getDescription() { + String lang = Locale.getDefault().getLanguage(); + String desc = null; + try { + desc = definition.getJSONObject("description").getString(lang); + } catch (JSONException e) { + // TODO: handle exception!! + try { + desc = definition.getJSONObject("description").getString(definition.getString("default_language")); + } catch (JSONException e2) { + // TODO: i can't believe you're doing it again! + } + } + + return desc; + } + + protected boolean hasEIP() { + try { JSONArray services = definition.getJSONArray(API_TERM_SERVICES); // returns ["openvpn"] - for (int i=0;i { - private static boolean[] hidden = null; - - public void hide(int position) { - hidden[getRealPosition(position)] = true; - notifyDataSetChanged(); - notifyDataSetInvalidated(); - } - - public void unHide(int position) { - hidden[getRealPosition(position)] = false; - notifyDataSetChanged(); - notifyDataSetInvalidated(); - } + private static boolean[] hidden = null; + + public void hide(int position) { + hidden[getRealPosition(position)] = true; + notifyDataSetChanged(); + notifyDataSetInvalidated(); + } + + public void unHide(int position) { + hidden[getRealPosition(position)] = false; + notifyDataSetChanged(); + notifyDataSetInvalidated(); + } public void showAllProviders() { - for(int i = 0; i < hidden.length; i++) + for (int i = 0; i < hidden.length; i++) hidden[i] = false; notifyDataSetChanged(); notifyDataSetInvalidated(); } - + public void hideAllBut(int position) { - for (int i = 0; i < hidden.length; i++) { + for (int i = 0; i < hidden.length; i++) { if (i != position) hidden[i] = true; else @@ -38,64 +38,66 @@ public class ProviderListAdapter extends RendererAdapter { notifyDataSetChanged(); notifyDataSetInvalidated(); } - - private int getRealPosition(int position) { - int hElements = getHiddenCountUpTo(position); - int diff = 0; - for(int i=0;i collection) { - super(layoutInflater, rendererBuilder, collection); - hidden = new boolean[collection.size()]; - for (int i = 0; i < collection.size(); i++) - hidden[i] = false; + super(layoutInflater, rendererBuilder, collection); + hidden = new boolean[collection.size()]; + for (int i = 0; i < collection.size(); i++) + hidden[i] = false; } - - @Override - public void add(Provider item) { - super.add(item); - if(getCollection().size() > hidden.length) { + + @Override + public void add(Provider item) { + super.add(item); + if (getCollection().size() > hidden.length) { boolean[] new_hidden = new boolean[hidden.length + 1]; System.arraycopy(hidden, 0, new_hidden, 0, hidden.length); new_hidden[hidden.length] = false; hidden = new_hidden; } - } - - @Override - public void remove(Provider item) { - super.remove(item); - boolean[] new_hidden = new boolean[hidden.length-1]; - System.arraycopy(hidden, 0, new_hidden, 0, hidden.length-1); - hidden = new_hidden; - } + } + + @Override + public void remove(Provider item) { + super.remove(item); + boolean[] new_hidden = new boolean[hidden.length - 1]; + System.arraycopy(hidden, 0, new_hidden, 0, hidden.length - 1); + hidden = new_hidden; + } protected int indexOf(Provider item) { int index = 0; diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java b/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java index 56b38a29..40fe8b5a 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java @@ -1,7 +1,9 @@ package se.leap.bitmaskclient; import android.content.res.*; + import com.pedrogomez.renderers.*; + import org.json.*; import java.io.*; @@ -23,7 +25,7 @@ public class ProviderManager implements AdapteeCollection { final protected static String URLS = "urls"; public static ProviderManager getInstance(AssetManager assets_manager, File external_files_dir) { - if(instance == null) + if (instance == null) instance = new ProviderManager(assets_manager); instance.addCustomProviders(external_files_dir); @@ -46,10 +48,10 @@ public class ProviderManager implements AdapteeCollection { private Set providersFromAssets(String directory, String[] relative_file_paths) { Set providers = new HashSet(); try { - for(String file : relative_file_paths) { - String main_url = extractMainUrlFromInputStream(assets_manager.open(directory + "/" + file)); + for (String file : relative_file_paths) { + String main_url = extractMainUrlFromInputStream(assets_manager.open(directory + "/" + file)); providers.add(new Provider(new URL(main_url))); - } + } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { @@ -69,7 +71,7 @@ public class ProviderManager implements AdapteeCollection { private Set providersFromFiles(String[] files) { Set providers = new HashSet(); try { - for(String file : files) { + for (String file : files) { String main_url = extractMainUrlFromInputStream(new FileInputStream(external_files_dir.getAbsolutePath() + "/" + file)); providers.add(new Provider(new URL(main_url))); } @@ -87,7 +89,7 @@ public class ProviderManager implements AdapteeCollection { byte[] bytes = new byte[0]; try { bytes = new byte[input_stream_file_contents.available()]; - if(input_stream_file_contents.read(bytes) > 0) { + if (input_stream_file_contents.read(bytes) > 0) { JSONObject file_contents = new JSONObject(new String(bytes)); main_url = file_contents.getString(Provider.MAIN_URL); } @@ -114,7 +116,7 @@ public class ProviderManager implements AdapteeCollection { @Override public Provider get(int index) { Iterator iterator = providers().iterator(); - while(iterator.hasNext() && index > 0) { + while (iterator.hasNext() && index > 0) { iterator.next(); index--; } @@ -123,7 +125,7 @@ public class ProviderManager implements AdapteeCollection { @Override public void add(Provider element) { - if(!default_providers.contains(element)) + if (!default_providers.contains(element)) custom_providers.add(element); } @@ -150,17 +152,17 @@ public class ProviderManager implements AdapteeCollection { } protected void saveCustomProvidersToFile() { - try { - for (Provider provider : custom_providers) { + try { + for (Provider provider : custom_providers) { File provider_file = new File(external_files_dir, provider.getName() + ".json"); - if(!provider_file.exists()) { - FileWriter writer = new FileWriter(provider_file); - writer.write(provider.toJson().toString()); - writer.close(); + if (!provider_file.exists()) { + FileWriter writer = new FileWriter(provider_file); + writer.write(provider.toJson().toString()); + writer.close(); + } } - } - } catch (IOException e) { - e.printStackTrace(); - } + } catch (IOException e) { + e.printStackTrace(); + } } } diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderRendererBuilder.java b/app/src/main/java/se/leap/bitmaskclient/ProviderRendererBuilder.java index 1b42e349..5a6e857d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderRendererBuilder.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderRendererBuilder.java @@ -1,17 +1,19 @@ package se.leap.bitmaskclient; import com.pedrogomez.renderers.*; + import java.util.*; /** * Created by parmegv on 4/12/14. */ - public class ProviderRendererBuilder extends RendererBuilder { - public ProviderRendererBuilder(Collection> prototypes) { - super(prototypes); - } - @Override - protected Class getPrototypeClass(Provider content) { - return ProviderRenderer.class; +public class ProviderRendererBuilder extends RendererBuilder { + public ProviderRendererBuilder(Collection> prototypes) { + super(prototypes); + } + + @Override + protected Class getPrototypeClass(Provider content) { + return ProviderRenderer.class; } } diff --git a/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java b/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java index 6346fc36..e92c6b7b 100644 --- a/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java @@ -1,6 +1,6 @@ /** * 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 @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - package se.leap.bitmaskclient; +package se.leap.bitmaskclient; import android.app.*; import android.content.*; @@ -26,21 +26,21 @@ import butterknife.*; /** * Implements the log in dialog, currently without progress dialog. - * + *

* It returns to the previous fragment when finished, and sends username and password to the authenticate method. - * - * It also notifies the user if the password is not valid. - * - * @author parmegv + *

+ * It also notifies the user if the password is not valid. * + * @author parmegv */ -public class SessionDialog extends DialogFragment{ +public class SessionDialog extends DialogFragment { + - final public static String TAG = SessionDialog.class.getSimpleName(); final public static String USERNAME = "username"; final public static String PASSWORD = "password"; + public static enum ERRORS { USERNAME_MISSING, PASSWORD_INVALID_LENGTH, @@ -59,66 +59,67 @@ public class SessionDialog extends DialogFragment{ public SessionDialog() { setArguments(Bundle.EMPTY); } - - public AlertDialog onCreateDialog(Bundle savedInstanceState) { - - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - LayoutInflater inflater = getActivity().getLayoutInflater(); - View view = inflater.inflate(R.layout.session_dialog, null); - ButterKnife.inject(this, view); - - Bundle arguments = getArguments(); - if (arguments != Bundle.EMPTY) { + + public AlertDialog onCreateDialog(Bundle savedInstanceState) { + + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + LayoutInflater inflater = getActivity().getLayoutInflater(); + View view = inflater.inflate(R.layout.session_dialog, null); + ButterKnife.inject(this, view); + + Bundle arguments = getArguments(); + if (arguments != Bundle.EMPTY) { setUp(arguments); - } - - builder.setView(view) - .setPositiveButton(R.string.login_button, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - String username = getEnteredUsername(); - String password = getEnteredPassword(); - dialog.dismiss(); - interface_with_Dashboard.logIn(username, password); - } - }) - .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - interface_with_Dashboard.cancelLoginOrSignup(); - } - }) - .setNeutralButton(R.string.signup_button, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - String username = getEnteredUsername(); - String password = getEnteredPassword(); - dialog.dismiss(); - interface_with_Dashboard.signUp(username, password); - } - }); - - return builder.create(); - } + } + + builder.setView(view) + .setPositiveButton(R.string.login_button, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + String username = getEnteredUsername(); + String password = getEnteredPassword(); + dialog.dismiss(); + interface_with_Dashboard.logIn(username, password); + } + }) + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + interface_with_Dashboard.cancelLoginOrSignup(); + } + }) + .setNeutralButton(R.string.signup_button, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + String username = getEnteredUsername(); + String password = getEnteredPassword(); + dialog.dismiss(); + interface_with_Dashboard.signUp(username, password); + } + }); + + return builder.create(); + } private void setUp(Bundle arguments) { is_eip_pending = arguments.getBoolean(EipFragment.IS_PENDING, false); if (arguments.containsKey(ERRORS.PASSWORD_INVALID_LENGTH.toString())) password_field.setError(getString(R.string.error_not_valid_password_user_message)); - else if(arguments.containsKey(ERRORS.RISEUP_WARNING.toString())) { + else if (arguments.containsKey(ERRORS.RISEUP_WARNING.toString())) { user_message.setVisibility(TextView.VISIBLE); user_message.setText(R.string.login_riseup_warning); - } if (arguments.containsKey(USERNAME)) { + } + if (arguments.containsKey(USERNAME)) { String username = arguments.getString(USERNAME); username_field.setText(username); } if (arguments.containsKey(ERRORS.USERNAME_MISSING.toString())) { username_field.setError(getString(R.string.username_ask)); } - if(arguments.containsKey(getString(R.string.user_message))) + if (arguments.containsKey(getString(R.string.user_message))) user_message.setText(arguments.getString(getString(R.string.user_message))); - else if(user_message.getVisibility() != TextView.VISIBLE) + else if (user_message.getVisibility() != TextView.VISIBLE) user_message.setVisibility(View.GONE); - if(!username_field.getText().toString().isEmpty() && password_field.isFocusable()) + if (!username_field.getText().toString().isEmpty() && password_field.isFocusable()) password_field.requestFocus(); } @@ -131,26 +132,27 @@ public class SessionDialog extends DialogFragment{ return password_field.getText().toString(); } - - /** - * Interface used to communicate SessionDialog with Dashboard. - * - * @author parmegv - * - */ - public interface SessionDialogInterface { - public void logIn(String username, String password); - public void signUp(String username, String password); - public void cancelLoginOrSignup(); + + /** + * Interface used to communicate SessionDialog with Dashboard. + * + * @author parmegv + */ + public interface SessionDialogInterface { + public void logIn(String username, String password); + + public void signUp(String username, String password); + + public void cancelLoginOrSignup(); } - SessionDialogInterface interface_with_Dashboard; - + SessionDialogInterface interface_with_Dashboard; + @Override public void onAttach(Activity activity) { super.onAttach(activity); try { - interface_with_Dashboard = (SessionDialogInterface) activity; + interface_with_Dashboard = (SessionDialogInterface) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement LogInDialogListener"); @@ -159,8 +161,8 @@ public class SessionDialog extends DialogFragment{ @Override public void onCancel(DialogInterface dialog) { - super.onCancel(dialog); - if(is_eip_pending) - interface_with_Dashboard.cancelLoginOrSignup(); + super.onCancel(dialog); + if (is_eip_pending) + interface_with_Dashboard.cancelLoginOrSignup(); } } diff --git a/app/src/main/java/se/leap/bitmaskclient/User.java b/app/src/main/java/se/leap/bitmaskclient/User.java index 6e20c165..4bbd9a91 100644 --- a/app/src/main/java/se/leap/bitmaskclient/User.java +++ b/app/src/main/java/se/leap/bitmaskclient/User.java @@ -1,6 +1,6 @@ /** * 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 @@ -19,21 +19,24 @@ package se.leap.bitmaskclient; public class User { private static String user_name = "You"; private static User user; - + public static User getInstance() { - if(user == null) { - user = new User(); - } - return user; + if (user == null) { + user = new User(); + } + return user; } public static void setUserName(String user_name) { - User.user_name = user_name; + User.user_name = user_name; } - private User() { } - - public static String userName() { return user_name; } + private User() { + } + + public static String userName() { + return user_name; + } public static boolean loggedIn() { return LeapSRPSession.loggedIn(); diff --git a/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java b/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java index db432a82..369df1a3 100644 --- a/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java @@ -1,6 +1,6 @@ /** * 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 @@ -25,47 +25,50 @@ public class UserSessionStatus extends Observable { private static UserSessionStatus current_status; public enum SessionStatus { - LOGGED_IN, - LOGGED_OUT, - NOT_LOGGED_IN, - DIDNT_LOG_OUT, - LOGGING_IN, - LOGGING_OUT, + LOGGED_IN, + LOGGED_OUT, + NOT_LOGGED_IN, + DIDNT_LOG_OUT, + LOGGING_IN, + LOGGING_OUT, SIGNING_UP } private static SessionStatus session_status = SessionStatus.NOT_LOGGED_IN; - + public static UserSessionStatus getInstance() { - if(current_status == null) { - current_status = new UserSessionStatus(); - } - return current_status; + if (current_status == null) { + current_status = new UserSessionStatus(); + } + return current_status; } - private UserSessionStatus() { } + private UserSessionStatus() { + } private void sessionStatus(SessionStatus session_status) { - this.session_status = session_status; + this.session_status = session_status; } - public SessionStatus sessionStatus() { return session_status; } + public SessionStatus sessionStatus() { + return session_status; + } public boolean inProgress() { return session_status == SessionStatus.LOGGING_IN || session_status == SessionStatus.LOGGING_OUT; } - + public static void updateStatus(SessionStatus session_status) { - current_status = getInstance(); - current_status.sessionStatus(session_status); - current_status.setChanged(); - current_status.notifyObservers(); + current_status = getInstance(); + current_status.sessionStatus(session_status); + current_status.setChanged(); + current_status.notifyObservers(); } @Override public String toString() { - return User.userName() + " is " - + session_status.toString().toLowerCase().replaceAll("_", " "); + return User.userName() + " is " + + session_status.toString().toLowerCase().replaceAll("_", " "); } } 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 f7206927..39ad7c08 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java @@ -1,6 +1,6 @@ /** * 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 @@ -17,16 +17,14 @@ package se.leap.bitmaskclient.eip; /** - * * Constants for intent passing, shared preferences * * @author Parménides GV - * */ public interface Constants { public final static String TAG = Constants.class.getSimpleName(); - + 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"; 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 6335f818..beed7948 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -1,6 +1,6 @@ /** * 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 @@ -33,7 +33,7 @@ import static se.leap.bitmaskclient.eip.Constants.*; * this IntentService. * Contains logic for parsing eip-service.json from the provider, configuring and selecting * gateways, and controlling {@link de.blinkt.openvpn.core.OpenVPNService} connections. - * + * * @author Sean Leonard * @author Parménides GV */ @@ -43,64 +43,64 @@ public final class EIP extends IntentService { 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; private static GatewaysManager gateways_manager = new GatewaysManager(); private static Gateway gateway; - - public EIP(){ - super(TAG); + + public EIP() { + super(TAG); } - + @Override public void onCreate() { - super.onCreate(); - - context = getApplicationContext(); + super.onCreate(); + + context = getApplicationContext(); preferences = getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE); - eip_definition = eipDefinitionFromPreferences(); - if(gateways_manager.isEmpty()) + eip_definition = eipDefinitionFromPreferences(); + if (gateways_manager.isEmpty()) gatewaysFromPreferences(); } @Override protected void onHandleIntent(Intent intent) { - String action = intent.getAction(); - mReceiver = intent.getParcelableExtra(RECEIVER_TAG); - - if ( action.equals(ACTION_START_EIP)) - startEIP(); - else if (action.equals(ACTION_STOP_EIP)) - stopEIP(); - else if (action.equals(ACTION_IS_EIP_RUNNING)) - isRunning(); + String action = intent.getAction(); + mReceiver = intent.getParcelableExtra(RECEIVER_TAG); + + if (action.equals(ACTION_START_EIP)) + startEIP(); + else if (action.equals(ACTION_STOP_EIP)) + stopEIP(); + else if (action.equals(ACTION_IS_EIP_RUNNING)) + isRunning(); else if (action.equals(ACTION_UPDATE_EIP_SERVICE)) - updateEIPService(); - else if (action.equals(ACTION_CHECK_CERT_VALIDITY)) - checkCertValidity(); + updateEIPService(); + else if (action.equals(ACTION_CHECK_CERT_VALIDITY)) + checkCertValidity(); } - + /** * Initiates an EIP connection by selecting a gateway and preparing and sending an * Intent to {@link de.blinkt.openvpn.LaunchVPN}. * It also sets up early routes. */ private void startEIP() { - if(gateways_manager.isEmpty()) - updateEIPService(); + if (gateways_manager.isEmpty()) + updateEIPService(); earlyRoutes(); - gateway = gateways_manager.select(); - if(gateway != null && gateway.getProfile() != null) { - mReceiver = EipFragment.getReceiver(); - launchActiveGateway(); - tellToReceiver(ACTION_START_EIP, Activity.RESULT_OK); - } else - tellToReceiver(ACTION_START_EIP, Activity.RESULT_CANCELED); + gateway = gateways_manager.select(); + if (gateway != null && gateway.getProfile() != null) { + mReceiver = EipFragment.getReceiver(); + launchActiveGateway(); + tellToReceiver(ACTION_START_EIP, Activity.RESULT_OK); + } else + tellToReceiver(ACTION_START_EIP, Activity.RESULT_CANCELED); } /** @@ -108,40 +108,40 @@ public final class EIP extends IntentService { * VpnService is started properly. */ private void earlyRoutes() { - Intent void_vpn_launcher = new Intent(context, VoidVpnLauncher.class); - void_vpn_launcher.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(void_vpn_launcher); + Intent void_vpn_launcher = new Intent(context, VoidVpnLauncher.class); + void_vpn_launcher.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(void_vpn_launcher); } - + private void launchActiveGateway() { - Intent intent = new Intent(this,LaunchVPN.class); - intent.setAction(Intent.ACTION_MAIN); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.putExtra(LaunchVPN.EXTRA_NAME, gateway.getProfile().getName()); - intent.putExtra(LaunchVPN.EXTRA_HIDELOG, true); - startActivity(intent); + Intent intent = new Intent(this, LaunchVPN.class); + intent.setAction(Intent.ACTION_MAIN); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.putExtra(LaunchVPN.EXTRA_NAME, gateway.getProfile().getName()); + intent.putExtra(LaunchVPN.EXTRA_HIDELOG, true); + startActivity(intent); } private void stopEIP() { - EipStatus eip_status = EipStatus.getInstance(); - int result_code = Activity.RESULT_CANCELED; - if(eip_status.isConnected() || eip_status.isConnecting()) - result_code = Activity.RESULT_OK; + EipStatus eip_status = EipStatus.getInstance(); + int result_code = Activity.RESULT_CANCELED; + if (eip_status.isConnected() || eip_status.isConnecting()) + result_code = Activity.RESULT_OK; - tellToReceiver(ACTION_STOP_EIP, result_code); + tellToReceiver(ACTION_STOP_EIP, result_code); } - + /** * Checks the last stored status notified by ics-openvpn * Sends Activity.RESULT_CANCELED to the ResultReceiver that made the * request if it's not connected, Activity.RESULT_OK otherwise. */ private void isRunning() { - EipStatus eip_status = EipStatus.getInstance(); - int resultCode = (eip_status.isConnected()) ? - Activity.RESULT_OK : - Activity.RESULT_CANCELED; - tellToReceiver(ACTION_IS_EIP_RUNNING, resultCode); + EipStatus eip_status = EipStatus.getInstance(); + int resultCode = (eip_status.isConnected()) ? + Activity.RESULT_OK : + Activity.RESULT_CANCELED; + tellToReceiver(ACTION_IS_EIP_RUNNING, resultCode); } /** @@ -149,27 +149,27 @@ public final class EIP extends IntentService { * TODO Implement API call to refresh eip-service.json from the provider */ private void updateEIPService() { - eip_definition = eipDefinitionFromPreferences(); - if(eip_definition.length() > 0) + eip_definition = eipDefinitionFromPreferences(); + if (eip_definition.length() > 0) updateGateways(); - tellToReceiver(ACTION_UPDATE_EIP_SERVICE, Activity.RESULT_OK); + tellToReceiver(ACTION_UPDATE_EIP_SERVICE, Activity.RESULT_OK); } private JSONObject eipDefinitionFromPreferences() { JSONObject result = new JSONObject(); - try { - String eip_definition_string = preferences.getString(KEY, ""); - if(!eip_definition_string.isEmpty()) { - result = new JSONObject(eip_definition_string); - } - } catch (JSONException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + try { + String eip_definition_string = preferences.getString(KEY, ""); + if (!eip_definition_string.isEmpty()) { + result = new JSONObject(eip_definition_string); + } + } catch (JSONException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } return result; } - private void updateGateways(){ + private void updateGateways() { gateways_manager.fromEipServiceJson(eip_definition); gatewaysToPreferences(); } @@ -187,15 +187,15 @@ public final class EIP extends IntentService { } private void checkCertValidity() { - VpnCertificateValidator validator = new VpnCertificateValidator(preferences.getString(CERTIFICATE, "")); - int resultCode = validator.isValid() ? - Activity.RESULT_OK : - Activity.RESULT_CANCELED; - tellToReceiver(ACTION_CHECK_CERT_VALIDITY, resultCode); + VpnCertificateValidator validator = new VpnCertificateValidator(preferences.getString(CERTIFICATE, "")); + int resultCode = validator.isValid() ? + Activity.RESULT_OK : + Activity.RESULT_CANCELED; + tellToReceiver(ACTION_CHECK_CERT_VALIDITY, resultCode); } private void tellToReceiver(String action, int resultCode) { - if (mReceiver != null){ + if (mReceiver != null) { Bundle resultData = new Bundle(); resultData.putString(REQUEST_TAG, action); mReceiver.send(resultCode, resultData); 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 d1ed0d27..e636c693 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java @@ -1,6 +1,6 @@ /** * 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 @@ -34,104 +34,105 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { private int localized_res_id; public static EipStatus getInstance() { - if(current_status == null) { - current_status = new EipStatus(); - VpnStatus.addStateListener(current_status); - } - return current_status; + if (current_status == null) { + current_status = new EipStatus(); + VpnStatus.addStateListener(current_status); + } + return current_status; } - private EipStatus() { } + private EipStatus() { + } @Override public void updateState(final String state, final String logmessage, final int localizedResId, final VpnStatus.ConnectionStatus level) { - updateStatus(state, logmessage, localizedResId, level); - if(isConnected() || isDisconnected()) { - setConnectedOrDisconnected(); - } else if(isConnecting()) - setConnecting(); - Log.d(TAG, "update state with level " + level); + updateStatus(state, logmessage, localizedResId, level); + if (isConnected() || isDisconnected()) { + setConnectedOrDisconnected(); + } else if (isConnecting()) + setConnecting(); + Log.d(TAG, "update state with level " + level); } private void updateStatus(final String state, final String logmessage, final int localizedResId, final VpnStatus.ConnectionStatus level) { - current_status = getInstance(); - current_status.setState(state); - current_status.setLogMessage(logmessage); - current_status.setLocalizedResId(localizedResId); - current_status.setLevel(level); - current_status.setChanged(); + current_status = getInstance(); + current_status.setState(state); + current_status.setLogMessage(logmessage); + current_status.setLocalizedResId(localizedResId); + current_status.setLevel(level); + current_status.setChanged(); } public boolean wantsToDisconnect() { - return wants_to_disconnect; + return wants_to_disconnect; } public boolean isConnecting() { - return - !isConnected() && - !isDisconnected() && - !isPaused(); + return + !isConnected() && + !isDisconnected() && + !isPaused(); } public boolean isConnected() { - return level == VpnStatus.ConnectionStatus.LEVEL_CONNECTED; + return level == VpnStatus.ConnectionStatus.LEVEL_CONNECTED; } public boolean isDisconnected() { - return level == VpnStatus.ConnectionStatus.LEVEL_NOTCONNECTED; + return level == VpnStatus.ConnectionStatus.LEVEL_NOTCONNECTED; } public boolean isPaused() { - return level == VpnStatus.ConnectionStatus.LEVEL_VPNPAUSED; + return level == VpnStatus.ConnectionStatus.LEVEL_VPNPAUSED; } public void setConnecting() { - wants_to_disconnect = false; - current_status.setChanged(); - current_status.notifyObservers(); + wants_to_disconnect = false; + current_status.setChanged(); + current_status.notifyObservers(); } public void setConnectedOrDisconnected() { - Log.d(TAG, "setConnectedOrDisconnected()"); - wants_to_disconnect = false; - current_status.setChanged(); - current_status.notifyObservers(); + Log.d(TAG, "setConnectedOrDisconnected()"); + wants_to_disconnect = false; + current_status.setChanged(); + current_status.notifyObservers(); } public void setDisconnecting() { - wants_to_disconnect = false; + wants_to_disconnect = false; } public String getState() { - return state; + return state; } public String getLogMessage() { - return log_message; + return log_message; } public int getLocalizedResId() { - return localized_res_id; + return localized_res_id; } public VpnStatus.ConnectionStatus getLevel() { - return level; + return level; } private void setState(String state) { - this.state = state; + this.state = state; } private void setLogMessage(String log_message) { - this.log_message = log_message; + this.log_message = log_message; } private void setLocalizedResId(int localized_res_id) { - this.localized_res_id = localized_res_id; + this.localized_res_id = localized_res_id; } private void setLevel(VpnStatus.ConnectionStatus level) { - EipStatus.level = level; + EipStatus.level = level; } public boolean errorInLast(int lines, Context context) { @@ -141,9 +142,9 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { VpnStatus.LogItem[] log = VpnStatus.getlogbuffer(); String message = ""; for (int i = 1; i <= lines && log.length > i; i++) { - message = log[log.length-i].getString(context); - for(int j = 0; j < error_keywords.length; j++) - if(message.contains(error_keywords[j])) + message = log[log.length - i].getString(context); + for (int j = 0; j < error_keywords.length; j++) + if (message.contains(error_keywords[j])) result = true; } return result; @@ -151,7 +152,7 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { @Override public String toString() { - return "State: " + state + " Level: " + level.toString(); + return "State: " + state + " Level: " + level.toString(); } } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java index 10ddc0ef..b2c7af8c 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java @@ -1,6 +1,6 @@ /** * 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 @@ -21,6 +21,7 @@ import android.util.*; import com.google.gson.*; import org.json.*; + import java.io.*; import de.blinkt.openvpn.*; @@ -30,12 +31,12 @@ import de.blinkt.openvpn.core.*; * Gateway provides objects defining gateways and their metadata. * Each instance contains a VpnProfile for OpenVPN specific data and member * variables describing capabilities and location (name) - * + * * @author Sean Leonard * @author Parménides GV */ public class Gateway { - + public final static String TAG = Gateway.class.getSimpleName(); private JSONObject general_configuration; @@ -45,86 +46,87 @@ public class Gateway { private String mName; private int timezone; private VpnProfile mVpnProfile; + /** * Build a gateway object from a JSON OpenVPN gateway definition in eip-service.json * and create a VpnProfile belonging to it. */ - public Gateway(JSONObject eip_definition, JSONObject secrets, JSONObject gateway){ + public Gateway(JSONObject eip_definition, JSONObject secrets, JSONObject gateway) { - this.gateway = gateway; + this.gateway = gateway; this.secrets = secrets; - general_configuration = getGeneralConfiguration(eip_definition); - timezone = getTimezone(eip_definition); - mName = locationAsName(eip_definition); + general_configuration = getGeneralConfiguration(eip_definition); + timezone = getTimezone(eip_definition); + mName = locationAsName(eip_definition); - mVpnProfile = createVPNProfile(); - mVpnProfile.mName = mName; + mVpnProfile = createVPNProfile(); + mVpnProfile.mName = mName; } private JSONObject getGeneralConfiguration(JSONObject eip_definition) { - try { - return eip_definition.getJSONObject("openvpn_configuration"); - } catch (JSONException e) { - return new JSONObject(); - } + try { + return eip_definition.getJSONObject("openvpn_configuration"); + } catch (JSONException e) { + return new JSONObject(); + } } private int getTimezone(JSONObject eip_definition) { - JSONObject location = getLocationInfo(eip_definition); - return location.optInt("timezone"); + JSONObject location = getLocationInfo(eip_definition); + return location.optInt("timezone"); } private String locationAsName(JSONObject eip_definition) { - JSONObject location = getLocationInfo(eip_definition); - return location.optString("name"); + JSONObject location = getLocationInfo(eip_definition); + return location.optString("name"); } private JSONObject getLocationInfo(JSONObject eip_definition) { - try { - JSONObject locations = eip_definition.getJSONObject("locations"); + try { + JSONObject locations = eip_definition.getJSONObject("locations"); - return locations.getJSONObject(gateway.getString("location")); - } catch (JSONException e) { - return new JSONObject(); - } + return locations.getJSONObject(gateway.getString("location")); + } catch (JSONException e) { + return new JSONObject(); + } } - + /** * Create and attach the VpnProfile to our gateway object */ - private VpnProfile createVPNProfile(){ - try { - ConfigParser cp = new ConfigParser(); - - VpnConfigGenerator vpn_configuration_generator = new VpnConfigGenerator(general_configuration, secrets, gateway); - String configuration = vpn_configuration_generator.generate(); - - cp.parseConfig(new StringReader(configuration)); - return cp.convertProfile(); - } catch (ConfigParser.ConfigParseError e) { - // FIXME We didn't get a VpnProfile! Error handling! and log level - Log.v(TAG,"Error creating VPNProfile"); - e.printStackTrace(); - return null; - } catch (IOException e) { - // FIXME We didn't get a VpnProfile! Error handling! and log level - Log.v(TAG,"Error creating VPNProfile"); - e.printStackTrace(); - return null; - } + private VpnProfile createVPNProfile() { + try { + ConfigParser cp = new ConfigParser(); + + VpnConfigGenerator vpn_configuration_generator = new VpnConfigGenerator(general_configuration, secrets, gateway); + String configuration = vpn_configuration_generator.generate(); + + cp.parseConfig(new StringReader(configuration)); + return cp.convertProfile(); + } catch (ConfigParser.ConfigParseError e) { + // FIXME We didn't get a VpnProfile! Error handling! and log level + Log.v(TAG, "Error creating VPNProfile"); + e.printStackTrace(); + return null; + } catch (IOException e) { + // FIXME We didn't get a VpnProfile! Error handling! and log level + Log.v(TAG, "Error creating VPNProfile"); + e.printStackTrace(); + return null; + } } public String getName() { - return mName; + return mName; } public VpnProfile getProfile() { - return mVpnProfile; + return mVpnProfile; } public int getTimezone() { - return timezone; + return timezone; } @Override diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaySelector.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaySelector.java index 11823511..90c8f890 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaySelector.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaySelector.java @@ -6,37 +6,37 @@ public class GatewaySelector { List gateways; public GatewaySelector(List gateways) { - this.gateways = gateways; + this.gateways = gateways; } public Gateway select() { - return closestGateway(); + return closestGateway(); } - + private Gateway closestGateway() { - TreeMap> offsets = calculateOffsets(); - return offsets.isEmpty() ? null : offsets.firstEntry().getValue().iterator().next(); + TreeMap> offsets = calculateOffsets(); + return offsets.isEmpty() ? null : offsets.firstEntry().getValue().iterator().next(); } - + private TreeMap> calculateOffsets() { - TreeMap> offsets = new TreeMap>(); - int localOffset = Calendar.getInstance().get(Calendar.ZONE_OFFSET) / 3600000; - for(Gateway gateway : gateways) { - int dist = timezoneDistance(localOffset, gateway.getTimezone()); - Set set = (offsets.get(dist) != null) ? - offsets.get(dist) : new HashSet(); - set.add(gateway); - offsets.put(dist, set); - } - return offsets; + TreeMap> offsets = new TreeMap>(); + int localOffset = Calendar.getInstance().get(Calendar.ZONE_OFFSET) / 3600000; + for (Gateway gateway : gateways) { + int dist = timezoneDistance(localOffset, gateway.getTimezone()); + Set set = (offsets.get(dist) != null) ? + offsets.get(dist) : new HashSet(); + set.add(gateway); + offsets.put(dist, set); + } + return offsets; } - + private int timezoneDistance(int local_timezone, int remote_timezone) { - // Distance along the numberline of Prime Meridian centric, assumes UTC-11 through UTC+12 - int dist = Math.abs(local_timezone - remote_timezone); - // Farther than 12 timezones and it's shorter around the "back" - if (dist > 12) - dist = 12 - (dist -12); // Well i'll be. Absolute values make equations do funny things. - return dist; + // Distance along the numberline of Prime Meridian centric, assumes UTC-11 through UTC+12 + int dist = Math.abs(local_timezone - remote_timezone); + // Farther than 12 timezones and it's shorter around the "back" + if (dist > 12) + dist = 12 - (dist - 12); // Well i'll be. Absolute values make equations do funny things. + return dist; } } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java index af5670f5..b41fcfd4 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java @@ -40,15 +40,18 @@ public class GatewaysManager { private SharedPreferences preferences; private List gateways = new ArrayList<>(); private ProfileManager profile_manager; - private Type list_type = new TypeToken>() {}.getType(); + private Type list_type = new TypeToken>() { + }.getType(); - public GatewaysManager() {} + public GatewaysManager() { + } public GatewaysManager(Context context, SharedPreferences preferences) { this.context = context; this.preferences = preferences; profile_manager = ProfileManager.getInstance(context); } + public Gateway select() { GatewaySelector gateway_selector = new GatewaySelector(gateways); return gateway_selector.select(); @@ -66,13 +69,13 @@ public class GatewaysManager { List gateways_list = new ArrayList(); try { gateways_list = new Gson().fromJson(gateways, list_type); - } catch(JsonSyntaxException e) { + } catch (JsonSyntaxException e) { gateways_list.add(new Gson().fromJson(gateways, Gateway.class)); } - if(gateways_list != null) { + if (gateways_list != null) { for (Gateway gateway : gateways_list) - addGateway(gateway); + addGateway(gateway); this.gateways.addAll(gateways_list); } else Log.d("GatewaysManager", "No gateways added"); @@ -85,21 +88,21 @@ public class GatewaysManager { public void fromEipServiceJson(JSONObject eip_definition) { try { - JSONArray gatewaysDefined = eip_definition.getJSONArray("gateways"); - for (int i = 0; i < gatewaysDefined.length(); i++) { - JSONObject gw = gatewaysDefined.getJSONObject(i); - if (isOpenVpnGateway(gw)) { - JSONObject secrets = secretsConfiguration(); - Gateway aux = new Gateway(eip_definition, secrets, gw); - if(!containsProfileWithSecrets(aux.getProfile())) { - addGateway(aux); - } - } - } - } catch (JSONException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + JSONArray gatewaysDefined = eip_definition.getJSONArray("gateways"); + for (int i = 0; i < gatewaysDefined.length(); i++) { + JSONObject gw = gatewaysDefined.getJSONObject(i); + if (isOpenVpnGateway(gw)) { + JSONObject secrets = secretsConfiguration(); + Gateway aux = new Gateway(eip_definition, secrets, gw); + if (!containsProfileWithSecrets(aux.getProfile())) { + addGateway(aux); + } + } + } + } catch (JSONException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } private boolean isOpenVpnGateway(JSONObject gateway) { @@ -127,10 +130,10 @@ public class GatewaysManager { boolean result = false; Collection profiles = profile_manager.getProfiles(); - for(VpnProfile aux : profiles) { + for (VpnProfile aux : profiles) { result = result || sameConnections(profile.mConnections, aux.mConnections) - && profile.mClientCertFilename.equalsIgnoreCase(aux.mClientCertFilename) - && profile.mClientKeyFilename.equalsIgnoreCase(aux.mClientKeyFilename); + && profile.mClientCertFilename.equalsIgnoreCase(aux.mClientCertFilename) + && profile.mClientKeyFilename.equalsIgnoreCase(aux.mClientKeyFilename); } return result; } @@ -149,9 +152,9 @@ public class GatewaysManager { private void removeDuplicatedGateway(Gateway gateway) { Iterator it = gateways.iterator(); List gateways_to_remove = new ArrayList<>(); - while(it.hasNext()) { + while (it.hasNext()) { Gateway aux = it.next(); - if(sameConnections(aux.getProfile().mConnections, gateway.getProfile().mConnections)) { + if (sameConnections(aux.getProfile().mConnections, gateway.getProfile().mConnections)) { gateways_to_remove.add(aux); } } @@ -160,21 +163,21 @@ public class GatewaysManager { } private void removeDuplicatedProfiles(VpnProfile original) { - Collection profiles = profile_manager.getProfiles(); + Collection profiles = profile_manager.getProfiles(); List remove_list = new ArrayList<>(); - for(VpnProfile aux : profiles) { - if (sameConnections(original.mConnections, aux.mConnections)) - remove_list.add(aux); - } + for (VpnProfile aux : profiles) { + if (sameConnections(original.mConnections, aux.mConnections)) + remove_list.add(aux); + } for (VpnProfile profile : remove_list) profile_manager.removeProfile(context, profile); } private boolean sameConnections(Connection[] c1, Connection[] c2) { int same_connections = 0; - for(Connection c1_aux : c1) { - for(Connection c2_aux : c2) - if(c2_aux.mServerName.equals(c1_aux.mServerName)) { + for (Connection c1_aux : c1) { + for (Connection c2_aux : c2) + if (c2_aux.mServerName.equals(c1_aux.mServerName)) { same_connections++; break; } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java index 39a802c6..5c9263b3 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java @@ -11,27 +11,27 @@ public class VoidVpnLauncher extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setUp(); + super.onCreate(savedInstanceState); + setUp(); } - + public void setUp() { - Intent blocking_intent = VpnService.prepare(getApplicationContext()); // stops the VPN connection created by another application. - if(blocking_intent != null) - startActivityForResult(blocking_intent, VPN_USER_PERMISSION); - else { - onActivityResult(VPN_USER_PERMISSION, RESULT_OK, null); - } + Intent blocking_intent = VpnService.prepare(getApplicationContext()); // stops the VPN connection created by another application. + if (blocking_intent != null) + startActivityForResult(blocking_intent, VPN_USER_PERMISSION); + else { + onActivityResult(VPN_USER_PERMISSION, RESULT_OK, null); + } } - protected void onActivityResult(int requestCode, int resultCode, Intent data){ - if(requestCode == VPN_USER_PERMISSION) { - if(resultCode == RESULT_OK) { - Intent void_vpn_service = new Intent(getApplicationContext(), VoidVpnService.class); - void_vpn_service.setAction(Constants.START_BLOCKING_VPN_PROFILE); - startService(void_vpn_service); - } - } - finish(); + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == VPN_USER_PERMISSION) { + if (resultCode == RESULT_OK) { + Intent void_vpn_service = new Intent(getApplicationContext(), VoidVpnService.class); + void_vpn_service.setAction(Constants.START_BLOCKING_VPN_PROFILE); + startService(void_vpn_service); + } + } + finish(); } } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java index e864288a..ac3d5d77 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java @@ -6,7 +6,7 @@ import android.os.*; import java.io.*; -public class VoidVpnService extends VpnService { +public class VoidVpnService extends VpnService { static final String TAG = VoidVpnService.class.getSimpleName(); static ParcelFileDescriptor fd; @@ -15,28 +15,28 @@ public class VoidVpnService extends VpnService { @Override public int onStartCommand(Intent intent, int flags, int startId) { - String action = intent != null ? intent.getAction() : ""; - if (action == Constants.START_BLOCKING_VPN_PROFILE) { - thread = new Thread(new Runnable() { - public void run() { - Builder builder = new Builder(); - builder.setSession("Blocking until running"); - builder.addAddress("10.42.0.8",16); - builder.addRoute("0.0.0.0", 1); - builder.addRoute("192.168.1.0", 24); - builder.addDnsServer("10.42.0.1"); - try { - fd = builder.establish(); + String action = intent != null ? intent.getAction() : ""; + if (action == Constants.START_BLOCKING_VPN_PROFILE) { + thread = new Thread(new Runnable() { + public void run() { + Builder builder = new Builder(); + builder.setSession("Blocking until running"); + builder.addAddress("10.42.0.8", 16); + builder.addRoute("0.0.0.0", 1); + builder.addRoute("192.168.1.0", 24); + builder.addDnsServer("10.42.0.1"); + try { + fd = builder.establish(); - } catch (Exception e) { - e.printStackTrace(); - } - android.util.Log.d(TAG, "VoidVpnService set up: fd = " + fd.toString()); - } - }); - thread.run(); - } - return 0; + } catch (Exception e) { + e.printStackTrace(); + } + android.util.Log.d(TAG, "VoidVpnService set up: fd = " + fd.toString()); + } + }); + thread.run(); + } + return 0; } @Override @@ -46,14 +46,14 @@ public class VoidVpnService extends VpnService { } public static void stop() { - if(thread != null) + if (thread != null) thread.interrupt(); closeFd(); } private static void closeFd() { try { - if(fd != null) { + if (fd != null) { android.util.Log.d(TAG, "VoidVpnService closing fd = " + fd.toString()); fd.close(); } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java index 27971c3d..025d049d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java @@ -1,6 +1,6 @@ /** * 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 @@ -33,32 +33,32 @@ public class VpnCertificateValidator { } public boolean isValid() { - if(!certificate.isEmpty()) { - X509Certificate certificate_x509 = ConfigHelper.parseX509CertificateFromString(certificate); - return isValid(certificate_x509); - } else return true; + if (!certificate.isEmpty()) { + X509Certificate certificate_x509 = ConfigHelper.parseX509CertificateFromString(certificate); + return isValid(certificate_x509); + } else return true; } - + private boolean isValid(X509Certificate certificate) { - Calendar offset_date = calculateOffsetCertificateValidity(certificate); - try { - Log.d(TAG, "offset_date = " + offset_date.getTime().toString()); - certificate.checkValidity(offset_date.getTime()); - return true; - } catch(CertificateExpiredException e) { - return false; - } catch(CertificateNotYetValidException e) { - return false; - } + Calendar offset_date = calculateOffsetCertificateValidity(certificate); + try { + Log.d(TAG, "offset_date = " + offset_date.getTime().toString()); + certificate.checkValidity(offset_date.getTime()); + return true; + } catch (CertificateExpiredException e) { + return false; + } catch (CertificateNotYetValidException e) { + return false; + } } private Calendar calculateOffsetCertificateValidity(X509Certificate certificate) { - Log.d(TAG, "certificate not after = " + certificate.getNotAfter()); - long preventive_time = Math.abs(certificate.getNotBefore().getTime() - certificate.getNotAfter().getTime())/2; - long current_date_millis = Calendar.getInstance().getTimeInMillis(); - - Calendar limit_date = Calendar.getInstance(); - limit_date.setTimeInMillis(current_date_millis + preventive_time); - return limit_date; + Log.d(TAG, "certificate not after = " + certificate.getNotAfter()); + long preventive_time = Math.abs(certificate.getNotBefore().getTime() - certificate.getNotAfter().getTime()) / 2; + long current_date_millis = Calendar.getInstance().getTimeInMillis(); + + Calendar limit_date = Calendar.getInstance(); + limit_date.setTimeInMillis(current_date_millis + preventive_time); + return limit_date; } } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java index 8b1bc793..0b9c5832 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java @@ -17,7 +17,9 @@ package se.leap.bitmaskclient.eip; import org.json.*; + import java.util.*; + import se.leap.bitmaskclient.*; public class VpnConfigGenerator { @@ -50,7 +52,7 @@ public class VpnConfigGenerator { String common_options = ""; try { Iterator keys = general_configuration.keys(); - while ( keys.hasNext() ){ + while (keys.hasNext()) { String key = keys.next().toString(); common_options += key + " "; @@ -83,11 +85,11 @@ public class VpnConfigGenerator { String ip_address = gateway.getString(ip_address_keyword); JSONObject capabilities = gateway.getJSONObject(capabilities_keyword); JSONArray ports = capabilities.getJSONArray(ports_keyword); - for (int i=0; i"; return ca + new_line + key + new_line + openvpn_cert; - } catch(JSONException e) { + } catch (JSONException e) { e.printStackTrace(); return ""; } -- cgit v1.2.3 From e54c7a5407da82feb6dc6fb0de5e2d9f3756b651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Tue, 24 Mar 2015 19:29:55 +0100 Subject: Remove all Logs. In the near future, I should implement an error feedback mechanism (ideally using ics-openvpn's log view), and avoid the e.printStackTrace() and Log.d("","") without losing information. --- app/src/main/java/se/leap/bitmaskclient/Dashboard.java | 1 - app/src/main/java/se/leap/bitmaskclient/EipFragment.java | 7 ------- app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java | 3 --- app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java | 3 --- app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java | 4 ---- app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java | 4 +--- app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java | 5 +---- .../java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java | 4 ---- 8 files changed, 2 insertions(+), 29 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index 2e9aa74c..ee64a1b3 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -421,7 +421,6 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn @Override public void onReceiveResult(int resultCode, Bundle resultData) { - Log.d(TAG, "onReceiveResult"); if (resultCode == ProviderAPI.SUCCESSFUL_SIGNUP) { String username = resultData.getString(SessionDialog.USERNAME); String password = resultData.getString(SessionDialog.PASSWORD); diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index 3ad658f5..02eedd77 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -76,8 +76,6 @@ public class EipFragment extends Fragment implements Observer { if (eip_status.isConnecting()) eip_switch.setVisibility(View.VISIBLE); - Log.d(TAG, "onCreateView, eip_switch is checked? " + eip_switch.isChecked()); - Bundle arguments = getArguments(); if (arguments != null && arguments.containsKey(START_ON_BOOT) && arguments.getBoolean(START_ON_BOOT)) startEipFromScratch(); @@ -149,8 +147,6 @@ public class EipFragment extends Fragment implements Observer { private boolean canLogInToStartEIP() { 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); return isAllowedRegistered && !isLoggedIn && !eip_status.isConnecting() && !eip_status.isConnected(); } @@ -283,7 +279,6 @@ public class EipFragment extends Fragment implements Observer { private void setConnectedUI() { hideProgressBar(); - Log.d(TAG, "setConnectedUi? " + eip_status.isConnected()); adjustSwitch(); is_starting_to_connect = false; status_message.setText(dashboard.getString(R.string.eip_state_connected)); @@ -302,12 +297,10 @@ public class EipFragment extends Fragment implements Observer { private void adjustSwitch() { 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); diff --git a/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java b/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java index 073d727f..9171e816 100644 --- a/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java +++ b/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java @@ -1,7 +1,6 @@ package se.leap.bitmaskclient; import android.content.*; -import android.util.*; import se.leap.bitmaskclient.eip.*; @@ -15,8 +14,6 @@ public class OnBootReceiver extends BroadcastReceiver { preferences = context.getSharedPreferences(Dashboard.SHARED_PREFERENCES, Context.MODE_PRIVATE); boolean provider_configured = !preferences.getString(Provider.KEY, "").isEmpty(); boolean start_on_boot = preferences.getBoolean(Dashboard.START_ON_BOOT, false); - Log.d("OnBootReceiver", "Provider configured " + String.valueOf(provider_configured)); - Log.d("OnBootReceiver", "Start on boot " + String.valueOf(start_on_boot)); if (provider_configured && start_on_boot) { Intent dashboard_intent = new Intent(context, Dashboard.class); dashboard_intent.setAction(Constants.ACTION_START_EIP); 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 e636c693..ad68f96e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java @@ -16,7 +16,6 @@ */ package se.leap.bitmaskclient.eip; -import android.util.*; import android.content.*; import java.util.*; @@ -51,7 +50,6 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { setConnectedOrDisconnected(); } else if (isConnecting()) setConnecting(); - Log.d(TAG, "update state with level " + level); } private void updateStatus(final String state, final String logmessage, final int localizedResId, final VpnStatus.ConnectionStatus level) { @@ -93,7 +91,6 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { } public void setConnectedOrDisconnected() { - Log.d(TAG, "setConnectedOrDisconnected()"); wants_to_disconnect = false; current_status.setChanged(); current_status.notifyObservers(); diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java index b2c7af8c..ff7d011e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java @@ -16,8 +16,6 @@ */ package se.leap.bitmaskclient.eip; -import android.util.*; - import com.google.gson.*; import org.json.*; @@ -106,12 +104,10 @@ public class Gateway { return cp.convertProfile(); } catch (ConfigParser.ConfigParseError e) { // FIXME We didn't get a VpnProfile! Error handling! and log level - Log.v(TAG, "Error creating VPNProfile"); e.printStackTrace(); return null; } catch (IOException e) { // FIXME We didn't get a VpnProfile! Error handling! and log level - Log.v(TAG, "Error creating VPNProfile"); e.printStackTrace(); return null; } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java index b41fcfd4..1c64328e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java @@ -17,7 +17,6 @@ package se.leap.bitmaskclient.eip; import android.content.*; -import android.util.*; import com.google.gson.*; import com.google.gson.reflect.*; @@ -77,8 +76,7 @@ public class GatewaysManager { for (Gateway gateway : gateways_list) addGateway(gateway); this.gateways.addAll(gateways_list); - } else - Log.d("GatewaysManager", "No gateways added"); + } } @Override diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java index ac3d5d77..dac92fe2 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java @@ -31,7 +31,6 @@ public class VoidVpnService extends VpnService { } catch (Exception e) { e.printStackTrace(); } - android.util.Log.d(TAG, "VoidVpnService set up: fd = " + fd.toString()); } }); thread.run(); @@ -53,10 +52,8 @@ public class VoidVpnService extends VpnService { private static void closeFd() { try { - if (fd != null) { - android.util.Log.d(TAG, "VoidVpnService closing fd = " + fd.toString()); + if (fd != null) fd.close(); - } } catch (IOException e) { e.printStackTrace(); } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java index 025d049d..8fce6a37 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java @@ -16,8 +16,6 @@ */ package se.leap.bitmaskclient.eip; -import android.util.*; - import java.security.cert.*; import java.util.*; @@ -42,7 +40,6 @@ public class VpnCertificateValidator { private boolean isValid(X509Certificate certificate) { Calendar offset_date = calculateOffsetCertificateValidity(certificate); try { - Log.d(TAG, "offset_date = " + offset_date.getTime().toString()); certificate.checkValidity(offset_date.getTime()); return true; } catch (CertificateExpiredException e) { @@ -53,7 +50,6 @@ public class VpnCertificateValidator { } private Calendar calculateOffsetCertificateValidity(X509Certificate certificate) { - Log.d(TAG, "certificate not after = " + certificate.getNotAfter()); long preventive_time = Math.abs(certificate.getNotBefore().getTime() - certificate.getNotAfter().getTime()) / 2; long current_date_millis = Calendar.getInstance().getTimeInMillis(); -- cgit v1.2.3 From a8b4c47e44ea7f2eb6f0c032af344fb04b255694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Tue, 24 Mar 2015 19:50:26 +0100 Subject: Conjugate the verb to be in user session status. --- .../java/se/leap/bitmaskclient/UserSessionStatus.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java b/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java index 369df1a3..e43c8a25 100644 --- a/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java @@ -68,7 +68,20 @@ public class UserSessionStatus extends Observable { @Override public String toString() { - return User.userName() + " is " + String username = User.userName(); + + return username + " " + conjugateToBe(username) + " " + session_status.toString().toLowerCase().replaceAll("_", " "); } + + private String conjugateToBe(String subject) { + String conjugation = ""; + if(subject.equalsIgnoreCase("I")) + conjugation = "am"; + else if(subject.equalsIgnoreCase("you") || subject.equalsIgnoreCase("we")|| subject.equalsIgnoreCase("they")) + conjugation = "are"; + else conjugation = "is"; + + return conjugation; + } } -- cgit v1.2.3 From 91cfa79e99421b5813cea11661ad057d9a75209c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Fri, 27 Mar 2015 13:43:36 +0100 Subject: 0.9.3 RC3 --- app/src/main/AndroidManifest.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 07315bdd..6d947bc3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,8 +17,8 @@ + android:versionCode="119" + android:versionName="0.9.3RC3" > -- cgit v1.2.3 From 65f1f65cd063b63ba7f3628fc67878e97f3c8447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Fri, 10 Apr 2015 11:18:02 +0200 Subject: 0.9.3 --- app/src/main/AndroidManifest.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6d947bc3..cc31de43 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,8 +17,8 @@ + android:versionCode="120" + android:versionName="0.9.3" > -- cgit v1.2.3