summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2013-07-02 19:20:58 +0200
committerSean Leonard <meanderingcode@aetherislands.net>2013-07-12 14:26:29 -0600
commit99a4d94564635f0223d447bc9bcf081cadd8ff36 (patch)
tree1beba3aeacae1e2e278a5bbaffa3cf44ce527154
parent210b562bd474e7d8c22becf62ea52399f0a6d9f9 (diff)
User messages are added to the new recovery dialog
When login is not successful, a new recovery dialog is prompted with a message about the previous error.
-rw-r--r--res/layout/log_in_dialog.xml7
-rwxr-xr-xres/values/strings.xml8
-rw-r--r--src/se/leap/leapclient/Dashboard.java13
-rw-r--r--src/se/leap/leapclient/LogInDialog.java26
-rw-r--r--src/se/leap/leapclient/NewProviderDialog.java2
-rw-r--r--src/se/leap/leapclient/ProviderAPI.java76
6 files changed, 81 insertions, 51 deletions
diff --git a/res/layout/log_in_dialog.xml b/res/layout/log_in_dialog.xml
index 6f28118..4c9fdba 100644
--- a/res/layout/log_in_dialog.xml
+++ b/res/layout/log_in_dialog.xml
@@ -6,6 +6,13 @@
android:orientation="vertical"
tools:context=".LogInDialog" >
+ <TextView
+ android:id="@+id/user_message"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
<EditText
android:id="@+id/username_entered"
android:layout_width="match_parent"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 83f614f..c7ef6c2 100755
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -276,6 +276,13 @@
<string name="use_anonymously_button">Use anonymously</string>
<string name="username_ask">Introduce your username</string>
<string name="password_ask">Enter your password</string>
+ <string name="user_message">User message</string>
+ <string name="error_bad_user_password_user_message">Not valid username and/or password.</string>
+ <string name="error_not_valid_password_user_message">Your password is not well-formed: it should have at least 8 characters.</string>
+ <string name="error_client_http_user_message">Try again: Client HTTP error</string>
+ <string name="error_io_exception_user_message">Try again: I/O error</string>
+ <string name="error_json_exception_user_message">Try again: Bad response from the server</string>
+ <string name="error_no_such_algorithm_exception_user_message">Update the app</string>
<string name="login_button">Log In</string>
<string name="logout_button">Log Out</string>
<string name="danger_checkbox">Trust completely</string>
@@ -295,7 +302,6 @@
<string name="server_is_down_message">Server is down.</string>
<string name="malformed_url">It doesn\'t seem to be a LEAP provider.</string>
<string name="certificate_error">This is not a trusted LEAP provider.</string>
- <string name="not_valid_password_message">Your password is not well-formed: it should have at least 8 characters.</string>
<string name="authenticating_title">Authenticating</string>
<string name="authenticating_message">Authenticating with entered login and password.</string>
<string name="logout_title">Log out</string>
diff --git a/src/se/leap/leapclient/Dashboard.java b/src/se/leap/leapclient/Dashboard.java
index 59c0f18..a330f9e 100644
--- a/src/se/leap/leapclient/Dashboard.java
+++ b/src/se/leap/leapclient/Dashboard.java
@@ -102,7 +102,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
buildDashboard();
if(data != null && data.hasExtra(ConfigHelper.LOG_IN)) {
View view = ((ViewGroup)findViewById(android.R.id.content)).getChildAt(0);
- logInDialog(view);
+ logInDialog(view, "");
}
} else if(resultCode == RESULT_CANCELED && data.hasExtra(ConfigHelper.QUIT)) {
finish();
@@ -270,7 +270,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
return true;
case R.id.login_button:
View view = ((ViewGroup)findViewById(android.R.id.content)).getChildAt(0);
- logInDialog(view);
+ logInDialog(view, "");
return true;
case R.id.logout_button:
logOut();
@@ -340,7 +340,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
* Shows the log in dialog.
* @param view from which the dialog is created.
*/
- public void logInDialog(View view) {
+ public void logInDialog(View view, String user_message) {
FragmentTransaction fragment_transaction = getFragmentManager().beginTransaction();
Fragment previous_log_in_dialog = getFragmentManager().findFragmentByTag(ConfigHelper.LOG_IN_DIALOG);
if (previous_log_in_dialog != null) {
@@ -349,6 +349,11 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
fragment_transaction.addToBackStack(null);
DialogFragment newFragment = LogInDialog.newInstance();
+ if(user_message != null && !user_message.isEmpty()) {
+ Bundle user_message_bundle = new Bundle();
+ user_message_bundle.putString(getResources().getString(R.string.user_message), user_message);
+ newFragment.setArguments(user_message_bundle);
+ }
newFragment.show(fragment_transaction, ConfigHelper.LOG_IN_DIALOG);
}
@@ -384,7 +389,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
Cookie session_id = new BasicClientCookie(session_id_cookie_key, session_id_string);
downloadAuthedUserCertificate(session_id);
} else if(resultCode == ConfigHelper.SRP_AUTHENTICATION_FAILED) {
- logInDialog(getCurrentFocus());
+ logInDialog(getCurrentFocus(), resultData.getString(getResources().getString(R.string.user_message)));
mProgressDialog.dismiss();
} else if(resultCode == ConfigHelper.LOGOUT_SUCCESSFUL) {
setResult(RESULT_OK);
diff --git a/src/se/leap/leapclient/LogInDialog.java b/src/se/leap/leapclient/LogInDialog.java
index 99b1962..0536c6d 100644
--- a/src/se/leap/leapclient/LogInDialog.java
+++ b/src/se/leap/leapclient/LogInDialog.java
@@ -9,7 +9,7 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
-import android.widget.Toast;
+import android.widget.TextView;
/**
* Implements the log in dialog, currently without progress dialog.
@@ -22,12 +22,16 @@ import android.widget.Toast;
*
*/
public class LogInDialog extends DialogFragment {
-
+
public AlertDialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View log_in_dialog_view = inflater.inflate(R.layout.log_in_dialog, null);
-
+
+ final TextView user_message = (TextView)log_in_dialog_view.findViewById(R.id.user_message);
+ if(getArguments() != null && getArguments().containsKey(getResources().getString(R.string.user_message))) {
+ user_message.setText(getArguments().getString(getResources().getString(R.string.user_message)));
+ } else user_message.setVisibility(View.GONE);
final EditText username_field = (EditText)log_in_dialog_view.findViewById(R.id.username_entered);
final EditText password_field = (EditText)log_in_dialog_view.findViewById(R.id.password_entered);
@@ -36,12 +40,7 @@ public class LogInDialog extends DialogFragment {
public void onClick(DialogInterface dialog, int id) {
String username = username_field.getText().toString().trim();
String password = password_field.getText().toString().trim();
- if(wellFormedPassword(password)) {
- interface_with_Dashboard.authenticate(username, password);
- } else {
- password_field.setText("");
- Toast.makeText(getActivity().getApplicationContext(), R.string.not_valid_password_message, Toast.LENGTH_LONG).show();
- }
+ interface_with_Dashboard.authenticate(username, password);
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@@ -52,15 +51,6 @@ public class LogInDialog extends DialogFragment {
return builder.create();
}
-
- /**
- * Validates a password
- * @param entered_password
- * @return true if the entered password length is greater or equal to eight (8).
- */
- private boolean wellFormedPassword(String entered_password) {
- return entered_password.length() >= 8;
- }
/**
* Interface used to communicate LogInDialog with Dashboard.
diff --git a/src/se/leap/leapclient/NewProviderDialog.java b/src/se/leap/leapclient/NewProviderDialog.java
index cf36171..3712e8f 100644
--- a/src/se/leap/leapclient/NewProviderDialog.java
+++ b/src/se/leap/leapclient/NewProviderDialog.java
@@ -68,7 +68,7 @@ public class NewProviderDialog extends DialogFragment {
Toast.makeText(getActivity().getApplicationContext(), R.string.valid_url_entered, Toast.LENGTH_LONG).show();
} else {
url_input_field.setText("");
- Toast.makeText(getActivity().getApplicationContext(), R.string.not_valid_password_message, Toast.LENGTH_LONG).show();
+ Toast.makeText(getActivity().getApplicationContext(), R.string.not_valid_url_entered, Toast.LENGTH_LONG).show();
}
}
})
diff --git a/src/se/leap/leapclient/ProviderAPI.java b/src/se/leap/leapclient/ProviderAPI.java
index 306ffa2..5238224 100644
--- a/src/se/leap/leapclient/ProviderAPI.java
+++ b/src/se/leap/leapclient/ProviderAPI.java
@@ -62,7 +62,7 @@ import android.widget.Toast;
/**
* Implements HTTP api methods used to manage communications with the provider server.
*
- * It's an IntentService because it downloads data fromt he Internet, so it operates in the background.
+ * It's an IntentService because it downloads data from the Internet, so it operates in the background.
*
* @author parmegv
* @author MeanderingCode
@@ -126,7 +126,10 @@ public class ProviderAPI extends IntentService {
if(session_id_bundle.getBoolean(ConfigHelper.RESULT_KEY)) {
receiver.send(ConfigHelper.SRP_AUTHENTICATION_SUCCESSFUL, session_id_bundle);
} else {
- receiver.send(ConfigHelper.SRP_AUTHENTICATION_FAILED, Bundle.EMPTY);
+ Bundle user_message_bundle = new Bundle();
+ String user_message_key = getResources().getString(R.string.user_message);
+ user_message_bundle.putString(user_message_key, session_id_bundle.getString(user_message_key));
+ receiver.send(ConfigHelper.SRP_AUTHENTICATION_FAILED, user_message_bundle);
}
}
else if ((task = task_for.getBundleExtra(ConfigHelper.LOG_OUT)) != null) {
@@ -176,42 +179,61 @@ public class ProviderAPI extends IntentService {
String username = (String) task.get(ConfigHelper.USERNAME_KEY);
String password = (String) task.get(ConfigHelper.PASSWORD_KEY);
- String authentication_server = (String) task.get(ConfigHelper.API_URL_KEY);
+ if(wellFormedPassword(password)) {
+ String authentication_server = (String) task.get(ConfigHelper.API_URL_KEY);
- SRPParameters params = new SRPParameters(new BigInteger(ConfigHelper.NG_1024, 16).toByteArray(), ConfigHelper.G.toByteArray(), BigInteger.ZERO.toByteArray(), "SHA-256");
- LeapSRPSession client = new LeapSRPSession(username, password, params);
- byte[] A = client.exponential();
- try {
- JSONObject saltAndB = sendAToSRPServer(authentication_server, username, new BigInteger(1, A).toString(16));
- if(saltAndB.length() > 0) {
- String salt = saltAndB.getString(ConfigHelper.SALT_KEY);
- byte[] Bbytes = new BigInteger(saltAndB.getString("B"), 16).toByteArray();
- byte[] M1 = client.response(new BigInteger(salt, 16).toByteArray(), Bbytes);
- JSONObject session_idAndM2 = sendM1ToSRPServer(authentication_server, username, M1);
- if( client.verify((byte[])session_idAndM2.get("M2")) == false ) {
- session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, false);
+ SRPParameters params = new SRPParameters(new BigInteger(ConfigHelper.NG_1024, 16).toByteArray(), ConfigHelper.G.toByteArray(), BigInteger.ZERO.toByteArray(), "SHA-256");
+ LeapSRPSession client = new LeapSRPSession(username, password, params);
+ byte[] A = client.exponential();
+ try {
+ JSONObject saltAndB = sendAToSRPServer(authentication_server, username, new BigInteger(1, A).toString(16));
+ if(saltAndB.length() > 0) {
+ String salt = saltAndB.getString(ConfigHelper.SALT_KEY);
+ byte[] Bbytes = new BigInteger(saltAndB.getString("B"), 16).toByteArray();
+ byte[] M1 = client.response(new BigInteger(salt, 16).toByteArray(), Bbytes);
+ JSONObject session_idAndM2 = sendM1ToSRPServer(authentication_server, username, M1);
+ if( client.verify((byte[])session_idAndM2.get("M2")) == false ) {
+ session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, false);
+ } else {
+ session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, true);
+ session_id_bundle.putString(ConfigHelper.SESSION_ID_KEY, session_idAndM2.getString(ConfigHelper.SESSION_ID_KEY));
+ session_id_bundle.putString(ConfigHelper.SESSION_ID_COOKIE_KEY, session_idAndM2.getString(ConfigHelper.SESSION_ID_COOKIE_KEY));
+ }
} else {
- session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, true);
- session_id_bundle.putString(ConfigHelper.SESSION_ID_KEY, session_idAndM2.getString(ConfigHelper.SESSION_ID_KEY));
- session_id_bundle.putString(ConfigHelper.SESSION_ID_COOKIE_KEY, session_idAndM2.getString(ConfigHelper.SESSION_ID_COOKIE_KEY));
+ session_id_bundle.putString(getResources().getString(R.string.user_message), getResources().getString(R.string.error_bad_user_password_user_message));
+ session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, false);
}
- } else {
+ } catch (ClientProtocolException e) {
session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, false);
+ session_id_bundle.putString(getResources().getString(R.string.user_message), getResources().getString(R.string.error_client_http_user_message));
+ } catch (IOException e) {
+ session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, false);
+ session_id_bundle.putString(getResources().getString(R.string.user_message), getResources().getString(R.string.error_io_exception_user_message));
+ } catch (JSONException e) {
+ session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, false);
+ session_id_bundle.putString(getResources().getString(R.string.user_message), getResources().getString(R.string.error_json_exception_user_message));
+ } catch (NoSuchAlgorithmException e) {
+ session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, false);
+ session_id_bundle.putString(getResources().getString(R.string.user_message), getResources().getString(R.string.error_no_such_algorithm_exception_user_message));
}
- } catch (ClientProtocolException e) {
- session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, false);
- } catch (IOException e) {
- session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, false);
- } catch (JSONException e) {
- session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, false);
- } catch (NoSuchAlgorithmException e) {
+ } else {
session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, false);
+ session_id_bundle.putString(getResources().getString(R.string.user_message), getResources().getString(R.string.error_not_valid_password_user_message));
}
-
+
return session_id_bundle;
}
/**
+ * Validates a password
+ * @param entered_password
+ * @return true if the entered password length is greater or equal to eight (8).
+ */
+ private boolean wellFormedPassword(String entered_password) {
+ return entered_password.length() >= 8;
+ }
+
+ /**
* Sends an HTTP POST request to the authentication server with the SRP Parameter A.
* @param server_url
* @param username