diff options
author | Parménides GV <parmegv@sdf.org> | 2013-03-18 11:13:54 +0100 |
---|---|---|
committer | Parménides GV <parmegv@sdf.org> | 2013-03-18 11:13:54 +0100 |
commit | f4f454d53b881563d82f392545fb17ef9283c5e3 (patch) | |
tree | 0d6424797a6953637a0025466db6afca9f2996e4 | |
parent | 203c8caca5a305b90fd0e69c965e503afe979354 (diff) |
If ca.crt from new provider is not trusted, we can download it without
problems assuming user wanted to trust it since s/he entered by
him/herself the URL.
Next step: refactor a bit, to make code more beautiful.
-rw-r--r-- | src/se/leap/leapclient/ConfigHelper.java | 3 | ||||
-rw-r--r-- | src/se/leap/leapclient/ProviderAPI.java | 29 |
2 files changed, 25 insertions, 7 deletions
diff --git a/src/se/leap/leapclient/ConfigHelper.java b/src/se/leap/leapclient/ConfigHelper.java index b6526691..8a0e2b45 100644 --- a/src/se/leap/leapclient/ConfigHelper.java +++ b/src/se/leap/leapclient/ConfigHelper.java @@ -142,7 +142,8 @@ public class ConfigHelper { 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(leap_keystore, "uer92jf".toCharArray()); + keystore_trusted.load(null, null); } finally { leap_keystore.close(); } diff --git a/src/se/leap/leapclient/ProviderAPI.java b/src/se/leap/leapclient/ProviderAPI.java index 01cbd01c..db5301e9 100644 --- a/src/se/leap/leapclient/ProviderAPI.java +++ b/src/se/leap/leapclient/ProviderAPI.java @@ -1,6 +1,7 @@ package se.leap.leapclient; import java.io.IOException; +import java.net.MalformedURLException; import java.net.URL; import java.security.Provider; import java.security.Security; @@ -68,20 +69,36 @@ public class ProviderAPI extends IntentService { String provider_main_url = (String) task.get(ConfigHelper.provider_key_url); String provider_name = provider_main_url.replaceFirst("http[s]?://", "").replaceFirst("\\/", "_"); String provider_json_url = guessURL(provider_main_url); + JSONObject provider_json = null; try { - JSONObject provider_json = getJSONFromProvider(provider_json_url); - String filename = provider_name + "_provider.json".replaceFirst("__", "_"); - ConfigHelper.saveFile(filename, provider_json.toString()); - - ProviderListContent.addItem(new ProviderItem(provider_name, ConfigHelper.openFileInputStream(filename), custom)); - receiver.send(ConfigHelper.CUSTOM_PROVIDER_ADDED, Bundle.EMPTY); + provider_json = getJSONFromProvider(provider_json_url); } catch (IOException e) { // TODO It could happen that an https site used a certificate not trusted. + try { + URL provider_url = new URL(provider_json_url); + String provider_json_string = new Scanner(provider_url.openStream()).useDelimiter("\\A").next(); + provider_json = new JSONObject(provider_json_string); + } catch (MalformedURLException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (JSONException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } + String filename = provider_name + "_provider.json".replaceFirst("__", "_"); + ConfigHelper.saveFile(filename, provider_json.toString()); + + ProviderListContent.addItem(new ProviderItem(provider_name, ConfigHelper.openFileInputStream(filename), custom)); + receiver.send(ConfigHelper.CUSTOM_PROVIDER_ADDED, Bundle.EMPTY); } } |