summaryrefslogtreecommitdiff
path: root/src/se/leap/bitmaskclient/ProviderAPI.java
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2013-07-09 18:13:09 +0200
committercyBerta <richy@cyborgsociety.org>2013-11-15 23:21:40 +0100
commitb6bec89fd40a24751e2371328a17ee2aad2903fe (patch)
treeb6f145c8457b71778df4856f0e72c674366f6462 /src/se/leap/bitmaskclient/ProviderAPI.java
parentea05c4bc15c8b1e96782706340412160364ebdc9 (diff)
ProviderAPI broadcasts progress for log in process
Login progress bar advances according to the srp stages.
Diffstat (limited to 'src/se/leap/bitmaskclient/ProviderAPI.java')
-rw-r--r--src/se/leap/bitmaskclient/ProviderAPI.java38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/se/leap/bitmaskclient/ProviderAPI.java b/src/se/leap/bitmaskclient/ProviderAPI.java
index e56c6ca9..cb2db6bf 100644
--- a/src/se/leap/bitmaskclient/ProviderAPI.java
+++ b/src/se/leap/bitmaskclient/ProviderAPI.java
@@ -97,7 +97,9 @@ public class ProviderAPI extends IntentService {
RECEIVER_KEY = "receiver",
SESSION_ID_COOKIE_KEY = "session_id_cookie_key",
SESSION_ID_KEY = "session_id",
- ERRORS = "errors"
+ ERRORS = "errors",
+ UPDATE_ACTION = "update_action",
+ UPDATE_DATA = "update data"
;
final public static int
@@ -245,35 +247,42 @@ public class ProviderAPI extends IntentService {
*/
private Bundle authenticateBySRP(Bundle task) {
Bundle session_id_bundle = new Bundle();
+ int progress = 0;
String username = (String) task.get(LogInDialog.USERNAME);
String password = (String) task.get(LogInDialog.PASSWORD);
if(validUserLoginData(username, password)) {
+
String authentication_server = (String) task.get(Provider.API_URL);
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();
+ broadcast_progress(progress++);
try {
JSONObject saltAndB = sendAToSRPServer(authentication_server, username, new BigInteger(1, A).toString(16));
if(saltAndB.length() > 0) {
String salt = saltAndB.getString(LeapSRPSession.SALT);
+ broadcast_progress(progress++);
byte[] Bbytes = new BigInteger(saltAndB.getString("B"), 16).toByteArray();
byte[] M1 = client.response(new BigInteger(salt, 16).toByteArray(), Bbytes);
if(M1 != null) {
+ broadcast_progress(progress++);
JSONObject session_idAndM2 = sendM1ToSRPServer(authentication_server, username, M1);
- if(session_idAndM2.has(LeapSRPSession.M2) && client.verify((byte[])session_idAndM2.get(LeapSRPSession.M2))) {
- session_id_bundle.putBoolean(RESULT_KEY, true);
- } else {
- session_id_bundle.putBoolean(RESULT_KEY, false);
- session_id_bundle.putString(getResources().getString(R.string.user_message), getResources().getString(R.string.error_bad_user_password_user_message));
- session_id_bundle.putString(LogInDialog.USERNAME, username);
- }
+ if(session_idAndM2.has(LeapSRPSession.M2) && client.verify((byte[])session_idAndM2.get(LeapSRPSession.M2))) {
+ session_id_bundle.putBoolean(RESULT_KEY, true);
+ broadcast_progress(progress++);
+ } else {
+ session_id_bundle.putBoolean(RESULT_KEY, false);
+ session_id_bundle.putString(getResources().getString(R.string.user_message), getResources().getString(R.string.error_bad_user_password_user_message));
+ session_id_bundle.putString(LogInDialog.USERNAME, username);
+ }
} else {
session_id_bundle.putBoolean(RESULT_KEY, false);
session_id_bundle.putString(LogInDialog.USERNAME, username);
session_id_bundle.putString(getResources().getString(R.string.user_message), getResources().getString(R.string.error_srp_math_error_user_message));
}
+ broadcast_progress(progress++);
} else {
session_id_bundle.putString(getResources().getString(R.string.user_message), getResources().getString(R.string.error_bad_user_password_user_message));
session_id_bundle.putString(LogInDialog.USERNAME, username);
@@ -319,6 +328,19 @@ public class ProviderAPI extends IntentService {
return session_id_bundle;
}
+
+ /**
+ * Sets up an intent with the progress value passed as a parameter
+ * and sends it as a broadcast.
+ * @param progress
+ */
+ private void broadcast_progress(int progress) {
+ Intent intentUpdate = new Intent();
+ intentUpdate.setAction(UPDATE_ACTION);
+ intentUpdate.addCategory(Intent.CATEGORY_DEFAULT);
+ intentUpdate.putExtra(UPDATE_DATA, progress);
+ sendBroadcast(intentUpdate);
+ }
/**
* Validates parameters entered by the user to log in