summaryrefslogtreecommitdiff
path: root/app/src/production
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/production')
-rw-r--r--app/src/production/java/se/leap/bitmaskclient/ProviderApiManager.java33
1 files changed, 20 insertions, 13 deletions
diff --git a/app/src/production/java/se/leap/bitmaskclient/ProviderApiManager.java b/app/src/production/java/se/leap/bitmaskclient/ProviderApiManager.java
index 5317118b..a6f0436d 100644
--- a/app/src/production/java/se/leap/bitmaskclient/ProviderApiManager.java
+++ b/app/src/production/java/se/leap/bitmaskclient/ProviderApiManager.java
@@ -38,6 +38,8 @@ import static se.leap.bitmaskclient.Constants.PROVIDER_VPN_CERTIFICATE;
import static se.leap.bitmaskclient.DownloadFailedDialog.DOWNLOAD_ERRORS.ERROR_CERTIFICATE_PINNING;
import static se.leap.bitmaskclient.DownloadFailedDialog.DOWNLOAD_ERRORS.ERROR_CORRUPTED_PROVIDER_JSON;
import static se.leap.bitmaskclient.ProviderAPI.ERRORS;
+import static se.leap.bitmaskclient.R.string.downloading_vpn_certificate_failed;
+import static se.leap.bitmaskclient.R.string.error_io_exception_user_message;
import static se.leap.bitmaskclient.R.string.malformed_url;
import static se.leap.bitmaskclient.R.string.warning_corrupted_provider_cert;
import static se.leap.bitmaskclient.R.string.warning_corrupted_provider_details;
@@ -172,27 +174,32 @@ public class ProviderApiManager extends ProviderApiManagerBase {
* @return true if certificate was downloaded correctly, false if provider.json is not present in SharedPreferences, or if the certificate url could not be parsed as a URI, or if there was an SSL error.
*/
@Override
- protected boolean updateVpnCertificate(Provider provider) {
+ protected Bundle updateVpnCertificate(Provider provider) {
+ Bundle result = new Bundle();
try {
JSONObject providerJson = provider.getDefinition();
String providerMainUrl = providerJson.getString(Provider.API_URL);
URL newCertStringUrl = new URL(providerMainUrl + "/" + providerJson.getString(Provider.API_VERSION) + "/" + PROVIDER_VPN_CERTIFICATE);
String certString = downloadWithProviderCA(provider.getCaCert(), newCertStringUrl.toString());
-
- if (ConfigHelper.checkErroneousDownload(certString))
- return false;
- else
- return loadCertificate(provider, certString);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return false;
- } catch (JSONException e) {
- // TODO Auto-generated catch block
+ if (ConfigHelper.checkErroneousDownload(certString)) {
+ if (certString == null || certString.isEmpty()) {
+ // probably 204
+ setErrorResult(result, error_io_exception_user_message, null);
+ } else {
+ String reasonToFail = pickErrorMessage(certString);
+ result.putString(ERRORS, reasonToFail);
+ result.putBoolean(BROADCAST_RESULT_KEY, false);
+ return result;
+ }
+ }
+ return loadCertificate(provider, certString);
+ } catch (IOException | JSONException e) {
+ // TODO try to get Provider Json
+ setErrorResult(result, downloading_vpn_certificate_failed, null);
e.printStackTrace();
- return false;
}
+ return result;
}
private Bundle downloadCACert(Provider provider) {