summaryrefslogtreecommitdiff
path: root/src/se/leap
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
parentea05c4bc15c8b1e96782706340412160364ebdc9 (diff)
ProviderAPI broadcasts progress for log in process
Login progress bar advances according to the srp stages.
Diffstat (limited to 'src/se/leap')
-rw-r--r--src/se/leap/bitmaskclient/ConfigHelper.java1
-rw-r--r--src/se/leap/bitmaskclient/Dashboard.java24
-rw-r--r--src/se/leap/bitmaskclient/ProviderAPI.java38
3 files changed, 54 insertions, 9 deletions
diff --git a/src/se/leap/bitmaskclient/ConfigHelper.java b/src/se/leap/bitmaskclient/ConfigHelper.java
index 97a62bb2..a29ff301 100644
--- a/src/se/leap/bitmaskclient/ConfigHelper.java
+++ b/src/se/leap/bitmaskclient/ConfigHelper.java
@@ -50,6 +50,7 @@ public class ConfigHelper {
public static SharedPreferences shared_preferences;
private static KeyStore keystore_trusted;
+
final public static String NG_1024 =
"eeaf0ab9adb38dd69c33f80afa8fc5e86072618775ff3c0b9ea2314c9c256576d674df7496ea81d3383b4813d692c6e0e0d5d8e250b98be48e495c1d6089dad15dc7d7b46154d6b6ce8ef4ad69b15d4982559b297bcf1885c529f566660e57ec68edbc3c05726cc02fd4cbf4976eaa9afd5138fe8376435b9fc61d2fc0eb06e3";
final public static BigInteger G = new BigInteger("2");
diff --git a/src/se/leap/bitmaskclient/Dashboard.java b/src/se/leap/bitmaskclient/Dashboard.java
index 7b47c667..0e6cb657 100644
--- a/src/se/leap/bitmaskclient/Dashboard.java
+++ b/src/se/leap/bitmaskclient/Dashboard.java
@@ -31,9 +31,11 @@ import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.app.ProgressDialog;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
@@ -66,6 +68,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
private ProgressDialog mProgressDialog;
private ProgressBar mProgressBar;
+ private ProviderAPIBroadcastReceiver_Update providerAPI_broadcast_receiver_update;
private static Context app;
private static SharedPreferences preferences;
private static Provider provider;
@@ -85,6 +88,11 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
PRNGFixes.apply();
mProgressBar = (ProgressBar) findViewById(R.id.progressbar_dashboard);
+ providerAPI_broadcast_receiver_update = new ProviderAPIBroadcastReceiver_Update();
+ IntentFilter update_intent_filter = new IntentFilter(ProviderAPI.UPDATE_ACTION);
+ update_intent_filter.addCategory(Intent.CATEGORY_DEFAULT);
+ registerReceiver(providerAPI_broadcast_receiver_update, update_intent_filter);
+
ConfigHelper.setSharedPreferences(getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE));
preferences = ConfigHelper.shared_preferences;
@@ -94,6 +102,12 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
else
buildDashboard();
}
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ unregisterReceiver(providerAPI_broadcast_receiver_update);
+ }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
@@ -375,5 +389,13 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
public static Context getAppContext() {
return app;
}
-
+
+ public class ProviderAPIBroadcastReceiver_Update extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ int update = intent.getIntExtra(ProviderAPI.UPDATE_DATA, 0);
+ mProgressBar.setProgress(update);
+ }
+ }
}
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