diff options
Diffstat (limited to 'src/se/leap/bitmaskclient')
-rw-r--r-- | src/se/leap/bitmaskclient/ConfigHelper.java | 139 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/ConfigurationWizard.java | 39 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/Dashboard.java | 97 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/EIP.java | 88 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/EipServiceFragment.java | 18 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/LeapHttpClient.java | 9 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/ProviderAPI.java | 48 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/ProviderDetailFragment.java | 11 |
8 files changed, 136 insertions, 313 deletions
diff --git a/src/se/leap/bitmaskclient/ConfigHelper.java b/src/se/leap/bitmaskclient/ConfigHelper.java index 6b49d7d7..a8bd3b7a 100644 --- a/src/se/leap/bitmaskclient/ConfigHelper.java +++ b/src/se/leap/bitmaskclient/ConfigHelper.java @@ -47,142 +47,12 @@ import android.util.Base64; * */ public class ConfigHelper { - - public static SharedPreferences shared_preferences; private static KeyStore keystore_trusted; final public static String NG_1024 = "eeaf0ab9adb38dd69c33f80afa8fc5e86072618775ff3c0b9ea2314c9c256576d674df7496ea81d3383b4813d692c6e0e0d5d8e250b98be48e495c1d6089dad15dc7d7b46154d6b6ce8ef4ad69b15d4982559b297bcf1885c529f566660e57ec68edbc3c05726cc02fd4cbf4976eaa9afd5138fe8376435b9fc61d2fc0eb06e3"; final public static BigInteger G = new BigInteger("2"); - - private static boolean checkSharedPrefs() { - try { - if(shared_preferences == null) - shared_preferences = Dashboard.getAppContext().getSharedPreferences(Dashboard.SHARED_PREFERENCES,Context.MODE_PRIVATE); - } catch (Exception e) { - return false; - } - - return true; - } - - /** - * Saves a JSON object into class scope Shared Preferences - * @param shared_preferences_key - * @param content - */ - public static void saveSharedPref(String shared_preferences_key, JSONObject content) { - - SharedPreferences.Editor shared_preferences_editor = shared_preferences - .edit(); - shared_preferences_editor.putString(shared_preferences_key, - content.toString()); - shared_preferences_editor.commit(); - } - - /** - * Saves a String object into class scope Shared Preferences - * @param shared_preferences_key - * @param content - */ - public static void saveSharedPref(String shared_preferences_key, String content) { - - SharedPreferences.Editor shared_preferences_editor = shared_preferences - .edit(); - shared_preferences_editor.putString(shared_preferences_key, - content); - shared_preferences_editor.commit(); - } - - /** - * Saves a boolean object into class scope Shared Preferences - * @param shared_preferences_key - * @param content - */ - public static void saveSharedPref(String shared_preferences_key, boolean content) { - - SharedPreferences.Editor shared_preferences_editor = shared_preferences - .edit(); - shared_preferences_editor.putBoolean(shared_preferences_key, content); - shared_preferences_editor.commit(); - } - - /** - * Saves an int into class scope Shared Preferences - * - * @param shared_preferences_key - * @param value - */ - protected static void saveSharedPref(String shared_preferences_key, int value) { - SharedPreferences.Editor shared_preferences_editor = shared_preferences.edit(); - shared_preferences_editor.putInt(shared_preferences_key, value).commit(); - } - - /** - * Gets String object from class scope Shared Preferences - * @param shared_preferences_key - * @return the string correspondent to the key parameter - */ - public static String getStringFromSharedPref(String shared_preferences_key) { - String content = null; - content = shared_preferences.getString(shared_preferences_key, ""); - return content; - } - - /** - * Gets JSON object from class scope Shared Preferences - * @param shared_preferences_key - * @return the JSON object correspondent to the key parameter - */ - public static JSONObject getJsonFromSharedPref(String shared_preferences_key) throws JSONException { - JSONObject content = null; - if ( checkSharedPrefs() ) { - String json_string = shared_preferences.getString(shared_preferences_key, ""); - content = new JSONObject(json_string); - } - - return content; - } - - /* - * This method defaults to false. - * If you use this method, be sure to fail-closed on false! - * TODO This is obviously less than ideal...solve it! - */ - public static boolean getBoolFromSharedPref(String shared_preferences_key) { - boolean value = false; - if ( checkSharedPrefs() ) { - value = shared_preferences.getBoolean(shared_preferences_key, false); - } - return value; - } - - /** - * Get an int from SharedPreferences - * - * @param shared_preferences_key Key to retrieve - * @return The value for the key or 0 - */ - protected static int getIntFromSharedPref(String shared_preferences_key) { - return shared_preferences.getInt(shared_preferences_key, 0); - } - - protected static boolean sharedPrefContainsKey(String shared_preferences_key) { - return shared_preferences.contains(shared_preferences_key); - } - /* - * This method defaults to false. - * If you use this method, be sure to fail-closed on false! - * TODO This is obviously less than ideal...solve it! - */ - public static boolean removeFromSharedPref(String shared_preferences_key) { - SharedPreferences.Editor shared_preferences_editor = shared_preferences - .edit(); - shared_preferences_editor.remove(shared_preferences_key); - return shared_preferences_editor.commit(); - } - public static boolean checkErroneousDownload(String downloaded_string) { try { if(new JSONObject(downloaded_string).has(ProviderAPI.ERRORS) || downloaded_string.isEmpty()) { @@ -214,15 +84,6 @@ public class ConfigHelper { System.arraycopy(in, i, ret, 0, len - i); return ret; } - - /** - * Sets class scope Shared Preferences - * @param shared_preferences - */ - public static void setSharedPreferences( - SharedPreferences shared_preferences) { - ConfigHelper.shared_preferences = shared_preferences; - } public static X509Certificate parseX509CertificateFromString(String certificate_string) { java.security.cert.Certificate certificate = null; diff --git a/src/se/leap/bitmaskclient/ConfigurationWizard.java b/src/se/leap/bitmaskclient/ConfigurationWizard.java index cf027660..e5ad5b3d 100644 --- a/src/se/leap/bitmaskclient/ConfigurationWizard.java +++ b/src/se/leap/bitmaskclient/ConfigurationWizard.java @@ -40,6 +40,7 @@ import android.content.BroadcastReceiver; import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.SharedPreferences;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.os.Handler;
@@ -85,10 +86,12 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD public ProviderAPIResultReceiver providerAPI_result_receiver;
private ProviderAPIBroadcastReceiver_Update providerAPI_broadcast_receiver_update;
+ private static SharedPreferences preferences; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ preferences = getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE);
setContentView(R.layout.configuration_wizard_activity);
mProgressBar = (ProgressBar) findViewById(R.id.progressbar_configuration_wizard);
@@ -101,10 +104,8 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD IntentFilter update_intent_filter = new IntentFilter(ProviderAPI.UPDATE_PROGRESSBAR);
update_intent_filter.addCategory(Intent.CATEGORY_DEFAULT);
registerReceiver(providerAPI_broadcast_receiver_update, update_intent_filter);
-
- ConfigHelper.setSharedPreferences(getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE));
-
- loadPreseededProviders();
+
+ loadPreseededProviders();
// Only create our fragments if we're not restoring a saved instance
if ( savedInstanceState == null ){
@@ -150,7 +151,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD if(resultCode == ProviderAPI.PROVIDER_OK) {
mConfigState.setAction(PROVIDER_SET);
- if (ConfigHelper.getBoolFromSharedPref(EIP.ALLOWED_ANON)){
+ if (preferences.getBoolean(EIP.ALLOWED_ANON, false)){
mConfigState.putExtra(SERVICES_RETRIEVED, true);
downloadAnonCert();
} else {
@@ -166,7 +167,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD showDownloadFailedDialog(getCurrentFocus(), reason_to_fail);
mProgressBar.setVisibility(ProgressBar.GONE);
progressbar_description.setVisibility(TextView.GONE);
- ConfigHelper.removeFromSharedPref(Provider.KEY); + preferences.edit().remove(Provider.KEY).commit(); setResult(RESULT_CANCELED, mConfigState);
}
else if(resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) {
@@ -204,15 +205,17 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD provider_list_fragment.hideAllBut(provider_index); boolean danger_on = true; - if(ConfigHelper.sharedPrefContainsKey(ProviderItem.DANGER_ON)) - danger_on = ConfigHelper.getBoolFromSharedPref(ProviderItem.DANGER_ON); + if(preferences.contains(ProviderItem.DANGER_ON)) + danger_on = preferences.getBoolean(ProviderItem.DANGER_ON, false); setUpProvider(selected_provider.providerMainUrl(), danger_on); }
@Override
public void onBackPressed() {
try {
- if(ConfigHelper.getJsonFromSharedPref(Provider.KEY) == null || ConfigHelper.getJsonFromSharedPref(Provider.KEY).length() == 0) {
+ boolean is_provider_set_up = new JSONObject(preferences.getString(Provider.KEY, "no provider")) != null ? true : false;
+ boolean is_provider_set_up_truly = new JSONObject(preferences.getString(Provider.KEY, "no provider")).length() != 0 ? true : false;
+ if(!is_provider_set_up || !is_provider_set_up_truly) {
askDashboardToQuitApp();
} else {
setResult(RESULT_OK);
@@ -275,12 +278,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD ProviderItem provider = providers_iterator.next();
if(provider.name().equalsIgnoreCase(id)) {
break;
-//<<<<<<< HEAD -// }
-// index++;
-//======= - } else index++;
-//>>>>>>> bug/more-detailed-response-to-CW-errors + } else index++; }
return index;
}
@@ -432,8 +430,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD }
private void autoSelectProvider(String provider_main_url, boolean danger_on) {
- - ConfigHelper.saveSharedPref(ProviderItem.DANGER_ON, danger_on);
+ getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().putBoolean(ProviderItem.DANGER_ON, danger_on).commit();
onItemSelected(getId(provider_main_url));
}
@@ -498,14 +495,10 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD public void cancelSettingUpProvider() {
provider_list_fragment = (ProviderListFragment) getFragmentManager().findFragmentByTag(ProviderListFragment.TAG);
- if(provider_list_fragment != null && ConfigHelper.sharedPrefContainsKey(ProviderItem.DANGER_ON)) {
+ if(provider_list_fragment != null && preferences.contains(ProviderItem.DANGER_ON)) {
provider_list_fragment.removeLastItem();
}
-
- ConfigHelper.removeFromSharedPref(Provider.KEY);
- ConfigHelper.removeFromSharedPref(ProviderItem.DANGER_ON);
- ConfigHelper.removeFromSharedPref(EIP.ALLOWED_ANON);
- ConfigHelper.removeFromSharedPref(EIP.KEY);
+ preferences.edit().remove(Provider.KEY).remove(ProviderItem.DANGER_ON).remove(EIP.ALLOWED_ANON).remove(EIP.KEY).commit();
}
@Override
diff --git a/src/se/leap/bitmaskclient/Dashboard.java b/src/se/leap/bitmaskclient/Dashboard.java index 44cf8247..07039a78 100644 --- a/src/se/leap/bitmaskclient/Dashboard.java +++ b/src/se/leap/bitmaskclient/Dashboard.java @@ -21,7 +21,6 @@ import org.json.JSONObject; import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.ProviderAPIResultReceiver.Receiver; -import se.leap.openvpn.MainActivity; import android.app.Activity; import android.app.AlertDialog; import android.app.DialogFragment; @@ -55,15 +54,11 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf protected static final int CONFIGURE_LEAP = 0; protected static final int SWITCH_PROVIDER = 1; - private static final String TAG_EIP_FRAGMENT = "EIP_DASHBOARD_FRAGMENT"; final public static String SHARED_PREFERENCES = "LEAPPreferences"; final public static String ACTION_QUIT = "quit"; public static final String REQUEST_CODE = "request_code"; - - - private ProgressBar mProgressBar; private TextView eipStatus; @@ -90,11 +85,10 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf mProgressBar = (ProgressBar) findViewById(R.id.eipProgress); - ConfigHelper.setSharedPreferences(getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE)); - preferences = ConfigHelper.shared_preferences; + preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); - authed_eip = ConfigHelper.getBoolFromSharedPref(EIP.AUTHED_EIP); - if (ConfigHelper.getStringFromSharedPref(Provider.KEY).isEmpty()) + authed_eip = preferences.getBoolean(EIP.AUTHED_EIP, false); + if (preferences.getString(Provider.KEY, "").isEmpty()) startActivityForResult(new Intent(this,ConfigurationWizard.class),CONFIGURE_LEAP); else buildDashboard(); @@ -110,9 +104,8 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf if ( requestCode == CONFIGURE_LEAP || requestCode == SWITCH_PROVIDER) { // It should be equivalent: if ( (requestCode == CONFIGURE_LEAP) || (data!= null && data.hasExtra(STOP_FIRST))) { if ( resultCode == RESULT_OK ){ - ConfigHelper.saveSharedPref(EIP.PARSED_SERIAL, 0); - ConfigHelper.saveSharedPref(EIP.AUTHED_EIP, authed_eip); - + getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().putInt(EIP.PARSED_SERIAL, 0).commit(); + getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().putBoolean(EIP.AUTHED_EIP, authed_eip).commit(); startService( new Intent(EIP.ACTION_UPDATE_EIP_SERVICE) ); buildDashboard(); @@ -181,8 +174,9 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf public boolean onPrepareOptionsMenu(Menu menu) { JSONObject provider_json; try { - provider_json = ConfigHelper.getJsonFromSharedPref(Provider.KEY); + provider_json = new JSONObject(getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE).getString(Provider.KEY, "")); JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); + if(service_description.getBoolean(Provider.ALLOW_REGISTRATION)) { if(authed_eip) { menu.findItem(R.id.login_button).setVisible(false); @@ -213,18 +207,14 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf intent = new Intent(this, AboutActivity.class); startActivity(intent); return true; - case R.id.legacy_interface: - intent = new Intent(this,MainActivity.class); - startActivity(intent); - return true; case R.id.switch_provider: if (Provider.getInstance().hasEIP()){ - if (ConfigHelper.getBoolFromSharedPref(EIP.AUTHED_EIP)){ + if (getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).getBoolean(EIP.AUTHED_EIP, false)){ logOut(); } eipStop(); } - ConfigHelper.removeFromSharedPref(Provider.KEY); + getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().remove(Provider.KEY).commit(); startActivityForResult(new Intent(this,ConfigurationWizard.class), SWITCH_PROVIDER); return true; case R.id.login_button: @@ -268,7 +258,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver); mProgressBar.setVisibility(ProgressBar.VISIBLE); - eipStatus.setText("Starting to login"); + eipStatus.setText(R.string.authenticating_message); //mProgressBar.setMax(4); startService(provider_API_command); } @@ -299,7 +289,9 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf if(mProgressBar == null) mProgressBar = (ProgressBar) findViewById(R.id.eipProgress); mProgressBar.setVisibility(ProgressBar.VISIBLE); if(eipStatus == null) eipStatus = (TextView) findViewById(R.id.eipStatus); - eipStatus.setText("Starting to logout"); + eipStatus.setText(R.string.logout_message); + // eipStatus.setText("Starting to logout"); + startService(provider_API_command); //mProgressBar.setMax(1); @@ -354,73 +346,76 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf setResult(RESULT_OK); authed_eip = true; - ConfigHelper.saveSharedPref(EIP.AUTHED_EIP, authed_eip); - invalidateOptionsMenu(); + getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().putBoolean(EIP.AUTHED_EIP, authed_eip).commit(); + invalidateOptionsMenu(); mProgressBar.setVisibility(ProgressBar.GONE); + changeStatusMessage(resultCode); //Cookie session_id = new BasicClientCookie(session_id_cookie_key, session_id_string); downloadAuthedUserCertificate(/*session_id*/); } else if(resultCode == ProviderAPI.SRP_AUTHENTICATION_FAILED) { logInDialog(getCurrentFocus(), resultData); - eipStatus.setText("Login failed"); - mProgressBar.setVisibility(ProgressBar.GONE); } else if(resultCode == ProviderAPI.LOGOUT_SUCCESSFUL) { authed_eip = false; - ConfigHelper.saveSharedPref(EIP.AUTHED_EIP, authed_eip); - - changeStatusMessage(resultCode); + getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().putBoolean(EIP.AUTHED_EIP, authed_eip).commit(); mProgressBar.setVisibility(ProgressBar.GONE); mProgressBar.setProgress(0); invalidateOptionsMenu(); setResult(RESULT_OK); + changeStatusMessage(resultCode); + } else if(resultCode == ProviderAPI.LOGOUT_FAILED) { setResult(RESULT_CANCELED); - eipStatus.setText("Didn't log out"); + changeStatusMessage(resultCode); mProgressBar.setVisibility(ProgressBar.GONE); - //mProgressBar.setProgress(0); - Toast.makeText(getApplicationContext(), R.string.log_out_failed_message, Toast.LENGTH_LONG).show(); } else if(resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) { setResult(RESULT_OK); + changeStatusMessage(resultCode); mProgressBar.setVisibility(ProgressBar.GONE); - changeStatusMessage(resultCode); - //mProgressBar.setProgress(0); - Toast.makeText(getApplicationContext(), R.string.successful_authed_cert_downloaded_message, Toast.LENGTH_LONG).show(); } else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) { setResult(RESULT_CANCELED); + changeStatusMessage(resultCode); mProgressBar.setVisibility(ProgressBar.GONE); - //mProgressBar.setProgress(0); - changeStatusMessage(resultCode); - Toast.makeText(getApplicationContext(), R.string.authed_cert_download_failed_message, Toast.LENGTH_LONG).show(); - } + } } private void changeStatusMessage(final int previous_result_code) { // TODO Auto-generated method stub ResultReceiver eip_status_receiver = new ResultReceiver(new Handler()){ - @Override - protected void onReceiveResult(int resultCode, Bundle resultData) { + protected void onReceiveResult(int resultCode, Bundle resultData){ super.onReceiveResult(resultCode, resultData); String request = resultData.getString(EIP.REQUEST_TAG); - if(resultCode == RESULT_OK) { - if(request.equalsIgnoreCase(EIP.ACTION_IS_EIP_RUNNING)) { - switch (previous_result_code) { - case ProviderAPI.LOGOUT_SUCCESSFUL: eipStatus.setText(R.string.anonymous_secured_status); break; + if (request.equalsIgnoreCase(EIP.ACTION_IS_EIP_RUNNING)){ + if (resultCode == Activity.RESULT_OK){ + + switch(previous_result_code){ + case ProviderAPI.SRP_AUTHENTICATION_SUCCESSFUL: eipStatus.setText(R.string.succesful_authentication_message); break; + case ProviderAPI.SRP_AUTHENTICATION_FAILED: eipStatus.setText(R.string.authentication_failed_message); break; case ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE: eipStatus.setText(R.string.authed_secured_status); break; - } + case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE: eipStatus.setText(R.string.incorrectly_downloaded_certificate_message); break; + case ProviderAPI.LOGOUT_SUCCESSFUL: eipStatus.setText(R.string.anonymous_secured_status); break; + case ProviderAPI.LOGOUT_FAILED: eipStatus.setText(R.string.log_out_failed_message); break; + + } } - } else { - if(request.equalsIgnoreCase(EIP.ACTION_IS_EIP_RUNNING)) { - switch (previous_result_code) { - case ProviderAPI.LOGOUT_SUCCESSFUL: eipStatus.setText(R.string.future_anonymous_secured_status); break; + else if(resultCode == Activity.RESULT_CANCELED){ + + switch(previous_result_code){ + + case ProviderAPI.SRP_AUTHENTICATION_SUCCESSFUL: eipStatus.setText(R.string.succesful_authentication_message); break; + case ProviderAPI.SRP_AUTHENTICATION_FAILED: eipStatus.setText(R.string.authentication_failed_message); break; case ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE: eipStatus.setText(R.string.future_authed_secured_status); break; + case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE: eipStatus.setText(R.string.incorrectly_downloaded_certificate_message); break; + case ProviderAPI.LOGOUT_SUCCESSFUL: eipStatus.setText(R.string.future_anonymous_secured_status); break; + case ProviderAPI.LOGOUT_FAILED: eipStatus.setText(R.string.log_out_failed_message); break; } } } + } }; - eipIsRunning(eip_status_receiver); - + eipIsRunning(eip_status_receiver); } /** diff --git a/src/se/leap/bitmaskclient/EIP.java b/src/se/leap/bitmaskclient/EIP.java index 2b7fd39f..70560919 100644 --- a/src/se/leap/bitmaskclient/EIP.java +++ b/src/se/leap/bitmaskclient/EIP.java @@ -35,13 +35,13 @@ import se.leap.openvpn.OpenVpnService; import se.leap.openvpn.OpenVpnService.LocalBinder; import se.leap.openvpn.ProfileManager; import se.leap.openvpn.VpnProfile; - import android.app.Activity; import android.app.IntentService; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; +import android.drm.DrmStore.Action; import android.os.Bundle; import android.os.IBinder; import android.os.ResultReceiver; @@ -72,6 +72,7 @@ public final class EIP extends IntentService { public final static String SERVICE_API_PATH = "config/eip-service.json"; public final static String RECEIVER_TAG = "receiverTag"; public final static String REQUEST_TAG = "requestTag"; + public final static String TAG = "se.leap.bitmaskclient.EIP"; private static Context context; @@ -96,13 +97,7 @@ public final class EIP extends IntentService { context = getApplicationContext(); - try { - eipDefinition = ConfigHelper.getJsonFromSharedPref(KEY); - parsedEipSerial = ConfigHelper.getIntFromSharedPref(PARSED_SERIAL); - } catch (JSONException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + updateEIPService(); this.retreiveVpnService(); } @@ -141,7 +136,6 @@ public final class EIP extends IntentService { } private static ServiceConnection mVpnServiceConn = new ServiceConnection() { - @Override public void onServiceConnected(ComponentName name, IBinder service) { LocalBinder binder = (LocalBinder) service; @@ -149,17 +143,22 @@ public final class EIP extends IntentService { mBound = true; if (mReceiver != null && mPending != null) { - + boolean running = mVpnService.isRunning(); + int resultCode = Activity.RESULT_CANCELED; - if (mPending.equals(ACTION_IS_EIP_RUNNING)) + if (mPending.equals(ACTION_IS_EIP_RUNNING)){ resultCode = (running) ? Activity.RESULT_OK : Activity.RESULT_CANCELED; - if (mPending.equals(ACTION_START_EIP)) + + } + else if (mPending.equals(ACTION_START_EIP)){ resultCode = (running) ? Activity.RESULT_OK : Activity.RESULT_CANCELED; - else if (mPending.equals(ACTION_STOP_EIP)) + } + else if (mPending.equals(ACTION_STOP_EIP)){ resultCode = (running) ? Activity.RESULT_CANCELED : Activity.RESULT_OK; + } Bundle resultData = new Bundle(); resultData.putString(REQUEST_TAG, ACTION_IS_EIP_RUNNING); mReceiver.send(resultCode, resultData); @@ -178,6 +177,7 @@ public final class EIP extends IntentService { mReceiver.send(Activity.RESULT_CANCELED, resultData); } } + }; @@ -190,25 +190,42 @@ public final class EIP extends IntentService { * Note: If the request to bind OpenVpnService is successful, the ResultReceiver * will be notified in {@link onServiceConnected()} */ - private void isRunning() { - Bundle resultData = new Bundle(); - resultData.putString(REQUEST_TAG, ACTION_IS_EIP_RUNNING); - int resultCode = Activity.RESULT_CANCELED; - if (mBound) { - resultCode = (mVpnService.isRunning()) ? Activity.RESULT_OK : Activity.RESULT_CANCELED; - - if (mReceiver != null){ - mReceiver.send(resultCode, resultData); - } - } else { - mPending = ACTION_IS_EIP_RUNNING; - boolean retrieved_vpn_service = retreiveVpnService(); - if(!retrieved_vpn_service && mReceiver != null) { - mReceiver.send(resultCode, resultData); - } - } - } - + + private void isRunning() { + Bundle resultData = new Bundle(); + resultData.putString(REQUEST_TAG, ACTION_IS_EIP_RUNNING); + int resultCode = Activity.RESULT_CANCELED; + if (mBound) { + resultCode = (mVpnService.isRunning()) ? Activity.RESULT_OK : Activity.RESULT_CANCELED; + + if (mReceiver != null){ + mReceiver.send(resultCode, resultData); + } + } else { + mPending = ACTION_IS_EIP_RUNNING; + boolean retrieved_vpn_service = retreiveVpnService(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + boolean running = false; + try { + running = mVpnService.isRunning(); + } catch (NullPointerException e){ + e.printStackTrace(); + } + + if (retrieved_vpn_service && running && mReceiver != null){ + mReceiver.send(Activity.RESULT_OK, resultData); + } + else{ + mReceiver.send(Activity.RESULT_CANCELED, resultData); + } + } + } + /** * Initiates an EIP connection by selecting a gateway and preparing and sending an * Intent to {@link se.leap.openvpn.LaunchVPN} @@ -250,8 +267,8 @@ public final class EIP extends IntentService { */ private void updateEIPService() { try { - eipDefinition = ConfigHelper.getJsonFromSharedPref(EIP.KEY); - parsedEipSerial = ConfigHelper.getIntFromSharedPref(PARSED_SERIAL); + eipDefinition = new JSONObject(getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).getString(KEY, "")); + parsedEipSerial = getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).getInt(PARSED_SERIAL, 0); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -315,8 +332,7 @@ public final class EIP extends IntentService { e.printStackTrace(); } } - - ConfigHelper.saveSharedPref(PARSED_SERIAL, eipDefinition.optInt(Provider.API_RETURN_SERIAL)); + getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().putInt(PARSED_SERIAL, eipDefinition.optInt(Provider.API_RETURN_SERIAL)).commit(); } /** diff --git a/src/se/leap/bitmaskclient/EipServiceFragment.java b/src/se/leap/bitmaskclient/EipServiceFragment.java index b409394b..74755a5c 100644 --- a/src/se/leap/bitmaskclient/EipServiceFragment.java +++ b/src/se/leap/bitmaskclient/EipServiceFragment.java @@ -24,7 +24,7 @@ import android.widget.RelativeLayout; import android.widget.Switch; import android.widget.TextView; -public class EipServiceFragment extends Fragment implements StateListener, OnClickListener, OnCheckedChangeListener { +public class EipServiceFragment extends Fragment implements StateListener, OnCheckedChangeListener { private static final String IS_EIP_PENDING = "is_eip_pending"; @@ -58,7 +58,6 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli eipFragment.findViewById(R.id.eipProgress).setVisibility(View.VISIBLE); eipStatus = (TextView) eipFragment.findViewById(R.id.eipStatus); - eipStatus.setOnClickListener(this); eipSwitch = (Switch) eipFragment.findViewById(R.id.eipSwitch); @@ -107,21 +106,6 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli } @Override - public void onClick(View buttonView) { - if (buttonView.equals(eipStatus)) - showEIPLog(); - } - - /** - * Launches the se.leap.openvpn.LogWindow Activity showing detailed OpenVPN log - */ - public void showEIPLog(){ - Intent intent = new Intent(getActivity().getBaseContext(),LogWindow.class); - intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); - startActivity(intent); - } - - @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (buttonView.equals(eipSwitch) && !eipAutoSwitched){ if (isChecked){ diff --git a/src/se/leap/bitmaskclient/LeapHttpClient.java b/src/se/leap/bitmaskclient/LeapHttpClient.java index 837da236..885b5105 100644 --- a/src/se/leap/bitmaskclient/LeapHttpClient.java +++ b/src/se/leap/bitmaskclient/LeapHttpClient.java @@ -34,7 +34,6 @@ import android.content.Context; * */ public class LeapHttpClient extends DefaultHttpClient { - final Context context; private static LeapHttpClient client; @@ -43,10 +42,8 @@ public class LeapHttpClient extends DefaultHttpClient { * @param context * @return the new client. */ - public static LeapHttpClient getInstance(Context context) { + public static LeapHttpClient getInstance(String cert_string) { if(client == null) { - client = new LeapHttpClient(context); - String cert_string = ConfigHelper.getStringFromSharedPref(Provider.CA_CERT); if(cert_string != null) { ConfigHelper.addTrustedCertificate("provider_ca_certificate", cert_string); } @@ -77,8 +74,4 @@ public class LeapHttpClient extends DefaultHttpClient { throw new AssertionError(e); } } - - public LeapHttpClient(Context context) { - this.context = context; - } } diff --git a/src/se/leap/bitmaskclient/ProviderAPI.java b/src/se/leap/bitmaskclient/ProviderAPI.java index ff6dd852..5344e471 100644 --- a/src/se/leap/bitmaskclient/ProviderAPI.java +++ b/src/se/leap/bitmaskclient/ProviderAPI.java @@ -444,25 +444,6 @@ public class ProviderAPI extends IntentService { * @return a bundle with a boolean value mapped to a key named RESULT_KEY, and which is true if the update was successful. */ private Bundle setUpProvider(Bundle task) { -//<<<<<<< HEAD -// Bundle result = new Bundle(); -// int progress = 0; -// boolean danger_on = task.getBoolean(ProviderItem.DANGER_ON); -// String provider_main_url = task.getString(Provider.MAIN_URL); -// if(downloadCACert(provider_main_url, danger_on)) { -// broadcast_progress(progress++); -// result.putBoolean(RESULT_KEY, true); -// if(getAndSetProviderJson(provider_main_url)) { -// broadcast_progress(progress++); -// if(getAndSetEipServiceJson()) -// broadcast_progress(progress++); -// } -// } -// return result; -// } -// -// -//======= int progress = 0; Bundle current_download = new Bundle(); @@ -496,8 +477,8 @@ public class ProviderAPI extends IntentService { private Bundle downloadCACert(String provider_main_url, boolean danger_on) { Bundle result = new Bundle(); String cert_string = downloadWithCommercialCA(provider_main_url + "/ca.crt", danger_on); - if(validCertificate(cert_string)) { - ConfigHelper.saveSharedPref(Provider.CA_CERT, cert_string); + if(validCertificate(cert_string)) { + getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().putString(Provider.CA_CERT, cert_string).commit(); result.putBoolean(RESULT_KEY, true); } else { String reason_to_fail = pickErrorMessage(cert_string); @@ -538,8 +519,8 @@ public class ProviderAPI extends IntentService { String name = provider_json.getString(Provider.NAME); //TODO setProviderName(name); - ConfigHelper.saveSharedPref(Provider.KEY, provider_json); - ConfigHelper.saveSharedPref(EIP.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIP.ALLOWED_ANON)); + getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().putString(Provider.KEY, provider_json.toString()).commit(); + getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().putBoolean(EIP.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIP.ALLOWED_ANON)).commit(); result.putBoolean(RESULT_KEY, true); } catch (JSONException e) { @@ -561,13 +542,13 @@ public class ProviderAPI extends IntentService { Bundle result = new Bundle(); String eip_service_json_string = ""; try { - JSONObject provider_json = ConfigHelper.getJsonFromSharedPref(Provider.KEY); + JSONObject provider_json = new JSONObject(getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).getString(Provider.KEY, "")); String eip_service_url = provider_json.getString(Provider.API_URL) + "/" + provider_json.getString(Provider.API_VERSION) + "/" + EIP.SERVICE_API_PATH; eip_service_json_string = downloadWithProviderCA(eip_service_url, true); JSONObject eip_service_json = new JSONObject(eip_service_json_string); eip_service_json.getInt(Provider.API_RETURN_SERIAL); - - ConfigHelper.saveSharedPref(EIP.KEY, eip_service_json); + + getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().putString(EIP.KEY, eip_service_json.toString()).commit(); result.putBoolean(RESULT_KEY, true); } catch (JSONException e) { @@ -685,7 +666,7 @@ public class ProviderAPI extends IntentService { } private javax.net.ssl.SSLSocketFactory getProviderSSLSocketFactory() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, KeyManagementException { - String provider_cert_string = ConfigHelper.getStringFromSharedPref(Provider.CA_CERT); + String provider_cert_string = getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).getString(Provider.CA_CERT,""); java.security.cert.Certificate provider_certificate = ConfigHelper.parseX509CertificateFromString(provider_cert_string); @@ -778,7 +759,7 @@ public class ProviderAPI extends IntentService { int responseCode = urlConnection.getResponseCode(); broadcast_progress(progress++); LeapSRPSession.setToken(""); - Log.d("logout", Integer.toString(responseCode)); + Log.d(TAG, Integer.toString(responseCode)); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -817,11 +798,12 @@ public class ProviderAPI extends IntentService { try { String type_of_certificate = task.getString(ConfigurationWizard.TYPE_OF_CERTIFICATE); - JSONObject provider_json = ConfigHelper.getJsonFromSharedPref(Provider.KEY); + JSONObject provider_json = new JSONObject(getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).getString(Provider.KEY, "")); + String provider_main_url = provider_json.getString(Provider.API_URL); URL new_cert_string_url = new URL(provider_main_url + "/" + provider_json.getString(Provider.API_VERSION) + "/" + EIP.CERTIFICATE); - boolean danger_on = ConfigHelper.getBoolFromSharedPref(ProviderItem.DANGER_ON); + boolean danger_on = getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).getBoolean(ProviderItem.DANGER_ON, false); String cert_string = downloadWithProviderCA(new_cert_string_url.toString(), danger_on); @@ -847,12 +829,12 @@ public class ProviderAPI extends IntentService { try { RSAPrivateKey keyCert = ConfigHelper.parseRsaKeyFromString(keyString); keyString = Base64.encodeToString( keyCert.getEncoded(), Base64.DEFAULT ); - ConfigHelper.saveSharedPref(EIP.PRIVATE_KEY, "-----BEGIN RSA PRIVATE KEY-----\n"+keyString+"-----END RSA PRIVATE KEY-----"); + getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().putString(EIP.PRIVATE_KEY, "-----BEGIN RSA PRIVATE KEY-----\n"+keyString+"-----END RSA PRIVATE KEY-----").commit(); X509Certificate certCert = ConfigHelper.parseX509CertificateFromString(certificateString); certificateString = Base64.encodeToString( certCert.getEncoded(), Base64.DEFAULT); - ConfigHelper.saveSharedPref(EIP.CERTIFICATE, "-----BEGIN CERTIFICATE-----\n"+certificateString+"-----END CERTIFICATE-----"); - + getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().putString(EIP.CERTIFICATE, "-----BEGIN CERTIFICATE-----\n"+certificateString+"-----END CERTIFICATE-----").commit(); + return true; } catch (CertificateException e) { // TODO Auto-generated catch block diff --git a/src/se/leap/bitmaskclient/ProviderDetailFragment.java b/src/se/leap/bitmaskclient/ProviderDetailFragment.java index fd8b29d9..3ed04184 100644 --- a/src/se/leap/bitmaskclient/ProviderDetailFragment.java +++ b/src/se/leap/bitmaskclient/ProviderDetailFragment.java @@ -11,6 +11,7 @@ import android.app.AlertDialog; import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
+import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@@ -28,7 +29,7 @@ public class ProviderDetailFragment extends DialogFragment { LayoutInflater inflater = getActivity().getLayoutInflater();
View provider_detail_view = inflater.inflate(R.layout.provider_detail_fragment, null);
- JSONObject provider_json = ConfigHelper.getJsonFromSharedPref(Provider.KEY);
+ JSONObject provider_json = new JSONObject(getActivity().getSharedPreferences(Dashboard.SHARED_PREFERENCES, getActivity().MODE_PRIVATE).getString(Provider.KEY, ""));
final TextView domain = (TextView)provider_detail_view.findViewById(R.id.provider_detail_domain);
domain.setText(provider_json.getString(Provider.DOMAIN));
@@ -82,11 +83,9 @@ public class ProviderDetailFragment extends DialogFragment { @Override
public void onCancel(DialogInterface dialog) {
- super.onCancel(dialog); - ConfigHelper.removeFromSharedPref(Provider.KEY);
- ConfigHelper.removeFromSharedPref(ProviderItem.DANGER_ON);
- ConfigHelper.removeFromSharedPref(EIP.ALLOWED_ANON);
- ConfigHelper.removeFromSharedPref(EIP.KEY); + super.onCancel(dialog);
+ SharedPreferences.Editor editor = getActivity().getSharedPreferences(Dashboard.SHARED_PREFERENCES, Activity.MODE_PRIVATE).edit();
+ editor.remove(Provider.KEY).remove(ProviderItem.DANGER_ON).remove(EIP.ALLOWED_ANON).remove(EIP.KEY).commit(); interface_with_configuration_wizard.showAllProviders(); }
|