summaryrefslogtreecommitdiff
path: root/src/se/leap/bitmaskclient/ProviderAPI.java
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2013-11-07 10:43:03 +0100
committerParménides GV <parmegv@sdf.org>2013-12-10 18:16:07 +0100
commit0bcf72490f726825121e355afbeaf5b14636eb4d (patch)
tree26ede1c88c45a60a8b36c44b745649edd077f1d0 /src/se/leap/bitmaskclient/ProviderAPI.java
parente89dc12bb93da0a638d9a199af4d91a54aa3556e (diff)
Retry button on failed downloads.
Next step: remove the provider from the list (big security hole, since all providers present on the list are assumed to be secure).
Diffstat (limited to 'src/se/leap/bitmaskclient/ProviderAPI.java')
-rw-r--r--src/se/leap/bitmaskclient/ProviderAPI.java46
1 files changed, 34 insertions, 12 deletions
diff --git a/src/se/leap/bitmaskclient/ProviderAPI.java b/src/se/leap/bitmaskclient/ProviderAPI.java
index 0070b307..5d049d42 100644
--- a/src/se/leap/bitmaskclient/ProviderAPI.java
+++ b/src/se/leap/bitmaskclient/ProviderAPI.java
@@ -116,12 +116,15 @@ public class ProviderAPI extends IntentService {
INCORRECTLY_DOWNLOADED_ANON_CERTIFICATE = 14
;
- public static boolean
+ private static boolean
CA_CERT_DOWNLOADED = false,
PROVIDER_JSON_DOWNLOADED = false,
EIP_SERVICE_JSON_DOWNLOADED = false
;
+ static private String last_provider_main_url;
+ static private boolean last_danger_on = false;
+
public ProviderAPI() {
super("ProviderAPI");
Log.v("ClassName", "Provider API");
@@ -425,21 +428,28 @@ public class ProviderAPI extends IntentService {
*/
private Bundle setUpProvider(Bundle task) {
int progress = 0;
- boolean danger_on = task.getBoolean(ProviderItem.DANGER_ON);
- String provider_main_url = task.getString(Provider.MAIN_URL);
+ Bundle current_download = new Bundle();
+
+ if(task != null && task.containsKey(ProviderItem.DANGER_ON) && task.containsKey(Provider.MAIN_URL)) {
+ last_danger_on = task.getBoolean(ProviderItem.DANGER_ON);
+ last_provider_main_url = task.getString(Provider.MAIN_URL);
+ CA_CERT_DOWNLOADED = PROVIDER_JSON_DOWNLOADED = EIP_SERVICE_JSON_DOWNLOADED = false;
+ }
- Bundle current_download = downloadCACert(provider_main_url, danger_on);
- if(current_download.containsKey(RESULT_KEY) && current_download.getBoolean(RESULT_KEY)) {
+ if(!CA_CERT_DOWNLOADED)
+ current_download = downloadCACert(last_provider_main_url, last_danger_on);
+ if(CA_CERT_DOWNLOADED || (current_download.containsKey(RESULT_KEY) && current_download.getBoolean(RESULT_KEY))) {
broadcast_progress(progress++);
- //CA_CERT_DOWNLOADED = true;
- current_download = getAndSetProviderJson(provider_main_url);
- if(current_download.containsKey(RESULT_KEY) && current_download.getBoolean(RESULT_KEY)) {
+ CA_CERT_DOWNLOADED = true;
+ if(!PROVIDER_JSON_DOWNLOADED)
+ current_download = getAndSetProviderJson(last_provider_main_url);
+ if(PROVIDER_JSON_DOWNLOADED || (current_download.containsKey(RESULT_KEY) && current_download.getBoolean(RESULT_KEY))) {
broadcast_progress(progress++);
- //PROVIDER_JSON_DOWNLOADED = true;
+ PROVIDER_JSON_DOWNLOADED = true;
current_download = getAndSetEipServiceJson();
if(current_download.containsKey(RESULT_KEY) && current_download.getBoolean(RESULT_KEY)) {
broadcast_progress(progress++);
- //EIP_SERVICE_JSON_DOWNLOADED = true;
+ EIP_SERVICE_JSON_DOWNLOADED = true;
}
}
}
@@ -457,15 +467,18 @@ public class ProviderAPI extends IntentService {
String reason_to_fail = cert_string;
result.putString(ERRORS, reason_to_fail);
result.putBoolean(RESULT_KEY, false);
-
}
return result;
}
+ public static boolean caCertDownloaded() {
+ return CA_CERT_DOWNLOADED;
+ }
+
private boolean validCertificate(String cert_string) {
boolean result = false;
- if(!cert_string.isEmpty()) {
+ if(!ConfigHelper.checkErrorenousDownload(cert_string)) {
X509Certificate certCert = ConfigHelper.parseX509CertificateFromString(cert_string);
try {
Base64.encodeToString( certCert.getEncoded(), Base64.DEFAULT);
@@ -498,6 +511,10 @@ public class ProviderAPI extends IntentService {
}
+ public static boolean providerJsonDownloaded() {
+ return PROVIDER_JSON_DOWNLOADED;
+ }
+
private Bundle getAndSetEipServiceJson() {
Bundle result = new Bundle();
String eip_service_json_string = "";
@@ -518,6 +535,11 @@ public class ProviderAPI extends IntentService {
}
return result;
}
+
+ public static boolean eipServiceDownloaded() {
+ return EIP_SERVICE_JSON_DOWNLOADED;
+ }
+
/**
* Tries to download the contents of the provided url using commercially validated CA certificate from chosen provider.
*