summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-01-14 19:44:10 +0100
committerParménides GV <parmegv@sdf.org>2014-01-14 19:54:58 +0100
commit1fe78d00244f52f903435c970c0ebf0071a08f36 (patch)
tree5e4f600dba76a39ab5fa23e13f638e6ce58b29fa
parentdbf1265f736c00aa31289e75818b1ec56311d31c (diff)
No sharedprefs methods in ConfigHelper.
This means we obtain the SharedPreferences object each time we want to use it. This yields to longer code lines while reading and writing to them.
-rw-r--r--src/se/leap/bitmaskclient/ConfigHelper.java139
-rw-r--r--src/se/leap/bitmaskclient/ConfigurationWizard.java39
-rw-r--r--src/se/leap/bitmaskclient/Dashboard.java29
-rw-r--r--src/se/leap/bitmaskclient/EIP.java15
-rw-r--r--src/se/leap/bitmaskclient/LeapHttpClient.java9
-rw-r--r--src/se/leap/bitmaskclient/ProviderAPI.java46
-rw-r--r--src/se/leap/bitmaskclient/ProviderDetailFragment.java11
-rw-r--r--src/se/leap/openvpn/VpnProfile.java8
8 files changed, 58 insertions, 238 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..e4b85b87 100644
--- a/src/se/leap/bitmaskclient/Dashboard.java
+++ b/src/se/leap/bitmaskclient/Dashboard.java
@@ -60,10 +60,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
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";
-
-
-
+ public static final String REQUEST_CODE = "request_code";
private ProgressBar mProgressBar;
private TextView eipStatus;
@@ -90,11 +87,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 +106,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 +176,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);
@@ -219,12 +215,12 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
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:
@@ -354,7 +350,8 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
setResult(RESULT_OK);
authed_eip = true;
- ConfigHelper.saveSharedPref(EIP.AUTHED_EIP, authed_eip);
+ getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().putBoolean(EIP.AUTHED_EIP, authed_eip).commit();
+
invalidateOptionsMenu();
mProgressBar.setVisibility(ProgressBar.GONE);
@@ -367,7 +364,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
mProgressBar.setVisibility(ProgressBar.GONE);
} else if(resultCode == ProviderAPI.LOGOUT_SUCCESSFUL) {
authed_eip = false;
- ConfigHelper.saveSharedPref(EIP.AUTHED_EIP, authed_eip);
+ getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).edit().putBoolean(EIP.AUTHED_EIP, authed_eip).commit();
changeStatusMessage(resultCode);
mProgressBar.setVisibility(ProgressBar.GONE);
diff --git a/src/se/leap/bitmaskclient/EIP.java b/src/se/leap/bitmaskclient/EIP.java
index 2b7fd39f..25ea88f7 100644
--- a/src/se/leap/bitmaskclient/EIP.java
+++ b/src/se/leap/bitmaskclient/EIP.java
@@ -96,13 +96,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();
}
@@ -250,8 +244,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 +309,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/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..c05e857b 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);
@@ -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();
}
diff --git a/src/se/leap/openvpn/VpnProfile.java b/src/se/leap/openvpn/VpnProfile.java
index 99e1c676..481819ad 100644
--- a/src/se/leap/openvpn/VpnProfile.java
+++ b/src/se/leap/openvpn/VpnProfile.java
@@ -22,6 +22,7 @@ import org.spongycastle.util.io.pem.PemObject;
import org.spongycastle.util.io.pem.PemWriter;
import se.leap.bitmaskclient.ConfigHelper;
+import se.leap.bitmaskclient.Dashboard;
import se.leap.bitmaskclient.EIP;
import se.leap.bitmaskclient.Provider;
import se.leap.bitmaskclient.R;
@@ -249,9 +250,10 @@ public class VpnProfile implements Serializable{
cfg+=insertFileData("cert",mClientCertFilename);
*/
// FIXME This is all we need...The whole switch statement can go...
- cfg+="<ca>\n"+ConfigHelper.getStringFromSharedPref(Provider.CA_CERT)+"\n</ca>\n";
- cfg+="<key>\n"+ConfigHelper.getStringFromSharedPref(EIP.PRIVATE_KEY)+"\n</key>\n";
- cfg+="<cert>\n"+ConfigHelper.getStringFromSharedPref(EIP.CERTIFICATE)+"\n</cert>\n";
+ SharedPreferences preferences = context.getSharedPreferences(Dashboard.SHARED_PREFERENCES, context.MODE_PRIVATE);
+ cfg+="<ca>\n"+preferences.getString(Provider.CA_CERT, "")+"\n</ca>\n";
+ cfg+="<key>\n"+preferences.getString(EIP.PRIVATE_KEY, "")+"\n</key>\n";
+ cfg+="<cert>\n"+preferences.getString(EIP.CERTIFICATE, "")+"\n</cert>\n";
break;
case VpnProfile.TYPE_USERPASS_PKCS12: