summaryrefslogtreecommitdiff
path: root/src/se/leap/leapclient/ProviderAPI.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/se/leap/leapclient/ProviderAPI.java')
-rw-r--r--src/se/leap/leapclient/ProviderAPI.java74
1 files changed, 49 insertions, 25 deletions
diff --git a/src/se/leap/leapclient/ProviderAPI.java b/src/se/leap/leapclient/ProviderAPI.java
index 944a0e7f..dc0b2aa6 100644
--- a/src/se/leap/leapclient/ProviderAPI.java
+++ b/src/se/leap/leapclient/ProviderAPI.java
@@ -17,6 +17,7 @@
package se.leap.leapclient;
import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
@@ -88,6 +89,17 @@ public class ProviderAPI extends IntentService {
private Handler mHandler;
+ final public static String
+ DOWNLOAD_JSON_FILES_BUNDLE_EXTRA = "downloadJSONFiles",
+ UPDATE_PROVIDER_DOTJSON = "updateProviderDotJSON",
+ DOWNLOAD_NEW_PROVIDER_DOTJSON = "downloadNewProviderDotJSON",
+ SRP_REGISTER = "srpRegister",
+ SRP_AUTH = "srpAuth",
+ LOG_OUT = "logOut",
+ DOWNLOAD_CERTIFICATE = "downloadUserAuthedCertificate",
+ PARAMETERS = "parameters"
+ ;
+
public ProviderAPI() {
super("ProviderAPI");
Log.v("ClassName", "Provider API");
@@ -110,53 +122,46 @@ public class ProviderAPI extends IntentService {
}
@Override
- protected void onHandleIntent(Intent task_for) {
- final ResultReceiver receiver = task_for.getParcelableExtra("receiver");
+ protected void onHandleIntent(Intent command) {
+ final ResultReceiver receiver = command.getParcelableExtra("receiver");
+ String action = command.getAction();
+ Bundle parameters = command.getBundleExtra(PARAMETERS);
- Bundle task;
- if((task = task_for.getBundleExtra(ConfigHelper.DOWNLOAD_JSON_FILES_BUNDLE_EXTRA)) != null) {
- if(!downloadJsonFiles(task)) {
+ if(action.equalsIgnoreCase(DOWNLOAD_JSON_FILES_BUNDLE_EXTRA)) {
+ if(!downloadJsonFiles(parameters)) {
receiver.send(ConfigHelper.INCORRECTLY_DOWNLOADED_JSON_FILES, Bundle.EMPTY);
} else {
receiver.send(ConfigHelper.CORRECTLY_DOWNLOADED_JSON_FILES, Bundle.EMPTY);
}
- }
- else if ((task = task_for.getBundleExtra(ConfigHelper.UPDATE_PROVIDER_DOTJSON)) != null) {
- Bundle result = updateProviderDotJSON(task);
+ } else if(action.equalsIgnoreCase(UPDATE_PROVIDER_DOTJSON)) {
+ Bundle result = updateProviderDotJSON(parameters);
if(result.getBoolean(ConfigHelper.RESULT_KEY)) {
receiver.send(ConfigHelper.CORRECTLY_UPDATED_PROVIDER_DOT_JSON, result);
- } else {
+ } else {
receiver.send(ConfigHelper.INCORRECTLY_UPDATED_PROVIDER_DOT_JSON, Bundle.EMPTY);
}
- }
- else if ((task = task_for.getBundleExtra(ConfigHelper.DOWNLOAD_NEW_PROVIDER_DOTJSON)) != null) {
- Bundle result = downloadNewProviderDotJSON(task);
+ } else if (action.equalsIgnoreCase(DOWNLOAD_NEW_PROVIDER_DOTJSON)) {
+ Bundle result = downloadNewProviderDotJSON(parameters);
if(result.getBoolean(ConfigHelper.RESULT_KEY)) {
receiver.send(ConfigHelper.CORRECTLY_UPDATED_PROVIDER_DOT_JSON, result);
} else {
receiver.send(ConfigHelper.INCORRECTLY_DOWNLOADED_JSON_FILES, Bundle.EMPTY);
}
- }
- else if ((task = task_for.getBundleExtra(ConfigHelper.SRP_AUTH)) != null) {
- Bundle session_id_bundle = authenticateBySRP(task);
+ } else if (action.equalsIgnoreCase(SRP_AUTH)) {
+ Bundle session_id_bundle = authenticateBySRP(parameters);
if(session_id_bundle.getBoolean(ConfigHelper.RESULT_KEY)) {
receiver.send(ConfigHelper.SRP_AUTHENTICATION_SUCCESSFUL, session_id_bundle);
} else {
- 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);
+ receiver.send(ConfigHelper.SRP_AUTHENTICATION_FAILED, session_id_bundle);
}
- }
- else if ((task = task_for.getBundleExtra(ConfigHelper.LOG_OUT)) != null) {
- if(logOut(task)) {
+ } else if (action.equalsIgnoreCase(LOG_OUT)) {
+ if(logOut(parameters)) {
receiver.send(ConfigHelper.LOGOUT_SUCCESSFUL, Bundle.EMPTY);
} else {
receiver.send(ConfigHelper.LOGOUT_FAILED, Bundle.EMPTY);
}
- }
- else if ((task = task_for.getBundleExtra(ConfigHelper.DOWNLOAD_CERTIFICATE)) != null) {
- if(getNewCert(task)) {
+ } else if (action.equalsIgnoreCase(DOWNLOAD_CERTIFICATE)) {
+ if(getNewCert(parameters)) {
receiver.send(ConfigHelper.CORRECTLY_DOWNLOADED_CERTIFICATE, Bundle.EMPTY);
} else {
receiver.send(ConfigHelper.INCORRECTLY_DOWNLOADED_CERTIFICATE, Bundle.EMPTY);
@@ -215,27 +220,34 @@ public class ProviderAPI extends IntentService {
} else {
session_id_bundle.putBoolean(ConfigHelper.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(ConfigHelper.USERNAME_KEY, username);
}
} 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(ConfigHelper.USERNAME_KEY, username);
session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, false);
}
} 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));
+ session_id_bundle.putString(ConfigHelper.USERNAME_KEY, username);
} 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));
+ session_id_bundle.putString(ConfigHelper.USERNAME_KEY, username);
} 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));
+ session_id_bundle.putString(ConfigHelper.USERNAME_KEY, username);
} 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));
+ session_id_bundle.putString(ConfigHelper.USERNAME_KEY, username);
}
} 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));
+ session_id_bundle.putString(ConfigHelper.USERNAME_KEY, username);
}
return session_id_bundle;
@@ -407,6 +419,9 @@ public class ProviderAPI extends IntentService {
displayToast(R.string.malformed_url);
} catch(SocketTimeoutException e) {
displayToast(R.string.server_is_down_message);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ displayToast(R.string.server_is_down_message);
} catch (IOException e) {
if(provider_url != null) {
json_file_content = getStringFromProviderWithCACertAdded(provider_url, danger_on);
@@ -447,6 +462,9 @@ public class ProviderAPI extends IntentService {
json_string = new Scanner(urlConnection.getInputStream()).useDelimiter("\\A").next();
} catch (MalformedURLException e) {
displayToast(R.string.malformed_url);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ displayToast(R.string.server_is_down_message);
} catch (IOException e) {
json_string = getStringFromProviderIgnoringCertificate(string_url);
}
@@ -499,6 +517,9 @@ public class ProviderAPI extends IntentService {
e.printStackTrace();
} catch (UnknownHostException e) {
displayToast(R.string.server_is_down_message);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ displayToast(R.string.server_is_down_message);
} catch (IOException e) {
// The downloaded certificate doesn't validate our https connection.
if(danger_on) {
@@ -552,6 +573,9 @@ public class ProviderAPI extends IntentService {
});
string = new Scanner(urlConnection.getInputStream()).useDelimiter("\\A").next();
System.out.println("String ignoring certificate = " + string);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ displayToast(R.string.server_is_down_message);
} catch (IOException e) {
// The downloaded certificate doesn't validate our https connection.
e.printStackTrace();