summaryrefslogtreecommitdiff
path: root/app/src/main/java/se
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/se')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java12
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java69
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/models/FeatureVersionCode.java1
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java11
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/utils/ConfigHelper.java5
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java6
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/activities/CustomProviderSetupActivity.java6
7 files changed, 78 insertions, 32 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java
index 2ccbe514..f4dbd6bd 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java
@@ -169,6 +169,18 @@ public class StartActivity extends Activity{
}
}
+ if (hasNewFeature(FeatureVersionCode.RISEUP_PROVIDER_LILYPAD_UPDATE) && (
+ getPackageName().equals("se.leap.riseupvpn") ||
+ ProviderObservable.getInstance().getCurrentProvider().getDomain().equals("riseup.net"))) {
+ // deletion of current configured provider so that a new provider setup is triggered
+ Provider provider = ProviderObservable.getInstance().getCurrentProvider();
+ if (provider != null && !provider.isDefault()) {
+ PreferenceHelper.deleteProviderDetailsFromPreferences(preferences, provider.getDomain());
+ PreferenceHelper.deleteCurrentProviderDetailsFromPreferences(preferences);
+ ProviderObservable.getInstance().updateProvider(new Provider());
+ }
+ }
+
// always check if manual gateway selection feature switch has been disabled
if (!BuildConfig.allow_manual_gateway_selection && PreferenceHelper.getPreferredCity(this) != null) {
PreferenceHelper.setPreferredCity(this, null);
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 ded62fa6..a95a14ef 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
@@ -69,6 +69,7 @@ import androidx.fragment.app.FragmentTransaction;
import java.util.Observable;
import java.util.Observer;
+import java.util.concurrent.atomic.AtomicBoolean;
import butterknife.BindView;
import butterknife.ButterKnife;
@@ -138,7 +139,8 @@ public class EipFragment extends Fragment implements Observer {
AlertDialog alertDialog;
private IOpenVPNServiceInternal mService;
- private ServiceConnection openVpnConnection;
+ // We use this service connection to detect if openvpn is running without network
+ private EipFragmentServiceConnection openVpnConnection;
@Override
public void onAttach(Context context) {
@@ -229,20 +231,16 @@ public class EipFragment extends Fragment implements Observer {
@Override
public void onResume() {
super.onResume();
- //FIXME: avoid race conditions while checking certificate an logging in at about the same time
- //eipCommand(Constants.EIP_ACTION_CHECK_CERT_VALIDITY);
- bindOpenVpnService();
+ if (!eipStatus.isDisconnected()) {
+ openVpnConnection.bindService();
+ }
handleNewState();
}
@Override
public void onPause() {
super.onPause();
-
- Activity activity = getActivity();
- if (activity != null) {
- getActivity().unbindService(openVpnConnection);
- }
+ openVpnConnection.unbindService();
}
@Override
@@ -414,6 +412,14 @@ public class EipFragment extends Fragment implements Observer {
if (observable instanceof EipStatus) {
eipStatus = (EipStatus) observable;
handleNewStateOnMain();
+
+ if (eipStatus.isConnecting()) {
+ openVpnConnection.bindService();
+ }
+ if ("NOPROCESS".equals(EipStatus.getInstance().getState())) {
+ //assure that the Service is shutdown completely if openvpn was stopped
+ openVpnConnection.unbindService();
+ }
} else if (observable instanceof ProviderObservable) {
provider = ((ProviderObservable) observable).getCurrentProvider();
} else if (observable instanceof TorStatusObservable && EipStatus.getInstance().isUpdatingVpnCert()) {
@@ -574,19 +580,6 @@ public class EipFragment extends Fragment implements Observer {
return isRunning;
}
- private void bindOpenVpnService() {
- Activity activity = getActivity();
- if (activity == null) {
- Log.e(TAG, "activity is null when binding OpenVpn");
- return;
- }
-
- Intent intent = new Intent(activity, OpenVPNService.class);
- intent.setAction(OpenVPNService.START_SERVICE);
- activity.bindService(intent, openVpnConnection, Context.BIND_AUTO_CREATE);
-
- }
-
private void greyscaleBackground() {
if (BuildConfig.use_color_filter) {
ColorMatrix matrix = new ColorMatrix();
@@ -631,6 +624,38 @@ public class EipFragment extends Fragment implements Observer {
}
private class EipFragmentServiceConnection implements ServiceConnection {
+ private final AtomicBoolean bind = new AtomicBoolean(false);
+
+ void bindService() {
+ Activity activity = getActivity();
+ if (activity == null) {
+ Log.e(TAG, "activity is null when binding OpenVpn");
+ return;
+ }
+ if (!bind.get()) {
+ activity.runOnUiThread(() -> {
+ Intent intent = new Intent(activity, OpenVPNService.class);
+ intent.setAction(OpenVPNService.START_SERVICE);
+
+ activity.bindService(intent, EipFragmentServiceConnection.this, Context.BIND_AUTO_CREATE);
+ bind.set(true);
+ });
+ }
+ }
+
+ void unbindService() {
+ Activity activity = getActivity();
+ if (activity == null) {
+ return;
+ }
+ if (bind.get()) {
+ activity.runOnUiThread(() -> {
+ activity.unbindService(EipFragmentServiceConnection.this);
+ bind.set(false);
+ });
+ }
+ }
+
@Override
public void onServiceConnected(ComponentName className,
IBinder service) {
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/models/FeatureVersionCode.java b/app/src/main/java/se/leap/bitmaskclient/base/models/FeatureVersionCode.java
index 95decb82..9f813415 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/models/FeatureVersionCode.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/models/FeatureVersionCode.java
@@ -4,4 +4,5 @@ public interface FeatureVersionCode {
int RENAMED_EIP_IN_PREFERENCES = 132;
int GEOIP_SERVICE = 148;
int CALYX_PROVIDER_LILYPAD_UPDATE = 163000;
+ int RISEUP_PROVIDER_LILYPAD_UPDATE = 164000;
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java b/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java
index 7b8f22af..13463167 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java
@@ -58,6 +58,7 @@ public final class Provider implements Parcelable {
private DefaultedURL mainUrl = new DefaultedURL();
private DefaultedURL apiUrl = new DefaultedURL();
private DefaultedURL geoipUrl = new DefaultedURL();
+ private String domain = "";
private String providerIp = ""; // ip of the provider main url
private String providerApiIp = ""; // ip of the provider api url
private String certificatePin = "";
@@ -253,7 +254,7 @@ public final class Provider implements Parcelable {
}
public String getDomain() {
- return mainUrl.getDomain();
+ return domain;
}
public String getMainUrlString() {
@@ -369,6 +370,7 @@ public final class Provider implements Parcelable {
@Override
public void writeToParcel(Parcel parcel, int i) {
+ parcel.writeString(getDomain());
parcel.writeString(getMainUrlString());
parcel.writeString(getProviderIp());
parcel.writeString(getProviderApiIp());
@@ -388,6 +390,7 @@ public final class Provider implements Parcelable {
//TODO: write a test for marshalling!
private Provider(Parcel in) {
try {
+ domain = in.readString();
mainUrl.setUrl(new URL(in.readString()));
String tmpString = in.readString();
if (!tmpString.isEmpty()) {
@@ -439,7 +442,8 @@ 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 getDomain().equals(p.getDomain()) &&
+ mainUrl.getDomain().equals(p.mainUrl.getDomain()) &&
definition.toString().equals(p.getDefinition().toString()) &&
eipServiceJson.toString().equals(p.getEipServiceJsonString()) &&
geoIpJson.toString().equals(p.getGeoIpJsonString()) &&
@@ -471,7 +475,7 @@ public final class Provider implements Parcelable {
@Override
public int hashCode() {
- return getDomain().hashCode();
+ return getMainUrlString().hashCode();
}
@Override
@@ -488,6 +492,7 @@ public final class Provider implements Parcelable {
this.allowAnonymous = definition.getJSONObject(Provider.SERVICE).getBoolean(PROVIDER_ALLOW_ANONYMOUS);
this.allowRegistered = definition.getJSONObject(Provider.SERVICE).getBoolean(PROVIDER_ALLOWED_REGISTERED);
this.apiVersion = getDefinition().getString(Provider.API_VERSION);
+ this.domain = getDefinition().getString(Provider.DOMAIN);
return true;
} catch (JSONException | ArrayIndexOutOfBoundsException | MalformedURLException e) {
return false;
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 91894fb8..dbcb55b0 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
@@ -51,6 +51,7 @@ import java.util.Calendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import okhttp3.internal.publicsuffix.PublicSuffixDatabase;
import se.leap.bitmaskclient.BuildConfig;
import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.providersetup.ProviderAPI;
@@ -273,6 +274,10 @@ public class ConfigHelper {
Matcher matcher = IPv4_PATTERN.matcher(ipv4);
return matcher.matches();
}
+
+ public static String getDomainFromMainURL(@NonNull String mainUrl) throws NullPointerException {
+ return PublicSuffixDatabase.get().getEffectiveTldPlusOne(mainUrl).replaceFirst("http[s]?://", "").replaceFirst("/.*", "");
+ }
public static boolean isCalyxOSWithTetheringSupport(Context context) {
return SystemPropertiesHelper.contains("ro.calyxos.version", context) &&
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java
index 607339fd..7b6a3ad6 100644
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java
+++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java
@@ -41,6 +41,7 @@ import static se.leap.bitmaskclient.base.models.Provider.CA_CERT;
import static se.leap.bitmaskclient.base.models.Provider.GEOIP_URL;
import static se.leap.bitmaskclient.base.models.Provider.PROVIDER_API_IP;
import static se.leap.bitmaskclient.base.models.Provider.PROVIDER_IP;
+import static se.leap.bitmaskclient.base.utils.ConfigHelper.getDomainFromMainURL;
import static se.leap.bitmaskclient.base.utils.ConfigHelper.getFingerprintFromCertificate;
import static se.leap.bitmaskclient.base.utils.ConfigHelper.getProviderFormattedString;
import static se.leap.bitmaskclient.base.utils.ConfigHelper.parseRsaKeyFromString;
@@ -1048,11 +1049,6 @@ public abstract class ProviderApiManagerBase {
return preferences.contains(Provider.KEY + "." + domain) && preferences.contains(CA_CERT + "." + domain);
}
- protected String getDomainFromMainURL(String mainUrl) {
- return mainUrl.replaceFirst("http[s]?://", "").replaceFirst("/.*", "");
-
- }
-
/**
* Interprets the error message as a JSON object and extract the "errors" keyword pair.
* If the error message is not a JSON object, then it is returned untouched.
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/CustomProviderSetupActivity.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/CustomProviderSetupActivity.java
index b90d14f8..0fff1ee2 100644
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/CustomProviderSetupActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/CustomProviderSetupActivity.java
@@ -31,6 +31,7 @@ import java.io.IOException;
import se.leap.bitmaskclient.BuildConfig;
import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.base.models.Provider;
+import se.leap.bitmaskclient.base.utils.ConfigHelper;
import se.leap.bitmaskclient.providersetup.ProviderAPICommand;
import static se.leap.bitmaskclient.BuildConfig.customProviderApiIp;
@@ -72,8 +73,9 @@ public class CustomProviderSetupActivity extends ProviderSetupBaseActivity {
try {
AssetManager assetsManager = getAssets();
Provider customProvider = new Provider(customProviderUrl, geoipUrl, customProviderIp, customProviderApiIp);
- String certificate = loadInputStreamAsString(assetsManager.open(customProvider.getDomain() + EXT_PEM));
- String providerDefinition = loadInputStreamAsString(assetsManager.open(customProvider.getDomain() + EXT_JSON));
+ String domain = ConfigHelper.getDomainFromMainURL(customProviderUrl);
+ String certificate = loadInputStreamAsString(assetsManager.open(domain + EXT_PEM));
+ String providerDefinition = loadInputStreamAsString(assetsManager.open(domain + EXT_JSON));
customProvider.setCaCert(certificate);
customProvider.define(new JSONObject(providerDefinition));
setProvider(customProvider);