summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Leonard <meanderingcode@aetherislands.net>2013-10-03 16:38:14 -0700
committerSean Leonard <meanderingcode@aetherislands.net>2013-10-03 16:38:14 -0700
commit697e7da6e1379ac23cd8dbb47a1246547abafda6 (patch)
tree07f7d05616c4c2d3a0425c96cc6ed8fc83f19d38
parent6112dcbb6a430651f172a7a07f2e9b7633299705 (diff)
parent83f18ec709d71d843155a8df853b014e5a599c01 (diff)
Merge branch 'feature/move-confighelper-constants' into develop
-rw-r--r--src/se/leap/leapclient/AboutFragment.java2
-rw-r--r--src/se/leap/leapclient/ConfigHelper.java93
-rw-r--r--src/se/leap/leapclient/ConfigurationWizard.java93
-rw-r--r--src/se/leap/leapclient/Dashboard.java64
-rw-r--r--src/se/leap/leapclient/EIP.java28
-rw-r--r--src/se/leap/leapclient/EipServiceFragment.java4
-rw-r--r--src/se/leap/leapclient/LeapHttpClient.java2
-rw-r--r--src/se/leap/leapclient/LeapSRPSession.java4
-rw-r--r--src/se/leap/leapclient/LogInDialog.java11
-rw-r--r--src/se/leap/leapclient/NewProviderDialog.java4
-rw-r--r--src/se/leap/leapclient/Provider.java18
-rw-r--r--src/se/leap/leapclient/ProviderAPI.java198
-rw-r--r--src/se/leap/leapclient/ProviderDetailFragment.java29
-rw-r--r--src/se/leap/leapclient/ProviderListContent.java15
-rw-r--r--src/se/leap/openvpn/LaunchVPN.java6
-rw-r--r--src/se/leap/openvpn/VpnProfile.java8
16 files changed, 275 insertions, 304 deletions
diff --git a/src/se/leap/leapclient/AboutFragment.java b/src/se/leap/leapclient/AboutFragment.java
index a3fbbf93..97cfb584 100644
--- a/src/se/leap/leapclient/AboutFragment.java
+++ b/src/se/leap/leapclient/AboutFragment.java
@@ -14,6 +14,8 @@ import android.widget.TextView;
import se.leap.leapclient.R;
public class AboutFragment extends Fragment {
+
+ final public static String TAG = "aboutFragment";
public static Fragment newInstance() {
AboutFragment provider_detail_fragment = new AboutFragment();
diff --git a/src/se/leap/leapclient/ConfigHelper.java b/src/se/leap/leapclient/ConfigHelper.java
index c88348f1..14b29787 100644
--- a/src/se/leap/leapclient/ConfigHelper.java
+++ b/src/se/leap/leapclient/ConfigHelper.java
@@ -17,9 +17,6 @@
package se.leap.leapclient;
import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.math.BigInteger;
import java.io.InputStream;
@@ -28,7 +25,6 @@ import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
-import java.security.PrivateKey;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
@@ -41,7 +37,6 @@ import org.json.JSONObject;
import android.content.Context;
import android.content.SharedPreferences;
-import android.os.Environment;
import android.util.Base64;
/**
@@ -55,81 +50,15 @@ public class ConfigHelper {
public static SharedPreferences shared_preferences;
private static KeyStore keystore_trusted;
-
- final public static String
- ABOUT_FRAGMENT = "aboutFragment",
- LOG_IN_DIALOG = "logInDialog",
- NEW_PROVIDER_DIALOG = "logInDialog",
- M1_KEY = "M1",
- M2_KEY = "M2",
- LOG_IN = "logIn",
- API_VERSION_KEY = "api_version",
- API_RETURN_SERIAL_KEY = "serial",
- RESULT_KEY = "result",
- RECEIVER_KEY = "receiver",
- PROVIDER_KEY = "provider",
- SERVICE_KEY = "service",
- ALLOWED_ANON = "allow_anonymous",
- MAIN_CERT_KEY = "main_cert",
- CERT_KEY = "cert",
- KEY_KEY = "key",
- EIP_SERVICE_KEY = "eip",
- EIP_PARSED_SERIAL = "eip_parsed_serial",
- TYPE_OF_CERTIFICATE = "type_of_certificate",
- ANON_CERTIFICATE = "anon_certificate",
- AUTHED_CERTIFICATE = "authed_certificate",
- SALT_KEY = "salt",
- SESSION_ID_COOKIE_KEY = "_session_id",
- SESSION_ID_KEY = "session_id",
- PREFERENCES_KEY = "LEAPPreferences",
- USER_DIRECTORY = "leap_android",
- PROVIDER_NAME = "provider_name",
- PROVIDER_ID = "provider_id",
- PROVIDER_MAIN_URL = "provider_main_url",
- PROVIDER_JSON_URL = "provider_json_url",
- CUSTOM = "custom",
- DANGER_ON = "danger_on",
- API_URL_KEY = "api_uri",
- USERNAME_KEY = "username",
- PASSWORD_KEY = "password",
- ALLOW_REGISTRATION_KEY = "allow_registration",
- EIP_SERVICE_API_PATH = "config/eip-service.json",
- ERRORS_KEY = "errors",
- RECEIVER_TAG = "receiverTag",
- REQUEST_TAG = "requestTag",
- PROVIDER_DETAILS_DIALOG = "providerDetailsFragment",
- DOMAIN = "domain",
- NAME = "name",
- DESCRIPTION = "description",
- QUIT = "quit"
- ;
-
+
final public static String NG_1024 =
"eeaf0ab9adb38dd69c33f80afa8fc5e86072618775ff3c0b9ea2314c9c256576d674df7496ea81d3383b4813d692c6e0e0d5d8e250b98be48e495c1d6089dad15dc7d7b46154d6b6ce8ef4ad69b15d4982559b297bcf1885c529f566660e57ec68edbc3c05726cc02fd4cbf4976eaa9afd5138fe8376435b9fc61d2fc0eb06e3";
final public static BigInteger G = new BigInteger("2");
-
- final public static int
- CUSTOM_PROVIDER_ADDED = 0,
- CORRECTLY_DOWNLOADED_JSON_FILES = 1,
- INCORRECTLY_DOWNLOADED_JSON_FILES = 2,
- SRP_AUTHENTICATION_SUCCESSFUL = 3,
- SRP_AUTHENTICATION_FAILED = 4,
- SRP_REGISTRATION_SUCCESSFUL = 5,
- SRP_REGISTRATION_FAILED = 6,
- LOGOUT_SUCCESSFUL = 7,
- LOGOUT_FAILED = 8,
- CORRECTLY_DOWNLOADED_CERTIFICATE = 9,
- INCORRECTLY_DOWNLOADED_CERTIFICATE = 10,
- CORRECTLY_UPDATED_PROVIDER_DOT_JSON = 11,
- INCORRECTLY_UPDATED_PROVIDER_DOT_JSON = 12,
- CORRECTLY_DOWNLOADED_ANON_CERTIFICATE = 13,
- INCORRECTLY_DOWNLOADED_ANON_CERTIFICATE = 14
- ;
private static boolean checkSharedPrefs() {
try {
- shared_preferences = Dashboard.getAppContext().getSharedPreferences(PREFERENCES_KEY,Context.MODE_PRIVATE);
+ shared_preferences = Dashboard.getAppContext().getSharedPreferences(Dashboard.SHARED_PREFERENCES,Context.MODE_PRIVATE);
} catch (Exception e) {
return false;
}
@@ -251,24 +180,6 @@ public class ConfigHelper {
}
/**
- * Opens a FileInputStream from the user directory of the external storage directory.
- * @param filename
- * @return a file input stream
- */
- public static FileInputStream openFileInputStream(String filename) {
- FileInputStream input_stream = null;
- File root = Environment.getExternalStorageDirectory();
- File leap_dir = new File(root.getAbsolutePath() + File.separator + USER_DIRECTORY);
- try {
- input_stream = new FileInputStream(leap_dir + File.separator + filename);
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return input_stream;
- }
-
- /**
* Treat the input as the MSB representation of a number,
* and lop off leading zero elements. For efficiency, the
* input is simply returned if no leading zeroes are found.
diff --git a/src/se/leap/leapclient/ConfigurationWizard.java b/src/se/leap/leapclient/ConfigurationWizard.java
index 05338bf4..dd9f4121 100644
--- a/src/se/leap/leapclient/ConfigurationWizard.java
+++ b/src/se/leap/leapclient/ConfigurationWizard.java
@@ -25,7 +25,6 @@ import org.json.JSONObject;
import se.leap.leapclient.ProviderAPIResultReceiver.Receiver;
import se.leap.leapclient.ProviderListContent.ProviderItem;
import se.leap.leapclient.R;
-import se.leap.openvpn.MainActivity;
import android.app.Activity;
import android.app.DialogFragment;
import android.app.Fragment;
@@ -39,7 +38,6 @@ import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
-import android.view.ViewGroup;
/**
* Activity that builds and shows the list of known available providers.
@@ -55,9 +53,13 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
private ProviderItem mSelectedProvider;
private ProgressDialog mProgressDialog;
private Intent mConfigState = new Intent();
+
+ final public static String TYPE_OF_CERTIFICATE = "type_of_certificate";
+ final public static String ANON_CERTIFICATE = "anon_certificate";
+ final public static String AUTHED_CERTIFICATE = "authed_certificate";
- protected static final String PROVIDER_SET = "PROVIDER SET";
- protected static final String SERVICES_RETRIEVED = "SERVICES RETRIEVED";
+ final protected static String PROVIDER_SET = "PROVIDER SET";
+ final protected static String SERVICES_RETRIEVED = "SERVICES RETRIEVED";
public ProviderAPIResultReceiver providerAPI_result_receiver;
@@ -70,7 +72,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler());
providerAPI_result_receiver.setReceiver(this);
- ConfigHelper.setSharedPreferences(getSharedPreferences(ConfigHelper.PREFERENCES_KEY, MODE_PRIVATE));
+ ConfigHelper.setSharedPreferences(getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE));
loadPreseededProviders();
@@ -91,21 +93,21 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
@Override
public void onReceiveResult(int resultCode, Bundle resultData) {
- if(resultCode == ConfigHelper.CORRECTLY_UPDATED_PROVIDER_DOT_JSON) {
+ if(resultCode == ProviderAPI.CORRECTLY_UPDATED_PROVIDER_DOT_JSON) {
JSONObject provider_json;
try {
- provider_json = new JSONObject(resultData.getString(ConfigHelper.PROVIDER_KEY));
- boolean danger_on = resultData.getBoolean(ConfigHelper.DANGER_ON);
- ConfigHelper.saveSharedPref(ConfigHelper.PROVIDER_KEY, provider_json);
- ConfigHelper.saveSharedPref(ConfigHelper.DANGER_ON, danger_on);
- ConfigHelper.saveSharedPref(ConfigHelper.ALLOWED_ANON, provider_json.getJSONObject(ConfigHelper.SERVICE_KEY).getBoolean(ConfigHelper.ALLOWED_ANON));
+ provider_json = new JSONObject(resultData.getString(Provider.KEY));
+ boolean danger_on = resultData.getBoolean(ProviderItem.DANGER_ON);
+ ConfigHelper.saveSharedPref(Provider.KEY, provider_json);
+ ConfigHelper.saveSharedPref(ProviderItem.DANGER_ON, danger_on);
+ ConfigHelper.saveSharedPref(EIP.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIP.ALLOWED_ANON));
mConfigState.setAction(PROVIDER_SET);
if(mProgressDialog != null) mProgressDialog.dismiss();
mProgressDialog = ProgressDialog.show(this, getResources().getString(R.string.config_wait_title), getResources().getString(R.string.config_connecting_provider), true);
mProgressDialog.setMessage(getResources().getString(R.string.config_downloading_services));
- if(resultData.containsKey(ConfigHelper.PROVIDER_ID))
- mSelectedProvider = getProvider(resultData.getString(ConfigHelper.PROVIDER_ID));
+ if(resultData.containsKey(Provider.NAME))
+ mSelectedProvider = getProvider(resultData.getString(Provider.NAME));
ProviderListFragment providerList = new ProviderListFragment();
@@ -123,12 +125,12 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
setResult(RESULT_CANCELED, mConfigState);
}
}
- else if(resultCode == ConfigHelper.INCORRECTLY_UPDATED_PROVIDER_DOT_JSON) {
+ else if(resultCode == ProviderAPI.INCORRECTLY_UPDATED_PROVIDER_DOT_JSON) {
mProgressDialog.dismiss();
setResult(RESULT_CANCELED, mConfigState);
}
- else if(resultCode == ConfigHelper.CORRECTLY_DOWNLOADED_JSON_FILES) {
- if (ConfigHelper.getBoolFromSharedPref(ConfigHelper.ALLOWED_ANON)){
+ else if(resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_JSON_FILES) {
+ if (ConfigHelper.getBoolFromSharedPref(EIP.ALLOWED_ANON)){
mProgressDialog.setMessage(getResources().getString(R.string.config_downloading_certificates));
mConfigState.putExtra(SERVICES_RETRIEVED, true);
downloadAnonCert();
@@ -139,15 +141,16 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
finish();
}
}
- else if(resultCode == ConfigHelper.INCORRECTLY_DOWNLOADED_JSON_FILES) {
+ else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_JSON_FILES) {
//Toast.makeText(getApplicationContext(), R.string.incorrectly_downloaded_json_files_message, Toast.LENGTH_LONG).show();
+ mProgressDialog.dismiss();
setResult(RESULT_CANCELED, mConfigState);
}
- else if(resultCode == ConfigHelper.CORRECTLY_DOWNLOADED_CERTIFICATE) {
+ else if(resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) {
mProgressDialog.dismiss();
setResult(RESULT_OK);
showProviderDetails(getCurrentFocus());
- } else if(resultCode == ConfigHelper.INCORRECTLY_DOWNLOADED_CERTIFICATE) {
+ } else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) {
mProgressDialog.dismiss();
//Toast.makeText(getApplicationContext(), R.string.incorrectly_downloaded_certificate_message, Toast.LENGTH_LONG).show();
setResult(RESULT_CANCELED, mConfigState);
@@ -170,7 +173,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
@Override
public void onBackPressed() {
try {
- if(ConfigHelper.getJsonFromSharedPref(ConfigHelper.PROVIDER_KEY) == null || ConfigHelper.getJsonFromSharedPref(ConfigHelper.PROVIDER_KEY).length() == 0) {
+ if(ConfigHelper.getJsonFromSharedPref(Provider.KEY) == null || ConfigHelper.getJsonFromSharedPref(Provider.KEY).length() == 0) {
askDashboardToQuitApp();
} else {
setResult(RESULT_OK);
@@ -183,7 +186,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
private void askDashboardToQuitApp() {
Intent ask_quit = new Intent();
- ask_quit.putExtra(ConfigHelper.QUIT, ConfigHelper.QUIT);
+ ask_quit.putExtra(Dashboard.ACTION_QUIT, Dashboard.ACTION_QUIT);
setResult(RESULT_CANCELED, ask_quit);
}
@@ -243,9 +246,9 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
// I think yes, but if so, where does this list live? leap.se, as it's the non-profit project for the software?
// If not, we should just be getting names/urls, and fetching the provider.json like in custom entries
provider_json = provider.provider_json;
- ConfigHelper.saveSharedPref(ConfigHelper.PROVIDER_KEY, provider_json);
- ConfigHelper.saveSharedPref(ConfigHelper.ALLOWED_ANON, provider_json.getJSONObject(ConfigHelper.SERVICE_KEY).getBoolean(ConfigHelper.ALLOWED_ANON));
- ConfigHelper.saveSharedPref(ConfigHelper.DANGER_ON, provider.danger_on);
+ ConfigHelper.saveSharedPref(Provider.KEY, provider_json);
+ ConfigHelper.saveSharedPref(EIP.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIP.ALLOWED_ANON));
+ ConfigHelper.saveSharedPref(ProviderItem.DANGER_ON, provider.danger_on);
mProgressDialog.setMessage(getResources().getString(R.string.config_downloading_services));
downloadJSONFiles(mSelectedProvider);
@@ -267,14 +270,14 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
Bundle parameters = new Bundle();
- parameters.putString(ConfigHelper.PROVIDER_KEY, provider.name);
- parameters.putString(ConfigHelper.MAIN_CERT_KEY, provider.cert_json_url);
- parameters.putString(ConfigHelper.EIP_SERVICE_KEY, provider.eip_service_json_url);
- parameters.putBoolean(ConfigHelper.DANGER_ON, provider.danger_on);
+ parameters.putString(Provider.KEY, provider.name);
+ parameters.putString(Provider.CA_CERT, provider.cert_json_url);
+ parameters.putString(EIP.KEY, provider.eip_service_json_url);
+ parameters.putBoolean(ProviderItem.DANGER_ON, provider.danger_on);
provider_API_command.setAction(ProviderAPI.DOWNLOAD_JSON_FILES_BUNDLE_EXTRA);
provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
- provider_API_command.putExtra(ConfigHelper.RECEIVER_KEY, providerAPI_result_receiver);
+ provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
startService(provider_API_command);
}
@@ -287,11 +290,11 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
Bundle parameters = new Bundle();
- parameters.putString(ConfigHelper.TYPE_OF_CERTIFICATE, ConfigHelper.ANON_CERTIFICATE);
+ parameters.putString(TYPE_OF_CERTIFICATE, ANON_CERTIFICATE);
provider_API_command.setAction(ProviderAPI.DOWNLOAD_CERTIFICATE);
provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
- provider_API_command.putExtra(ConfigHelper.RECEIVER_KEY, providerAPI_result_receiver);
+ provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
startService(provider_API_command);
}
@@ -302,14 +305,14 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
*/
public void addAndSelectNewProvider(View view) {
FragmentTransaction fragment_transaction = getFragmentManager().beginTransaction();
- Fragment previous_new_provider_dialog = getFragmentManager().findFragmentByTag(ConfigHelper.NEW_PROVIDER_DIALOG);
+ Fragment previous_new_provider_dialog = getFragmentManager().findFragmentByTag(NewProviderDialog.TAG);
if (previous_new_provider_dialog != null) {
fragment_transaction.remove(previous_new_provider_dialog);
}
fragment_transaction.addToBackStack(null);
DialogFragment newFragment = NewProviderDialog.newInstance();
- newFragment.show(fragment_transaction, ConfigHelper.NEW_PROVIDER_DIALOG);
+ newFragment.show(fragment_transaction, NewProviderDialog.TAG);
}
/**
@@ -320,14 +323,14 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
*/
public void showProviderDetails(View view) {
FragmentTransaction fragment_transaction = getFragmentManager().beginTransaction();
- Fragment previous_provider_details_dialog = getFragmentManager().findFragmentByTag(ConfigHelper.PROVIDER_DETAILS_DIALOG);
+ Fragment previous_provider_details_dialog = getFragmentManager().findFragmentByTag(ProviderDetailFragment.TAG);
if (previous_provider_details_dialog != null) {
fragment_transaction.remove(previous_provider_details_dialog);
}
fragment_transaction.addToBackStack(null);
DialogFragment newFragment = ProviderDetailFragment.newInstance();
- newFragment.show(fragment_transaction, ConfigHelper.PROVIDER_DETAILS_DIALOG);
+ newFragment.show(fragment_transaction, ProviderDetailFragment.TAG);
}
@Override
@@ -335,12 +338,12 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
Intent provider_API_command = new Intent(this, ProviderAPI.class);
Bundle parameters = new Bundle();
- parameters.putString(ConfigHelper.PROVIDER_MAIN_URL, provider_main_url);
- parameters.putBoolean(ConfigHelper.DANGER_ON, danger_on);
+ parameters.putString(Provider.MAIN_URL, provider_main_url);
+ parameters.putBoolean(ProviderItem.DANGER_ON, danger_on);
provider_API_command.setAction(ProviderAPI.DOWNLOAD_NEW_PROVIDER_DOTJSON);
provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
- provider_API_command.putExtra(ConfigHelper.RECEIVER_KEY, providerAPI_result_receiver);
+ provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
startService(provider_API_command);
}
@@ -355,13 +358,13 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
Intent provider_API_command = new Intent(this, ProviderAPI.class);
Bundle parameters = new Bundle();
- parameters.putString(ConfigHelper.PROVIDER_NAME, provider_name);
- parameters.putString(ConfigHelper.PROVIDER_JSON_URL, provider_json_url);
- parameters.putBoolean(ConfigHelper.DANGER_ON, danger_on);
+ parameters.putString(Provider.NAME, provider_name);
+ parameters.putString(Provider.DOT_JSON_URL, provider_json_url);
+ parameters.putBoolean(ProviderItem.DANGER_ON, danger_on);
provider_API_command.setAction(ProviderAPI.UPDATE_PROVIDER_DOTJSON);
provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
- provider_API_command.putExtra(ConfigHelper.RECEIVER_KEY, providerAPI_result_receiver);
+ provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
startService(provider_API_command);
}
@@ -390,19 +393,19 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
*/
public void showAboutFragment(View view) {
FragmentTransaction fragment_transaction = getFragmentManager().beginTransaction();
- Fragment previous_about_fragment = getFragmentManager().findFragmentByTag(ConfigHelper.ABOUT_FRAGMENT);
+ Fragment previous_about_fragment = getFragmentManager().findFragmentByTag(AboutFragment.TAG);
if (previous_about_fragment == null) {
fragment_transaction.addToBackStack(null);
Fragment newFragment = AboutFragment.newInstance();
- fragment_transaction.replace(R.id.configuration_wizard_layout, newFragment, ConfigHelper.ABOUT_FRAGMENT).commit();
+ fragment_transaction.replace(R.id.configuration_wizard_layout, newFragment, AboutFragment.TAG).commit();
}
}
@Override
public void login() {
Intent ask_login = new Intent();
- ask_login.putExtra(ConfigHelper.LOG_IN, ConfigHelper.LOG_IN);
+ ask_login.putExtra(LogInDialog.VERB, LogInDialog.VERB);
setResult(RESULT_OK, ask_login);
finish();
}
diff --git a/src/se/leap/leapclient/Dashboard.java b/src/se/leap/leapclient/Dashboard.java
index 2f1418e8..371663b7 100644
--- a/src/se/leap/leapclient/Dashboard.java
+++ b/src/se/leap/leapclient/Dashboard.java
@@ -54,6 +54,8 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
protected static final int CONFIGURE_LEAP = 0;
private static final String TAG_EIP_FRAGMENT = "EIP_DASHBOARD_FRAGMENT";
+ final public static String SHARED_PREFERENCES = "LEAPPreferences";
+ final public static String ACTION_QUIT = "quit";
private ProgressDialog mProgressDialog;
@@ -73,10 +75,10 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
app = this;
- ConfigHelper.setSharedPreferences(getSharedPreferences(ConfigHelper.PREFERENCES_KEY, MODE_PRIVATE));
+ ConfigHelper.setSharedPreferences(getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE));
preferences = ConfigHelper.shared_preferences;
- if (ConfigHelper.getStringFromSharedPref(ConfigHelper.PROVIDER_KEY).isEmpty())
+ if (ConfigHelper.getStringFromSharedPref(Provider.KEY).isEmpty())
startActivityForResult(new Intent(this,ConfigurationWizard.class),CONFIGURE_LEAP);
else
buildDashboard();
@@ -88,11 +90,11 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
if ( resultCode == RESULT_OK ){
startService( new Intent(EIP.ACTION_UPDATE_EIP_SERVICE) );
buildDashboard();
- if(data != null && data.hasExtra(ConfigHelper.LOG_IN)) {
+ if(data != null && data.hasExtra(LogInDialog.VERB)) {
View view = ((ViewGroup)findViewById(android.R.id.content)).getChildAt(0);
logInDialog(view, Bundle.EMPTY);
}
- } else if(resultCode == RESULT_CANCELED && data.hasExtra(ConfigHelper.QUIT)) {
+ } else if(resultCode == RESULT_CANCELED && data.hasExtra(ACTION_QUIT)) {
finish();
} else
configErrorDialog();
@@ -118,8 +120,8 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
.setNegativeButton(getResources().getString(R.string.setup_error_close_button), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- SharedPreferences.Editor prefsEdit = getSharedPreferences(ConfigHelper.PREFERENCES_KEY, MODE_PRIVATE).edit();
- prefsEdit.remove(ConfigHelper.PROVIDER_KEY).commit();
+ SharedPreferences.Editor prefsEdit = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE).edit();
+ prefsEdit.remove(Provider.KEY).commit();
finish();
}
})
@@ -151,9 +153,9 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
public boolean onPrepareOptionsMenu(Menu menu) {
JSONObject provider_json;
try {
- provider_json = ConfigHelper.getJsonFromSharedPref(ConfigHelper.PROVIDER_KEY);
- JSONObject service_description = provider_json.getJSONObject(ConfigHelper.SERVICE_KEY);
- if(service_description.getBoolean(ConfigHelper.ALLOW_REGISTRATION_KEY)) {
+ provider_json = ConfigHelper.getJsonFromSharedPref(Provider.KEY);
+ JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE);
+ if(service_description.getBoolean(Provider.ALLOW_REGISTRATION)) {
if(authed) {
menu.findItem(R.id.login_button).setVisible(false);
menu.findItem(R.id.logout_button).setVisible(true);
@@ -214,13 +216,13 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
Intent provider_API_command = new Intent(this, ProviderAPI.class);
Bundle parameters = new Bundle();
- parameters.putString(ConfigHelper.USERNAME_KEY, username);
- parameters.putString(ConfigHelper.PASSWORD_KEY, password);
+ parameters.putString(LogInDialog.USERNAME, username);
+ parameters.putString(LogInDialog.PASSWORD, password);
JSONObject provider_json;
try {
- provider_json = new JSONObject(preferences.getString(ConfigHelper.PROVIDER_KEY, ""));
- parameters.putString(ConfigHelper.API_URL_KEY, provider_json.getString(ConfigHelper.API_URL_KEY) + "/" + provider_json.getString(ConfigHelper.API_VERSION_KEY));
+ provider_json = new JSONObject(preferences.getString(Provider.KEY, ""));
+ parameters.putString(Provider.API_URL, provider_json.getString(Provider.API_URL) + "/" + provider_json.getString(Provider.API_VERSION));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -228,7 +230,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
provider_API_command.setAction(ProviderAPI.SRP_AUTH);
provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
- provider_API_command.putExtra(ConfigHelper.RECEIVER_KEY, providerAPI_result_receiver);
+ provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
if(mProgressDialog != null) mProgressDialog.dismiss();
mProgressDialog = ProgressDialog.show(this, getResources().getString(R.string.authenticating_title), getResources().getString(R.string.authenticating_message), true);
@@ -247,8 +249,8 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
JSONObject provider_json;
try {
- provider_json = new JSONObject(preferences.getString(ConfigHelper.PROVIDER_KEY, ""));
- parameters.putString(ConfigHelper.API_URL_KEY, provider_json.getString(ConfigHelper.API_URL_KEY) + "/" + provider_json.getString(ConfigHelper.API_VERSION_KEY));
+ provider_json = new JSONObject(preferences.getString(Provider.KEY, ""));
+ parameters.putString(Provider.API_URL, provider_json.getString(Provider.API_URL) + "/" + provider_json.getString(Provider.API_VERSION));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -256,7 +258,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
provider_API_command.setAction(ProviderAPI.LOG_OUT);
provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
- provider_API_command.putExtra(ConfigHelper.RECEIVER_KEY, providerAPI_result_receiver);
+ provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
if(mProgressDialog != null) mProgressDialog.dismiss();
mProgressDialog = ProgressDialog.show(this, getResources().getString(R.string.logout_title), getResources().getString(R.string.logout_message), true);
@@ -269,7 +271,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
*/
public void logInDialog(View view, Bundle resultData) {
FragmentTransaction fragment_transaction = getFragmentManager().beginTransaction();
- Fragment previous_log_in_dialog = getFragmentManager().findFragmentByTag(ConfigHelper.LOG_IN_DIALOG);
+ Fragment previous_log_in_dialog = getFragmentManager().findFragmentByTag(LogInDialog.TAG);
if (previous_log_in_dialog != null) {
fragment_transaction.remove(previous_log_in_dialog);
}
@@ -279,12 +281,12 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
if(resultData != null && !resultData.isEmpty()) {
Bundle user_message_bundle = new Bundle();
String user_message = resultData.getString(getResources().getString(R.string.user_message));
- String username = resultData.getString(ConfigHelper.USERNAME_KEY);
+ String username = resultData.getString(LogInDialog.USERNAME);
user_message_bundle.putString(getResources().getString(R.string.user_message), user_message);
- user_message_bundle.putString(ConfigHelper.USERNAME_KEY, username);
+ user_message_bundle.putString(LogInDialog.USERNAME, username);
newFragment.setArguments(user_message_bundle);
}
- newFragment.show(fragment_transaction, ConfigHelper.LOG_IN_DIALOG);
+ newFragment.show(fragment_transaction, LogInDialog.TAG);
}
/**
@@ -298,45 +300,45 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
Intent provider_API_command = new Intent(this, ProviderAPI.class);
Bundle parameters = new Bundle();
- parameters.putString(ConfigHelper.TYPE_OF_CERTIFICATE, ConfigHelper.AUTHED_CERTIFICATE);
+ parameters.putString(ConfigurationWizard.TYPE_OF_CERTIFICATE, ConfigurationWizard.AUTHED_CERTIFICATE);
/*parameters.putString(ConfigHelper.SESSION_ID_COOKIE_KEY, session_id.getName());
parameters.putString(ConfigHelper.SESSION_ID_KEY, session_id.getValue());*/
provider_API_command.setAction(ProviderAPI.DOWNLOAD_CERTIFICATE);
provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
- provider_API_command.putExtra(ConfigHelper.RECEIVER_KEY, providerAPI_result_receiver);
+ provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
startService(provider_API_command);
}
@Override
public void onReceiveResult(int resultCode, Bundle resultData) {
- if(resultCode == ConfigHelper.SRP_AUTHENTICATION_SUCCESSFUL){
- String session_id_cookie_key = resultData.getString(ConfigHelper.SESSION_ID_COOKIE_KEY);
- String session_id_string = resultData.getString(ConfigHelper.SESSION_ID_KEY);
+ if(resultCode == ProviderAPI.SRP_AUTHENTICATION_SUCCESSFUL){
+ String session_id_cookie_key = resultData.getString(ProviderAPI.SESSION_ID_COOKIE_KEY);
+ String session_id_string = resultData.getString(ProviderAPI.SESSION_ID_KEY);
setResult(RESULT_OK);
authed = true;
invalidateOptionsMenu();
//Cookie session_id = new BasicClientCookie(session_id_cookie_key, session_id_string);
downloadAuthedUserCertificate(/*session_id*/);
- } else if(resultCode == ConfigHelper.SRP_AUTHENTICATION_FAILED) {
+ } else if(resultCode == ProviderAPI.SRP_AUTHENTICATION_FAILED) {
mProgressDialog.dismiss();
logInDialog(getCurrentFocus(), resultData);
- } else if(resultCode == ConfigHelper.LOGOUT_SUCCESSFUL) {
+ } else if(resultCode == ProviderAPI.LOGOUT_SUCCESSFUL) {
authed = false;
invalidateOptionsMenu();
setResult(RESULT_OK);
mProgressDialog.dismiss();
- } else if(resultCode == ConfigHelper.LOGOUT_FAILED) {
+ } else if(resultCode == ProviderAPI.LOGOUT_FAILED) {
setResult(RESULT_CANCELED);
mProgressDialog.dismiss();
Toast.makeText(getApplicationContext(), R.string.log_out_failed_message, Toast.LENGTH_LONG).show();
- } else if(resultCode == ConfigHelper.CORRECTLY_DOWNLOADED_CERTIFICATE) {
+ } else if(resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) {
setResult(RESULT_OK);
mProgressDialog.dismiss();
Toast.makeText(getApplicationContext(), R.string.successful_authed_cert_downloaded_message, Toast.LENGTH_LONG).show();
- } else if(resultCode == ConfigHelper.INCORRECTLY_DOWNLOADED_CERTIFICATE) {
+ } else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) {
setResult(RESULT_CANCELED);
mProgressDialog.dismiss();
Toast.makeText(getApplicationContext(), R.string.authed_cert_download_failed_message, Toast.LENGTH_LONG).show();
diff --git a/src/se/leap/leapclient/EIP.java b/src/se/leap/leapclient/EIP.java
index e0685c15..0a537b4d 100644
--- a/src/se/leap/leapclient/EIP.java
+++ b/src/se/leap/leapclient/EIP.java
@@ -62,6 +62,14 @@ public final class EIP extends IntentService {
public final static String ACTION_UPDATE_EIP_SERVICE = "se.leap.leapclient.UPDATE_EIP_SERVICE";
public final static String ACTION_IS_EIP_RUNNING = "se.leap.leapclient.IS_RUNNING";
public final static String EIP_NOTIFICATION = "EIP_NOTIFICATION";
+ public final static String ALLOWED_ANON = "allow_anonymous";
+ public final static String CERTIFICATE = "cert";
+ public final static String PRIVATE_KEY = "private_key";
+ public final static String KEY = "eip";
+ public final static String PARSED_SERIAL = "eip_parsed_serial";
+ 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";
private static Context context;
private static ResultReceiver mReceiver;
@@ -86,8 +94,8 @@ public final class EIP extends IntentService {
context = getApplicationContext();
try {
- eipDefinition = ConfigHelper.getJsonFromSharedPref(ConfigHelper.EIP_SERVICE_KEY);
- parsedEipSerial = ConfigHelper.getIntFromSharedPref(ConfigHelper.EIP_PARSED_SERIAL);
+ eipDefinition = ConfigHelper.getJsonFromSharedPref(KEY);
+ parsedEipSerial = ConfigHelper.getIntFromSharedPref(PARSED_SERIAL);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -107,7 +115,7 @@ public final class EIP extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
String action = intent.getAction();
- mReceiver = intent.getParcelableExtra(ConfigHelper.RECEIVER_TAG);
+ mReceiver = intent.getParcelableExtra(RECEIVER_TAG);
if ( action == ACTION_IS_EIP_RUNNING )
this.isRunning();
@@ -150,7 +158,7 @@ public final class EIP extends IntentService {
resultCode = (running) ? Activity.RESULT_CANCELED
: Activity.RESULT_OK;
Bundle resultData = new Bundle();
- resultData.putString(ConfigHelper.REQUEST_TAG, EIP_NOTIFICATION);
+ resultData.putString(REQUEST_TAG, EIP_NOTIFICATION);
mReceiver.send(resultCode, resultData);
mPending = null;
@@ -163,7 +171,7 @@ public final class EIP extends IntentService {
if (mReceiver != null){
Bundle resultData = new Bundle();
- resultData.putString(ConfigHelper.REQUEST_TAG, EIP_NOTIFICATION);
+ resultData.putString(REQUEST_TAG, EIP_NOTIFICATION);
mReceiver.send(Activity.RESULT_CANCELED, resultData);
}
}
@@ -181,7 +189,7 @@ public final class EIP extends IntentService {
*/
private void isRunning() {
Bundle resultData = new Bundle();
- resultData.putString(ConfigHelper.REQUEST_TAG, ACTION_IS_EIP_RUNNING);
+ resultData.putString(REQUEST_TAG, ACTION_IS_EIP_RUNNING);
int resultCode = Activity.RESULT_CANCELED;
if (mBound) {
resultCode = (mVpnService.isRunning()) ? Activity.RESULT_OK : Activity.RESULT_CANCELED;
@@ -208,7 +216,7 @@ public final class EIP extends IntentService {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(LaunchVPN.EXTRA_KEY, activeGateway.mVpnProfile.getUUID().toString() );
intent.putExtra(LaunchVPN.EXTRA_NAME, activeGateway.mVpnProfile.getName() );
- intent.putExtra(ConfigHelper.RECEIVER_TAG, mReceiver);
+ intent.putExtra(RECEIVER_TAG, mReceiver);
startActivity(intent);
mPending = ACTION_START_EIP;
}
@@ -225,7 +233,7 @@ public final class EIP extends IntentService {
if (mReceiver != null){
Bundle resultData = new Bundle();
- resultData.putString(ConfigHelper.REQUEST_TAG, ACTION_STOP_EIP);
+ resultData.putString(REQUEST_TAG, ACTION_STOP_EIP);
mReceiver.send(Activity.RESULT_OK, resultData);
}
}
@@ -237,7 +245,7 @@ public final class EIP extends IntentService {
*/
private void updateEIPService() {
try {
- eipDefinition = ConfigHelper.getJsonFromSharedPref(ConfigHelper.EIP_SERVICE_KEY);
+ eipDefinition = ConfigHelper.getJsonFromSharedPref(EIP.KEY);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -294,7 +302,7 @@ public final class EIP extends IntentService {
}
}
- ConfigHelper.saveSharedPref(ConfigHelper.EIP_PARSED_SERIAL, eipDefinition.optInt(ConfigHelper.API_RETURN_SERIAL_KEY));
+ ConfigHelper.saveSharedPref(PARSED_SERIAL, eipDefinition.optInt(Provider.API_RETURN_SERIAL));
}
/**
diff --git a/src/se/leap/leapclient/EipServiceFragment.java b/src/se/leap/leapclient/EipServiceFragment.java
index c18f83da..628572b4 100644
--- a/src/se/leap/leapclient/EipServiceFragment.java
+++ b/src/se/leap/leapclient/EipServiceFragment.java
@@ -159,7 +159,7 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli
private void eipCommand(String action){
// TODO validate "action"...how do we get the list of intent-filters for a class via Android API?
Intent vpnIntent = new Intent(action);
- vpnIntent.putExtra(ConfigHelper.RECEIVER_TAG, mEIPReceiver);
+ vpnIntent.putExtra(EIP.RECEIVER_TAG, mEIPReceiver);
getActivity().startService(vpnIntent);
}
@@ -214,7 +214,7 @@ public class EipServiceFragment extends Fragment implements StateListener, OnCli
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);
- String request = resultData.getString(ConfigHelper.REQUEST_TAG);
+ String request = resultData.getString(EIP.REQUEST_TAG);
boolean checked = false;
if (request == EIP.ACTION_IS_EIP_RUNNING) {
diff --git a/src/se/leap/leapclient/LeapHttpClient.java b/src/se/leap/leapclient/LeapHttpClient.java
index ed926d28..5dca31e9 100644
--- a/src/se/leap/leapclient/LeapHttpClient.java
+++ b/src/se/leap/leapclient/LeapHttpClient.java
@@ -46,7 +46,7 @@ public class LeapHttpClient extends DefaultHttpClient {
public static LeapHttpClient getInstance(Context context) {
if(client == null) {
client = new LeapHttpClient(context);
- String cert_string = ConfigHelper.getStringFromSharedPref(ConfigHelper.MAIN_CERT_KEY);
+ String cert_string = ConfigHelper.getStringFromSharedPref(Provider.CA_CERT);
if(cert_string != null) {
ConfigHelper.addTrustedCertificate("provider_ca_certificate", cert_string);
}
diff --git a/src/se/leap/leapclient/LeapSRPSession.java b/src/se/leap/leapclient/LeapSRPSession.java
index 9451c1be..5a78219b 100644
--- a/src/se/leap/leapclient/LeapSRPSession.java
+++ b/src/se/leap/leapclient/LeapSRPSession.java
@@ -34,6 +34,10 @@ import org.jboss.security.srp.SRPParameters;
*
*/
public class LeapSRPSession {
+
+ final public static String SALT = "salt";
+ final public static String M1 = "M1";
+ final public static String M2 = "M2";
private SRPParameters params;
private String username;
diff --git a/src/se/leap/leapclient/LogInDialog.java b/src/se/leap/leapclient/LogInDialog.java
index 8e8bb65a..73833a13 100644
--- a/src/se/leap/leapclient/LogInDialog.java
+++ b/src/se/leap/leapclient/LogInDialog.java
@@ -38,7 +38,14 @@ import android.widget.TextView;
*
*/
public class LogInDialog extends DialogFragment {
-
+
+
+ final public static String TAG = "logInDialog";
+ final public static String VERB = "log in";
+ final public static String USERNAME = "username";
+ final public static String PASSWORD = "password";
+
+
public AlertDialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
@@ -51,7 +58,7 @@ public class LogInDialog extends DialogFragment {
final EditText username_field = (EditText)log_in_dialog_view.findViewById(R.id.username_entered);
if(getArguments() != null && getArguments().containsKey(getResources().getString(R.string.user_message))) {
- String username = getArguments().getString(ConfigHelper.USERNAME_KEY);
+ String username = getArguments().getString(USERNAME);
username_field.setText(username);
username_field.setHint("");
}
diff --git a/src/se/leap/leapclient/NewProviderDialog.java b/src/se/leap/leapclient/NewProviderDialog.java
index 0b9d8fd0..5cb16f7d 100644
--- a/src/se/leap/leapclient/NewProviderDialog.java
+++ b/src/se/leap/leapclient/NewProviderDialog.java
@@ -36,7 +36,9 @@ import android.widget.Toast;
*
*/
public class NewProviderDialog extends DialogFragment {
-
+
+ final public static String TAG = "newProviderDialog";
+
public interface NewProviderDialogInterface {
public void saveAndSelectProvider(String url_provider, boolean danger_on);
}
diff --git a/src/se/leap/leapclient/Provider.java b/src/se/leap/leapclient/Provider.java
index cdcd56c5..2846ea60 100644
--- a/src/se/leap/leapclient/Provider.java
+++ b/src/se/leap/leapclient/Provider.java
@@ -42,7 +42,21 @@ public final class Provider implements Serializable {
private static SharedPreferences preferences = null;
// Represents our Provider's provider.json
private static JSONObject definition = null;
-
+
+ final public static String
+ API_URL = "api_uri",
+ API_VERSION = "api_version",
+ ALLOW_REGISTRATION = "allow_registration",
+ API_RETURN_SERIAL = "serial",
+ SERVICE = "service",
+ KEY = "provider",
+ CA_CERT = "ca_cert",
+ NAME = "name",
+ DESCRIPTION = "description",
+ DOMAIN = "domain",
+ MAIN_URL = "main_url",
+ DOT_JSON_URL = "provider_json_url"
+ ;
// Array of what API versions we understand
protected static final String[] API_VERSIONS = {"1"}; // I assume we might encounter arbitrary version "numbers"
@@ -82,7 +96,7 @@ public final class Provider implements Serializable {
//preferences = context.getgetPreferences(0); // 0 == MODE_PRIVATE, but we don't extend Android's classes...
// Load SharedPreferences
- preferences = activity.getSharedPreferences(ConfigHelper.PREFERENCES_KEY,Context.MODE_PRIVATE);
+ preferences = activity.getSharedPreferences(Dashboard.SHARED_PREFERENCES,Context.MODE_PRIVATE);
// Inflate our provider.json data
try {
definition = new JSONObject( preferences.getString("provider", "") );
diff --git a/src/se/leap/leapclient/ProviderAPI.java b/src/se/leap/leapclient/ProviderAPI.java
index 0b3e6f45..e7d329f8 100644
--- a/src/se/leap/leapclient/ProviderAPI.java
+++ b/src/se/leap/leapclient/ProviderAPI.java
@@ -89,7 +89,30 @@ public class ProviderAPI extends IntentService {
SRP_AUTH = "srpAuth",
LOG_OUT = "logOut",
DOWNLOAD_CERTIFICATE = "downloadUserAuthedCertificate",
- PARAMETERS = "parameters"
+ PARAMETERS = "parameters",
+ RESULT_KEY = "result",
+ RECEIVER_KEY = "receiver",
+ SESSION_ID_COOKIE_KEY = "session_id_cookie_key",
+ SESSION_ID_KEY = "session_id",
+ ERRORS = "errors"
+ ;
+
+ final public static int
+ CUSTOM_PROVIDER_ADDED = 0,
+ CORRECTLY_DOWNLOADED_JSON_FILES = 1,
+ INCORRECTLY_DOWNLOADED_JSON_FILES = 2,
+ SRP_AUTHENTICATION_SUCCESSFUL = 3,
+ SRP_AUTHENTICATION_FAILED = 4,
+ SRP_REGISTRATION_SUCCESSFUL = 5,
+ SRP_REGISTRATION_FAILED = 6,
+ LOGOUT_SUCCESSFUL = 7,
+ LOGOUT_FAILED = 8,
+ CORRECTLY_DOWNLOADED_CERTIFICATE = 9,
+ INCORRECTLY_DOWNLOADED_CERTIFICATE = 10,
+ CORRECTLY_UPDATED_PROVIDER_DOT_JSON = 11,
+ INCORRECTLY_UPDATED_PROVIDER_DOT_JSON = 12,
+ CORRECTLY_DOWNLOADED_ANON_CERTIFICATE = 13,
+ INCORRECTLY_DOWNLOADED_ANON_CERTIFICATE = 14
;
public ProviderAPI() {
@@ -122,42 +145,42 @@ public class ProviderAPI extends IntentService {
if(action.equalsIgnoreCase(DOWNLOAD_JSON_FILES_BUNDLE_EXTRA)) {
if(!downloadJsonFiles(parameters)) {
- receiver.send(ConfigHelper.INCORRECTLY_DOWNLOADED_JSON_FILES, Bundle.EMPTY);
+ receiver.send(INCORRECTLY_DOWNLOADED_JSON_FILES, Bundle.EMPTY);
} else {
- receiver.send(ConfigHelper.CORRECTLY_DOWNLOADED_JSON_FILES, Bundle.EMPTY);
+ receiver.send(CORRECTLY_DOWNLOADED_JSON_FILES, Bundle.EMPTY);
}
} else if(action.equalsIgnoreCase(UPDATE_PROVIDER_DOTJSON)) {
Bundle result = updateProviderDotJSON(parameters);
- if(result.getBoolean(ConfigHelper.RESULT_KEY)) {
- receiver.send(ConfigHelper.CORRECTLY_UPDATED_PROVIDER_DOT_JSON, result);
+ if(result.getBoolean(RESULT_KEY)) {
+ receiver.send(CORRECTLY_UPDATED_PROVIDER_DOT_JSON, result);
} else {
- receiver.send(ConfigHelper.INCORRECTLY_UPDATED_PROVIDER_DOT_JSON, Bundle.EMPTY);
+ receiver.send(INCORRECTLY_UPDATED_PROVIDER_DOT_JSON, Bundle.EMPTY);
}
} else if (action.equalsIgnoreCase(DOWNLOAD_NEW_PROVIDER_DOTJSON)) {
Bundle result = downloadNewProviderDotJSON(parameters);
- if(result.getBoolean(ConfigHelper.RESULT_KEY)) {
- receiver.send(ConfigHelper.CORRECTLY_UPDATED_PROVIDER_DOT_JSON, result);
+ if(result.getBoolean(RESULT_KEY)) {
+ receiver.send(CORRECTLY_UPDATED_PROVIDER_DOT_JSON, result);
} else {
- receiver.send(ConfigHelper.INCORRECTLY_DOWNLOADED_JSON_FILES, Bundle.EMPTY);
+ receiver.send(INCORRECTLY_DOWNLOADED_JSON_FILES, Bundle.EMPTY);
}
} else if (action.equalsIgnoreCase(SRP_AUTH)) {
Bundle session_id_bundle = authenticateBySRP(parameters);
- if(session_id_bundle.getBoolean(ConfigHelper.RESULT_KEY)) {
- receiver.send(ConfigHelper.SRP_AUTHENTICATION_SUCCESSFUL, session_id_bundle);
+ if(session_id_bundle.getBoolean(RESULT_KEY)) {
+ receiver.send(SRP_AUTHENTICATION_SUCCESSFUL, session_id_bundle);
} else {
- receiver.send(ConfigHelper.SRP_AUTHENTICATION_FAILED, session_id_bundle);
+ receiver.send(SRP_AUTHENTICATION_FAILED, session_id_bundle);
}
} else if (action.equalsIgnoreCase(LOG_OUT)) {
if(logOut(parameters)) {
- receiver.send(ConfigHelper.LOGOUT_SUCCESSFUL, Bundle.EMPTY);
+ receiver.send(LOGOUT_SUCCESSFUL, Bundle.EMPTY);
} else {
- receiver.send(ConfigHelper.LOGOUT_FAILED, Bundle.EMPTY);
+ receiver.send(LOGOUT_FAILED, Bundle.EMPTY);
}
} else if (action.equalsIgnoreCase(DOWNLOAD_CERTIFICATE)) {
if(getNewCert(parameters)) {
- receiver.send(ConfigHelper.CORRECTLY_DOWNLOADED_CERTIFICATE, Bundle.EMPTY);
+ receiver.send(CORRECTLY_DOWNLOADED_CERTIFICATE, Bundle.EMPTY);
} else {
- receiver.send(ConfigHelper.INCORRECTLY_DOWNLOADED_CERTIFICATE, Bundle.EMPTY);
+ receiver.send(INCORRECTLY_DOWNLOADED_CERTIFICATE, Bundle.EMPTY);
}
}
}
@@ -168,17 +191,18 @@ public class ProviderAPI extends IntentService {
* @return true if eip-service.json was parsed as a JSON object correctly.
*/
private boolean downloadJsonFiles(Bundle task) {
- String cert_url = task.getString(ConfigHelper.MAIN_CERT_KEY);
- String eip_service_json_url = task.getString(ConfigHelper.EIP_SERVICE_KEY);
- boolean danger_on = task.getBoolean(ConfigHelper.DANGER_ON);
+ String cert_url = task.getString(Provider.CA_CERT);
+ String eip_service_json_url = task.getString(EIP.KEY);
+ boolean danger_on = task.getBoolean(ProviderItem.DANGER_ON);
try {
String cert_string = downloadWithCommercialCA(cert_url, danger_on);
+ if(cert_string.isEmpty()) return false;
X509Certificate certCert = ConfigHelper.parseX509CertificateFromString(cert_string);
cert_string = Base64.encodeToString( certCert.getEncoded(), Base64.DEFAULT);
- ConfigHelper.saveSharedPref(ConfigHelper.MAIN_CERT_KEY, "-----BEGIN CERTIFICATE-----\n"+cert_string+"-----END CERTIFICATE-----");
+ ConfigHelper.saveSharedPref(Provider.CA_CERT, "-----BEGIN CERTIFICATE-----\n"+cert_string+"-----END CERTIFICATE-----");
String eip_service_string = downloadWithCommercialCA(eip_service_json_url, danger_on);
- ConfigHelper.saveSharedPref(ConfigHelper.EIP_SERVICE_KEY, new JSONObject(eip_service_string));
+ ConfigHelper.saveSharedPref(EIP.KEY, new JSONObject(eip_service_string));
return true;
} catch (JSONException e) {
@@ -194,15 +218,15 @@ public class ProviderAPI extends IntentService {
* Starts the authentication process using SRP protocol.
*
* @param task containing: username, password and api url.
- * @return a bundle with a boolean value mapped to a key named ConfigHelper.RESULT_KEY, and which is true if authentication was successful.
+ * @return a bundle with a boolean value mapped to a key named RESULT_KEY, and which is true if authentication was successful.
*/
private Bundle authenticateBySRP(Bundle task) {
Bundle session_id_bundle = new Bundle();
- String username = (String) task.get(ConfigHelper.USERNAME_KEY);
- String password = (String) task.get(ConfigHelper.PASSWORD_KEY);
+ String username = (String) task.get(LogInDialog.USERNAME);
+ String password = (String) task.get(LogInDialog.PASSWORD);
if(wellFormedPassword(password)) {
- String authentication_server = (String) task.get(ConfigHelper.API_URL_KEY);
+ String authentication_server = (String) task.get(Provider.API_URL);
SRPParameters params = new SRPParameters(new BigInteger(ConfigHelper.NG_1024, 16).toByteArray(), ConfigHelper.G.toByteArray(), BigInteger.ZERO.toByteArray(), "SHA-256");
LeapSRPSession client = new LeapSRPSession(username, password, params);
@@ -210,40 +234,38 @@ public class ProviderAPI extends IntentService {
try {
JSONObject saltAndB = sendAToSRPServer(authentication_server, username, new BigInteger(1, A).toString(16));
if(saltAndB.length() > 0) {
- String salt = saltAndB.getString(ConfigHelper.SALT_KEY);
+ String salt = saltAndB.getString(LeapSRPSession.SALT);
byte[] Bbytes = new BigInteger(saltAndB.getString("B"), 16).toByteArray();
byte[] M1 = client.response(new BigInteger(salt, 16).toByteArray(), Bbytes);
JSONObject session_idAndM2 = sendM1ToSRPServer(authentication_server, username, M1);
- if(session_idAndM2.has("M2") && client.verify((byte[])session_idAndM2.get("M2"))) {
- session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, true);
- //session_id_bundle.putString(ConfigHelper.SESSION_ID_KEY, session_idAndM2.getString(ConfigHelper.SESSION_ID_KEY));
- //session_id_bundle.putString(ConfigHelper.SESSION_ID_COOKIE_KEY, session_idAndM2.getString(ConfigHelper.SESSION_ID_COOKIE_KEY));
+ if(session_idAndM2.has(LeapSRPSession.M2) && client.verify((byte[])session_idAndM2.get(LeapSRPSession.M2))) {
+ session_id_bundle.putBoolean(RESULT_KEY, true);
} else {
- session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, false);
+ session_id_bundle.putBoolean(RESULT_KEY, false);
session_id_bundle.putString(getResources().getString(R.string.user_message), getResources().getString(R.string.error_bad_user_password_user_message));
- session_id_bundle.putString(ConfigHelper.USERNAME_KEY, username);
+ session_id_bundle.putString(LogInDialog.USERNAME, username);
}
} else {
session_id_bundle.putString(getResources().getString(R.string.user_message), getResources().getString(R.string.error_bad_user_password_user_message));
- session_id_bundle.putString(ConfigHelper.USERNAME_KEY, username);
- session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, false);
+ session_id_bundle.putString(LogInDialog.USERNAME, username);
+ session_id_bundle.putBoolean(RESULT_KEY, false);
}
} catch (ClientProtocolException e) {
- session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, false);
+ session_id_bundle.putBoolean(RESULT_KEY, false);
session_id_bundle.putString(getResources().getString(R.string.user_message), getResources().getString(R.string.error_client_http_user_message));
- session_id_bundle.putString(ConfigHelper.USERNAME_KEY, username);
+ session_id_bundle.putString(LogInDialog.USERNAME, username);
} catch (IOException e) {
- session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, false);
+ session_id_bundle.putBoolean(RESULT_KEY, false);
session_id_bundle.putString(getResources().getString(R.string.user_message), getResources().getString(R.string.error_io_exception_user_message));
- session_id_bundle.putString(ConfigHelper.USERNAME_KEY, username);
+ session_id_bundle.putString(LogInDialog.USERNAME, username);
} catch (JSONException e) {
- session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, false);
+ session_id_bundle.putBoolean(RESULT_KEY, false);
session_id_bundle.putString(getResources().getString(R.string.user_message), getResources().getString(R.string.error_json_exception_user_message));
- session_id_bundle.putString(ConfigHelper.USERNAME_KEY, username);
+ session_id_bundle.putString(LogInDialog.USERNAME, username);
} catch (NoSuchAlgorithmException e) {
- session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, false);
+ session_id_bundle.putBoolean(RESULT_KEY, false);
session_id_bundle.putString(getResources().getString(R.string.user_message), getResources().getString(R.string.error_no_such_algorithm_exception_user_message));
- session_id_bundle.putString(ConfigHelper.USERNAME_KEY, username);
+ session_id_bundle.putString(LogInDialog.USERNAME, username);
} catch (KeyManagementException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -255,9 +277,9 @@ public class ProviderAPI extends IntentService {
e.printStackTrace();
}
} else {
- session_id_bundle.putBoolean(ConfigHelper.RESULT_KEY, false);
+ session_id_bundle.putBoolean(RESULT_KEY, false);
session_id_bundle.putString(getResources().getString(R.string.user_message), getResources().getString(R.string.error_not_valid_password_user_message));
- session_id_bundle.putString(ConfigHelper.USERNAME_KEY, username);
+ session_id_bundle.putString(LogInDialog.USERNAME, username);
}
return session_id_bundle;
@@ -319,11 +341,11 @@ public class ProviderAPI extends IntentService {
JSONObject session_idAndM2 = new JSONObject();
if(json_response.length() > 0) {
- byte[] M2_not_trimmed = new BigInteger(json_response.getString(ConfigHelper.M2_KEY), 16).toByteArray();
+ byte[] M2_not_trimmed = new BigInteger(json_response.getString(LeapSRPSession.M2), 16).toByteArray();
/*Cookie session_id_cookie = LeapHttpClient.getInstance(getApplicationContext()).getCookieStore().getCookies().get(0);
session_idAndM2.put(ConfigHelper.SESSION_ID_COOKIE_KEY, session_id_cookie.getName());
session_idAndM2.put(ConfigHelper.SESSION_ID_KEY, session_id_cookie.getValue());*/
- session_idAndM2.put(ConfigHelper.M2_KEY, ConfigHelper.trim(M2_not_trimmed));
+ session_idAndM2.put(LeapSRPSession.M2, ConfigHelper.trim(M2_not_trimmed));
}
return session_idAndM2;
}
@@ -365,7 +387,7 @@ public class ProviderAPI extends IntentService {
urlConnection.disconnect();
Log.d("Error", error_response);
json_response = new JSONObject(error_response);
- if(!json_response.isNull(ConfigHelper.ERRORS_KEY) || json_response.has(ConfigHelper.ERRORS_KEY)) {
+ if(!json_response.isNull(ERRORS) || json_response.has(ERRORS)) {
return new JSONObject();
}
}
@@ -398,30 +420,30 @@ public class ProviderAPI extends IntentService {
/**
* Downloads a provider.json from a given URL, adding a new provider using the given name.
* @param task containing a boolean meaning if the provider is custom or not, another boolean meaning if the user completely trusts this provider, the provider name and its provider.json url.
- * @return a bundle with a boolean value mapped to a key named ConfigHelper.RESULT_KEY, and which is true if the update was successful.
+ * @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 updateProviderDotJSON(Bundle task) {
Bundle result = new Bundle();
- boolean custom = task.getBoolean(ConfigHelper.CUSTOM);
- boolean danger_on = task.getBoolean(ConfigHelper.DANGER_ON);
- String provider_json_url = task.getString(ConfigHelper.PROVIDER_JSON_URL);
- String provider_name = task.getString(ConfigHelper.PROVIDER_NAME);
+ boolean custom = task.getBoolean(ProviderItem.CUSTOM);
+ boolean danger_on = task.getBoolean(ProviderItem.DANGER_ON);
+ String provider_json_url = task.getString(Provider.DOT_JSON_URL);
+ String provider_name = task.getString(Provider.NAME);
try {
String provider_dot_json_string = downloadWithCommercialCA(provider_json_url, danger_on);
if(provider_dot_json_string.isEmpty()) {
- result.putBoolean(ConfigHelper.RESULT_KEY, false);
+ result.putBoolean(RESULT_KEY, false);
} else {
JSONObject provider_json = new JSONObject(provider_dot_json_string);
- ConfigHelper.saveSharedPref(ConfigHelper.ALLOWED_ANON, provider_json.getJSONObject(ConfigHelper.SERVICE_KEY).getBoolean(ConfigHelper.ALLOWED_ANON));
+ ConfigHelper.saveSharedPref(EIP.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIP.ALLOWED_ANON));
//ProviderListContent.addItem(new ProviderItem(provider_name, provider_json_url, provider_json, custom, danger_on));
- result.putBoolean(ConfigHelper.RESULT_KEY, true);
- result.putString(ConfigHelper.PROVIDER_KEY, provider_json.toString());
- result.putBoolean(ConfigHelper.DANGER_ON, danger_on);
+ result.putBoolean(RESULT_KEY, true);
+ result.putString(Provider.KEY, provider_json.toString());
+ result.putBoolean(ProviderItem.DANGER_ON, danger_on);
}
} catch (JSONException e) {
- result.putBoolean(ConfigHelper.RESULT_KEY, false);
+ result.putBoolean(RESULT_KEY, false);
}
return result;
@@ -435,32 +457,32 @@ public class ProviderAPI extends IntentService {
private Bundle downloadNewProviderDotJSON(Bundle task) {
Bundle result = new Bundle();
boolean custom = true;
- boolean danger_on = task.getBoolean(ConfigHelper.DANGER_ON);
+ boolean danger_on = task.getBoolean(ProviderItem.DANGER_ON);
- String provider_main_url = (String) task.get(ConfigHelper.PROVIDER_MAIN_URL);
+ String provider_main_url = (String) task.get(Provider.MAIN_URL);
String provider_name = provider_main_url.replaceFirst("http[s]?://", "").replaceFirst("\\/", "_");
String provider_json_url = guessProviderDotJsonURL(provider_main_url);
String provider_json_string = downloadWithCommercialCA(provider_json_url, danger_on);
try {
if(provider_json_string.isEmpty()) {
- result.putBoolean(ConfigHelper.RESULT_KEY, false);
+ result.putBoolean(RESULT_KEY, false);
} else {
JSONObject provider_json = new JSONObject(provider_json_string);
- ConfigHelper.saveSharedPref(ConfigHelper.PROVIDER_KEY, provider_json);
- ConfigHelper.saveSharedPref(ConfigHelper.DANGER_ON, danger_on);
- ConfigHelper.saveSharedPref(ConfigHelper.ALLOWED_ANON, provider_json.getJSONObject(ConfigHelper.SERVICE_KEY).getBoolean(ConfigHelper.ALLOWED_ANON));
+ ConfigHelper.saveSharedPref(Provider.KEY, provider_json);
+ ConfigHelper.saveSharedPref(ProviderItem.DANGER_ON, danger_on);
+ ConfigHelper.saveSharedPref(EIP.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIP.ALLOWED_ANON));
ProviderItem added_provider = new ProviderItem(provider_name, provider_json_url, provider_json, custom, danger_on);
ProviderListContent.addItem(added_provider);
- result.putString(ConfigHelper.PROVIDER_ID, added_provider.getId());
- result.putBoolean(ConfigHelper.RESULT_KEY, true);
- result.putString(ConfigHelper.PROVIDER_KEY, provider_json.toString());
- result.putBoolean(ConfigHelper.DANGER_ON, danger_on);
+ result.putString(Provider.NAME, added_provider.getName());
+ result.putBoolean(RESULT_KEY, true);
+ result.putString(Provider.KEY, provider_json.toString());
+ result.putBoolean(ProviderItem.DANGER_ON, danger_on);
}
} catch (JSONException e) {
- result.putBoolean(ConfigHelper.RESULT_KEY, false);
+ result.putBoolean(RESULT_KEY, false);
}
return result;
@@ -551,7 +573,7 @@ public class ProviderAPI extends IntentService {
}
private javax.net.ssl.SSLSocketFactory getProviderSSLSocketFactory() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, KeyManagementException {
- String provider_cert_string = ConfigHelper.getStringFromSharedPref(ConfigHelper.MAIN_CERT_KEY);
+ String provider_cert_string = ConfigHelper.getStringFromSharedPref(Provider.CA_CERT);
java.security.cert.Certificate provider_certificate = ConfigHelper.parseX509CertificateFromString(provider_cert_string);
@@ -642,7 +664,7 @@ public class ProviderAPI extends IntentService {
*/
private boolean logOut(Bundle task) {
try {
- String delete_url = task.getString(ConfigHelper.API_URL_KEY) + "/logout";
+ String delete_url = task.getString(Provider.API_URL) + "/logout";
HttpsURLConnection urlConnection = (HttpsURLConnection)new URL(delete_url).openConnection();
urlConnection.setRequestMethod("DELETE");
@@ -685,30 +707,14 @@ public class ProviderAPI extends IntentService {
* @return true if certificate was downloaded correctly, false if provider.json or danger_on flag are not present in SharedPreferences, or if the certificate url could not be parsed as a URI, or if there was an SSL error.
*/
private boolean getNewCert(Bundle task) {
- //String type_of_certificate = task.getString(ConfigHelper.TYPE_OF_CERTIFICATE);
+
try {
- JSONObject provider_json = ConfigHelper.getJsonFromSharedPref(ConfigHelper.PROVIDER_KEY);
- URL provider_main_url = new URL(provider_json.getString(ConfigHelper.API_URL_KEY));
- String new_cert_string_url = provider_main_url.toString() + "/" + provider_json.getString(ConfigHelper.API_VERSION_KEY) + "/" + ConfigHelper.CERT_KEY;
-
- /*Cookie cookie = null;
- if(type_of_certificate.equalsIgnoreCase(ConfigHelper.AUTHED_CERTIFICATE)) {
- List<Cookie> list_cookies = LeapHttpClient.getInstance(getApplicationContext()).getCookieStore().getCookies();
- for(Cookie aux_cookie : list_cookies) {
- if(aux_cookie.getName().equalsIgnoreCase(ConfigHelper.SESSION_ID_COOKIE_KEY)) {
- cookie = aux_cookie;
- break;
- }
- }*/
- //HttpCookie session_id_cookie = new HttpCookie(task.getString(ConfigHelper.SESSION_ID_COOKIE_KEY), task.getString(ConfigHelper.SESSION_ID_KEY));
- /*HttpCookie session_id_cookie = new HttpCookie(cookie.getName(), cookie.getValue());
-
- CookieManager cookieManager = new CookieManager();
- cookieManager.getCookieStore().add(provider_main_url.toURI(), session_id_cookie);
- CookieHandler.setDefault(cookieManager);*/
- //}
-
- boolean danger_on = ConfigHelper.getBoolFromSharedPref(ConfigHelper.DANGER_ON);
+ String type_of_certificate = task.getString(ConfigurationWizard.TYPE_OF_CERTIFICATE);
+ JSONObject provider_json = ConfigHelper.getJsonFromSharedPref(Provider.KEY);
+ URL provider_main_url = new URL(provider_json.getString(Provider.API_URL));
+ String new_cert_string_url = provider_main_url.toString() + "/" + provider_json.getString(Provider.API_VERSION) + "/" + EIP.CERTIFICATE;
+
+ boolean danger_on = ConfigHelper.getBoolFromSharedPref(ProviderItem.DANGER_ON);
String cert_string = downloadWithCommercialCA(new_cert_string_url, danger_on);
if(!cert_string.isEmpty()) {
// API returns concatenated cert & key. Split them for OpenVPN options
@@ -725,11 +731,11 @@ public class ProviderAPI extends IntentService {
try {
RSAPrivateKey keyCert = ConfigHelper.parseRsaKeyFromString(keyString);
keyString = Base64.encodeToString( keyCert.getEncoded(), Base64.DEFAULT );
- ConfigHelper.saveSharedPref(ConfigHelper.KEY_KEY, "-----BEGIN RSA PRIVATE KEY-----\n"+keyString+"-----END RSA PRIVATE KEY-----");
+ ConfigHelper.saveSharedPref(EIP.PRIVATE_KEY, "-----BEGIN RSA PRIVATE KEY-----\n"+keyString+"-----END RSA PRIVATE KEY-----");
X509Certificate certCert = ConfigHelper.parseX509CertificateFromString(certificateString);
certificateString = Base64.encodeToString( certCert.getEncoded(), Base64.DEFAULT);
- ConfigHelper.saveSharedPref(ConfigHelper.CERT_KEY, "-----BEGIN CERTIFICATE-----\n"+certificateString+"-----END CERTIFICATE-----");
+ ConfigHelper.saveSharedPref(EIP.CERTIFICATE, "-----BEGIN CERTIFICATE-----\n"+certificateString+"-----END CERTIFICATE-----");
return true;
} catch (CertificateException e) {
diff --git a/src/se/leap/leapclient/ProviderDetailFragment.java b/src/se/leap/leapclient/ProviderDetailFragment.java
index 600be58f..e7af140a 100644
--- a/src/se/leap/leapclient/ProviderDetailFragment.java
+++ b/src/se/leap/leapclient/ProviderDetailFragment.java
@@ -3,6 +3,8 @@ package se.leap.leapclient;
import org.json.JSONException;
import org.json.JSONObject;
+import se.leap.leapclient.ProviderListContent.ProviderItem;
+
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
@@ -14,6 +16,9 @@ import android.view.View;
import android.widget.TextView;
public class ProviderDetailFragment extends DialogFragment {
+
+ final public static String TAG = "providerDetailFragment";
+
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
@@ -22,14 +27,14 @@ 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(ConfigHelper.PROVIDER_KEY);
+ JSONObject provider_json = ConfigHelper.getJsonFromSharedPref(Provider.KEY);
final TextView domain = (TextView)provider_detail_view.findViewById(R.id.provider_detail_domain);
- domain.setText(provider_json.getString(ConfigHelper.DOMAIN));
+ domain.setText(provider_json.getString(Provider.DOMAIN));
final TextView name = (TextView)provider_detail_view.findViewById(R.id.provider_detail_name);
- name.setText(provider_json.getJSONObject(ConfigHelper.NAME).getString("en"));
+ name.setText(provider_json.getJSONObject(Provider.NAME).getString("en"));
final TextView description = (TextView)provider_detail_view.findViewById(R.id.provider_detail_description);
- description.setText(provider_json.getJSONObject(ConfigHelper.DESCRIPTION).getString("en"));
+ description.setText(provider_json.getJSONObject(Provider.DESCRIPTION).getString("en"));
builder.setView(provider_detail_view);
builder.setTitle(R.string.provider_details_fragment_title);
@@ -58,8 +63,8 @@ public class ProviderDetailFragment extends DialogFragment {
private boolean anon_allowed(JSONObject provider_json) {
try {
- JSONObject service_description = provider_json.getJSONObject(ConfigHelper.SERVICE_KEY);
- return service_description.has(ConfigHelper.ALLOWED_ANON) && service_description.getBoolean(ConfigHelper.ALLOWED_ANON);
+ JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE);
+ return service_description.has(EIP.ALLOWED_ANON) && service_description.getBoolean(EIP.ALLOWED_ANON);
} catch (JSONException e) {
return false;
}
@@ -67,8 +72,8 @@ public class ProviderDetailFragment extends DialogFragment {
private boolean registration_allowed(JSONObject provider_json) {
try {
- JSONObject service_description = provider_json.getJSONObject(ConfigHelper.SERVICE_KEY);
- return service_description.has(ConfigHelper.ALLOW_REGISTRATION_KEY) && service_description.getBoolean(ConfigHelper.ALLOW_REGISTRATION_KEY);
+ JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE);
+ return service_description.has(Provider.ALLOW_REGISTRATION) && service_description.getBoolean(Provider.ALLOW_REGISTRATION);
} catch (JSONException e) {
return false;
}
@@ -77,10 +82,10 @@ public class ProviderDetailFragment extends DialogFragment {
@Override
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
- ConfigHelper.removeFromSharedPref(ConfigHelper.PROVIDER_KEY);
- ConfigHelper.removeFromSharedPref(ConfigHelper.DANGER_ON);
- ConfigHelper.removeFromSharedPref(ConfigHelper.ALLOWED_ANON);
- ConfigHelper.removeFromSharedPref(ConfigHelper.EIP_SERVICE_KEY);
+ ConfigHelper.removeFromSharedPref(Provider.KEY);
+ ConfigHelper.removeFromSharedPref(ProviderItem.DANGER_ON);
+ ConfigHelper.removeFromSharedPref(EIP.ALLOWED_ANON);
+ ConfigHelper.removeFromSharedPref(EIP.KEY);
}
public static DialogFragment newInstance() {
diff --git a/src/se/leap/leapclient/ProviderListContent.java b/src/se/leap/leapclient/ProviderListContent.java
index 714ed5f4..6cd92430 100644
--- a/src/se/leap/leapclient/ProviderListContent.java
+++ b/src/se/leap/leapclient/ProviderListContent.java
@@ -52,7 +52,12 @@ public class ProviderListContent {
/**
* A provider item.
*/
- public static class ProviderItem {
+ public static class ProviderItem {
+
+
+ final public static String CUSTOM = "custom";
+ final public static String DANGER_ON = "danger_on";
+
public boolean custom = false;
public String id;
public String name;
@@ -79,11 +84,11 @@ public class ProviderListContent {
JSONObject file_contents = new JSONObject(urls_file_content);
id = name;
this.name = name;
- provider_json_url = file_contents.getString(ConfigHelper.PROVIDER_JSON_URL);
+ provider_json_url = file_contents.getString(Provider.DOT_JSON_URL);
domain = new URL(provider_json_url).getHost();
//provider_json_filename = file_contents.getString("assets_json_provider");
eip_service_json_url = file_contents.getString("json_eip_service");
- cert_json_url = file_contents.getString(ConfigHelper.CERT_KEY);
+ cert_json_url = file_contents.getString(EIP.CERTIFICATE);
this.custom = custom;
this.danger_on = danger_on;
} catch (MalformedURLException e) {
@@ -114,7 +119,7 @@ public class ProviderListContent {
this.provider_json = provider_json;
this.name = provider_json.getJSONObject("name").getString("en");
domain = new URL(provider_json_url).getHost();
- eip_service_json_url = provider_json.getString(ConfigHelper.API_URL_KEY) + "/" + provider_json.getString(ConfigHelper.API_VERSION_KEY) + "/" + ConfigHelper.EIP_SERVICE_API_PATH;
+ eip_service_json_url = provider_json.getString(Provider.API_URL) + "/" + provider_json.getString(Provider.API_VERSION) + "/" + EIP.SERVICE_API_PATH;
cert_json_url = provider_json.getString("ca_cert_uri");
this.custom = custom;
this.danger_on = danger_on;
@@ -134,7 +139,7 @@ public class ProviderListContent {
return name;
}
- public String getId() {
+ public String getName() {
return id;
}
}
diff --git a/src/se/leap/openvpn/LaunchVPN.java b/src/se/leap/openvpn/LaunchVPN.java
index 1df6be96..73003c7e 100644
--- a/src/se/leap/openvpn/LaunchVPN.java
+++ b/src/se/leap/openvpn/LaunchVPN.java
@@ -106,7 +106,7 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener {
final String action = intent.getAction();
// If something wants feedback, they sent us a Receiver
- mReceiver = intent.getParcelableExtra(ConfigHelper.RECEIVER_TAG);
+ mReceiver = intent.getParcelableExtra(EIP.RECEIVER_TAG);
// If the intent is a request to create a shortcut, we'll do that and exit
@@ -285,7 +285,7 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener {
// User does not want us to start, so we just vanish (well, now we tell our receiver, then vanish)
Bundle resultData = new Bundle();
// For now, nothing else is calling, so this "request" string is good enough
- resultData.putString(ConfigHelper.REQUEST_TAG, EIP.ACTION_START_EIP);
+ resultData.putString(EIP.REQUEST_TAG, EIP.ACTION_START_EIP);
mReceiver.send(RESULT_CANCELED, resultData);
finish();
}
@@ -373,7 +373,7 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener {
// Tell whom-it-may-concern that we started VPN
Bundle resultData = new Bundle();
// For now, nothing else is calling, so this "request" string is good enough
- resultData.putString(ConfigHelper.REQUEST_TAG, EIP.ACTION_START_EIP);
+ resultData.putString(EIP.REQUEST_TAG, EIP.ACTION_START_EIP);
mReceiver.send(RESULT_OK, resultData);
finish();
diff --git a/src/se/leap/openvpn/VpnProfile.java b/src/se/leap/openvpn/VpnProfile.java
index 2262f565..5752081a 100644
--- a/src/se/leap/openvpn/VpnProfile.java
+++ b/src/se/leap/openvpn/VpnProfile.java
@@ -22,6 +22,8 @@ import org.spongycastle.util.io.pem.PemObject;
import org.spongycastle.util.io.pem.PemWriter;
import se.leap.leapclient.ConfigHelper;
+import se.leap.leapclient.EIP;
+import se.leap.leapclient.Provider;
import se.leap.leapclient.R;
import android.content.Context;
@@ -246,9 +248,9 @@ 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(ConfigHelper.MAIN_CERT_KEY)+"\n</ca>\n";
- cfg+="<key>\n"+ConfigHelper.getStringFromSharedPref(ConfigHelper.KEY_KEY)+"\n</key>\n";
- cfg+="<cert>\n"+ConfigHelper.getStringFromSharedPref(ConfigHelper.CERT_KEY)+"\n</cert>\n";
+ 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";
break;
case VpnProfile.TYPE_USERPASS_PKCS12: