summaryrefslogtreecommitdiff
path: root/src/se/leap/leapclient/ProviderAPI.java
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2013-06-04 16:31:39 +0200
committerParménides GV <parmegv@sdf.org>2013-06-04 16:31:39 +0200
commitac47aab124d63add14189cb3d03e3a05361a7932 (patch)
tree9ecec4edd5668c727c994ea14205849a3a3144a8 /src/se/leap/leapclient/ProviderAPI.java
parent7b75fbe9ca3b2d6175b124b26f5d8f527b15d1bd (diff)
Fixed 2 important bugs.
LeapSRPSession was doing bad SRP calculations when salt byte array started with a 0. Now I trimmed that array before using it. ProviderAPI was not timing out when a server didn't respond. Now, I use a timeout of 1 second to stop waiting for a response.
Diffstat (limited to 'src/se/leap/leapclient/ProviderAPI.java')
-rw-r--r--src/se/leap/leapclient/ProviderAPI.java13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/se/leap/leapclient/ProviderAPI.java b/src/se/leap/leapclient/ProviderAPI.java
index d5e164d6..a6a2d6be 100644
--- a/src/se/leap/leapclient/ProviderAPI.java
+++ b/src/se/leap/leapclient/ProviderAPI.java
@@ -15,8 +15,10 @@ import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.HttpCookie;
import java.net.MalformedURLException;
+import java.net.SocketTimeoutException;
import java.net.URISyntaxException;
import java.net.URL;
+import java.net.URLConnection;
import java.util.Scanner;
import javax.net.ssl.HostnameVerifier;
@@ -296,12 +298,17 @@ public class ProviderAPI extends IntentService {
String json_file_content = "";
URL provider_url = null;
+ int seconds_of_timeout = 1;
try {
provider_url = new URL(string_url);
- json_file_content = new Scanner(provider_url.openStream()).useDelimiter("\\A").next();
+ URLConnection url_connection = provider_url.openConnection();
+ url_connection.setConnectTimeout(seconds_of_timeout*1000);
+ json_file_content = new Scanner(url_connection.getInputStream()).useDelimiter("\\A").next();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
+ } catch(SocketTimeoutException e) {
+ return "";
} catch (IOException e) {
// TODO SSLHandshakeException
// This means that we have not added ca.crt to the trusted certificates.
@@ -310,8 +317,10 @@ public class ProviderAPI extends IntentService {
}
//json_file_content = downloadStringFromProviderWithCACertAdded(string_url);
e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
}
-
+
return json_file_content;
}