summaryrefslogtreecommitdiff
path: root/app/src/main/java/se
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2024-10-26 01:47:00 +0200
committercyberta <cyberta@riseup.net>2024-12-11 00:09:34 +0000
commit980b0038ac33ea650450fe70025f2a72402307c3 (patch)
tree8b7f4ce31e46620dd84f97e984b6f40c9f7f285f /app/src/main/java/se
parent53381d8985bf881723d065a0cc6f7ae465d72933 (diff)
add new java swagger model classes to Provider model, replace java models of generated go swagger structs
Diffstat (limited to 'app/src/main/java/se')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java117
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV5.java60
2 files changed, 115 insertions, 62 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java b/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java
index 3545caca..5db87f50 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java
@@ -46,17 +46,18 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.security.PrivateKey;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import de.blinkt.openvpn.core.connection.Connection.TransportProtocol;
import de.blinkt.openvpn.core.connection.Connection.TransportType;
-import mobilemodels.Bridges;
-import mobilemodels.Gateways;
-import models.ModelsBridge;
-import models.ModelsEIPService;
-import models.ModelsProvider;
+import io.swagger.client.JSON;
+import io.swagger.client.model.ModelsBridge;
+import io.swagger.client.model.ModelsEIPService;
+import io.swagger.client.model.ModelsGateway;
+import io.swagger.client.model.ModelsProvider;
import motd.IStringCollection;
import motd.Motd;
@@ -77,11 +78,10 @@ public final class Provider implements Parcelable {
private String apiUrl = "";
private String geoipUrl = "";
private String motdUrl = "";
- private Gateways gateways = null;
-
+ private ModelsEIPService modelsEIPService = null;
private ModelsProvider modelsProvider = null;
- private ModelsEIPService service = null;
- private Bridges bridges = null;
+ private ModelsGateway[] modelsGateways = null;
+ private ModelsBridge[] modelsBridges = null;
private String domain = "";
private String providerIp = ""; // ip of the provider main url
private String providerApiIp = ""; // ip of the provider api url
@@ -193,27 +193,27 @@ public final class Provider implements Parcelable {
}
};
- public void setBridges(Bridges bridges) {
- this.bridges = bridges;
+ public void setBridges(ModelsBridge[] bridges) {
+ this.modelsBridges = bridges;
}
- public Bridges getBridges() {
- return this.bridges;
+ public ModelsBridge[] getBridges() {
+ return this.modelsBridges;
}
- public void setGateways(Gateways gateways) {
- this.gateways = gateways;
+ public void setGateways(ModelsGateway[] gateways) {
+ this.modelsGateways = gateways;
}
- public Gateways getGateways() {
- return gateways;
+ public ModelsGateway[] getGateways() {
+ return modelsGateways;
}
public void setService(ModelsEIPService service) {
- this.service = service;
+ this.modelsEIPService = service;
}
public ModelsEIPService getService() {
- return this.service;
+ return this.modelsEIPService;
}
public boolean isConfigured() {
@@ -228,8 +228,8 @@ public final class Provider implements Parcelable {
} else {
return !mainUrl.isEmpty() &&
modelsProvider != null &&
- service != null &&
- gateways != null &&
+ modelsEIPService != null &&
+ modelsGateways != null &&
hasVpnCertificate() &&
hasPrivateKey();
}
@@ -281,12 +281,11 @@ public final class Provider implements Parcelable {
// ignore
}
} else {
- if (bridges == null) return false;
- for (int i = 0; i < bridges.length(); i++) {
- ModelsBridge bridge = bridges.get(i);
+ if (modelsBridges == null) return false;
+ for (ModelsBridge bridge : modelsBridges) {
for (Pair<TransportType, TransportProtocol> transportPair : transportTypes) {
if (transportPair.first.toString().equals(bridge.getType()) &&
- transportPair.second.toString().equals(bridge.getTransport())) {
+ transportPair.second.toString().equals(bridge.getTransport())) {
return true;
}
}
@@ -474,7 +473,7 @@ public final class Provider implements Parcelable {
}
public boolean hasServiceInfo() {
- return service != null;
+ return modelsEIPService != null;
}
public boolean hasGatewaysInDifferentLocations() {
@@ -512,6 +511,13 @@ public final class Provider implements Parcelable {
parcel.writeStringList(new ArrayList<>(lastMotdSeenHashes));
parcel.writeInt(shouldUpdateVpnCertificate ? 0 : 1);
parcel.writeParcelable(introducer, 0);
+ if (apiVersion == 5) {
+ Gson gson = JSON.createGson().create();
+ parcel.writeString(modelsProvider != null ? gson.toJson(modelsProvider) : "");
+ parcel.writeString(modelsEIPService != null ? gson.toJson(modelsEIPService) : "");
+ parcel.writeString(modelsBridges != null ? gson.toJson(modelsBridges) : "");
+ parcel.writeString(modelsGateways != null ? gson.toJson(modelsGateways) : "");
+ }
}
@@ -574,6 +580,25 @@ public final class Provider implements Parcelable {
this.lastMotdSeenHashes = new HashSet<>(lastMotdSeenHashes);
this.shouldUpdateVpnCertificate = in.readInt() == 0;
this.introducer = in.readParcelable(Introducer.class.getClassLoader());
+ if (this.apiVersion == 5) {
+ Gson gson = JSON.createGson().create();
+ tmpString = in.readString();
+ if (!tmpString.isEmpty()) {
+ this.setModelsProvider(gson.fromJson(tmpString, ModelsProvider.class));
+ }
+ tmpString = in.readString();
+ if (!tmpString.isEmpty()) {
+ this.setService(gson.fromJson(tmpString, ModelsEIPService.class));
+ }
+ tmpString = in.readString();
+ if (!tmpString.isEmpty()) {
+ this.setBridges(gson.fromJson(tmpString, ModelsBridge[].class));
+ }
+ tmpString = in.readString();
+ if (!tmpString.isEmpty()) {
+ this.setGateways(gson.fromJson(tmpString, ModelsGateway[].class));
+ }
+ }
} catch (MalformedURLException | JSONException e) {
e.printStackTrace();
}
@@ -585,24 +610,28 @@ public final class Provider implements Parcelable {
if (o instanceof Provider) {
Provider p = (Provider) o;
return getDomain().equals(p.getDomain()) &&
- getHostFromUrl(mainUrl).equals(getHostFromUrl(p.getMainUrl())) &&
- definition.toString().equals(p.getDefinition().toString()) &&
- eipServiceJson.toString().equals(p.getEipServiceJsonString()) &&
- geoIpJson.toString().equals(p.getGeoIpJsonString()) &&
- motdJson.toString().equals(p.getMotdJsonString()) &&
- providerIp.equals(p.getProviderIp()) &&
- providerApiIp.equals(p.getProviderApiIp()) &&
- apiUrl.equals(p.getApiUrl()) &&
- geoipUrl.equals(p.getGeoipUrl()) &&
- motdUrl.equals(p.getMotdUrl()) &&
- certificatePin.equals(p.getCertificatePin()) &&
- certificatePinEncoding.equals(p.getCertificatePinEncoding()) &&
- caCert.equals(p.getCaCert()) &&
- apiVersion == p.getApiVersion() &&
- privateKeyString.equals(p.getPrivateKeyString()) &&
- vpnCertificate.equals(p.getVpnCertificate()) &&
- allowAnonymous == p.allowsAnonymous() &&
- allowRegistered == p.allowsRegistered();
+ getHostFromUrl(mainUrl).equals(getHostFromUrl(p.getMainUrl())) &&
+ definition.toString().equals(p.getDefinition().toString()) &&
+ eipServiceJson.toString().equals(p.getEipServiceJsonString()) &&
+ geoIpJson.toString().equals(p.getGeoIpJsonString()) &&
+ motdJson.toString().equals(p.getMotdJsonString()) &&
+ providerIp.equals(p.getProviderIp()) &&
+ providerApiIp.equals(p.getProviderApiIp()) &&
+ apiUrl.equals(p.getApiUrl()) &&
+ geoipUrl.equals(p.getGeoipUrl()) &&
+ motdUrl.equals(p.getMotdUrl()) &&
+ certificatePin.equals(p.getCertificatePin()) &&
+ certificatePinEncoding.equals(p.getCertificatePinEncoding()) &&
+ caCert.equals(p.getCaCert()) &&
+ apiVersion == p.getApiVersion() &&
+ privateKeyString.equals(p.getPrivateKeyString()) &&
+ vpnCertificate.equals(p.getVpnCertificate()) &&
+ allowAnonymous == p.allowsAnonymous() &&
+ allowRegistered == p.allowsRegistered() &&
+ modelsProvider.equals(p.modelsProvider) &&
+ modelsEIPService.equals(p.modelsEIPService) &&
+ Arrays.equals(modelsBridges, p.modelsBridges) &&
+ Arrays.equals(modelsGateways, p.modelsGateways);
} else return false;
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV5.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV5.java
index 254591a2..6e748afa 100644
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV5.java
+++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV5.java
@@ -38,11 +38,13 @@ import java.security.cert.X509Certificate;
import java.util.ArrayList;
import de.blinkt.openvpn.core.VpnStatus;
+import io.swagger.client.JSON;
+import io.swagger.client.model.ModelsBridge;
+import io.swagger.client.model.ModelsEIPService;
+import io.swagger.client.model.ModelsGateway;
+import io.swagger.client.model.ModelsProvider;
import mobile.BitmaskMobile;
-import mobilemodels.Bridges;
-import mobilemodels.Gateways;
-import models.ModelsEIPService;
-import models.ModelsProvider;
+import se.leap.bitmaskclient.BuildConfig;
import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.base.models.Provider;
import se.leap.bitmaskclient.base.models.ProviderObservable;
@@ -119,7 +121,8 @@ public class ProviderApiManagerV5 extends ProviderApiManagerBase implements IPro
configureBaseCountryCode(bm, parameters);
try {
- ModelsEIPService service = bm.getService();
+ String serviceJson = bm.getService();
+ ModelsEIPService service = JSON.createGson().create().fromJson(serviceJson, ModelsEIPService.class);
provider.setService(service);
} catch (Exception e) {
return eventSender.setErrorResult(currentDownload, R.string.config_error_found, null);
@@ -127,19 +130,24 @@ public class ProviderApiManagerV5 extends ProviderApiManagerBase implements IPro
if (PreferenceHelper.getUseBridges()) {
try {
- Bridges bridges = bm.getAllBridges("", "", "", "");
- if (bridges.length() == 0) {
+ String bridgesJson = bm.getAllBridges("", "", "", "");
+ if (bridgesJson.isEmpty()) {
//TODO send no bridges error event
}
+ ModelsBridge[] bridges = JSON.createGson().create().fromJson(bridgesJson, ModelsBridge[].class);
provider.setBridges(bridges);
} catch (Exception e) {
// TODO: send failed to fetch bridges event
}
} else {
- Gateways gateways = null;
- try {
- gateways = bm.getAllGateways("", "", "");
- provider.setGateways(gateways);
+ try {
+ String gatewaysJson = bm.getAllGateways("", "", "");
+ if (gatewaysJson.isEmpty()) {
+ //TODO send no bridges error event
+ }
+ ModelsGateway[] gateways = JSON.createGson().create().fromJson(gatewaysJson, ModelsGateway[].class);
+
+ provider.setGateways(gateways);
} catch (Exception e) {
// TODO: send
return eventSender.setErrorResult(currentDownload, R.string.config_error_found, null);
@@ -189,33 +197,49 @@ public class ProviderApiManagerV5 extends ProviderApiManagerBase implements IPro
configureBaseCountryCode(bm, parameters);
try {
- ModelsProvider p = bm.getProvider();
+ String providerJson = bm.getProvider();
+ Log.d(TAG, "provider Json reponse: " + providerJson);
+ ModelsProvider p = JSON.createGson().create().fromJson(providerJson, ModelsProvider.class);
provider.setModelsProvider(p);
ProviderSetupObservable.updateProgress(DOWNLOADED_PROVIDER_JSON);
} catch (Exception e) {
+ Log.w(TAG, "failed fo fetch provider.json: " + e.getMessage());
+ e.printStackTrace();
return eventSender.setErrorResult(currentDownload, R.string.error_json_exception_user_message, null);
}
try {
- ModelsEIPService service = bm.getService();
+ String serviceJson = bm.getService();
+ Log.d(TAG, "service Json reponse: " + serviceJson);
+ ModelsEIPService service = JSON.createGson().create().fromJson(serviceJson, ModelsEIPService.class);
provider.setService(service);
ProviderSetupObservable.updateProgress(DOWNLOADED_EIP_SERVICE_JSON);
} catch (Exception e) {
+ Log.w(TAG, "failed to fetch service.json: " + e.getMessage());
+ e.printStackTrace();
return eventSender.setErrorResult(currentDownload, R.string.error_json_exception_user_message, null);
}
try {
// TODO: check if provider supports this API endpoint?
- Gateways gateways = bm.getAllGateways("", "", "");
+ String gatewaysJson = bm.getAllGateways("", "", "");
+ Log.d(TAG, "gateways Json reponse: " + gatewaysJson);
+ ModelsGateway[] gateways = JSON.createGson().create().fromJson(gatewaysJson, ModelsGateway[].class);
provider.setGateways(gateways);
} catch (Exception e) {
+ Log.w(TAG, "failed to fetch gateways: " + e.getMessage());
+ e.printStackTrace();
return eventSender.setErrorResult(currentDownload, R.string.error_json_exception_user_message, null);
}
try {
// TODO: check if provider supports this API endpoint?
- Bridges bridges = bm.getAllBridges("", "", "", "");
+ String bridgesJson = bm.getAllBridges("", "", "", "");
+ Log.d(TAG, "bridges Json reponse: " + bridgesJson);
+ ModelsBridge[] bridges = JSON.createGson().create().fromJson(bridgesJson, ModelsBridge[].class);
provider.setBridges(bridges);
} catch (Exception e) {
+ Log.w(TAG, "failed to fetch bridges: " + e.getMessage());
+ e.printStackTrace();
return eventSender.setErrorResult(currentDownload, R.string.error_json_exception_user_message, null);
}
@@ -237,14 +261,14 @@ public class ProviderApiManagerV5 extends ProviderApiManagerBase implements IPro
TorStatusObservable.getStatus() == OFF) {
try {
// FIXME: doGeolocationLookup currently sets the country code implicitly, change that in bitmask-core
- bm.doGeolocationLookup();
+ cc = bm.getGeolocation();
} catch (Exception e) {
// print exception and ignore
e.printStackTrace();
+ cc = "";
}
- } else {
- bm.setCountryCode(cc);
}
+ bm.setCountryCode(cc);
}
Bundle validateProviderDetails(Provider provider) {