diff options
author | cyberta <cyberta@riseup.net> | 2020-07-24 10:20:22 -0700 |
---|---|---|
committer | cyberta <cyberta@riseup.net> | 2020-07-24 10:20:22 -0700 |
commit | bdd909d1faae569f27d61ad510d11fad74a5a27c (patch) | |
tree | c3266b79c930a6a902814e6c58c457280ed67c2a /app/src/insecure/java/se/leap | |
parent | 4198c9b3bb1fee4bfcb3009ac9d80610ead13466 (diff) | |
parent | 38f5720502fda7b89ce204fe4afdffa67ac0ae82 (diff) |
Merge branch 'support_geoip' into 'master'
Support geoip
See merge request leap/bitmask_android!108
Diffstat (limited to 'app/src/insecure/java/se/leap')
-rw-r--r-- | app/src/insecure/java/se/leap/bitmaskclient/ProviderApiManager.java | 56 |
1 files changed, 49 insertions, 7 deletions
diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ProviderApiManager.java b/app/src/insecure/java/se/leap/bitmaskclient/ProviderApiManager.java index b67f6fa5..a111e907 100644 --- a/app/src/insecure/java/se/leap/bitmaskclient/ProviderApiManager.java +++ b/app/src/insecure/java/se/leap/bitmaskclient/ProviderApiManager.java @@ -136,15 +136,14 @@ public class ProviderApiManager extends ProviderApiManagerBase { private Bundle getAndSetProviderJson(Provider provider, boolean dangerOn) { Bundle result = new Bundle(); - String caCert = provider.getCaCert(); JSONObject providerDefinition = provider.getDefinition(); String providerMainUrl = provider.getMainUrlString(); String providerDotJsonString; - if(providerDefinition.length() == 0 || caCert.isEmpty()) + if(providerDefinition.length() == 0 || provider.getCaCert().isEmpty()) providerDotJsonString = downloadWithCommercialCA(providerMainUrl + "/provider.json", dangerOn); else - providerDotJsonString = downloadFromApiUrlWithProviderCA("/provider.json", caCert, provider, dangerOn); + providerDotJsonString = downloadFromApiUrlWithProviderCA("/provider.json", provider, dangerOn); if (ConfigHelper.checkErroneousDownload(providerDotJsonString) || !isValidJson(providerDotJsonString)) { setErrorResult(result, malformed_url, null); @@ -230,6 +229,44 @@ public class ProviderApiManager extends ProviderApiManagerBase { return result; } + /** + * Fetches the Geo ip Json, containing a list of gateways sorted by distance from the users current location + * + * @param provider + * @return + */ + @Override + protected Bundle getGeoIPJson(Provider provider) { + Bundle result = new Bundle(); + + if (!provider.shouldUpdateGeoIpJson() || provider.getGeoipUrl().isDefault()) { + result.putBoolean(BROADCAST_RESULT_KEY, false); + return result; + } + + + try { + URL geoIpUrl = provider.getGeoipUrl().getUrl(); + + String geoipJsonString = downloadFromUrlWithProviderCA(geoIpUrl.toString(), provider, lastDangerOn); + JSONObject geoipJson = new JSONObject(geoipJsonString); + + if (geoipJson.has(ERRORS)) { + result.putBoolean(BROADCAST_RESULT_KEY, false); + } else { + provider.setGeoIpJson(geoipJson); + provider.setLastEipServiceUpdate(System.currentTimeMillis()); + result.putBoolean(BROADCAST_RESULT_KEY, true); + } + + + } catch (JSONException | NullPointerException e) { + result.putBoolean(BROADCAST_RESULT_KEY, false); + e.printStackTrace(); + } + return result; + } + private Bundle downloadCACert(Provider provider, boolean dangerOn) { Bundle result = new Bundle(); @@ -291,16 +328,21 @@ public class ProviderApiManager extends ProviderApiManagerBase { return responseString; } - private String downloadFromApiUrlWithProviderCA(String path, String caCert, Provider provider, boolean dangerOn) { + private String downloadFromApiUrlWithProviderCA(String path, Provider provider, boolean dangerOn) { + String baseUrl = provider.getApiUrlString(); + String urlString = baseUrl + path; + + return downloadFromUrlWithProviderCA(urlString, provider, dangerOn); + } + + private String downloadFromUrlWithProviderCA(String urlString, Provider provider, boolean dangerOn) { String responseString; JSONObject errorJson = new JSONObject(); - String baseUrl = provider.getApiUrlString(); - OkHttpClient okHttpClient = clientGenerator.initSelfSignedCAHttpClient(caCert, errorJson); + OkHttpClient okHttpClient = clientGenerator.initSelfSignedCAHttpClient(provider.getCaCert(), errorJson); if (okHttpClient == null) { return errorJson.toString(); } - String urlString = baseUrl + path; List<Pair<String, String>> headerArgs = getAuthorizationHeader(); responseString = sendGetStringToServer(urlString, headerArgs, okHttpClient); |