All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pe.gob.id.sdk2.utils.MySSLConnectionSocketFactory Maven / Gradle / Ivy

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;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy