summaryrefslogtreecommitdiff
path: root/src/se/leap/leapclient/ConfigHelper.java
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2013-04-15 16:30:13 +0200
committerParménides GV <parmegv@sdf.org>2013-04-15 16:30:13 +0200
commitbb4e2e8f16f79c59806a017d8f37e2bdd10a4e87 (patch)
tree6e1c13f8b23774277e427953215143fa7d51dbb5 /src/se/leap/leapclient/ConfigHelper.java
parent60e5f181c1a9f4f1851aafd059971ba5d05748f3 (diff)
parent5f66e5765f52aab1907939018e40578e939dbc5f (diff)
Merge branch 'wizard' into feature/wizard
Conflicts: src/se/leap/leapclient/ConfigHelper.java src/se/leap/leapclient/ConfigurationWizard.java src/se/leap/leapclient/ProviderAPI.java
Diffstat (limited to 'src/se/leap/leapclient/ConfigHelper.java')
-rw-r--r--src/se/leap/leapclient/ConfigHelper.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/se/leap/leapclient/ConfigHelper.java b/src/se/leap/leapclient/ConfigHelper.java
index 52365762..11401df5 100644
--- a/src/se/leap/leapclient/ConfigHelper.java
+++ b/src/se/leap/leapclient/ConfigHelper.java
@@ -8,6 +8,13 @@ import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigInteger;
+import java.io.InputStream;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
import org.json.JSONException;
import org.json.JSONObject;
@@ -19,6 +26,7 @@ import android.util.Log;
public class ConfigHelper {
public static SharedPreferences shared_preferences;
+ private static KeyStore keystore_trusted;
final static String downloadJsonFilesBundleExtra = "downloadJSONFiles";
final static String downloadNewProviderDotJSON = "downloadNewProviderDotJSON";
@@ -104,4 +112,68 @@ public class ConfigHelper {
SharedPreferences shared_preferences) {
ConfigHelper.shared_preferences = shared_preferences;
}
+
+ public static void addTrustedCertificate(String provider, InputStream inputStream) {
+ CertificateFactory cf;
+ try {
+ cf = CertificateFactory.getInstance("X.509");
+ X509Certificate cert =
+ (X509Certificate)cf.generateCertificate(inputStream);
+ keystore_trusted.setCertificateEntry(provider, cert);
+ } catch (CertificateException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (KeyStoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ public static void addTrustedCertificate(String provider, String certificate) {
+ String filename_to_save = provider + "_certificate.cer";
+ saveFile(filename_to_save, certificate);
+ CertificateFactory cf;
+ try {
+ cf = CertificateFactory.getInstance("X.509");
+ X509Certificate cert =
+ (X509Certificate)cf.generateCertificate(openFileInputStream(filename_to_save));
+ keystore_trusted.setCertificateEntry(provider, cert);
+ } catch (CertificateException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } 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
+ keystore_trusted.load(leap_keystore, "uer92jf".toCharArray());
+ //keystore_trusted.load(null, null);
+ } finally {
+ 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();
+ }
+ }
}