summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java39
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java5
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Constants.java32
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java11
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/FeatureVersionCode.java5
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java4
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java5
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/StartActivity.java112
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/VpnFragment.java31
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIP.java32
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIPConstants.java44
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java5
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java4
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java4
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java4
15 files changed, 154 insertions, 183 deletions
diff --git a/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java b/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java
index a1fc7cdc..d5931c83 100644
--- a/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java
+++ b/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java
@@ -423,45 +423,6 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar.
private TextView mSpeedView;
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (item.getItemId() == R.id.clearlog) {
- ladapter.clearLog();
- return true;
- } else if (item.getItemId() == R.id.cancel) {
- Intent intent = new Intent(getActivity(), DisconnectVPN.class);
- startActivity(intent);
- return true;
- } else if (item.getItemId() == R.id.send) {
- ladapter.shareLog();
- } else if (item.getItemId() == R.id.edit_vpn) {
- VpnProfile lastConnectedprofile = ProfileManager.get(getActivity(), VpnStatus.getLastConnectedVPNProfile());
-
- if (lastConnectedprofile != null) {
- Intent vprefintent = new Intent(getActivity(), Dashboard.class)
- .putExtra(VpnProfile.EXTRA_PROFILEUUID, lastConnectedprofile.getUUIDString());
- startActivityForResult(vprefintent, START_VPN_CONFIG);
- } else {
- Toast.makeText(getActivity(), R.string.log_no_last_vpn, Toast.LENGTH_LONG).show();
- }
- } else if (item.getItemId() == R.id.toggle_time) {
- showHideOptionsPanel();
- } else if (item.getItemId() == android.R.id.home) {
- // This is called when the Home (Up) button is pressed
- // in the Action Bar.
- Intent parentActivityIntent = new Intent(getActivity(), Dashboard.class);
- parentActivityIntent.addFlags(
- Intent.FLAG_ACTIVITY_CLEAR_TOP |
- Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(parentActivityIntent);
- getActivity().finish();
- return true;
-
- }
- return super.onOptionsItemSelected(item);
-
- }
-
private void showHideOptionsPanel() {
boolean optionsVisible = (mOptionsLayout.getVisibility() != View.GONE);
diff --git a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java
index 5dae1227..21520dc4 100644
--- a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java
@@ -51,7 +51,6 @@ import javax.inject.Inject;
import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnItemClick;
-import se.leap.bitmaskclient.eip.EIPConstants;
import se.leap.bitmaskclient.userstatus.SessionDialog;
import static android.view.View.GONE;
@@ -220,7 +219,7 @@ public abstract class BaseConfigurationWizard extends Activity
e.printStackTrace();
}
- if (preferences.getBoolean(EIPConstants.ALLOWED_ANON, false)) {
+ if (preferences.getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS, false)) {
mConfigState.putExtra(SERVICES_RETRIEVED, true);
downloadVpnCertificate();
@@ -297,7 +296,7 @@ public abstract class BaseConfigurationWizard extends Activity
public void cancelSettingUpProvider() {
mConfigState.setAction(PROVIDER_NOT_SET);
adapter.showAllProviders();
- preferences.edit().remove(Provider.KEY).remove(EIPConstants.ALLOWED_ANON).remove(EIPConstants.KEY).apply();
+ preferences.edit().remove(Provider.KEY).remove(Constants.PROVIDER_ALLOW_ANONYMOUS).remove(Constants.PROVIDER_KEY).apply();
}
private void askDashboardToQuitApp() {
diff --git a/app/src/main/java/se/leap/bitmaskclient/Constants.java b/app/src/main/java/se/leap/bitmaskclient/Constants.java
index 4ce09892..8723191c 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Constants.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Constants.java
@@ -1,6 +1,38 @@
package se.leap.bitmaskclient;
public interface Constants {
+
+ //////////////////////////////////////////////
+ // PREFERENCES CONSTANTS
+ /////////////////////////////////////////////
+
String SHARED_PREFERENCES = "LEAPPreferences";
String PREFERENCES_APP_VERSION = "bitmask version";
+
+
+ //////////////////////////////////////////////
+ // EIP CONSTANTS
+ /////////////////////////////////////////////
+
+ String EIP_ACTION_CHECK_CERT_VALIDITY = "EIP.CHECK_CERT_VALIDITY";
+ String EIP_ACTION_START = "EIP.START";
+ String EIP_ACTION_STOP = "EIP.STOP";
+ String EIP_ACTION_UPDATE = "EIP.UPDATE";
+ String EIP_ACTION_IS_RUNNING = "EIP.IS_RUNNING";
+ String EIP_ACTION_BLOCK_VPN_PROFILE = "EIP.ACTION_BLOCK_VPN_PROFILE";
+
+ String EIP_NOTIFICATION = "EIP.NOTIFICATION";
+ String EIP_RECEIVER = "EIP.RECEIVER";
+ String EIP_REQUEST = "EIP.REQUEST";
+
+
+ //////////////////////////////////////////////
+ // PROVIDER CONSTANTS
+ /////////////////////////////////////////////
+ String PROVIDER_ALLOW_ANONYMOUS = "allow_anonymous";
+ String PROVIDER_ALLOWED_REGISTERED = "allow_registration";
+ String PROVIDER_VPN_CERTIFICATE = "cert";
+ String PROVIDER_PRIVATE_KEY = "Constants.PROVIDER_PRIVATE_KEY";
+ String PROVIDER_KEY = "Constants.PROVIDER_KEY";
+ String PROVIDER_CONFIGURED = "Constants.PROVIDER_CONFIGURED";
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index e2366551..1f0477c9 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -41,7 +41,6 @@ import java.net.URL;
import butterknife.ButterKnife;
import butterknife.InjectView;
-import se.leap.bitmaskclient.eip.EIPConstants;
import se.leap.bitmaskclient.userstatus.SessionDialog;
import se.leap.bitmaskclient.userstatus.User;
import se.leap.bitmaskclient.userstatus.UserStatusFragment;
@@ -131,7 +130,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec
private boolean providerInSharedPreferences() {
return preferences != null &&
- preferences.getBoolean(EIPConstants.PROVIDER_CONFIGURED, false);
+ preferences.getBoolean(Constants.PROVIDER_CONFIGURED, false);
}
@@ -160,7 +159,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec
switch (versionCode) {
case 91: // 0.6.0 without Bug #5999
case 101: // 0.8.0
- if (!preferences.getString(EIPConstants.KEY, "").isEmpty())
+ if (!preferences.getString(Constants.PROVIDER_KEY, "").isEmpty())
eip_fragment.updateEipService();
break;
}
@@ -205,7 +204,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec
@SuppressLint("CommitPrefEdits")
private void providerToPreferences(Provider provider) {
- preferences.edit().putBoolean(EIPConstants.PROVIDER_CONFIGURED, true).commit();
+ preferences.edit().putBoolean(Constants.PROVIDER_CONFIGURED, true).commit();
preferences.edit().putString(Provider.MAIN_URL, provider.mainUrl().toString()).apply();
preferences.edit().putString(Provider.KEY, provider.definition().toString()).apply();
}
@@ -225,7 +224,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec
.setNegativeButton(getResources().getString(R.string.setup_error_close_button), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- preferences.edit().remove(Provider.KEY).remove(EIPConstants.PROVIDER_CONFIGURED).apply();
+ preferences.edit().remove(Provider.KEY).remove(Constants.PROVIDER_CONFIGURED).apply();
finish();
}
})
@@ -316,7 +315,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec
public void downloadVpnCertificate() {
boolean is_authenticated = User.loggedIn();
- boolean allowed_anon = preferences.getBoolean(EIPConstants.ALLOWED_ANON, false);
+ boolean allowed_anon = preferences.getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS, false);
if (allowed_anon || is_authenticated)
ProviderAPICommand.execute(Bundle.EMPTY, ProviderAPI.DOWNLOAD_CERTIFICATE, providerAPI_result_receiver);
else
diff --git a/app/src/main/java/se/leap/bitmaskclient/FeatureVersionCode.java b/app/src/main/java/se/leap/bitmaskclient/FeatureVersionCode.java
new file mode 100644
index 00000000..b2a39c1a
--- /dev/null
+++ b/app/src/main/java/se/leap/bitmaskclient/FeatureVersionCode.java
@@ -0,0 +1,5 @@
+package se.leap.bitmaskclient;
+
+public interface FeatureVersionCode {
+ int MULTIPLE_PROFILES = 132;
+}
diff --git a/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java b/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java
index a72a8809..9394e1b1 100644
--- a/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java
+++ b/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java
@@ -2,8 +2,6 @@ package se.leap.bitmaskclient;
import android.content.*;
-import se.leap.bitmaskclient.eip.EIPConstants;
-
public class OnBootReceiver extends BroadcastReceiver {
@@ -17,7 +15,7 @@ public class OnBootReceiver extends BroadcastReceiver {
boolean start_on_boot = preferences.getBoolean(Dashboard.START_ON_BOOT, false);
if (provider_configured && start_on_boot) {
Intent dashboard_intent = new Intent(context, Dashboard.class);
- dashboard_intent.setAction(EIPConstants.ACTION_START_EIP);
+ dashboard_intent.setAction(Constants.EIP_ACTION_START);
dashboard_intent.putExtra(Dashboard.ON_BOOT, true);
dashboard_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(dashboard_intent);
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java b/app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java
index 81852983..6e3b8b08 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java
@@ -67,7 +67,6 @@ import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.TlsVersion;
-import se.leap.bitmaskclient.eip.EIPConstants;
import se.leap.bitmaskclient.userstatus.SessionDialog;
import se.leap.bitmaskclient.userstatus.User;
import se.leap.bitmaskclient.userstatus.UserStatus;
@@ -817,11 +816,11 @@ public abstract class ProviderApiBase extends IntentService {
RSAPrivateKey key = ConfigHelper.parseRsaKeyFromString(keyString);
keyString = Base64.encodeToString(key.getEncoded(), Base64.DEFAULT);
- preferences.edit().putString(EIPConstants.PRIVATE_KEY, "-----BEGIN RSA PRIVATE KEY-----\n" + keyString + "-----END RSA PRIVATE KEY-----").commit();
+ preferences.edit().putString(Constants.PROVIDER_PRIVATE_KEY, "-----BEGIN RSA PRIVATE KEY-----\n" + keyString + "-----END RSA PRIVATE KEY-----").commit();
X509Certificate certificate = ConfigHelper.parseX509CertificateFromString(certificateString);
certificateString = Base64.encodeToString(certificate.getEncoded(), Base64.DEFAULT);
- preferences.edit().putString(EIPConstants.VPN_CERTIFICATE, "-----BEGIN CERTIFICATE-----\n" + certificateString + "-----END CERTIFICATE-----").commit();
+ preferences.edit().putString(Constants.PROVIDER_VPN_CERTIFICATE, "-----BEGIN CERTIFICATE-----\n" + certificateString + "-----END CERTIFICATE-----").commit();
return true;
} catch (CertificateException e) {
// TODO Auto-generated catch block
diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java
index 0ccc5b41..1bf81aea 100644
--- a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java
@@ -31,40 +31,76 @@ public class StartActivity extends Activity {
private static final int UPGRADE = 2;
private static final int DOWNGRADE = 3;
+ private int versionCode;
+ private int previousVersionCode;
+
+ private SharedPreferences preferences;
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE);
+
+ Log.d(TAG, "Started");
+
+ switch (checkAppStart()) {
+ case NORMAL:
+ break;
+
+ case FIRST:
+ // TODO start ProfileCreation & replace below code
+ break;
+
+ case UPGRADE:
+ executeUpgrade();
+ // TODO show donation dialog
+ break;
+
+ case DOWNGRADE:
+ // TODO think how and why this should happen and what todo
+ break;
+ }
+
+ // initialize app necessities
+ ProviderAPICommand.initialize(this);
+ VpnStatus.initLogCache(getApplicationContext().getCacheDir());
+ User.init(getString(R.string.default_username));
+
+ // go to Dashboard
+ Intent intent = new Intent(this, MainActivity.class);
+ startActivity(intent);
+ }
+
/**
* check if normal start, first run, up or downgrade
* @return @StartupMode
*/
@StartupMode
private int checkAppStart() {
- SharedPreferences preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE);
try {
- int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
- int lastDetectedVersion = preferences.getInt(Constants.PREFERENCES_APP_VERSION, -1);
+ versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
+ previousVersionCode = preferences.getInt(Constants.PREFERENCES_APP_VERSION, -1);
// versions do match -> normal start
- if (versionCode == lastDetectedVersion) {
+ if (versionCode == previousVersionCode) {
Log.d(TAG, "App start was: NORMAL START");
return NORMAL;
}
- // something changed -> save current version
- preferences.edit().putInt(Constants.PREFERENCES_APP_VERSION, versionCode).apply();
-
// no previous app version -> first start
- if (lastDetectedVersion == -1 ) {
- Log.d(TAG, "App start was: FIRST START");
+ if (previousVersionCode == -1 ) {
+ Log.d(TAG, "FIRST START");
return FIRST;
}
// version has increased -> upgrade
- if (versionCode > lastDetectedVersion) {
- Log.d(TAG, "App start was: UPGRADE");
+ if (versionCode > previousVersionCode) {
+ Log.d(TAG, "UPGRADE");
return UPGRADE;
}
// version has decreased -> downgrade
- if (versionCode < lastDetectedVersion) {
- Log.d(TAG, "App start was: DOWNGRADE");
+ if (versionCode < previousVersionCode) {
+ Log.d(TAG, "DOWNGRADE");
return DOWNGRADE;
}
@@ -75,41 +111,25 @@ public class StartActivity extends Activity {
return NORMAL;
}
-
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- Intent intent;
-
- Log.d(TAG, "Started");
-
- switch (checkAppStart()) {
- case NORMAL:
- break;
-
- case FIRST:
- // TODO start ProfileCreation & replace below code
- intent = new Intent(this, Dashboard.class);
- startActivity(intent);
- break;
-
- case UPGRADE:
- // TODO appropriate data copying
- // TODO show donation dialog
- break;
-
- case DOWNGRADE:
- // TODO think how and why this should happen and what todo
- break;
+ /**
+ * execute necessary upgrades for version change
+ */
+ private void executeUpgrade() {
+ if (hasNewFeature(FeatureVersionCode.MULTIPLE_PROFILES)) {
+ // TODO prepare usage of multiple profiles
}
- // initialize app necessities
- ProviderAPICommand.initialize(this);
- VpnStatus.initLogCache(getApplicationContext().getCacheDir());
- User.init(getString(R.string.default_username));
+ // ensure all upgrades have passed before storing new information
+ preferences.edit().putInt(Constants.PREFERENCES_APP_VERSION, versionCode).apply();
+ }
- // go to Dashboard
- intent = new Intent(this, MainActivity.class);
- startActivity(intent);
+ /**
+ * check if an upgrade passed or moved to given milestone
+ * @param featureVersionCode Version code of the Milestone FeatureVersionCode.MILE_STONE
+ * @return true if milestone is reached - false otherwise
+ */
+ private boolean hasNewFeature(int featureVersionCode) {
+ return previousVersionCode < featureVersionCode && versionCode >= featureVersionCode;
}
+
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java b/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java
index eff02193..f787a955 100644
--- a/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java
@@ -32,11 +32,10 @@ import de.blinkt.openvpn.core.IOpenVPNServiceInternal;
import de.blinkt.openvpn.core.OpenVPNService;
import de.blinkt.openvpn.core.ProfileManager;
import de.blinkt.openvpn.core.VpnStatus;
-import mbanje.kurt.fabbutton.*;
-import se.leap.bitmaskclient.eip.EIPConstants;
import se.leap.bitmaskclient.eip.EIP;
import se.leap.bitmaskclient.eip.EipStatus;
import se.leap.bitmaskclient.eip.VoidVpnService;
+import se.leap.bitmaskclient.userstatus.FabButton;
public class VpnFragment extends Fragment implements Observer {
@@ -115,7 +114,7 @@ public class VpnFragment extends Fragment implements Observer {
public void onResume() {
super.onResume();
//FIXME: avoid race conditions while checking certificate an logging in at about the same time
- //eipCommand(EIPConstants.ACTION_CHECK_CERT_VALIDITY);
+ //eipCommand(Constants.EIP_ACTION_CHECK_CERT_VALIDITY);
handleNewState(eip_status);
bindOpenVpnService();
}
@@ -164,13 +163,13 @@ public class VpnFragment extends Fragment implements Observer {
}
private boolean canStartEIP() {
- boolean certificateExists = !Dashboard.preferences.getString(EIPConstants.VPN_CERTIFICATE, "").isEmpty();
- boolean isAllowedAnon = Dashboard.preferences.getBoolean(EIPConstants.ALLOWED_ANON, false);
+ boolean certificateExists = !Dashboard.preferences.getString(Constants.PROVIDER_VPN_CERTIFICATE, "").isEmpty();
+ boolean isAllowedAnon = Dashboard.preferences.getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS, false);
return (isAllowedAnon || certificateExists) && !eip_status.isConnected() && !eip_status.isConnecting();
}
private boolean canLogInToStartEIP() {
- boolean isAllowedRegistered = Dashboard.preferences.getBoolean(EIPConstants.ALLOWED_REGISTERED, false);
+ boolean isAllowedRegistered = Dashboard.preferences.getBoolean(Constants.PROVIDER_ALLOWED_REGISTERED, false);
boolean isLoggedIn = !LeapSRPSession.getToken().isEmpty();
return isAllowedRegistered && !isLoggedIn && !eip_status.isConnecting() && !eip_status.isConnected();
}
@@ -207,7 +206,7 @@ public class VpnFragment extends Fragment implements Observer {
eip_status.setConnecting();
saveStatus();
- eipCommand(EIPConstants.ACTION_START_EIP);
+ eipCommand(Constants.EIP_ACTION_START);
}
private void stop() {
@@ -230,7 +229,7 @@ public class VpnFragment extends Fragment implements Observer {
}
protected void stopEipIfPossible() {
- eipCommand(EIPConstants.ACTION_STOP_EIP);
+ eipCommand(Constants.EIP_ACTION_STOP);
}
private void downloadEIPServiceConfig() {
@@ -258,7 +257,7 @@ public class VpnFragment extends Fragment implements Observer {
}
protected void updateEipService() {
- eipCommand(EIPConstants.ACTION_UPDATE_EIP_SERVICE);
+ eipCommand(Constants.EIP_ACTION_UPDATE);
}
/**
@@ -271,7 +270,7 @@ public class VpnFragment extends Fragment implements Observer {
// TODO validate "action"...how do we get the list of intent-filters for a class via Android API?
Intent vpn_intent = new Intent(dashboard.getApplicationContext(), EIP.class);
vpn_intent.setAction(action);
- vpn_intent.putExtra(EIPConstants.RECEIVER_TAG, eip_receiver);
+ vpn_intent.putExtra(Constants.EIP_RECEIVER, eip_receiver);
dashboard.startService(vpn_intent);
}
@@ -344,9 +343,9 @@ public class VpnFragment extends Fragment implements Observer {
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);
- String request = resultData.getString(EIPConstants.REQUEST_TAG);
+ String request = resultData.getString(Constants.EIP_REQUEST);
- if (request.equals(EIPConstants.ACTION_START_EIP)) {
+ if (request.equals(Constants.EIP_ACTION_START)) {
switch (resultCode) {
case Activity.RESULT_OK:
break;
@@ -354,7 +353,7 @@ public class VpnFragment extends Fragment implements Observer {
break;
}
- } else if (request.equals(EIPConstants.ACTION_STOP_EIP)) {
+ } else if (request.equals(Constants.EIP_ACTION_STOP)) {
switch (resultCode) {
case Activity.RESULT_OK:
stop();
@@ -362,14 +361,14 @@ public class VpnFragment extends Fragment implements Observer {
case Activity.RESULT_CANCELED:
break;
}
- } else if (request.equals(EIPConstants.EIP_NOTIFICATION)) {
+ } else if (request.equals(Constants.EIP_NOTIFICATION)) {
switch (resultCode) {
case Activity.RESULT_OK:
break;
case Activity.RESULT_CANCELED:
break;
}
- } else if (request.equals(EIPConstants.ACTION_CHECK_CERT_VALIDITY)) {
+ } else if (request.equals(Constants.EIP_ACTION_CHECK_CERT_VALIDITY)) {
switch (resultCode) {
case Activity.RESULT_OK:
break;
@@ -377,7 +376,7 @@ public class VpnFragment extends Fragment implements Observer {
dashboard.downloadVpnCertificate();
break;
}
- } else if (request.equals(EIPConstants.ACTION_UPDATE_EIP_SERVICE)) {
+ } else if (request.equals(Constants.EIP_ACTION_UPDATE)) {
switch (resultCode) {
case Activity.RESULT_OK:
if (wants_to_connect)
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 8bbdf901..0b35dc3d 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
@@ -25,8 +25,6 @@ import org.json.*;
import de.blinkt.openvpn.*;
import se.leap.bitmaskclient.*;
-import static se.leap.bitmaskclient.eip.EIPConstants.*;
-
/**
* EIP is the abstract base class for interacting with and managing the Encrypted
* Internet Proxy connection. Connections are started, stopped, and queried through
@@ -68,17 +66,17 @@ public final class EIP extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
String action = intent.getAction();
- mReceiver = intent.getParcelableExtra(RECEIVER_TAG);
+ mReceiver = intent.getParcelableExtra(Constants.EIP_RECEIVER);
- if (action.equals(ACTION_START_EIP))
+ if (action.equals(Constants.EIP_ACTION_START))
startEIP();
- else if (action.equals(ACTION_STOP_EIP))
+ else if (action.equals(Constants.EIP_ACTION_STOP))
stopEIP();
- else if (action.equals(ACTION_IS_EIP_RUNNING))
+ else if (action.equals(Constants.EIP_ACTION_IS_RUNNING))
isRunning();
- else if (action.equals(ACTION_UPDATE_EIP_SERVICE))
+ else if (action.equals(Constants.EIP_ACTION_UPDATE))
updateEIPService();
- else if (action.equals(ACTION_CHECK_CERT_VALIDITY))
+ else if (action.equals(Constants.EIP_ACTION_CHECK_CERT_VALIDITY))
checkCertValidity();
}
@@ -96,9 +94,9 @@ public final class EIP extends IntentService {
if (gateway != null && gateway.getProfile() != null) {
mReceiver = VpnFragment.getReceiver();
launchActiveGateway();
- tellToReceiver(ACTION_START_EIP, Activity.RESULT_OK);
+ tellToReceiver(Constants.EIP_ACTION_START, Activity.RESULT_OK);
} else
- tellToReceiver(ACTION_START_EIP, Activity.RESULT_CANCELED);
+ tellToReceiver(Constants.EIP_ACTION_START, Activity.RESULT_CANCELED);
}
/**
@@ -126,7 +124,7 @@ public final class EIP extends IntentService {
if (eip_status.isConnected() || eip_status.isConnecting())
result_code = Activity.RESULT_OK;
- tellToReceiver(ACTION_STOP_EIP, result_code);
+ tellToReceiver(Constants.EIP_ACTION_STOP, result_code);
}
/**
@@ -139,7 +137,7 @@ public final class EIP extends IntentService {
int resultCode = (eip_status.isConnected()) ?
Activity.RESULT_OK :
Activity.RESULT_CANCELED;
- tellToReceiver(ACTION_IS_EIP_RUNNING, resultCode);
+ tellToReceiver(Constants.EIP_ACTION_IS_RUNNING, resultCode);
}
/**
@@ -150,13 +148,13 @@ public final class EIP extends IntentService {
eip_definition = eipDefinitionFromPreferences();
if (eip_definition.length() > 0)
updateGateways();
- tellToReceiver(ACTION_UPDATE_EIP_SERVICE, Activity.RESULT_OK);
+ tellToReceiver(Constants.EIP_ACTION_UPDATE, Activity.RESULT_OK);
}
private JSONObject eipDefinitionFromPreferences() {
JSONObject result = new JSONObject();
try {
- String eip_definition_string = preferences.getString(KEY, "");
+ String eip_definition_string = preferences.getString(Constants.PROVIDER_KEY, "");
if (!eip_definition_string.isEmpty()) {
result = new JSONObject(eip_definition_string);
}
@@ -186,17 +184,17 @@ public final class EIP extends IntentService {
}
private void checkCertValidity() {
- VpnCertificateValidator validator = new VpnCertificateValidator(preferences.getString(VPN_CERTIFICATE, ""));
+ VpnCertificateValidator validator = new VpnCertificateValidator(preferences.getString(Constants.PROVIDER_VPN_CERTIFICATE, ""));
int resultCode = validator.isValid() ?
Activity.RESULT_OK :
Activity.RESULT_CANCELED;
- tellToReceiver(ACTION_CHECK_CERT_VALIDITY, resultCode);
+ tellToReceiver(Constants.EIP_ACTION_CHECK_CERT_VALIDITY, resultCode);
}
private void tellToReceiver(String action, int resultCode) {
if (mReceiver != null) {
Bundle resultData = new Bundle();
- resultData.putString(REQUEST_TAG, action);
+ resultData.putString(Constants.EIP_REQUEST, action);
mReceiver.send(resultCode, resultData);
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIPConstants.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIPConstants.java
deleted file mode 100644
index a56868f1..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EIPConstants.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * Copyright (c) 2013 LEAP Encryption Access Project and contributers
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package se.leap.bitmaskclient.eip;
-
-/**
- * EIPConstants for intent passing, shared preferences
- *
- * @author Parménides GV <parmegv@sdf.org>
- */
-public interface EIPConstants {
-
- String TAG = "Constants";
-
- String ACTION_CHECK_CERT_VALIDITY = TAG + ".CHECK_CERT_VALIDITY";
- String ACTION_START_EIP = TAG + ".START_EIP";
- String ACTION_STOP_EIP = TAG + ".STOP_EIP";
- String ACTION_UPDATE_EIP_SERVICE = TAG + ".UPDATE_EIP_SERVICE";
- String ACTION_IS_EIP_RUNNING = TAG + ".IS_RUNNING";
- String EIP_NOTIFICATION = TAG + ".EIP_NOTIFICATION";
- String ALLOWED_ANON = "allow_anonymous";
- String ALLOWED_REGISTERED = "allow_registration";
- String VPN_CERTIFICATE = "cert";
- String PRIVATE_KEY = TAG + ".PRIVATE_KEY";
- String KEY = TAG + ".KEY";
- String RECEIVER_TAG = TAG + ".RECEIVER_TAG";
- String REQUEST_TAG = TAG + ".REQUEST_TAG";
- String START_BLOCKING_VPN_PROFILE = TAG + ".START_BLOCKING_VPN_PROFILE";
- String PROVIDER_CONFIGURED = TAG + ".PROVIDER_CONFIGURED";
-
-}
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 25c99098..43c16d00 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java
@@ -36,6 +36,7 @@ import java.util.List;
import de.blinkt.openvpn.VpnProfile;
import de.blinkt.openvpn.core.Connection;
import de.blinkt.openvpn.core.ProfileManager;
+import se.leap.bitmaskclient.Constants;
import se.leap.bitmaskclient.Provider;
/**
@@ -123,8 +124,8 @@ public class GatewaysManager {
JSONObject result = new JSONObject();
try {
result.put(Provider.CA_CERT, preferences.getString(Provider.CA_CERT, ""));
- result.put(EIPConstants.PRIVATE_KEY, preferences.getString(EIPConstants.PRIVATE_KEY, ""));
- result.put(EIPConstants.VPN_CERTIFICATE, preferences.getString(EIPConstants.VPN_CERTIFICATE, ""));
+ result.put(Constants.PROVIDER_PRIVATE_KEY, preferences.getString(Constants.PROVIDER_PRIVATE_KEY, ""));
+ result.put(Constants.PROVIDER_VPN_CERTIFICATE, preferences.getString(Constants.PROVIDER_VPN_CERTIFICATE, ""));
} catch (JSONException e) {
e.printStackTrace();
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java
index 8ce8aa81..b1aab79c 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java
@@ -5,6 +5,8 @@ import android.content.*;
import android.net.*;
import android.os.*;
+import se.leap.bitmaskclient.Constants;
+
public class VoidVpnLauncher extends Activity {
private static final int VPN_USER_PERMISSION = 71;
@@ -28,7 +30,7 @@ public class VoidVpnLauncher extends Activity {
if (requestCode == VPN_USER_PERMISSION) {
if (resultCode == RESULT_OK) {
Intent void_vpn_service = new Intent(getApplicationContext(), VoidVpnService.class);
- void_vpn_service.setAction(EIPConstants.START_BLOCKING_VPN_PROFILE);
+ void_vpn_service.setAction(Constants.EIP_ACTION_BLOCK_VPN_PROFILE);
startService(void_vpn_service);
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
index 629b4304..ff375553 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
@@ -6,6 +6,8 @@ import android.os.*;
import java.io.*;
+import se.leap.bitmaskclient.Constants;
+
public class VoidVpnService extends VpnService {
static final String TAG = VoidVpnService.class.getSimpleName();
@@ -16,7 +18,7 @@ public class VoidVpnService extends VpnService {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
String action = intent != null ? intent.getAction() : "";
- if (action == EIPConstants.START_BLOCKING_VPN_PROFILE) {
+ if (action == Constants.EIP_ACTION_BLOCK_VPN_PROFILE) {
thread = new Thread(new Runnable() {
public void run() {
Builder builder = new Builder();
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 33993139..54563ec4 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java
@@ -118,14 +118,14 @@ public class VpnConfigGenerator {
String key =
"<key>"
+ new_line
- + secrets.getString(EIPConstants.PRIVATE_KEY)
+ + secrets.getString(Constants.PROVIDER_PRIVATE_KEY)
+ new_line
+ "</key>";
String openvpn_cert =
"<cert>"
+ new_line
- + secrets.getString(EIPConstants.VPN_CERTIFICATE)
+ + secrets.getString(Constants.PROVIDER_VPN_CERTIFICATE)
+ new_line
+ "</cert>";