summaryrefslogtreecommitdiff
path: root/src/se/leap/leapclient/ConfigHelper.java
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2013-05-13 20:39:34 +0200
committerParménides GV <parmegv@sdf.org>2013-05-13 20:39:34 +0200
commit80a8106afc8956008beb9d1ed9396f1d695d5b7b (patch)
treeb0ba5869a5d739949bc4178b399536dd4857c5c4 /src/se/leap/leapclient/ConfigHelper.java
parent84a11bb1620d2b9080992427c847b58007f2304a (diff)
A bit more clean.
I've upper cased ConfigHelper constants. I've created a new method in ConfigHelper, to send requests to a server, that it's used when sending A and M1.
Diffstat (limited to 'src/se/leap/leapclient/ConfigHelper.java')
-rw-r--r--src/se/leap/leapclient/ConfigHelper.java185
1 files changed, 71 insertions, 114 deletions
diff --git a/src/se/leap/leapclient/ConfigHelper.java b/src/se/leap/leapclient/ConfigHelper.java
index 0dab26f4..5d44f004 100644
--- a/src/se/leap/leapclient/ConfigHelper.java
+++ b/src/se/leap/leapclient/ConfigHelper.java
@@ -1,6 +1,5 @@
package se.leap.leapclient;
-
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
@@ -28,103 +27,94 @@ public class ConfigHelper {
public static SharedPreferences shared_preferences;
private static KeyStore keystore_trusted;
- final static String downloadJsonFilesBundleExtra = "downloadJSONFiles";
- final static String updateProviderDotJSON = "updateProviderDotJSON";
- final static String downloadNewProviderDotJSON = "downloadNewProviderDotJSON";
- final public static String logInDialog = "logInDialog";
- final public static String newProviderDialog = "logInDialog";
- final public static String srpRegister = "srpRegister";
- final public static String srpAuth = "srpAuth";
- public static String logIn = "logIn";
- public static String logOut = "logOut";
- public static String downloadUserAuthedCertificate = "downloadUserAuthedCertificate";
- public static String api_version_key = "api_version";
- final public static String resultKey = "result";
- final static String provider_key = "provider";
- final static String service_key = "service";
- final static String main_cert_key = "main_cert";
- final static String cert_key = "cert";
- final static String eip_service_key = "eip";
- final static String session_id_cookie_key = "session_id_cookie_key";
- final static String session_id_key = "session_id";
- public static final String PREFERENCES_KEY = "LEAPPreferences";
- public static final String user_directory = "leap_android";
- final public static String provider_name = "provider_name";
- final public static String provider_main_url = "provider_main_url";
- final public static String provider_json_url = "provider_json_url";
- final public static String custom = "custom";
- final public static String danger_on = "danger_on";
- final public static String api_url_key = "api_uri";
- final public static String username_key = "username";
- final public static String password_key = "password";
- final public static String allow_registration_key = "allow_registration";
- final public static String eip_service_api_path = "config/eip-service.json";
+ final public static String
+ DOWNLOAD_JSON_FILES_BUNDLE_EXTRA = "downloadJSONFiles",
+ UPDATE_PROVIDER_DOTJSON = "updateProviderDotJSON",
+ DOWNLOAD_NEW_PROVIDER_DOTJSON = "downloadNewProviderDotJSON",
+ LOG_IN_DIALOG = "logInDialog",
+ NEW_PROVIDER_DIALOG = "logInDialog",
+ SRP_REGISTER = "srpRegister",
+ SRP_AUTH = "srpAuth",
+ LOG_IN = "logIn",
+ LOG_OUT = "logOut",
+ DOWNLOAD_USER_AUTHED_CERTIFICATE = "downloadUserAuthedCertificate",
+ API_VERSION_KEY = "api_version",
+ RESULT_KEY = "result",
+ PROVIDER_KEY = "provider",
+ SERVICE_KEY = "service",
+ MAIN_CERT_KEY = "main_cert",
+ CERT_KEY = "cert",
+ EIP_SERVICE_KEY = "eip",
+ SALT_KEY = "salt",
+ SESSION_ID_COOKIE_KEY = "session_id_cookie_key",
+ SESSION_ID_KEY = "session_id",
+ PREFERENCES_KEY = "LEAPPreferences",
+ USER_DIRECTORY = "leap_android",
+ PROVIDER_NAME = "provider_name",
+ 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"
+ ;
- final public static String NG_1024 =
- "eeaf0ab9adb38dd69c33f80afa8fc5e86072618775ff3c0b9ea2314c9c256576d674df7496ea81d3383b4813d692c6e0e0d5d8e250b98be48e495c1d6089dad15dc7d7b46154d6b6ce8ef4ad69b15d4982559b297bcf1885c529f566660e57ec68edbc3c05726cc02fd4cbf4976eaa9afd5138fe8376435b9fc61d2fc0eb06e3";
- final public static BigInteger g = BigInteger.valueOf(2);
+ 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_AUTHED_USER_CERTIFICATE = 9,
+ INCORRECTLY_DOWNLOADED_AUTHED_USER_CERTIFICATE = 10,
+ CORRECTLY_UPDATED_PROVIDER_DOT_JSON = 11,
+ INCORRECTLY_UPDATED_PROVIDER_DOT_JSON = 12
+ ;
- final public static int CUSTOM_PROVIDER_ADDED = 0;
- final public static int CORRECTLY_DOWNLOADED_JSON_FILES = 1;
- final public static int INCORRECTLY_DOWNLOADED_JSON_FILES = 2;
- final public static int SRP_AUTHENTICATION_SUCCESSFUL = 3;
- final public static int SRP_AUTHENTICATION_FAILED = 4;
- final public static int SRP_REGISTRATION_SUCCESSFUL = 5;
- final public static int SRP_REGISTRATION_FAILED = 6;
- final public static int LOGOUT_SUCCESSFUL = 7;
- final public static int LOGOUT_FAILED = 8;
- final public static int CORRECTLY_DOWNLOADED_AUTHED_USER_CERTIFICATE = 9;
- final public static int INCORRECTLY_DOWNLOADED_AUTHED_USER_CERTIFICATE = 10;
- final public static int CORRECTLY_UPDATED_PROVIDER_DOT_JSON = 11;
- final public static int INCORRECTLY_UPDATED_PROVIDER_DOT_JSON = 12;
+ 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();
+ }
- static String getStringFromSharedPref(String shared_preferences_key) {
+ public static String getStringFromSharedPref(String shared_preferences_key) {
String value = "";
- //TODO This is not OK -> when reading provider.json it only shows "open"
if(shared_preferences != null) {
String content = shared_preferences.getString(shared_preferences_key, "");
try {
JSONObject json_object = new JSONObject(content);
value = json_object.toString();
- /*JSONArray names = json_object.names();
- String key = names.getString(0);
- value = json_object.getString(key);*/
} catch (JSONException e) {
value = content;
}
}
return value;
}
-
- 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();
- System.out.println("Shared preferences updated: key = "
- + shared_preferences_key
- + " Content = "
- + shared_preferences.getString(
- shared_preferences_key, "Default"));
- }
- static void rescueJSONException(JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- static void saveFile(String filename, String content) {
+ public static void saveFile(String filename, String content) {
File root = Environment.getExternalStorageDirectory();
- File leap_dir = new File(root.getAbsolutePath() + File.separator + user_directory);
+ File leap_dir = new File(root.getAbsolutePath() + File.separator + USER_DIRECTORY);
if (!leap_dir.isDirectory()) {
leap_dir.mkdir();
}
try {
if (!leap_dir.isDirectory()) {
throw new IOException(
- "Unable to create directory " + user_directory + ". Maybe the SD card is mounted?");
+ "Unable to create directory " + USER_DIRECTORY + ". Maybe the SD card is mounted?");
}
File outputFile = new File(leap_dir, filename);
BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile));
@@ -135,10 +125,10 @@ public class ConfigHelper {
}
}
- static FileInputStream openFileInputStream(String filename) {
+ 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);
+ File leap_dir = new File(root.getAbsolutePath() + File.separator + USER_DIRECTORY);
try {
input_stream = new FileInputStream(leap_dir + File.separator + filename);
} catch (FileNotFoundException e) {
@@ -178,7 +168,8 @@ public class ConfigHelper {
X509Certificate cert =
(X509Certificate)cf.generateCertificate(openFileInputStream(filename_to_save));
if(keystore_trusted == null) {
- getNewKeystore(null);
+ keystore_trusted = KeyStore.getInstance("BKS");
+ keystore_trusted.load(null);
}
keystore_trusted.setCertificateEntry(provider, cert);
} catch (CertificateException e) {
@@ -187,50 +178,16 @@ public class ConfigHelper {
} catch (KeyStoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
- }
- }
-
- public static KeyStore getKeystore() {
- return keystore_trusted;
- }
-
- public static void getNewKeystore(InputStream leap_keystore) {
- try {
- keystore_trusted = KeyStore.getInstance("BKS");
- try {
- // Initialize the keystore with the provided trusted certificates
- // Also provide the password of the keystore
- if(leap_keystore != null) {
- //keystore_trusted.load(leap_keystore, "uer92jf".toCharArray());
- keystore_trusted.load(null, null);
- } else {
- keystore_trusted.load(null, null);
- }
- } finally {
- if(leap_keystore != null)
- leap_keystore.close();
- }
- } catch (KeyStoreException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
- } catch (CertificateException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
-
- public static int getSrpAuthenticationFailed() {
- return SRP_AUTHENTICATION_FAILED;
- }
- static String extractProviderName(String provider_main_url) {
-
- return null;
+ public static KeyStore getKeystore() {
+ return keystore_trusted;
}
}