summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2019-10-19 01:48:40 +0200
committercyBerta <cyberta@riseup.net>2019-10-19 01:48:40 +0200
commit6053926be4aab408547ec77d6208cf4e2448eb51 (patch)
treef9c416b9bc78a6863ca1958d914df244e0e0568a /app
parent1c57a692843218179d421f2473789ad3c9efe977 (diff)
configure Gateways either from preferences or from current provider object
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java44
1 files changed, 38 insertions, 6 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java
index 5da40977..17a15c95 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java
@@ -33,12 +33,15 @@ import java.util.LinkedHashMap;
import de.blinkt.openvpn.core.ConfigParser;
import de.blinkt.openvpn.core.VpnStatus;
+import de.blinkt.openvpn.core.connection.Connection;
import se.leap.bitmaskclient.Provider;
+import se.leap.bitmaskclient.ProviderObservable;
import se.leap.bitmaskclient.utils.PreferenceHelper;
import static se.leap.bitmaskclient.Constants.GATEWAYS;
import static se.leap.bitmaskclient.Constants.PROVIDER_PRIVATE_KEY;
import static se.leap.bitmaskclient.Constants.PROVIDER_VPN_CERTIFICATE;
+import static se.leap.bitmaskclient.utils.PreferenceHelper.getUsePluggableTransports;
/**
* @author parmegv
@@ -52,9 +55,15 @@ public class GatewaysManager {
private LinkedHashMap<String, Gateway> gateways = new LinkedHashMap<>();
private Type listType = new TypeToken<ArrayList<Gateway>>() {}.getType();
- GatewaysManager(Context context, SharedPreferences preferences) {
+ public GatewaysManager(Context context, SharedPreferences preferences) {
this.preferences = preferences;
this.context = context;
+ configureFromPreferences();
+ }
+
+ public GatewaysManager(Context context) {
+ configureFromCurrentProvider();
+ this.context = context;
}
/**
@@ -90,7 +99,7 @@ public class GatewaysManager {
* parse gateways from eipDefinition
* @param eipDefinition eipServiceJson
*/
- void fromEipServiceJson(JSONObject eipDefinition) {
+ private void fromEipServiceJson(JSONObject eipDefinition, JSONObject secrets) {
JSONArray gatewaysDefined = new JSONArray();
try {
gatewaysDefined = eipDefinition.getJSONArray(GATEWAYS);
@@ -101,7 +110,6 @@ public class GatewaysManager {
for (int i = 0; i < gatewaysDefined.length(); i++) {
try {
JSONObject gw = gatewaysDefined.getJSONObject(i);
- JSONObject secrets = secretsConfiguration();
Gateway aux = new Gateway(eipDefinition, secrets, gw, this.context);
if (gateways.get(aux.getRemoteIP()) == null) {
addGateway(aux);
@@ -113,7 +121,7 @@ public class GatewaysManager {
}
}
- private JSONObject secretsConfiguration() {
+ private JSONObject secretsConfigurationFromPreferences() {
JSONObject result = new JSONObject();
try {
result.put(Provider.CA_CERT, preferences.getString(Provider.CA_CERT, ""));
@@ -125,6 +133,20 @@ public class GatewaysManager {
return result;
}
+ private JSONObject secretsConfigurationFromCurrentProvider() {
+ JSONObject result = new JSONObject();
+ Provider provider = ProviderObservable.getInstance().getCurrentProvider();
+
+ try {
+ result.put(Provider.CA_CERT, provider.getCaCert());
+ result.put(PROVIDER_PRIVATE_KEY, provider.getPrivateKey());
+ result.put(PROVIDER_VPN_CERTIFICATE, provider.getVpnCertificate());
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+
void clearGateways() {
gateways.clear();
@@ -137,9 +159,19 @@ public class GatewaysManager {
/**
* read EipServiceJson from preferences and set gateways
*/
- void configureFromPreferences() {
+ private void configureFromPreferences() {
fromEipServiceJson(
- PreferenceHelper.getEipDefinitionFromPreferences(preferences)
+ PreferenceHelper.getEipDefinitionFromPreferences(preferences), secretsConfigurationFromPreferences()
);
}
+
+ private void configureFromCurrentProvider() {
+ try {
+ JSONObject json = ProviderObservable.getInstance().getCurrentProvider().getEipServiceJson();
+ fromEipServiceJson(json, secretsConfigurationFromCurrentProvider());
+ } catch (NullPointerException npe) {
+ npe.printStackTrace();
+ }
+
+ }
}