summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2015-01-02 01:32:22 +0100
committerParménides GV <parmegv@sdf.org>2015-01-02 01:32:22 +0100
commit407e3767744e39a59845423246a9ad427d933304 (patch)
tree18aeb9c1a2fb8d3dda42a2df04db8b9e3da3de17
parentd23ec1613855f6582b0e79c1a9fc1538d6099944 (diff)
Update vpn profiles correctly.
Before we add a new profile, we check if there are any duplicated ones with the same server IPs and ports. If they've the same credentials of the new one, we don't add anything; if not, we remove the old ones and add the new.
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIP.java22
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java15
2 files changed, 20 insertions, 17 deletions
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 cf6006e5..10d222c2 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
@@ -125,8 +125,9 @@ public final class EIP extends IntentService {
if(gateway != null && gateway.getProfile() != null) {
mReceiver = EipFragment.getReceiver();
launchActiveGateway();
- }
- tellToReceiver(ACTION_START_EIP, Activity.RESULT_OK);
+ tellToReceiver(ACTION_START_EIP, Activity.RESULT_OK);
+ } else
+ tellToReceiver(ACTION_START_EIP, Activity.RESULT_CANCELED);
}
/**
@@ -144,6 +145,8 @@ public final class EIP extends IntentService {
intent.setAction(Intent.ACTION_MAIN);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(LaunchVPN.EXTRA_NAME, gateway.getProfile().getName());
+ Log.d(TAG, gateway.getProfile().mClientCertFilename);
+ Log.d(TAG, gateway.getProfile().mClientKeyFilename);
intent.putExtra(LaunchVPN.EXTRA_HIDELOG, true);
startActivity(intent);
}
@@ -206,7 +209,7 @@ public final class EIP extends IntentService {
JSONObject gw = gatewaysDefined.getJSONObject(i);
if (isOpenVpnGateway(gw)) {
Gateway gateway = new Gateway(eip_definition, context, gw);
- if(!gateways.contains(gateway)) {
+ if(!containsProfileWithSecrets(gateway.getProfile())) {
addGateway(gateway);
}
}
@@ -260,6 +263,17 @@ public final class EIP extends IntentService {
return false;
}
+ private boolean containsProfileWithSecrets(VpnProfile profile) {
+ if(!containsProfile(profile)) return false;
+
+ Collection<VpnProfile> profiles = profile_manager.getProfiles();
+ for(VpnProfile aux : profiles) {
+ return profile.mClientCertFilename.equalsIgnoreCase(aux.mClientCertFilename)
+ && profile.mClientKeyFilename.equalsIgnoreCase(aux.mClientKeyFilename);
+ }
+
+ return false;
+ }
private VpnProfile duplicatedProfile(VpnProfile profile) {
VpnProfile duplicated = null;
Collection<VpnProfile> profiles = profile_manager.getProfiles();
@@ -290,7 +304,7 @@ public final class EIP extends IntentService {
List<Gateway> gateways_to_remove = new ArrayList<>();
while(it.hasNext()) {
Gateway aux = it.next();
- if(aux.getProfile().mConnections == profile.mConnections)
+ if(sameConnections(aux.getProfile().mConnections, profile.mConnections))
gateways_to_remove.add(aux);
}
gateways.removeAll(gateways_to_remove);
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 e23f67c7..005d0eec 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java
@@ -25,6 +25,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
+import java.io.Serializable;
import java.io.StringReader;
import java.util.Collection;
import java.util.Iterator;
@@ -42,7 +43,7 @@ import se.leap.bitmaskclient.Dashboard;
* @author Sean Leonard <meanderingcode@aetherislands.net>
* @author Parménides GV <parmegv@sdf.org>
*/
-public class Gateway {
+public class Gateway implements Serializable {
private String TAG = Gateway.class.getSimpleName();
@@ -137,16 +138,4 @@ public class Gateway {
public int getTimezone() {
return timezone;
}
-
- @Override
- public boolean equals(Object o) {
- if(o instanceof Gateway) {
- VpnProfile compared_profile = ((Gateway) o).getProfile();
- return compared_profile.mConnections.equals(mVpnProfile.mConnections)
- && compared_profile.mClientCertFilename != mVpnProfile.mClientCertFilename
- && compared_profile.mClientKeyFilename != mVpnProfile.mClientKeyFilename;
- }
- else
- return super.equals(o);
- }
}