summaryrefslogtreecommitdiff
path: root/app/src/production
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2022-05-17 15:54:22 +0200
committercyBerta <cyberta@riseup.net>2022-05-18 10:46:21 +0200
commit8301b4bc5b24561b77d3381ea2e8ff8c72368669 (patch)
tree1cebba44623701c0ff83ab114916e2e31de3bf7c /app/src/production
parent18d3cc0ccbaf3bb9e797fcd542d180669b92dbd8 (diff)
use snowflake if necessary to update invalid vpn cert. Show cert update message in UI
Diffstat (limited to 'app/src/production')
-rw-r--r--app/src/production/java/se/leap/bitmaskclient/providersetup/ProviderApiManager.java46
1 files changed, 25 insertions, 21 deletions
diff --git a/app/src/production/java/se/leap/bitmaskclient/providersetup/ProviderApiManager.java b/app/src/production/java/se/leap/bitmaskclient/providersetup/ProviderApiManager.java
index d1de62a0..63b24ea2 100644
--- a/app/src/production/java/se/leap/bitmaskclient/providersetup/ProviderApiManager.java
+++ b/app/src/production/java/se/leap/bitmaskclient/providersetup/ProviderApiManager.java
@@ -199,29 +199,22 @@ public class ProviderApiManager extends ProviderApiManagerBase {
@Override
protected Bundle updateVpnCertificate(Provider provider) {
Bundle result = new Bundle();
- try {
- URL newCertStringUrl = new URL(provider.getApiUrlWithVersion() + "/" + PROVIDER_VPN_CERTIFICATE);
-
- String certString = downloadWithProviderCA(provider.getCaCert(), newCertStringUrl.toString());
- if (DEBUG_MODE) {
- VpnStatus.logDebug("[API] VPN CERT: " + certString);
- }
- if (ConfigHelper.checkErroneousDownload(certString)) {
- if (certString == null || certString.isEmpty()) {
- // probably 204
- setErrorResult(result, error_io_exception_user_message, null);
- } else {
- setErrorResult(result, certString);
- return result;
- }
+ String certString = downloadFromVersionedApiUrlWithProviderCA("/" + PROVIDER_VPN_CERTIFICATE, provider);
+ if (DEBUG_MODE) {
+ VpnStatus.logDebug("[API] VPN CERT: " + certString);
+ }
+ if (ConfigHelper.checkErroneousDownload(certString)) {
+ if (TorStatusObservable.getStatus() != OFF && TorStatusObservable.getProxyPort() != -1) {
+ setErrorResult(result, downloading_vpn_certificate_failed, null);
+ } else if (certString == null || certString.isEmpty() ){
+ // probably 204
+ setErrorResult(result, error_io_exception_user_message, null);
+ } else {
+ setErrorResult(result, certString);
}
- return loadCertificate(provider, certString);
- } catch (IOException e) {
- // TODO try to get Provider Json
- setErrorResult(result, downloading_vpn_certificate_failed, null);
- e.printStackTrace();
+ return result;
}
- return result;
+ return loadCertificate(provider, certString);
}
/**
@@ -352,6 +345,17 @@ public class ProviderApiManager extends ProviderApiManagerBase {
return downloadFromUrlWithProviderCA(urlString, provider);
}
+ /**
+ * Tries to download the contents of $base_url/$version/$path using not commercially validated CA certificate from chosen provider.
+ *
+ * @return an empty string if it fails, the response body if not.
+ */
+ private String downloadFromVersionedApiUrlWithProviderCA(String path, Provider provider) {
+ String baseUrl = provider.getApiUrlWithVersion();
+ String urlString = baseUrl + path;
+ return downloadFromUrlWithProviderCA(urlString, provider);
+ }
+
private String downloadFromUrlWithProviderCA(String urlString, Provider provider) {
return downloadFromUrlWithProviderCA(urlString, provider, true);
}