summaryrefslogtreecommitdiff
path: root/src/se
diff options
context:
space:
mode:
Diffstat (limited to 'src/se')
-rw-r--r--src/se/leap/bitmaskclient/ConfigurationWizard.java96
-rw-r--r--src/se/leap/bitmaskclient/ProviderAPI.java89
-rw-r--r--src/se/leap/bitmaskclient/ProviderListContent.java2
3 files changed, 18 insertions, 169 deletions
diff --git a/src/se/leap/bitmaskclient/ConfigurationWizard.java b/src/se/leap/bitmaskclient/ConfigurationWizard.java
index 2c6c52c3..362e3c7a 100644
--- a/src/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/src/se/leap/bitmaskclient/ConfigurationWizard.java
@@ -31,7 +31,6 @@ import android.app.DialogFragment;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
-import android.app.ListFragment;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
@@ -125,17 +124,10 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
.replace(R.id.configuration_wizard_layout, new_provider_list_fragment, ProviderListFragment.TAG)
.commit();
}
-
- private void setProviderList(ProviderListFragment new_provider_list_fragment) {
- FragmentManager fragmentManager = getFragmentManager();
- fragmentManager.beginTransaction()
- .replace(R.id.configuration_wizard_layout, new_provider_list_fragment, ProviderListFragment.TAG)
- .commit();
- }
@Override
public void onReceiveResult(int resultCode, Bundle resultData) {
- if(resultCode == ProviderAPI.CORRECTLY_UPDATED_PROVIDER_DOT_JSON) {
+ if(resultCode == ProviderAPI.PROVIDER_OK) {
JSONObject provider_json;
try {
provider_json = new JSONObject(resultData.getString(Provider.KEY));
@@ -184,42 +176,16 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
//refreshProviderList(0);
//Toast.makeText(this, getResources().getString(R.string.config_error_parsing), Toast.LENGTH_LONG);
setResult(RESULT_CANCELED, mConfigState);
- }
- }
- else if(resultCode == ProviderAPI.INCORRECTLY_UPDATED_PROVIDER_DOT_JSON) {
+ }
+ } else if(resultCode == ProviderAPI.PROVIDER_NOK) {
+ //refreshProviderList(0);
String reason_to_fail = resultData.getString(ProviderAPI.ERRORS);
showDownloadFailedDialog(getCurrentFocus(), reason_to_fail);
- refreshProviderList(0);
mProgressBar.setVisibility(ProgressBar.GONE);
- progressbar_description.setVisibility(TextView.GONE);
+ progressbar_description.setVisibility(TextView.GONE);
ConfigHelper.removeFromSharedPref(Provider.KEY);
setResult(RESULT_CANCELED, mConfigState);
}
- else if(resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_JSON_FILES) {
- mProgressBar.incrementProgressBy(1);
- if (ConfigHelper.getBoolFromSharedPref(EIP.ALLOWED_ANON)){
- mConfigState.putExtra(SERVICES_RETRIEVED, true);
- downloadAnonCert();
- } else {
- mProgressBar.incrementProgressBy(1);
- mProgressBar.setVisibility(ProgressBar.GONE);
- progressbar_description.setVisibility(TextView.GONE);
- //refreshProviderList(0);
- //Toast.makeText(getApplicationContext(), R.string.success, Toast.LENGTH_LONG).show();
- setResult(RESULT_OK);
- showProviderDetails(getCurrentFocus());
- }
- }
- else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_JSON_FILES) {
- //Toast.makeText(getApplicationContext(), R.string.incorrectly_downloaded_json_files_message, Toast.LENGTH_LONG).show();
- String reason_to_fail = resultData.getString(ProviderAPI.ERRORS);
- showDownloadFailedDialog(getCurrentFocus(), reason_to_fail);
- refreshProviderList(0);
- //Toast.makeText(getApplicationContext(), R.string.incorrectly_downloaded_json_files_message,
- mProgressBar.setVisibility(ProgressBar.GONE);
- progressbar_description.setVisibility(TextView.GONE);
- setResult(RESULT_CANCELED, mConfigState);
- }
else if(resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) {
mProgressBar.incrementProgressBy(1);
mProgressBar.setVisibility(ProgressBar.GONE);
@@ -247,7 +213,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
int provider_index = getProviderIndex(id);
startProgressBar(provider_index);
mSelectedProvider = selected_provider;
- updateProviderDotJson(mSelectedProvider.providerMainUrl(), true);
+ setUpProvider(mSelectedProvider.providerMainUrl(), true);
}
@Override
@@ -351,34 +317,6 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
return loaded_preseeded_providers;
}
-
- /**
- * Asks ProviderAPI to download provider site's certificate and eip-service.json
- *
- * URLs are fetched from the provider parameter
- * @param provider_json describing the provider from which certificate and eip-service.json files are going to be downloaded
- */
- private void downloadJSONFiles(JSONObject provider_json, boolean danger_on) {
- try {
- Intent provider_API_command = new Intent(this, ProviderAPI.class);
-
- Bundle parameters = new Bundle();
-
- parameters.putBoolean(ProviderItem.DANGER_ON, danger_on);
- parameters.putString(Provider.CA_CERT, provider_json.getString("ca_cert_uri"));
- String eip_service_url = provider_json.getString(Provider.API_URL) + "/" + provider_json.getString(Provider.API_VERSION) + "/config/eip-service.json";
- parameters.putString(EIP.KEY, eip_service_url);
-
- provider_API_command.setAction(ProviderAPI.DOWNLOAD_JSON_FILES_BUNDLE_EXTRA);
- provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
- provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
-
- startService(provider_API_command);
- } catch (JSONException e) {
- //TODO Show error to the user. This will eventually be transformed to "unselectProvider()", which will show the graphical notice itself.
- ConfigHelper.removeFromSharedPref(Provider.KEY);
- }
- }
/**
* Asks ProviderAPI to download an anonymous (anon) VPN certificate.
@@ -451,27 +389,13 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
public void showAndSelectProvider(String provider_main_url, boolean danger_on) {
showProvider(provider_main_url, danger_on);
- updateProviderDotJson(provider_main_url, danger_on);
+ setUpProvider(provider_main_url, danger_on);
}
private void showProvider(final String provider_main_url, final boolean danger_on) {
String provider_name = provider_main_url.replaceFirst("http[s]?://", "").replaceFirst("\\/", "_");
- final ProviderItem added_provider = new ProviderItem(provider_name, provider_main_url);
-
- //ProviderListContent.addItem(added_provider);
- provider_list_fragment.addItem(added_provider);
- /*ProviderListFragment provider_list_fragment = (ProviderListFragment) getFragmentManager().findFragmentByTag(ProviderListFragment.TAG);
- //provider_list_fragment.notifyAdapter();
+ ProviderItem added_provider = new ProviderItem(provider_name, provider_main_url);
provider_list_fragment.addItem(added_provider);
- refreshProviderList(0);
-
- runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- provider_list_fragment.addItem(added_provider);
- }
- });*/
}
/**
@@ -480,14 +404,14 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
* @param provider_main_url
* @param danger_on tells if HTTPS client should bypass certificate errors
*/
- public void updateProviderDotJson(String provider_main_url, boolean danger_on) {
+ public void setUpProvider(String provider_main_url, boolean danger_on) {
Intent provider_API_command = new Intent(this, ProviderAPI.class);
Bundle parameters = new Bundle();
parameters.putString(Provider.MAIN_URL, provider_main_url);
parameters.putBoolean(ProviderItem.DANGER_ON, danger_on);
- provider_API_command.setAction(ProviderAPI.UPDATE_PROVIDER_DOTJSON);
+ provider_API_command.setAction(ProviderAPI.SET_UP_PROVIDER);
provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
diff --git a/src/se/leap/bitmaskclient/ProviderAPI.java b/src/se/leap/bitmaskclient/ProviderAPI.java
index 75b8c28d..60ed1e1f 100644
--- a/src/se/leap/bitmaskclient/ProviderAPI.java
+++ b/src/se/leap/bitmaskclient/ProviderAPI.java
@@ -85,8 +85,7 @@ public class ProviderAPI extends IntentService {
private Handler mHandler;
final public static String
- DOWNLOAD_JSON_FILES_BUNDLE_EXTRA = "downloadJSONFiles",
- UPDATE_PROVIDER_DOTJSON = "updateProviderDotJSON",
+ SET_UP_PROVIDER = "setUpProvider",
DOWNLOAD_NEW_PROVIDER_DOTJSON = "downloadNewProviderDotJSON",
SRP_REGISTER = "srpRegister",
SRP_AUTH = "srpAuth",
@@ -105,8 +104,6 @@ public class ProviderAPI extends IntentService {
final public static int
CUSTOM_PROVIDER_ADDED = 0,
- CORRECTLY_DOWNLOADED_JSON_FILES = 1,
- INCORRECTLY_DOWNLOADED_JSON_FILES = 2,
SRP_AUTHENTICATION_SUCCESSFUL = 3,
SRP_AUTHENTICATION_FAILED = 4,
SRP_REGISTRATION_SUCCESSFUL = 5,
@@ -115,8 +112,8 @@ public class ProviderAPI extends IntentService {
LOGOUT_FAILED = 8,
CORRECTLY_DOWNLOADED_CERTIFICATE = 9,
INCORRECTLY_DOWNLOADED_CERTIFICATE = 10,
- CORRECTLY_UPDATED_PROVIDER_DOT_JSON = 11,
- INCORRECTLY_UPDATED_PROVIDER_DOT_JSON = 12,
+ PROVIDER_OK = 11,
+ PROVIDER_NOK = 12,
CORRECTLY_DOWNLOADED_ANON_CERTIFICATE = 13,
INCORRECTLY_DOWNLOADED_ANON_CERTIFICATE = 14
;
@@ -143,19 +140,12 @@ public class ProviderAPI extends IntentService {
String action = command.getAction();
Bundle parameters = command.getBundleExtra(PARAMETERS);
- if(action.equalsIgnoreCase(DOWNLOAD_JSON_FILES_BUNDLE_EXTRA)) {
- Bundle result = downloadJsonFiles(parameters);
+ if(action.equalsIgnoreCase(SET_UP_PROVIDER)) {
+ Bundle result = setUpProvider(parameters);
if(result.getBoolean(RESULT_KEY)) {
- receiver.send(CORRECTLY_DOWNLOADED_JSON_FILES, Bundle.EMPTY);
- } else {
- receiver.send(INCORRECTLY_DOWNLOADED_JSON_FILES, result);
- }
- } else if(action.equalsIgnoreCase(UPDATE_PROVIDER_DOTJSON)) {
- Bundle result = updateProviderDotJSON(parameters);
- if(result.getBoolean(RESULT_KEY)) {
- receiver.send(CORRECTLY_UPDATED_PROVIDER_DOT_JSON, result);
+ receiver.send(PROVIDER_OK, result);
} else {
- receiver.send(INCORRECTLY_UPDATED_PROVIDER_DOT_JSON, Bundle.EMPTY);
+ receiver.send(PROVIDER_NOK, Bundle.EMPTY);
}
} else if (action.equalsIgnoreCase(SRP_AUTH)) {
Bundle session_id_bundle = authenticateBySRP(parameters);
@@ -178,60 +168,6 @@ public class ProviderAPI extends IntentService {
}
}
}
-
- /**
- * Downloads the main cert and the eip-service.json files given through the task parameter
- * @param task
- * @return true if eip-service.json was parsed as a JSON object correctly.
- */
- private Bundle downloadJsonFiles(Bundle task) {
- Bundle result = new Bundle();
- String cert_url = task.getString(Provider.CA_CERT);
- String eip_service_json_url = task.getString(EIP.KEY);
- boolean danger_on = task.getBoolean(ProviderItem.DANGER_ON);
- try {
- String cert_string = downloadWithCommercialCA(cert_url, danger_on);
-
- if(ConfigHelper.checkErroneousDownload(cert_string)) {
- JSONObject possible_errors = new JSONObject(cert_string);
- String reason_to_fail = "";
- if(cert_string.isEmpty())
- reason_to_fail = "Empty certificate downloaded";
- else
- reason_to_fail = possible_errors.getString(ERRORS);
- result.putString(ERRORS, reason_to_fail);
- result.putBoolean(RESULT_KEY, false);
- } else {
- X509Certificate certCert = ConfigHelper.parseX509CertificateFromString(cert_string);
- cert_string = Base64.encodeToString( certCert.getEncoded(), Base64.DEFAULT);
- ConfigHelper.saveSharedPref(Provider.CA_CERT, "-----BEGIN CERTIFICATE-----\n"+cert_string+"-----END CERTIFICATE-----");
- }
- } catch (JSONException e) {
- e.printStackTrace();
- result.putBoolean(RESULT_KEY, false);
- } catch (CertificateException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- result.putBoolean(RESULT_KEY, false);
- }
-
- try {
- String eip_service_string = downloadWithCommercialCA(eip_service_json_url, danger_on);
- JSONObject eip_service_json = new JSONObject(eip_service_string);
- if(eip_service_json.has(ERRORS)) {
- String reason_to_fail = eip_service_json.getString(ERRORS);
- result.putString(ERRORS, reason_to_fail);
- result.putBoolean(RESULT_KEY, false);
- }
- else ConfigHelper.saveSharedPref(EIP.KEY, eip_service_json);
-
- result.putBoolean(RESULT_KEY, true);
- } catch (JSONException e) {
- result.putBoolean(RESULT_KEY, false);
- }
-
- return result;
- }
/**
* Starts the authentication process using SRP protocol.
@@ -483,7 +419,7 @@ public class ProviderAPI extends IntentService {
* @param task containing a boolean meaning if the provider is custom or not, another boolean meaning if the user completely trusts this provider, the provider name and its provider.json url.
* @return a bundle with a boolean value mapped to a key named RESULT_KEY, and which is true if the update was successful.
*/
- private Bundle updateProviderDotJSON(Bundle task) {
+ private Bundle setUpProvider(Bundle task) {
Bundle result = new Bundle();
boolean danger_on = task.getBoolean(ProviderItem.DANGER_ON);
String provider_main_url = task.getString(Provider.MAIN_URL);
@@ -737,15 +673,6 @@ public class ProviderAPI extends IntentService {
}
return string;
}
-
- /**
- * Tries to guess the provider.json url given the main provider url.
- * @param provider_main_url
- * @return the guessed provider.json url
- */
- private String guessProviderDotJsonURL(String provider_main_url) {
- return provider_main_url + "/provider.json";
- }
/**
* Logs out from the api url retrieved from the task.
diff --git a/src/se/leap/bitmaskclient/ProviderListContent.java b/src/se/leap/bitmaskclient/ProviderListContent.java
index b13c5db4..e1ca4f9a 100644
--- a/src/se/leap/bitmaskclient/ProviderListContent.java
+++ b/src/se/leap/bitmaskclient/ProviderListContent.java
@@ -28,8 +28,6 @@ import java.net.MalformedURLException;
import org.json.JSONException;
import org.json.JSONObject;
-import android.app.Activity;
-
/**
* Models the provider list shown in the ConfigurationWizard.
*