Merge pull request #11458 from volzhs/fix-trustmanager-master

Fix TrustManager for Android

[ci skip]
This commit is contained in:
Rémi Verschelde 2017-09-21 14:06:55 +02:00 committed by GitHub
commit 4664d03a0e

View File

@ -36,12 +36,9 @@ import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.net.ssl.TrustManagerFactory;
import org.apache.http.conn.ssl.SSLSocketFactory;
@ -56,19 +53,10 @@ public class CustomSSLSocketFactory extends SSLSocketFactory {
public CustomSSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
super(truststore);
TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
tmf.init(truststore);
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
sslContext.init(null, new TrustManager[] { tm }, null);
sslContext.init(null, tmf.getTrustManagers(), null);
}
@Override