summaryrefslogtreecommitdiff
path: root/app/src/production/java/se
diff options
context:
space:
mode:
authorFup Duck <fupduck@sacknagel.com>2018-02-15 21:27:17 +0100
committerFup Duck <fupduck@sacknagel.com>2018-02-15 21:27:17 +0100
commit6c1434addf1ee25a8c7ce30c240e2033d5075f35 (patch)
tree13f0ab9d1c61ff64c1870338c02013f2caf32851 /app/src/production/java/se
parent9b6c368a25510c462ea357121c97edb6d0310021 (diff)
8797 - pair programming effort
Diffstat (limited to 'app/src/production/java/se')
-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) {