diff options
author | Fup Duck <fupduck@sacknagel.com> | 2018-02-11 14:39:27 +0100 |
---|---|---|
committer | Fup Duck <fupduck@sacknagel.com> | 2018-02-11 14:39:27 +0100 |
commit | 1b97d5dfc596763c03d584d089a1e00edd1eecbc (patch) | |
tree | 4bea5ba0e5c00fefa5adca48514046af6139e80d /app/src/main/java/se/leap | |
parent | ca82cdf77ee4d30b820a1f936315c6c5be78359d (diff) |
8827 - merge request discussions
* add deleteProviderDetailsFromPreferences to ConfigHelper
* validate every field in Provider.equals
* add reset() method to Provider
Diffstat (limited to 'app/src/main/java/se/leap')
3 files changed, 63 insertions, 36 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java b/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java index f8204b20..086ba216 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java @@ -16,7 +16,6 @@ */ package se.leap.bitmaskclient; -import android.annotation.SuppressLint; import android.content.SharedPreferences; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -412,5 +411,19 @@ public class ConfigHelper { } } + public static void deleteProviderDetailsFromPreferences(@NonNull SharedPreferences preferences, String providerDomain) { + preferences.edit(). + remove(Provider.KEY + "." + providerDomain). + remove(Provider.CA_CERT + "." + providerDomain). + remove(Provider.CA_CERT_FINGERPRINT + "." + providerDomain). + remove(Provider.MAIN_URL + "." + providerDomain). + remove(Provider.KEY + "." + providerDomain). + remove(Provider.CA_CERT + "." + providerDomain). + remove(PROVIDER_EIP_DEFINITION + "." + providerDomain). + remove(PROVIDER_PRIVATE_KEY + "." + providerDomain). + remove(PROVIDER_VPN_CERTIFICATE + "." + providerDomain). + apply(); + } + } diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java index e53dd4fb..4937ed58 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Provider.java +++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java @@ -21,13 +21,11 @@ import android.os.Parcelable; import com.google.gson.Gson; -import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.net.MalformedURLException; import java.net.URL; -import java.util.Arrays; import java.util.Locale; import static se.leap.bitmaskclient.Constants.PROVIDER_ALLOWED_REGISTERED; @@ -41,14 +39,14 @@ import static se.leap.bitmaskclient.ProviderAPI.ERRORS; public final class Provider implements Parcelable { private JSONObject definition = new JSONObject(); // Represents our Provider's provider.json - private JSONObject eipServiceJson = new JSONObject(); // Represents our Provider's provider.json + private JSONObject eipServiceJson = new JSONObject(); private DefaultedURL mainUrl = new DefaultedURL(); private DefaultedURL apiUrl = new DefaultedURL(); private String certificatePin = ""; private String certificatePinEncoding = ""; private String caCert = ""; private String caCertFingerprint = ""; - private String apiVerson = ""; + private String apiVersion = ""; private String privateKey = ""; private String vpnCertificate = ""; @@ -68,17 +66,9 @@ public final class Provider implements Parcelable { NAME = "name", DESCRIPTION = "description", DOMAIN = "domain", - MAIN_URL = "main_url", - DOT_JSON_URL = "provider_json_url"; + MAIN_URL = "main_url"; - // Array of what API versions we understand - protected static final String[] API_VERSIONS = {"1"}; // I assume we might encounter arbitrary version "numbers" - // Some API pieces we want to know about - private static final String API_TERM_SERVICES = "services"; private static final String API_TERM_NAME = "name"; - private static final String API_TERM_DOMAIN = "domain"; - private static final String API_TERM_DEFAULT_LANGUAGE = "default_language"; - protected static final String[] API_EIP_TYPES = {"openvpn"}; public Provider() { } @@ -164,7 +154,7 @@ public final class Provider implements Parcelable { } } - protected JSONObject getDefinition() { + public JSONObject getDefinition() { return definition; } @@ -198,7 +188,7 @@ public final class Provider implements Parcelable { } public String getApiVersion() { - return apiVerson; + return apiVersion; } protected String certificatePin() { return certificatePin; } @@ -296,7 +286,20 @@ public final class Provider implements Parcelable { public boolean equals(Object o) { if (o instanceof Provider) { Provider p = (Provider) o; - return p.getDomain().equals(getDomain()); + return p.getDomain().equals(getDomain()) && + definition.equals(p.getDefinition()) && + eipServiceJson.equals(p.getEipServiceJson())&& + mainUrl.equals(p.getMainUrl()) && + apiUrl.equals(p.getApiUrl()) && + certificatePin.equals(p.getCertificatePin()) && + certificatePinEncoding.equals(p.getCertificatePinEncoding()) && + caCert.equals(p.getCaCert()) && + caCertFingerprint.equals(p.getCaCertFingerprint()) && + apiVersion.equals(p.getApiVersion()) && + privateKey.equals(p.getPrivateKey()) && + vpnCertificate.equals(p.getVpnCertificate()) && + allowAnonymous == p.allowsAnonymous() && + allowRegistered == p.allowsRegistered(); } else return false; } @@ -365,7 +368,7 @@ public final class Provider implements Parcelable { this.apiUrl.setUrl(new URL(definition.getString(API_URL))); this.allowAnonymous = definition.getJSONObject(Provider.SERVICE).getBoolean(PROVIDER_ALLOW_ANONYMOUS); this.allowRegistered = definition.getJSONObject(Provider.SERVICE).getBoolean(PROVIDER_ALLOWED_REGISTERED); - this.apiVerson = getDefinition().getString(Provider.API_VERSION); + this.apiVersion = getDefinition().getString(Provider.API_VERSION); } catch (JSONException | ArrayIndexOutOfBoundsException | MalformedURLException e) { e.printStackTrace(); } @@ -429,4 +432,31 @@ public final class Provider implements Parcelable { public boolean hasVpnCertificate() { return getVpnCertificate() != null && getVpnCertificate().length() >0 ; } + + public String getCertificatePin() { + return certificatePin; + } + + public String getCertificatePinEncoding() { + return certificatePinEncoding; + } + + /** + * resets everything except the main url + */ + public void reset() { + definition = new JSONObject(); + eipServiceJson = new JSONObject(); + apiUrl = new DefaultedURL(); + certificatePin = ""; + certificatePinEncoding = ""; + caCert = ""; + caCertFingerprint = ""; + apiVersion = ""; + privateKey = ""; + vpnCertificate = ""; + allowRegistered = false; + allowAnonymous = false; + } + } diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java b/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java index 5fe6ed05..1284ca64 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java @@ -211,11 +211,8 @@ public abstract class ProviderApiManagerBase { } void resetProviderDetails(Provider provider) { - provider.setCaCert(""); - provider.define(new JSONObject()); - provider.setEipServiceJson(new JSONObject()); - - deleteProviderDetailsFromPreferences(provider.getDomain()); + provider.reset(); + ConfigHelper.deleteProviderDetailsFromPreferences(preferences, provider.getDomain()); } String formatErrorMessage(final int toastStringId) { @@ -772,19 +769,6 @@ public abstract class ProviderApiManagerBase { return ""; } - protected void deleteProviderDetailsFromPreferences(String providerDomain) { - - if (preferences.contains(Provider.KEY + "." + providerDomain)) { - preferences.edit().remove(Provider.KEY + "." + providerDomain).apply(); - } - if (preferences.contains(Provider.CA_CERT + "." + providerDomain)) { - preferences.edit().remove(Provider.CA_CERT + "." + providerDomain).apply(); - } - if (preferences.contains(Provider.CA_CERT_FINGERPRINT + "." + providerDomain)) { - preferences.edit().remove(Provider.CA_CERT_FINGERPRINT + "." + providerDomain).apply(); - } - } - protected String getPersistedCaCertFingerprint(String providerDomain) { try { return getPersistedProviderDefinition(providerDomain).getString(Provider.CA_CERT_FINGERPRINT); |