summaryrefslogtreecommitdiff
path: root/app/src/production
diff options
context:
space:
mode:
authorcyberta <cyberta@riseup.net>2017-11-09 10:32:45 -0800
committercyberta <cyberta@riseup.net>2017-11-09 10:32:45 -0800
commitf6e7474c37bd2ee65b290474f5ea601082ca7eb4 (patch)
tree91a8b79da9aa1ed5bf84d1890721e346609f1048 /app/src/production
parentbd49ce4456af6b71ef8aea96d58aae5baaab069a (diff)
parent859c2b4496618c8142c70610ebba395e9aa4d5dc (diff)
Merge branch '8778_invalid_provider_error_handling' into 'master'
#8778 fixes invalid provider error handling See merge request leap/bitmask_android!15
Diffstat (limited to 'app/src/production')
-rw-r--r--app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java12
1 files changed, 9 insertions, 3 deletions
diff --git a/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java
index 982080de..70a2c27c 100644
--- a/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java
+++ b/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java
@@ -107,6 +107,12 @@ public class ProviderAPI extends ProviderApiBase {
else
provider_dot_json_string = downloadWithCommercialCA(provider_main_url + "/provider.json", provider_ca_cert_fingerprint);
+ if (!isValidJson(provider_dot_json_string)) {
+ result.putString(ERRORS, getString(malformed_url));
+ result.putBoolean(RESULT_KEY, false);
+ return result;
+ }
+
try {
JSONObject provider_json = new JSONObject(provider_dot_json_string);
provider_api_url = provider_json.getString(Provider.API_URL) + "/" + provider_json.getString(Provider.API_VERSION);
@@ -147,7 +153,7 @@ public class ProviderAPI extends ProviderApiBase {
preferences.edit().putString(Constants.KEY, eip_service_json.toString()).commit();
result.putBoolean(RESULT_KEY, true);
- } catch (JSONException e) {
+ } catch (NullPointerException | JSONException e) {
String reason_to_fail = pickErrorMessage(eip_service_json_string);
result.putString(ERRORS, reason_to_fail);
result.putBoolean(RESULT_KEY, false);
@@ -171,7 +177,7 @@ public class ProviderAPI extends ProviderApiBase {
String cert_string = downloadWithProviderCA(new_cert_string_url.toString());
- if (cert_string.isEmpty() || ConfigHelper.checkErroneousDownload(cert_string))
+ if (cert_string == null || cert_string.isEmpty() || ConfigHelper.checkErroneousDownload(cert_string))
return false;
else
return loadCertificate(cert_string);
@@ -253,7 +259,7 @@ public class ProviderAPI extends ProviderApiBase {
responseString = sendGetStringToServer(string_url, headerArgs, okHttpClient);
- if (responseString.contains(ERRORS)) {
+ if (responseString != null && responseString.contains(ERRORS)) {
try {
// try to download with provider CA on certificate error
JSONObject responseErrorJson = new JSONObject(responseString);