summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/build.gradle3
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Provider.java42
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java1
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderListBaseActivity.java2
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderManager.java5
-rw-r--r--app/src/normal/assets/urls/riseup.net.url3
-rw-r--r--app/src/sharedTest/java/se.leap.bitmaskclient/testutils/TestSetupHelper.java7
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/ProviderTest.java2
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java14
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java4
-rw-r--r--app/src/test/resources/riseup_geoip.json20
11 files changed, 77 insertions, 26 deletions
diff --git a/app/build.gradle b/app/build.gradle
index 6c236669..088be987 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -41,6 +41,7 @@ android {
buildConfigField "String", "customProviderUrl", '""'
buildConfigField "String", "customProviderIp", '""'
buildConfigField "String", "customProviderApiIp", '""'
+ buildConfigField "String", "geoipUrl", '""'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
dexOptions {
@@ -97,6 +98,8 @@ android {
//static ip address of the provider api, using a self signed certificate to serve provider.json, eip-service.json etc.
def customProviderApiIp = '"198.252.153.107"'
buildConfigField "String", "customProviderApiIp", customProviderApiIp
+ def geoipUrl = '"https://api.black.riseup.net:9001/json"'
+ buildConfigField "String", "geoipUrl", geoipUrl
//Change the versionCode as needed
//versionCode 1
//Change the versionName as needed
diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java
index 4dd7c76e..8db3cc97 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Provider.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java
@@ -50,6 +50,7 @@ public final class Provider implements Parcelable {
private JSONObject eipServiceJson = new JSONObject();
private DefaultedURL mainUrl = new DefaultedURL();
private DefaultedURL apiUrl = new DefaultedURL();
+ private DefaultedURL geoipUrl = new DefaultedURL();
private String providerIp = "";
private String providerApiIp = "";
private String certificatePin = "";
@@ -78,21 +79,35 @@ public final class Provider implements Parcelable {
DOMAIN = "domain",
MAIN_URL = "main_url",
PROVIDER_IP = "provider_ip",
- PROVIDER_API_IP = "provider_api_ip";
+ PROVIDER_API_IP = "provider_api_ip",
+ GEOIP_URL = "geoip_url";
private static final String API_TERM_NAME = "name";
public Provider() { }
public Provider(String mainUrl) {
+ this(mainUrl, null);
+ }
+
+ public Provider(String mainUrl, String geoipUrl) {
try {
this.mainUrl.setUrl(new URL(mainUrl));
} catch (MalformedURLException e) {
this.mainUrl = new DefaultedURL();
}
+ try {
+ this.geoipUrl.setUrl(new URL(geoipUrl));
+ } catch (MalformedURLException e) {
+ this.geoipUrl = new DefaultedURL();
+ }
}
public Provider(String mainUrl, String providerIp, String providerApiIp) {
+ this(mainUrl, null, providerIp, providerApiIp);
+ }
+
+ public Provider(String mainUrl, String geoipUrl, String providerIp, String providerApiIp) {
try {
this.mainUrl.setUrl(new URL(mainUrl));
if (providerIp != null) {
@@ -103,21 +118,18 @@ public final class Provider implements Parcelable {
}
} catch (MalformedURLException e) {
e.printStackTrace();
+ return;
}
- }
-
- public Provider(String mainUrl, String providerIp, String providerApiIp, String caCert, String definition) {
try {
- this.mainUrl.setUrl(new URL(mainUrl));
+ this.geoipUrl.setUrl(new URL(geoipUrl));
} catch (MalformedURLException e) {
- e.printStackTrace();
- }
- if (this.providerIp != null) {
- this.providerIp = providerIp;
- }
- if (this.providerApiIp != null) {
- this.providerApiIp = providerApiIp;
+ this.geoipUrl = new DefaultedURL();
}
+ }
+
+
+ public Provider(String mainUrl, String geoipUrl, String providerIp, String providerApiIp, String caCert, String definition) {
+ this(mainUrl, geoipUrl, providerIp, providerApiIp);
if (caCert != null) {
this.caCert = caCert;
}
@@ -241,6 +253,10 @@ public final class Provider implements Parcelable {
return apiUrl;
}
+ protected DefaultedURL getGeoipUrl() {
+ return geoipUrl;
+ }
+
protected String getApiUrlWithVersion() {
return getApiUrlString() + "/" + getApiVersion();
}
@@ -321,6 +337,7 @@ public final class Provider implements Parcelable {
parcel.writeString(getMainUrlString());
parcel.writeString(getProviderIp());
parcel.writeString(getProviderApiIp());
+ parcel.writeString(getGeoipUrl().toString());
parcel.writeString(getDefinitionString());
parcel.writeString(getCaCert());
parcel.writeString(getEipServiceJsonString());
@@ -340,6 +357,7 @@ public final class Provider implements Parcelable {
providerIp.equals(p.getProviderIp()) &&
providerApiIp.equals(p.getProviderApiIp()) &&
apiUrl.equals(p.getApiUrl()) &&
+ geoipUrl.equals(p.getGeoipUrl()) &&
certificatePin.equals(p.getCertificatePin()) &&
certificatePinEncoding.equals(p.getCertificatePinEncoding()) &&
caCert.equals(p.getCaCert()) &&
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java
index 9d34b38f..df67f282 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java
@@ -53,6 +53,7 @@ public class ProviderAPI extends JobIntentService implements ProviderApiManagerB
LOG_OUT = "logOut",
DOWNLOAD_VPN_CERTIFICATE = "downloadUserAuthedVPNCertificate",
UPDATE_INVALID_VPN_CERTIFICATE = "ProviderAPI.UPDATE_INVALID_VPN_CERTIFICATE",
+ GEOSERVICE = "geoService",
PARAMETERS = "parameters",
RECEIVER_KEY = "receiver",
ERRORS = "errors",
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderListBaseActivity.java b/app/src/main/java/se/leap/bitmaskclient/ProviderListBaseActivity.java
index 7c45c921..a7d0f916 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderListBaseActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderListBaseActivity.java
@@ -106,7 +106,7 @@ public abstract class ProviderListBaseActivity extends ProviderSetupBaseActivity
}
public void showAndSelectProvider(String newURL) {
- provider = new Provider(newURL, "", "");
+ provider = new Provider(newURL, null, null);
autoSelectProvider();
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java b/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java
index 6d074a7a..c23ad270 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java
@@ -20,6 +20,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import static se.leap.bitmaskclient.Provider.GEOIP_URL;
import static se.leap.bitmaskclient.Provider.MAIN_URL;
import static se.leap.bitmaskclient.Provider.PROVIDER_API_IP;
import static se.leap.bitmaskclient.Provider.PROVIDER_IP;
@@ -90,18 +91,20 @@ public class ProviderManager implements AdapteeCollection<Provider> {
String providerApiIp = null;
String certificate = null;
String providerDefinition = null;
+ String geoipUrl = null;
try {
String provider = file.substring(0, file.length() - ".url".length());
InputStream providerFile = assetsManager.open(directory + "/" + file);
mainUrl = extractKeyFromInputStream(providerFile, MAIN_URL);
providerIp = extractKeyFromInputStream(providerFile, PROVIDER_IP);
providerApiIp = extractKeyFromInputStream(providerFile, PROVIDER_API_IP);
+ geoipUrl = extractKeyFromInputStream(providerFile, GEOIP_URL);
certificate = loadInputStreamAsString(assetsManager.open(provider + EXT_PEM));
providerDefinition = loadInputStreamAsString(assetsManager.open(provider + EXT_JSON));
} catch (IOException e) {
e.printStackTrace();
}
- providers.add(new Provider(mainUrl, providerIp, providerApiIp, certificate, providerDefinition));
+ providers.add(new Provider(mainUrl, geoipUrl, providerIp, providerApiIp, certificate, providerDefinition));
}
return providers;
diff --git a/app/src/normal/assets/urls/riseup.net.url b/app/src/normal/assets/urls/riseup.net.url
index a4a90f90..cfea527c 100644
--- a/app/src/normal/assets/urls/riseup.net.url
+++ b/app/src/normal/assets/urls/riseup.net.url
@@ -1,5 +1,6 @@
{
"main_url" : "https://riseup.net",
"provider_ip" : "198.252.153.70",
- "provider_api_ip" : "198.252.153.107"
+ "provider_api_ip" : "198.252.153.107",
+ "geoip_url" : "https://api.black.riseup.net:9001"
}
diff --git a/app/src/sharedTest/java/se.leap.bitmaskclient/testutils/TestSetupHelper.java b/app/src/sharedTest/java/se.leap.bitmaskclient/testutils/TestSetupHelper.java
index c7c85f8d..69fffcb4 100644
--- a/app/src/sharedTest/java/se.leap.bitmaskclient/testutils/TestSetupHelper.java
+++ b/app/src/sharedTest/java/se.leap.bitmaskclient/testutils/TestSetupHelper.java
@@ -51,12 +51,14 @@ public class TestSetupHelper {
public static Provider getConfiguredProvider() throws IOException, JSONException {
- return getProvider(null, null, null, null, null, null);
+ return getProvider(null, null, null, null, null, null, null);
}
- public static Provider getProvider(String domain, String providerIp, String providerApiIp, String caCertFile, String providerJson, String eipServiceJson) {
+ public static Provider getProvider(String domain, String geoipUrl, String providerIp, String providerApiIp, String caCertFile, String providerJson, String eipServiceJson) {
if (domain == null)
domain = "https://riseup.net";
+ if (geoipUrl == null)
+ geoipUrl = "https://api.black.riseup.net:9001/json";
if (providerIp == null) {
providerIp = "";
}
@@ -74,6 +76,7 @@ public class TestSetupHelper {
try {
Provider p = new Provider(
domain,
+ geoipUrl,
providerIp,
providerApiIp,
getInputAsString(TestSetupHelper.class.getClassLoader().getResourceAsStream(caCertFile)),
diff --git a/app/src/test/java/se/leap/bitmaskclient/ProviderTest.java b/app/src/test/java/se/leap/bitmaskclient/ProviderTest.java
index 0f9d358e..5e55add0 100644
--- a/app/src/test/java/se/leap/bitmaskclient/ProviderTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/ProviderTest.java
@@ -55,6 +55,7 @@ public class ProviderTest {
null,
null,
null,
+ null,
"ptdemo.bitmask.eip-service.json");
assertTrue(p1.supportsPluggableTransports());
}
@@ -67,6 +68,7 @@ public class ProviderTest {
null,
null,
null,
+ null,
"eip-service-two-gateways.json");
assertFalse(p1.supportsPluggableTransports());
}
diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
index 417c4bfc..be3d2e12 100644
--- a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
@@ -107,7 +107,7 @@ public class GatewaysManagerTest {
@Test
public void testGatewayManagerFromCurrentProvider_misconfiguredProvider_noGateways() throws IOException, NullPointerException {
- Provider provider = getProvider(null, null, null, null, null, "ptdemo_misconfigured_gateway.json");
+ Provider provider = getProvider(null, null, null, null, null, null, "ptdemo_misconfigured_gateway.json");
MockHelper.mockProviderObserver(provider);
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
assertEquals(0, gatewaysManager.size());
@@ -115,7 +115,7 @@ public class GatewaysManagerTest {
@Test
public void testGatewayManagerFromCurrentProvider_threeGateways() {
- Provider provider = getProvider(null, null, null,null, null, "ptdemo_three_mixed_gateways.json");
+ Provider provider = getProvider(null, null, null, null,null, null, "ptdemo_three_mixed_gateways.json");
MockHelper.mockProviderObserver(provider);
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
assertEquals(3, gatewaysManager.size());
@@ -123,7 +123,7 @@ public class GatewaysManagerTest {
@Test
public void TestGetPosition_VpnProfileExtistingObfs4_returnPositionZero() throws JSONException, ConfigParser.ConfigParseError, IOException {
- Provider provider = getProvider(null, null, null, null, null, "ptdemo_three_mixed_gateways.json");
+ Provider provider = getProvider(null, null, null, null, null, null, "ptdemo_three_mixed_gateways.json");
JSONObject eipServiceJson = provider.getEipServiceJson();
JSONObject gateway1 = eipServiceJson.getJSONArray(GATEWAYS).getJSONObject(0);
MockHelper.mockProviderObserver(provider);
@@ -140,7 +140,7 @@ public class GatewaysManagerTest {
@Test
public void TestGetPosition_VpnProfileExtistingOpenvpn_returnPositionZero() throws JSONException, ConfigParser.ConfigParseError, IOException {
- Provider provider = getProvider(null, null, null, null, null, "ptdemo_three_mixed_gateways.json");
+ Provider provider = getProvider(null, null, null, null, null, null, "ptdemo_three_mixed_gateways.json");
JSONObject eipServiceJson = provider.getEipServiceJson();
JSONObject gateway1 = eipServiceJson.getJSONArray(GATEWAYS).getJSONObject(0);
MockHelper.mockProviderObserver(provider);
@@ -157,7 +157,7 @@ public class GatewaysManagerTest {
@Test
public void TestGetPosition_VpnProfileDifferentIp_returnMinusOne() throws JSONException, ConfigParser.ConfigParseError, IOException {
- Provider provider = getProvider(null, null, null, null, null, "ptdemo_three_mixed_gateways.json");
+ Provider provider = getProvider(null, null, null, null, null, null, "ptdemo_three_mixed_gateways.json");
JSONObject eipServiceJson = provider.getEipServiceJson();
JSONObject gateway1 = eipServiceJson.getJSONArray(GATEWAYS).getJSONObject(0);
MockHelper.mockProviderObserver(provider);
@@ -174,7 +174,7 @@ public class GatewaysManagerTest {
@Test
public void TestGetPosition_VpnProfileMoscow_returnOne() throws JSONException, ConfigParser.ConfigParseError, IOException {
- Provider provider = getProvider(null, null, null, null, null, "ptdemo_three_mixed_gateways.json");
+ Provider provider = getProvider(null, null, null, null, null, null, "ptdemo_three_mixed_gateways.json");
JSONObject eipServiceJson = provider.getEipServiceJson();
JSONObject gateway1 = eipServiceJson.getJSONArray(GATEWAYS).getJSONObject(1);
MockHelper.mockProviderObserver(provider);
@@ -191,7 +191,7 @@ public class GatewaysManagerTest {
@Test
public void TestSelectN_selectFirstObfs4Connection_returnThirdGateway() throws JSONException, ConfigParser.ConfigParseError, IOException {
- Provider provider = getProvider(null, null, null, null, null, "ptdemo_two_openvpn_one_pt_gateways.json");
+ Provider provider = getProvider(null, null, null, null, null, null, "ptdemo_two_openvpn_one_pt_gateways.json");
JSONObject eipServiceJson = provider.getEipServiceJson();
JSONObject gateway3 = eipServiceJson.getJSONArray(GATEWAYS).getJSONObject(2);
diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java
index 753a9474..7a96310c 100644
--- a/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java
@@ -269,7 +269,7 @@ public class ProviderApiManagerTest {
@Test
public void test_handleIntentSetupProvider_preseededProviderAndCA_outdatedCertificate() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, JSONException {
- Provider provider = getProvider(null ,null, null, "outdated_cert.pem", null, null);
+ Provider provider = getProvider(null ,null, null, null, "outdated_cert.pem", null, null);
mockProviderApiConnector(NO_ERROR);
providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
@@ -386,7 +386,7 @@ public class ProviderApiManagerTest {
@Test
public void test_handleIntentSetupProvider_outdatedPreseededProviderAndCA_successfulConfiguration() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, JSONException {
- Provider provider = getProvider(null, null, null, null, "riseup_net_outdated_config.json", null);
+ Provider provider = getProvider(null, null, null, null, null, "riseup_net_outdated_config.json", null);
mockFingerprintForCertificate(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
mockProviderApiConnector(NO_ERROR);
diff --git a/app/src/test/resources/riseup_geoip.json b/app/src/test/resources/riseup_geoip.json
new file mode 100644
index 00000000..b646052e
--- /dev/null
+++ b/app/src/test/resources/riseup_geoip.json
@@ -0,0 +1,20 @@
+{
+ "ip":"51.158.144.32",
+ "cc":"FR",
+ "city":"Paris",
+ "lat":48.8628,
+ "lon":2.3292,
+ "gateways":[
+ "mouette.riseup.net",
+ "hoatzin.riseup.net",
+ "zarapito.riseup.net",
+ "redshank.riseup.net",
+ "shag.riseup.net",
+ "yal.riseup.net",
+ "gaei.riseup.net",
+ "cisne.riseup.net",
+ "swan.riseup.net",
+ "garza.riseup.net",
+ "gaviota.riseup.net"
+ ]
+} \ No newline at end of file