1
0
Fork 0
mirror of https://github.com/MatomoCamp/matomocamp-companion-android.git synced 2024-09-19 16:13:46 +02:00

Removed HTTPS security hacks where no longer necessary

This commit is contained in:
Christophe Beyls 2016-05-07 17:44:43 +02:00
parent 657be5c2ad
commit e1ac84d605

View file

@ -10,16 +10,11 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
/** /**
* Utility class to perform HTTP requests. * Utility class to perform HTTP requests.
@ -36,31 +31,13 @@ public class HttpUtils {
System.setProperty("http.keepAlive", "false"); System.setProperty("http.keepAlive", "false");
} }
// Bypass hostname verification // Bypass hostname verification on older devices
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
public boolean verify(String hostname, SSLSession session) { HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
return true; public boolean verify(String hostname, SSLSession session) {
} return true;
}); }
});
// Trust all HTTPS certificates
TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[]{};
}
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
}};
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
e.printStackTrace();
} }
} }