From 283e7531d551521dc48efa9b010127ff54316326 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 4 Jul 2019 16:44:35 +0200 Subject: create one vpnprofile per transport per gateway. implement basis to switch between obfs4 and plain openvpn connections --- .../java/se/leap/bitmaskclient/eip/Gateway.java | 37 ++++++++++++++++------ 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java index 50fe74b7..9bc07764 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java @@ -16,16 +16,21 @@ */ package se.leap.bitmaskclient.eip; +import android.support.annotation.NonNull; + import com.google.gson.Gson; import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; +import java.util.HashMap; import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.core.ConfigParser; +import de.blinkt.openvpn.core.connection.Connection; +import static se.leap.bitmaskclient.Constants.IP_ADDRESS; import static se.leap.bitmaskclient.Constants.LOCATION; import static se.leap.bitmaskclient.Constants.LOCATIONS; import static se.leap.bitmaskclient.Constants.NAME; @@ -54,7 +59,7 @@ public class Gateway { private String name; private int timezone; private int apiVersion; - private VpnProfile vpnProfile; + private HashMap vpnProfiles; /** * Build a gateway object from a JSON OpenVPN gateway definition in eip-service.json @@ -69,9 +74,13 @@ public class Gateway { timezone = getTimezone(eipDefinition); name = locationAsName(eipDefinition); apiVersion = getApiVersion(eipDefinition); - vpnProfile = createVPNProfile(); - if (vpnProfile != null) { - vpnProfile.mName = name; + vpnProfiles = createVPNProfiles(); + } + + private void addProfileInfos(HashMap profiles) { + for (VpnProfile profile : profiles.values()) { + profile.mName = name; + profile.mGatewayIp = gateway.optString(IP_ADDRESS); } } @@ -92,6 +101,10 @@ public class Gateway { return eipDefinition.optInt(VERSION); } + public String getRemoteIP() { + return gateway.optString(IP_ADDRESS); + } + private String locationAsName(JSONObject eipDefinition) { JSONObject location = getLocationInfo(eipDefinition); return location.optString(NAME); @@ -110,23 +123,29 @@ public class Gateway { /** * Create and attach the VpnProfile to our gateway object */ - private VpnProfile createVPNProfile() { + private @NonNull HashMap createVPNProfiles() { + HashMap profiles = new HashMap<>(); try { VpnConfigGenerator vpnConfigurationGenerator = new VpnConfigGenerator(generalConfiguration, secrets, gateway, apiVersion); - return vpnConfigurationGenerator.generateVpnProfile(); + profiles = vpnConfigurationGenerator.generateVpnProfiles(); + addProfileInfos(profiles); } catch (ConfigParser.ConfigParseError | IOException | JSONException e) { // FIXME We didn't get a VpnProfile! Error handling! and log level e.printStackTrace(); - return null; } + return profiles; } public String getName() { return name; } - public VpnProfile getProfile() { - return vpnProfile; + public HashMap getProfiles() { + return vpnProfiles; + } + + public VpnProfile getProfile(Connection.TransportType transportType) { + return vpnProfiles.get(transportType); } public int getTimezone() { -- cgit v1.2.3