diff options
author | cyberta <cyberta@riseup.net> | 2022-08-06 18:37:13 +0000 |
---|---|---|
committer | cyberta <cyberta@riseup.net> | 2022-08-06 18:37:13 +0000 |
commit | b1cb49a2f78c80db0b3fa037a0b4e3c1c9c7dd61 (patch) | |
tree | 77effd84682014db0db950113cab239fa4370dc4 /app/src/main/java/se/leap/bitmaskclient/base | |
parent | 3bdbe09ffd7f4039f37af93b0da6b0965e09e0bd (diff) | |
parent | 598105bbaa383b27cadb682b76cdf00e5ad58369 (diff) |
Merge branch 'update_obfuscation_pinning_defaults' into 'master'
Update obfuscation pinning defaults
See merge request leap/bitmask_android!204
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/base')
6 files changed, 67 insertions, 55 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java index d993a119..ded62fa6 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java @@ -467,7 +467,7 @@ public class EipFragment extends Fragment implements Observer { setMainButtonEnabled(true); mainButton.updateState(true, false, false); Connection.TransportType transportType = PreferenceHelper.getUseBridges(getContext()) ? Connection.TransportType.OBFS4 : Connection.TransportType.OPENVPN; - locationButton.setLocationLoad(gatewaysManager.getLoadForLocation(VpnStatus.getLastConnectedVpnName(), transportType)); + locationButton.setLocationLoad(PreferenceHelper.useObfuscationPinning(getContext()) ? GatewaysManager.Load.UNKNOWN : gatewaysManager.getLoadForLocation(VpnStatus.getLastConnectedVpnName(), transportType)); locationButton.setText(VpnStatus.getLastConnectedVpnName()); locationButton.showBridgeIndicator(VpnStatus.isUsingBridges()); locationButton.showRecommendedIndicator(getPreferredCity(getContext())== null); diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/ObfuscationProxyDialog.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/ObfuscationProxyDialog.java index df78214d..6829d9f1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/ObfuscationProxyDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/ObfuscationProxyDialog.java @@ -31,12 +31,10 @@ public class ObfuscationProxyDialog extends AppCompatDialogFragment { AppCompatEditText ipField; AppCompatEditText portField; AppCompatEditText certificateField; - AppCompatSpinner gatewayHost; AppCompatButton saveButton; AppCompatButton useDefaultsButton; AppCompatButton cancelButton; IconSwitchEntry kcpSwitch; - ArrayAdapter<String> gatewayHosts; @NonNull @Override @@ -49,7 +47,6 @@ public class ObfuscationProxyDialog extends AppCompatDialogFragment { ipField = binding.ipField; portField = binding.portField; certificateField = binding.certField; - gatewayHost = binding.gatewayHost; saveButton = binding.buttonSave; useDefaultsButton = binding.buttonDefaults; cancelButton = binding.buttonCancel; @@ -61,16 +58,6 @@ public class ObfuscationProxyDialog extends AppCompatDialogFragment { kcpSwitch.setChecked(PreferenceHelper.getObfuscationPinningKCP(getContext())); GatewaysManager gatewaysManager = new GatewaysManager(getContext()); - ArrayList<String> hostsList = gatewaysManager.getHosts(); - - hostsList.add(0, "Select a Gateway"); - gatewayHosts = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, hostsList); - gatewayHosts.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - gatewayHost.setAdapter(gatewayHosts); - String selectedHost = PreferenceHelper.getObfuscationPinningGatewayHost(getContext()); - if (selectedHost != null) { - gatewayHost.setSelection(gatewayHosts.getPosition(selectedHost)); - } saveButton.setOnClickListener(v -> { String ip = TextUtils.isEmpty(ipField.getText()) ? null : ipField.getText().toString(); @@ -79,12 +66,9 @@ public class ObfuscationProxyDialog extends AppCompatDialogFragment { PreferenceHelper.setObfuscationPinningPort(v.getContext(), port); String cert = TextUtils.isEmpty(certificateField.getText()) ? null : certificateField.getText().toString(); PreferenceHelper.setObfuscationPinningCert(v.getContext(), cert); - String gatewayHostName = gatewayHost.getSelectedItemPosition() == 0 ? null : gatewayHosts.getItem(gatewayHost.getSelectedItemPosition()); - PreferenceHelper.setObfuscationPinningGatewayHost(v.getContext(), gatewayHostName); - PreferenceHelper.setObfuscationPinningGatewayIP(v.getContext(), gatewaysManager.getIpForHost(gatewayHostName)); PreferenceHelper.setObfuscationPinningKCP(v.getContext(), kcpSwitch.isChecked()); - PreferenceHelper.setUseObfuscationPinning(v.getContext(), ip != null && port != null && cert != null && gatewayHostName != null); - PreferenceHelper.setObfuscationPinningGatewayLocation(v.getContext(), gatewaysManager.getLocationNameForHost(gatewayHostName)); + PreferenceHelper.setUseObfuscationPinning(v.getContext(), ip != null && port != null && cert != null); + PreferenceHelper.setObfuscationPinningGatewayLocation(v.getContext(), gatewaysManager.getLocationNameForIP(ip, v.getContext())); dismiss(); }); @@ -93,11 +77,6 @@ public class ObfuscationProxyDialog extends AppCompatDialogFragment { ipField.setText(ObfsVpnHelper.obfsvpnIP()); portField.setText(ObfsVpnHelper.obfsvpnPort()); certificateField.setText(ObfsVpnHelper.obfsvpnCert()); - int position = gatewayHosts.getPosition(ObfsVpnHelper.gatewayHost()); - if (position == -1) { - position = 0; - } - gatewayHost.setSelection(position); kcpSwitch.setChecked(ObfsVpnHelper.useKcp()); }); diff --git a/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java b/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java index 8fbac35e..fd9f2a9b 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java @@ -50,8 +50,6 @@ public interface Constants { String OBFUSCATION_PINNING_PORT = "obfuscation_pinning_port"; String OBFUSCATION_PINNING_CERT = "obfuscation_pinning_cert"; String OBFUSCATION_PINNING_KCP = "obfuscation_pinning_udp"; - String OBFUSCATION_PINNING_GW_HOST = "obfuscation_pinning_gw_host"; - String OBFUSCATION_PINNING_GW_IP = "obfuscation_pinning_gw_ip"; String OBFUSCATION_PINNING_LOCATION = "obfuscation_pinning_location"; diff --git a/app/src/main/java/se/leap/bitmaskclient/base/models/GatewayJson.java b/app/src/main/java/se/leap/bitmaskclient/base/models/GatewayJson.java new file mode 100644 index 00000000..8aca58c6 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/base/models/GatewayJson.java @@ -0,0 +1,61 @@ +package se.leap.bitmaskclient.base.models; + +import androidx.annotation.NonNull; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.annotations.SerializedName; + +import org.json.JSONObject; + +public class GatewayJson { + private String location; + @SerializedName(value = "ip_address") + private String ipAddress; + @SerializedName(value = "ip_address6") + private String ipAddress6; + private String host; + private Capabilities capabilities; + + public GatewayJson(String location, String ipAddress, String ipAddress6, String host, Capabilities capabilities) { + this.location = location; + this.ipAddress = ipAddress; + this.ipAddress6 = ipAddress6; + this.host = host; + this.capabilities = capabilities; + } + + @NonNull + @Override + public String toString() { + return new Gson().toJson(this); + } + + public static GatewayJson fromJson(JSONObject json) { + GsonBuilder builder = new GsonBuilder(); + return builder.create().fromJson(json.toString(), GatewayJson.class); + } + + public static class Capabilities { + private Boolean adblock; + @SerializedName(value = "filter_dns") + private Boolean filterDns; + private Boolean limited; + private Transport[] transport; + @SerializedName(value = "user_ips") + private Boolean userIps; + + public Capabilities(Boolean adblock, Boolean filterDns, Boolean limited, Transport[] transport, Boolean userIps) { + this.adblock = adblock; + this.filterDns = filterDns; + this.limited = limited; + this.transport = transport; + this.userIps = userIps; + } + @NonNull + @Override + public String toString() { + return new Gson().toJson(this); + } + } +} diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/ConfigHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/ConfigHelper.java index c4e2fb17..91894fb8 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/utils/ConfigHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/ConfigHelper.java @@ -290,11 +290,9 @@ public class ConfigHelper { return BuildConfig.obfsvpn_ip != null && BuildConfig.obfsvpn_port != null && BuildConfig.obfsvpn_cert != null && - BuildConfig.obfsvpn_gateway_host != null && !BuildConfig.obfsvpn_ip.isEmpty() && !BuildConfig.obfsvpn_port.isEmpty() && - !BuildConfig.obfsvpn_cert.isEmpty() && - !BuildConfig.obfsvpn_gateway_host.isEmpty(); + !BuildConfig.obfsvpn_cert.isEmpty(); } public static String obfsvpnIP() { return BuildConfig.obfsvpn_ip; @@ -305,10 +303,6 @@ public class ConfigHelper { public static String obfsvpnCert() { return BuildConfig.obfsvpn_cert; } - public static String gatewayHost() { - return BuildConfig.obfsvpn_gateway_host; - } - public static boolean useKcp() { return BuildConfig.obfsvpn_use_kcp; } diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java index d9beffd3..4abeed1a 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java @@ -12,8 +12,6 @@ import static se.leap.bitmaskclient.base.models.Constants.GATEWAY_PINNING; import static se.leap.bitmaskclient.base.models.Constants.LAST_UPDATE_CHECK; import static se.leap.bitmaskclient.base.models.Constants.LAST_USED_PROFILE; import static se.leap.bitmaskclient.base.models.Constants.OBFUSCATION_PINNING_CERT; -import static se.leap.bitmaskclient.base.models.Constants.OBFUSCATION_PINNING_GW_HOST; -import static se.leap.bitmaskclient.base.models.Constants.OBFUSCATION_PINNING_GW_IP; import static se.leap.bitmaskclient.base.models.Constants.OBFUSCATION_PINNING_IP; import static se.leap.bitmaskclient.base.models.Constants.OBFUSCATION_PINNING_KCP; import static se.leap.bitmaskclient.base.models.Constants.OBFUSCATION_PINNING_LOCATION; @@ -279,8 +277,7 @@ public class PreferenceHelper { getBoolean(context, USE_OBFUSCATION_PINNING, false) && !TextUtils.isEmpty(getObfuscationPinningIP(context)) && !TextUtils.isEmpty(getObfuscationPinningCert(context)) && - !TextUtils.isEmpty(getObfuscationPinningPort(context)) && - !TextUtils.isEmpty(getObfuscationPinningGatewayHost(context)); + !TextUtils.isEmpty(getObfuscationPinningPort(context)); } public static void setObfuscationPinningIP(Context context, String ip) { @@ -307,23 +304,6 @@ public class PreferenceHelper { return getString(context, OBFUSCATION_PINNING_CERT, null); } - public static void setObfuscationPinningGatewayHost(Context context, String gatewayIP) { - putString(context, OBFUSCATION_PINNING_GW_HOST, gatewayIP); - } - - public static String getObfuscationPinningGatewayHost(Context context) { - return getString(context, OBFUSCATION_PINNING_GW_HOST, null); - } - - - public static void setObfuscationPinningGatewayIP(Context context, String ipForHost) { - putString(context, OBFUSCATION_PINNING_GW_IP, ipForHost); - } - - public static String getObfuscationPinningGatewayIP(Context context) { - return getString(context, OBFUSCATION_PINNING_GW_IP, null); - } - public static void setObfuscationPinningGatewayLocation(Context context, String location) { putString(context, OBFUSCATION_PINNING_LOCATION, location); } @@ -357,7 +337,7 @@ public class PreferenceHelper { } public static String getPreferredCity(Context context) { - return getString(context, PREFERRED_CITY, null); + return useObfuscationPinning(context) ? null : getString(context, PREFERRED_CITY, null); } @WorkerThread |