pe.gob.id.sdk2.utils.MySSLConnectionSocketFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of idgobpe_sdk2_java Show documentation
Show all versions of idgobpe_sdk2_java Show documentation
SDK for connect with ID Gob.pe
The newest version!
package pe.gob.id.sdk2.utils;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.ssl.TrustStrategy;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
/**
* @author Paulo Portugal
*/
public class MySSLConnectionSocketFactory {
public static SSLConnectionSocketFactory getConnectionSocketFactory() {
SSLConnectionSocketFactory sslcf = null;
try {
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
}).build();
HostnameVerifier hnv = new NoopHostnameVerifier();
sslcf = new SSLConnectionSocketFactory(sslContext, hnv);
} catch (Exception e) {
sslcf = null;
}
return sslcf;
}
}