|
|
@@ -30,11 +30,20 @@ import java.net.MalformedURLException;
|
|
|
import java.net.ProtocolException;
|
|
|
import java.net.URL;
|
|
|
import java.net.URLEncoder;
|
|
|
+import java.security.SecureRandom;
|
|
|
+import java.security.cert.X509Certificate;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
+import javax.net.ssl.HostnameVerifier;
|
|
|
+import javax.net.ssl.HttpsURLConnection;
|
|
|
+import javax.net.ssl.SSLContext;
|
|
|
+import javax.net.ssl.SSLSession;
|
|
|
+import javax.net.ssl.TrustManager;
|
|
|
+import javax.net.ssl.X509TrustManager;
|
|
|
+
|
|
|
public class Network {
|
|
|
|
|
|
public static final int REQUEST_TIMEOUT = 15 * 1000; // request
|
|
|
@@ -63,6 +72,39 @@ public class Network {
|
|
|
public static final int RESULT_VER_LOW = -15;
|
|
|
public static int RESULT_AUTH_EXPIRED = 99;
|
|
|
|
|
|
+
|
|
|
+ public static void handleSSLHandshake() {
|
|
|
+ try {
|
|
|
+ TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
|
|
|
+ public X509Certificate[] getAcceptedIssuers() {
|
|
|
+ return new X509Certificate[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void checkClientTrusted(X509Certificate[] certs, String authType) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void checkServerTrusted(X509Certificate[] certs, String authType) {
|
|
|
+ }
|
|
|
+ }};
|
|
|
+
|
|
|
+ SSLContext sc = SSLContext.getInstance("TLS");
|
|
|
+ // trustAllCerts信任所有的证书
|
|
|
+ sc.init(null, trustAllCerts, new SecureRandom());
|
|
|
+ HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
|
|
+ HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
|
|
|
+ @Override
|
|
|
+ public boolean verify(String hostname, SSLSession session) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public static String getJson(String url, Bundle parms,int timeout)
|
|
|
{
|
|
|
String TAG = "net_dbg@GetJson";
|
|
|
@@ -77,6 +119,15 @@ public class Network {
|
|
|
URL _url;
|
|
|
_url = new URL(url);
|
|
|
connection = (HttpURLConnection) _url.openConnection();
|
|
|
+
|
|
|
+// connection.setHostnameVerifier(new HostnameVerifier() {
|
|
|
+// @Override
|
|
|
+// public boolean verify(String hostname, SSLSession session) {
|
|
|
+// return true;
|
|
|
+// }
|
|
|
+// });
|
|
|
+
|
|
|
+
|
|
|
connection.setReadTimeout(timeout);
|
|
|
connection.setConnectTimeout(timeout);
|
|
|
// 设置请求方式
|