summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/custom/assets/ptdemo.bitmask.secrets.json4
-rw-r--r--app/src/main/java/de/blinkt/openvpn/VpnProfile.java2
-rw-r--r--app/src/main/java/de/blinkt/openvpn/core/ProfileManager.java0
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIP.java8
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java37
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java50
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java19
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/EipStatusTest.java6
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java9
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java89
-rw-r--r--app/src/test/resources/ptdemo.bitmask.eip-service.json4
-rw-r--r--app/src/test/resources/ptdemo_pt_tcp_udp.eip-service.json2
-rw-r--r--app/src/test/resources/ptdemo_pt_udp_tcp.eip-service.json2
-rw-r--r--app/src/test/resources/ptdemo_three_mixed_gateways.json133
14 files changed, 261 insertions, 104 deletions
diff --git a/app/src/custom/assets/ptdemo.bitmask.secrets.json b/app/src/custom/assets/ptdemo.bitmask.secrets.json
index 7d84bd79..61f1fe1d 100644
--- a/app/src/custom/assets/ptdemo.bitmask.secrets.json
+++ b/app/src/custom/assets/ptdemo.bitmask.secrets.json
@@ -1,5 +1,5 @@
{
"ca_cert":"-----BEGIN CERTIFICATE-----\nMIIFjTCCA3WgAwIBAgIBATANBgkqhkiG9w0BAQ0FADBZMRgwFgYDVQQKDA9SaXNl\ndXAgTmV0d29ya3MxGzAZBgNVBAsMEmh0dHBzOi8vcmlzZXVwLm5ldDEgMB4GA1UE\nAwwXUmlzZXVwIE5ldHdvcmtzIFJvb3QgQ0EwHhcNMTQwNDI4MDAwMDAwW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/app/src/main/java/de/blinkt/openvpn/VpnProfile.java b/app/src/main/java/de/blinkt/openvpn/VpnProfile.java
index dc12c6a8..f139fdc9 100644
--- a/app/src/main/java/de/blinkt/openvpn/VpnProfile.java
+++ b/app/src/main/java/de/blinkt/openvpn/VpnProfile.java
@@ -174,6 +174,7 @@ public class VpnProfile implements Serializable, Cloneable {
// timestamp when the profile was last used
public long mLastUsed;
public String importedProfileHash;
+ //TODO: cleanup here
/* Options no longer used in new profiles */
public String mServerName = "openvpn.example.com";
public String mServerPort = "1194";
@@ -184,6 +185,7 @@ public class VpnProfile implements Serializable, Cloneable {
// set members to default values
private UUID mUuid;
private int mProfileVersion;
+ public String mGatewayIp;
public boolean mUsePluggableTransports;
public VpnProfile(String name, Connection.TransportType transportType) {
diff --git a/app/src/main/java/de/blinkt/openvpn/core/ProfileManager.java b/app/src/main/java/de/blinkt/openvpn/core/ProfileManager.java
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/app/src/main/java/de/blinkt/openvpn/core/ProfileManager.java
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
index a5434871..1d702ec1 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
@@ -53,6 +53,8 @@ import se.leap.bitmaskclient.R;
import static android.app.Activity.RESULT_CANCELED;
import static android.app.Activity.RESULT_OK;
import static android.content.Intent.CATEGORY_DEFAULT;
+import static de.blinkt.openvpn.core.connection.Connection.TransportType.OBFS4;
+import static de.blinkt.openvpn.core.connection.Connection.TransportType.OPENVPN;
import static se.leap.bitmaskclient.Constants.BROADCAST_EIP_EVENT;
import static se.leap.bitmaskclient.Constants.BROADCAST_GATEWAY_SETUP_OBSERVER_EVENT;
import static se.leap.bitmaskclient.Constants.BROADCAST_RESULT_CODE;
@@ -203,7 +205,7 @@ public final class EIP extends JobIntentService implements Observer {
GatewaysManager gatewaysManager = gatewaysFromPreferences();
Gateway gateway = gatewaysManager.select(nClosestGateway);
- if (gateway != null && gateway.getProfile() != null) {
+ if (gateway != null && !gateway.getProfiles().isEmpty()) {
launchActiveGateway(gateway, nClosestGateway);
tellToReceiverOrBroadcast(EIP_ACTION_START, RESULT_OK);
} else
@@ -218,7 +220,7 @@ public final class EIP extends JobIntentService implements Observer {
GatewaysManager gatewaysManager = gatewaysFromPreferences();
Gateway gateway = gatewaysManager.select(0);
- if (gateway != null && gateway.getProfile() != null) {
+ if (gateway != null && !gateway.getProfiles().isEmpty()) {
launchActiveGateway(gateway, 0);
} else {
Log.d(TAG, "startEIPAlwaysOnVpn no active profile available!");
@@ -242,7 +244,7 @@ public final class EIP extends JobIntentService implements Observer {
*/
private void launchActiveGateway(@NonNull Gateway gateway, int nClosestGateway) {
Intent intent = new Intent(BROADCAST_GATEWAY_SETUP_OBSERVER_EVENT);
- intent.putExtra(PROVIDER_PROFILE, gateway.getProfile());
+ intent.putExtra(PROVIDER_PROFILE, gateway.getProfile(OPENVPN));
intent.putExtra(Gateway.KEY_N_CLOSEST_GATEWAY, nClosestGateway);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
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<Connection.TransportType, VpnProfile> 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<Connection.TransportType, VpnProfile> 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<Connection.TransportType, VpnProfile> createVPNProfiles() {
+ HashMap<Connection.TransportType, VpnProfile> 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<Connection.TransportType, VpnProfile> getProfiles() {
+ return vpnProfiles;
+ }
+
+ public VpnProfile getProfile(Connection.TransportType transportType) {
+ return vpnProfiles.get(transportType);
}
public int getTimezone() {
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 cd3ec1c6..f7038bab 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java
@@ -28,20 +28,14 @@ import org.json.JSONObject;
import java.lang.reflect.Type;
import java.util.ArrayList;
-import java.util.List;
+import java.util.LinkedHashMap;
-import de.blinkt.openvpn.VpnProfile;
-import de.blinkt.openvpn.core.connection.Connection;
import se.leap.bitmaskclient.Provider;
import se.leap.bitmaskclient.utils.PreferenceHelper;
-import static se.leap.bitmaskclient.Constants.CAPABILITIES;
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.Constants.TRANSPORT;
-import static se.leap.bitmaskclient.Constants.TYPE;
-import static se.leap.bitmaskclient.Constants.VERSION;
/**
* @author parmegv
@@ -52,7 +46,7 @@ public class GatewaysManager {
private Context context;
private SharedPreferences preferences;
- private List<Gateway> gateways = new ArrayList<>();
+ private LinkedHashMap<String, Gateway> gateways = new LinkedHashMap<>();
private Type listType = new TypeToken<ArrayList<Gateway>>() {}.getType();
GatewaysManager(Context context, SharedPreferences preferences) {
@@ -65,7 +59,7 @@ public class GatewaysManager {
* @return the n closest Gateway
*/
public Gateway select(int nClosest) {
- GatewaySelector gatewaySelector = new GatewaySelector(gateways);
+ GatewaySelector gatewaySelector = new GatewaySelector(new ArrayList<>(gateways.values()));
return gatewaySelector.select(nClosest);
}
@@ -96,52 +90,20 @@ public class GatewaysManager {
void fromEipServiceJson(JSONObject eipDefinition) {
try {
JSONArray gatewaysDefined = eipDefinition.getJSONArray(GATEWAYS);
- int apiVersion = eipDefinition.getInt(VERSION);
for (int i = 0; i < gatewaysDefined.length(); i++) {
JSONObject gw = gatewaysDefined.getJSONObject(i);
JSONObject secrets = secretsConfiguration();
Gateway aux = new Gateway(eipDefinition, secrets, gw);
- if (!gateways.contains(aux)) {
+ if (gateways.get(aux.getRemoteIP()) == null) {
addGateway(aux);
}
}
- } catch (JSONException e) {
+ } catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
- /**
- * check if a gateway is an OpenVpn gateway
- * @param gateway to check
- * @return true if gateway is an OpenVpn gateway otherwise false
- */
- private boolean isOpenVpnGateway(JSONObject gateway, int apiVersion) {
- switch (apiVersion) {
- default:
- case 1:
- try {
- String transport = gateway.getJSONObject(CAPABILITIES).getJSONArray(TRANSPORT).toString();
- return transport.contains("openvpn");
- } catch (JSONException e) {
- return false;
- }
- case 2:
- try {
- JSONArray transports = gateway.getJSONObject(CAPABILITIES).getJSONArray(TRANSPORT);
- for (int i = 0; i < transports.length(); i++) {
- JSONObject transport = transports.getJSONObject(i);
- if (transport.optString(TYPE).equals("openvpn")) {
- return true;
- }
- }
- return false;
- } catch (JSONException e) {
- return false;
- }
- }
- }
-
private JSONObject secretsConfiguration() {
JSONObject result = new JSONObject();
try {
@@ -160,7 +122,7 @@ public class GatewaysManager {
}
private void addGateway(Gateway gateway) {
- gateways.add(gateway);
+ gateways.put(gateway.getRemoteIP(), gateway);
}
/**
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java
index 18c557dc..6b76e8d9 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java
@@ -22,6 +22,7 @@ import org.json.JSONObject;
import java.io.IOException;
import java.io.StringReader;
+import java.util.HashMap;
import java.util.Iterator;
import de.blinkt.openvpn.VpnProfile;
@@ -52,8 +53,6 @@ public class VpnConfigGenerator {
private JSONObject obfs4Transport;
private int apiVersion;
- private ConfigParser icsOpenvpnConfigParser = new ConfigParser();
-
public final static String TAG = VpnConfigGenerator.class.getSimpleName();
private final String newLine = System.getProperty("line.separator"); // Platform new line
@@ -85,16 +84,17 @@ public class VpnConfigGenerator {
}
}
- public VpnProfile generateVpnProfile() throws IllegalStateException,
- IOException,
+ public HashMap<Connection.TransportType, VpnProfile> generateVpnProfiles() throws
ConfigParser.ConfigParseError,
- NumberFormatException, JSONException {
-
+ NumberFormatException,
+ JSONException,
+ IOException {
+ HashMap<Connection.TransportType, VpnProfile> profiles = new HashMap<>();
+ profiles.put(OPENVPN, createProfile(OPENVPN));
if (supportsObfs4()) {
- return createProfile(OBFS4);
+ profiles.put(OBFS4, createProfile(OBFS4));
}
-
- return createProfile(OPENVPN);
+ return profiles;
}
private boolean supportsObfs4(){
@@ -113,6 +113,7 @@ public class VpnConfigGenerator {
private VpnProfile createProfile(Connection.TransportType transportType) throws IOException, ConfigParser.ConfigParseError, JSONException {
String configuration = getConfigurationString(transportType);
+ ConfigParser icsOpenvpnConfigParser = new ConfigParser();
icsOpenvpnConfigParser.parseConfig(new StringReader(configuration));
if (transportType == OBFS4) {
icsOpenvpnConfigParser.setDispatcherOptions(getDispatcherOptions());
diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/EipStatusTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/EipStatusTest.java
index 8495f962..8ba7f5fc 100644
--- a/app/src/test/java/se/leap/bitmaskclient/eip/EipStatusTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/EipStatusTest.java
@@ -10,6 +10,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
import de.blinkt.openvpn.VpnProfile;
import de.blinkt.openvpn.core.ConnectionStatus;
import de.blinkt.openvpn.core.VpnStatus;
+import de.blinkt.openvpn.core.connection.Connection;
import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.testutils.MockHelper;
import se.leap.bitmaskclient.testutils.TestSetupHelper;
@@ -23,6 +24,7 @@ import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_START;
import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_VPNPAUSED;
import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT;
import static de.blinkt.openvpn.core.ConnectionStatus.UNKNOWN_LEVEL;
+import static de.blinkt.openvpn.core.connection.Connection.TransportType.OPENVPN;
import static junit.framework.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.powermock.api.mockito.PowerMockito.doNothing;
@@ -61,7 +63,7 @@ public class EipStatusTest {
public void testUpdateState_LEVEL_VPNPAUSED_hasPersistentTun() throws Exception {
mockStatic(PreferenceHelper.class);
- VpnProfile mockVpnProfile = new VpnProfile("mockProfile");
+ VpnProfile mockVpnProfile = new VpnProfile("mockProfile", OPENVPN);
mockVpnProfile.mPersistTun = true;
doNothing().when(PreferenceHelper.class);
VpnStatus.setLastConnectedVpnProfile(null, mockVpnProfile);
@@ -74,7 +76,7 @@ public class EipStatusTest {
public void testUpdateState_LEVEL_VPNPAUSED_hasNotPersistentTun() throws Exception {
mockStatic(PreferenceHelper.class);
- VpnProfile mockVpnProfile = new VpnProfile("mockProfile");
+ VpnProfile mockVpnProfile = new VpnProfile("mockProfile", OPENVPN);
mockVpnProfile.mPersistTun = false;
doNothing().when(PreferenceHelper.class);
VpnStatus.setLastConnectedVpnProfile(null, mockVpnProfile);
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 160e5ddd..0412b11a 100644
--- a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
@@ -57,6 +57,15 @@ public class GatewaysManagerTest {
assertEquals(0, gatewaysManager.size());
}
+ @Test
+ public void testFromEipServiceJson_ignoreDuplicateGateways_apiv3() throws Exception {
+ String eipServiceJson = TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_three_mixed_gateways.json"));
+ gatewaysManager.fromEipServiceJson(new JSONObject(eipServiceJson));
+ assertEquals(3, gatewaysManager.size());
+ eipServiceJson = TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo.bitmask.eip-service.json"));
+ gatewaysManager.fromEipServiceJson(new JSONObject(eipServiceJson));
+ assertEquals(3, gatewaysManager.size());
+ }
@Test
public void testFromEipServiceJson_ignoreDuplicateGateways() throws Exception {
diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java
index 20a5968d..40da8e43 100644
--- a/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java
@@ -16,11 +16,16 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.io.File;
+import java.util.HashMap;
import de.blinkt.openvpn.VpnProfile;
+import de.blinkt.openvpn.core.connection.Connection;
import se.leap.bitmaskclient.testutils.MockHelper;
import se.leap.bitmaskclient.testutils.TestSetupHelper;
+import static de.blinkt.openvpn.core.connection.Connection.TransportType.OBFS4;
+import static de.blinkt.openvpn.core.connection.Connection.TransportType.OPENVPN;
+import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
@@ -44,7 +49,7 @@ public class VpnConfigGeneratorTest {
private JSONObject gateway;
private JSONObject secrets;
- String expectedVPNConfig_tcp_udp = "# Config for OpenVPN 2.x\n" +
+ String expectedVPNConfig_v1_tcp_udp = "# Config for OpenVPN 2.x\n" +
"# Enables connection to GUI\n" +
"management /data/data/se.leap.bitmask/mgmtsocket unix\n" +
"management-client\n" +
@@ -162,7 +167,7 @@ public class VpnConfigGeneratorTest {
"keepalive 10 30 \n" +
"tls-cipher DHE-RSA-AES128-SHA";
- String expectedVPNConfig_udp_tcp = "# Config for OpenVPN 2.x\n" +
+ String expectedVPNConfig_v1_udp_tcp = "# Config for OpenVPN 2.x\n" +
"# Enables connection to GUI\n" +
"management /data/data/se.leap.bitmask/mgmtsocket unix\n" +
"management-client\n" +
@@ -280,7 +285,7 @@ public class VpnConfigGeneratorTest {
"keepalive 10 30 \n" +
"tls-cipher DHE-RSA-AES128-SHA";
- String expectedVPNConfig_pt_tcp = "# Config for OpenVPN 2.x\n" +
+ String expectedVPNConfig_v3_obfs4 = "# Config for OpenVPN 2.x\n" +
"# Enables connection to GUI\n" +
"management /data/data/se.leap.bitmask/mgmtsocket unix\n" +
"management-client\n" +
@@ -297,8 +302,7 @@ public class VpnConfigGeneratorTest {
"connect-retry 2 300\n" +
"resolv-retry 60\n" +
"dev tun\n" +
- "remote 127.0.0.1 1234 tcp-client\n" +
- "remote 37.218.247.60 1195 tcp-client\n" +
+ "remote 127.0.0.1 4430 tcp-client\n" +
"<ca>\n" +
"-----BEGIN CERTIFICATE-----\n" +
"MIIFbzCCA1egAwIBAgIBATANBgkqhkiG9w0BAQ0FADBKMRgwFgYDVQQDDA9CaXRt\n" +
@@ -386,6 +390,7 @@ public class VpnConfigGeneratorTest {
"-----END CERTIFICATE-----\n" +
"</cert>\n" +
"crl-verify file missing in config profile\n" +
+ "route 37.218.247.60 255.255.255.255 net_gateway\n"+
"remote-cert-tls server\n" +
"cipher AES-128-CBC\n" +
"auth SHA1\n" +
@@ -398,7 +403,7 @@ public class VpnConfigGeneratorTest {
"keepalive 10 30 \n" +
"tls-cipher DHE-RSA-AES128-SHA \n";
- String expectedVPNConfig_pt_tcp_udp = "# Config for OpenVPN 2.x\n" +
+ String expectedVPNConfig_v3_ovpn_tcp_udp = "# Config for OpenVPN 2.x\n" +
"# Enables connection to GUI\n" +
"management /data/data/se.leap.bitmask/mgmtsocket unix\n" +
"management-client\n" +
@@ -415,7 +420,6 @@ public class VpnConfigGeneratorTest {
"connect-retry 2 300\n" +
"resolv-retry 60\n" +
"dev tun\n" +
- "remote 127.0.0.1 1234 tcp-client\n" +
"remote 37.218.247.60 1195 tcp-client\n" +
"remote 37.218.247.60 1195 udp\n" +
"<ca>\n" +
@@ -517,7 +521,7 @@ public class VpnConfigGeneratorTest {
"keepalive 10 30 \n" +
"tls-cipher DHE-RSA-AES128-SHA \n";
- String expectedVPNConfig_pt_udp_tcp = "# Config for OpenVPN 2.x\n" +
+ String expectedVPNConfig_v3_ovpn_udp_tcp = "# Config for OpenVPN 2.x\n" +
"# Enables connection to GUI\n" +
"management /data/data/se.leap.bitmask/mgmtsocket unix\n" +
"management-client\n" +
@@ -534,7 +538,6 @@ public class VpnConfigGeneratorTest {
"connect-retry 2 300\n" +
"resolv-retry 60\n" +
"dev tun\n" +
- "remote 127.0.0.1 1234 tcp-client\n" +
"remote 37.218.247.60 1195 udp\n" +
"remote 37.218.247.60 1195 tcp-client\n" +
"<ca>\n" +
@@ -655,45 +658,69 @@ public class VpnConfigGeneratorTest {
public void testGenerateVpnProfile_v1_tcp_udp() throws Exception {
gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("gateway_tcp_udp.json")));
vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 1);
- VpnProfile vpnProfile = vpnConfigGenerator.generateVpnProfile();
- assertTrue(vpnProfile.getConfigFile(context, false).trim().equals(expectedVPNConfig_tcp_udp.trim()));
+ HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
+ assertFalse(vpnProfiles.containsKey(OBFS4));
+ assertTrue(vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim().equals(expectedVPNConfig_v1_tcp_udp.trim()));
}
@Test
public void testGenerateVpnProfile_v1_udp_tcp() throws Exception {
gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("gateway_udp_tcp.json")));
vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 1);
- VpnProfile vpnConfig = vpnConfigGenerator.generateVpnProfile();
- assertTrue(vpnConfig.getConfigFile(context, false).trim().equals(expectedVPNConfig_udp_tcp.trim()));
+ HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
+ assertFalse(vpnProfiles.containsKey(OBFS4));
+ assertTrue(vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim().equals(expectedVPNConfig_v1_udp_tcp.trim()));
}
@Test
- public void testGenerateVpnProfile_v2_pt_tcp() throws Exception {
- gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo.bitmask.eip-service.json"))).getJSONArray("gateways").getJSONObject(0);
+ public void testGenerateVpnProfile_v2_tcp_udp() throws Exception {
+ gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("gateway_tcp_udp.json")));
vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 2);
- VpnProfile vpnProfile = vpnConfigGenerator.generateVpnProfile();
- vpnProfile.mConnections[0].setServerPort("1234");
- System.out.println(vpnProfile.getConfigFile(context, false));
- assertTrue(vpnProfile.getConfigFile(context, false).trim().equals(expectedVPNConfig_pt_tcp.trim()));
+ HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
+ assertFalse(vpnProfiles.containsKey(OBFS4));
+ assertTrue(vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim().equals(expectedVPNConfig_v1_tcp_udp.trim()));
}
@Test
- public void testGenerateVpnProfile_v2_pt_tcp_udp() throws Exception {
- gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_pt_tcp_udp.eip-service.json"))).getJSONArray("gateways").getJSONObject(0);
+ public void testGenerateVpnProfile_v2_udp_tcp() throws Exception {
+ gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("gateway_udp_tcp.json")));
vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 2);
- VpnProfile vpnProfile = vpnConfigGenerator.generateVpnProfile();
- vpnProfile.mConnections[0].setServerPort("1234");
- System.out.println(vpnProfile.getConfigFile(context, false));
- assertTrue(vpnProfile.getConfigFile(context, false).trim().equals(expectedVPNConfig_pt_tcp_udp.trim()));
+ HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
+ assertFalse(vpnProfiles.containsKey(OBFS4));
+ assertTrue(vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim().equals(expectedVPNConfig_v1_udp_tcp.trim()));
}
+
@Test
- public void testGenerateVpnProfile_v2_pt_udp_tcp() throws Exception {
+ public void testGenerateVpnProfile_v3_obfs4() throws Exception {
+ gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo.bitmask.eip-service.json"))).getJSONArray("gateways").getJSONObject(0);
+ vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3);
+ HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
+ assertTrue(vpnProfiles.containsKey(OBFS4));
+ assertTrue(vpnProfiles.containsKey(OPENVPN));
+ System.out.println(vpnProfiles.get(OBFS4).getConfigFile(context, false));
+ assertTrue(vpnProfiles.get(OBFS4).getConfigFile(context, false).trim().equals(expectedVPNConfig_v3_obfs4.trim()));
+ }
+
+ @Test
+ public void testGenerateVpnProfile_v3_ovpn_tcp_udp() throws Exception {
+ gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_pt_tcp_udp.eip-service.json"))).getJSONArray("gateways").getJSONObject(0);
+ vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3);
+ HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
+ assertTrue(vpnProfiles.containsKey(OBFS4));
+ assertTrue(vpnProfiles.containsKey(OPENVPN));
+ System.out.println(vpnProfiles.get(OPENVPN).getConfigFile(context, false));
+ assertTrue(vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim().equals(expectedVPNConfig_v3_ovpn_tcp_udp.trim()));
+ }
+
+ @Test
+ public void testGenerateVpnProfile_v3_ovpn_udp_tcp() throws Exception {
gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_pt_udp_tcp.eip-service.json"))).getJSONArray("gateways").getJSONObject(0);
- vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 2);
- VpnProfile vpnProfile = vpnConfigGenerator.generateVpnProfile();
- vpnProfile.mConnections[0].setServerPort("1234");
- System.out.println(vpnProfile.getConfigFile(context, false));
- assertTrue(vpnProfile.getConfigFile(context, false).trim().equals(expectedVPNConfig_pt_udp_tcp.trim()));
+ vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3);
+ HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
+ assertTrue(vpnProfiles.containsKey(OBFS4));
+ assertTrue(vpnProfiles.containsKey(OPENVPN));
+ System.out.println(vpnProfiles.get(OPENVPN).getConfigFile(context, false));
+ assertTrue(vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim().equals(expectedVPNConfig_v3_ovpn_udp_tcp.trim()));
}
} \ No newline at end of file
diff --git a/app/src/test/resources/ptdemo.bitmask.eip-service.json b/app/src/test/resources/ptdemo.bitmask.eip-service.json
index 38146a40..e5ede239 100644
--- a/app/src/test/resources/ptdemo.bitmask.eip-service.json
+++ b/app/src/test/resources/ptdemo.bitmask.eip-service.json
@@ -15,7 +15,7 @@
"23049"
],
"options": {
- "cert": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
+ "cert": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1",
"iat-mode": "0"
}
},
@@ -60,5 +60,5 @@
"verb" : "3"
},
"serial":2,
- "version":2
+ "version":3
} \ No newline at end of file
diff --git a/app/src/test/resources/ptdemo_pt_tcp_udp.eip-service.json b/app/src/test/resources/ptdemo_pt_tcp_udp.eip-service.json
index 4337547b..f39a1597 100644
--- a/app/src/test/resources/ptdemo_pt_tcp_udp.eip-service.json
+++ b/app/src/test/resources/ptdemo_pt_tcp_udp.eip-service.json
@@ -61,5 +61,5 @@
"verb" : "3"
},
"serial":2,
- "version":2
+ "version":3
} \ No newline at end of file
diff --git a/app/src/test/resources/ptdemo_pt_udp_tcp.eip-service.json b/app/src/test/resources/ptdemo_pt_udp_tcp.eip-service.json
index 4161fced..71c9857a 100644
--- a/app/src/test/resources/ptdemo_pt_udp_tcp.eip-service.json
+++ b/app/src/test/resources/ptdemo_pt_udp_tcp.eip-service.json
@@ -61,5 +61,5 @@
"verb" : "3"
},
"serial":2,
- "version":2
+ "version":3
} \ No newline at end of file
diff --git a/app/src/test/resources/ptdemo_three_mixed_gateways.json b/app/src/test/resources/ptdemo_three_mixed_gateways.json
new file mode 100644
index 00000000..f81da6b3
--- /dev/null
+++ b/app/src/test/resources/ptdemo_three_mixed_gateways.json
@@ -0,0 +1,133 @@
+{
+ "gateways":[
+ {
+ "capabilities":{
+ "adblock":false,
+ "filter_dns":false,
+ "limited":false,
+ "transport":[
+ {
+ "type":"obfs4",
+ "protocols":[
+ "tcp"
+ ],
+ "ports":[
+ "23049"
+ ],
+ "options": {
+ "cert": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1",
+ "iat-mode": "0"
+ }
+ },
+ {
+ "type":"openvpn",
+ "protocols":[
+ "tcp"
+ ],
+ "ports":[
+ "1195"
+ ]
+ }
+ ],
+ "user_ips":false
+ },
+ "host":"pt.demo.bitmask.net",
+ "ip_address":"37.218.247.60",
+ "location":"Amsterdam"
+ },
+ {
+ "capabilities":{
+ "adblock":false,
+ "filter_dns":false,
+ "limited":false,
+ "transport":[
+ {
+ "type":"obfs4",
+ "protocols":[
+ "tcp"
+ ],
+ "ports":[
+ "443"
+ ],
+ "options": {
+ "cert": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX2",
+ "iat-mode": "0"
+ }
+ },
+ {
+ "type":"openvpn",
+ "protocols":[
+ "tcp"
+ ],
+ "ports":[
+ "1195"
+ ]
+ }
+ ],
+ "user_ips":false
+ },
+ "host":"moscow.bitmask.net",
+ "ip_address":"3.21.247.89",
+ "location":"moscow"
+ },
+ {
+ "capabilities":{
+ "adblock":false,
+ "filter_dns":false,
+ "limited":false,
+ "transport":[
+ {
+ "type":"openvpn",
+ "protocols":[
+ "tcp",
+ "udp"
+ ],
+ "ports":[
+ "1195"
+ ]
+ }
+ ],
+ "user_ips":false
+ },
+ "host":"manila.bitmask.net",
+ "ip_address":"37.12.247.10",
+ "location":"manila"
+ }
+ ],
+ "locations":{
+ "Amsterdam":{
+ "country_code":"NL",
+ "hemisphere":"N",
+ "name":"Amsterdam",
+ "timezone":"-1"
+ },
+ "moscow": {
+ "country_code": "RU",
+ "hemisphere": "N",
+ "name": "Moscow",
+ "timezone": "+3"
+ },
+ "manila": {
+ "country_code": "PH",
+ "hemisphere": "N",
+ "name": "Manila",
+ "timezone": "+8"
+ }
+ },
+ "openvpn_configuration":{
+ "auth":"SHA1",
+ "cipher":"AES-256-CBC",
+ "keepalive":"10 30",
+ "tls-cipher":"DHE-RSA-AES128-SHA",
+ "tun-ipv6":true,
+ "dev" : "tun",
+ "sndbuf" : "0",
+ "rcvbuf" : "0",
+ "nobind" : true,
+ "persist-key" : true,
+ "key-direction" : "1",
+ "verb" : "3"
+ },
+ "serial":2,
+ "version":3
+} \ No newline at end of file