Example usage for javax.net.ssl HttpsURLConnection getDefaultSSLSocketFactory

List of usage examples for javax.net.ssl HttpsURLConnection getDefaultSSLSocketFactory

Introduction

In this page you can find the example usage for javax.net.ssl HttpsURLConnection getDefaultSSLSocketFactory.

Prototype

public static SSLSocketFactory getDefaultSSLSocketFactory() 

Source Link

Document

Gets the default static SSLSocketFactory that is inherited by new instances of this class.

Usage

From source file:com.gt.cl.http.CLSSLSocketFactory.java

/**
 * Creates the default SSL socket factory.
 * This constructor is used exclusively to instantiate the factory for
 * {@link #getSocketFactory getSocketFactory}.
 *//*  www  .  j  a  va  2s . c  om*/
private CLSSLSocketFactory() {
    super();
    this.sslcontext = null;
    this.socketfactory = HttpsURLConnection.getDefaultSSLSocketFactory();
    this.nameResolver = null;
}

From source file:com.android.exchange.SSLSocketFactory.java

/**
 * Creates the default SSL socket factory.
 * This constructor is used exclusively to instantiate the factory for
 * {@link #getSocketFactory getSocketFactory}.
 *//*from   w  ww .  j  a v  a  2  s . c o m*/
private SSLSocketFactory() {
    super();
    this.sslcontext = null;
    this.socketfactory = HttpsURLConnection.getDefaultSSLSocketFactory();
    this.nameResolver = null;
}

From source file:com.google.jplurk.net.AndroidSSLSocketFactory.java

/**
 * Creates the default SSL socket factory.
 * This constructor is used exclusively to instantiate the factory for
 * {@link #getSocketFactory getSocketFactory}.
 *//* w ww.  j a v a2s.  c om*/
private AndroidSSLSocketFactory() {
    super();
    this.sslcontext = null;
    this.socketfactory = HttpsURLConnection.getDefaultSSLSocketFactory();
    this.nameResolver = null;
}

From source file:info.guardianproject.net.ModSSLSocketFactory.java

/**
 * Creates the default SSL socket factory.
 * This constructor is used exclusively to instantiate the factory for
 * {@link #getSocketFactory getSocketFactory}.
 *//*from www .  j  av  a2  s . c om*/
private ModSSLSocketFactory(String host, int port) {
    super();
    this.sslcontext = null;
    this.socketfactory = HttpsURLConnection.getDefaultSSLSocketFactory();
    //this.nameResolver = null;
    this.mSocksSocketFactory = new SocksSocketFactory(host, port);
}

From source file:javax.microedition.ims.core.xdm.CustomSSLSocketFactory.java

/**
 * Creates the default SSL socket factory.
 * This constructor is used exclusively to instantiate the factory for
 * {@link #getSocketFactory getSocketFactory}.
 *//*from w  w w  .  j  a va  2 s  . c o m*/
private CustomSSLSocketFactory() {
    super();
    this.sslcontext = null;
    this.socketfactory = HttpsURLConnection.getDefaultSSLSocketFactory();
    this.nameResolver = null;
}

From source file:info.guardianproject.net.http.ModSSLSocketFactory.java

/**
 * Creates the default SSL socket factory.
 * This constructor is used exclusively to instantiate the factory for
 * {@link #getSocketFactory getSocketFactory}.
 *//*from  ww  w . j  a  va 2  s .  c o  m*/
private ModSSLSocketFactory() {
    super();
    this.sslcontext = null;
    this.socketfactory = HttpsURLConnection.getDefaultSSLSocketFactory();
    this.nameResolver = null;
}

From source file:org.wso2.carbon.identity.sts.passive.ui.PassiveSTS.java

private void openURLWithNoTrust(String realm) throws IOException {
    // Create a trust manager that does not validate certificate chains
    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
        @Override//from  w w  w.  ja va 2 s . com
        public X509Certificate[] getAcceptedIssuers() {
            return new X509Certificate[0];
        }

        @Override
        public void checkClientTrusted(X509Certificate[] certs, String authType) {
            // Nothing to implement
        }

        @Override
        public void checkServerTrusted(X509Certificate[] certs, String authType) {
            // Nothing to implement
        }
    } };

    // Ignore differences between given hostname and certificate hostname
    HostnameVerifier hv = new HostnameVerifier() {
        @Override
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
    };

    // Install the all-trusting trust manager
    try {
        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new SecureRandom());
        SSLSocketFactory defaultSSLSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
        HostnameVerifier defaultHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
        String renegotiation = System.getProperty("sun.security.ssl.allowUnsafeRenegotiation");
        try {
            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
            HttpsURLConnection.setDefaultHostnameVerifier(hv);
            System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true");
            new URL(realm).getContent();
        } finally {
            HttpsURLConnection.setDefaultSSLSocketFactory(defaultSSLSocketFactory);
            HttpsURLConnection.setDefaultHostnameVerifier(defaultHostnameVerifier);
            System.getProperty("sun.security.ssl.allowUnsafeRenegotiation", renegotiation);
        }
    } catch (Exception ignore) {
        if (log.isDebugEnabled()) {
            log.debug("Error while installing trust manager", ignore);
        }
    }
}

From source file:org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.java

private static PoolingHttpClientConnectionManager createConnManager() {

    String sslProtocolsStr = System.getProperty("https.protocols");
    String cipherSuitesStr = System.getProperty("https.cipherSuites");
    String[] sslProtocols = sslProtocolsStr != null ? sslProtocolsStr.split(" *, *") : null;
    String[] cipherSuites = cipherSuitesStr != null ? cipherSuitesStr.split(" *, *") : null;

    SSLConnectionSocketFactory sslConnectionSocketFactory;
    if (SSL_INSECURE) {
        try {//from  w ww  .  java2  s.c  o  m
            SSLContext sslContext = new SSLContextBuilder().useSSL()
                    .loadTrustMaterial(null, new RelaxedTrustStrategy(IGNORE_SSL_VALIDITY_DATES)).build();
            sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, sslProtocols, cipherSuites,
                    SSL_ALLOW_ALL ? SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER
                            : SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
        } catch (Exception ex) {
            throw new SSLInitializationException(ex.getMessage(), ex);
        }
    } else {
        sslConnectionSocketFactory = new SSLConnectionSocketFactory(
                HttpsURLConnection.getDefaultSSLSocketFactory(), sslProtocols, cipherSuites,
                SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
    }

    Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
            .register("http", PlainConnectionSocketFactory.INSTANCE)
            .register("https", sslConnectionSocketFactory).build();

    PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(registry);
    if (PERSISTENT_POOL) {
        connManager.setDefaultMaxPerRoute(MAX_CONN_PER_ROUTE);
        connManager.setMaxTotal(MAX_CONN_TOTAL);
    } else {
        connManager.setMaxTotal(1);
    }
    return connManager;
}

From source file:org.apache.maven.wagon.providers.http.AbstractHttpClientWagonFixed.java

@SuppressWarnings("checkstyle:linelength")
private static PoolingHttpClientConnectionManager createConnManager() {

    String sslProtocolsStr = System.getProperty("https.protocols");
    String cipherSuitesStr = System.getProperty("https.cipherSuites");
    String[] sslProtocols = sslProtocolsStr != null ? sslProtocolsStr.split(" *, *") : null;
    String[] cipherSuites = cipherSuitesStr != null ? cipherSuitesStr.split(" *, *") : null;

    SSLConnectionSocketFactory sslConnectionSocketFactory;
    if (SSL_INSECURE) {
        try {/*  www.  ja  v a2s . c  o m*/
            SSLContext sslContext = new SSLContextBuilder().useSSL()
                    .loadTrustMaterial(null, new RelaxedTrustStrategy(IGNORE_SSL_VALIDITY_DATES)).build();
            sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, sslProtocols, cipherSuites,
                    SSL_ALLOW_ALL ? SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER
                            : SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
        } catch (Exception ex) {
            throw new SSLInitializationException(ex.getMessage(), ex);
        }
    } else {
        sslConnectionSocketFactory = new SSLConnectionSocketFactory(
                HttpsURLConnection.getDefaultSSLSocketFactory(), sslProtocols, cipherSuites,
                SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
    }

    Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
            .register("http", PlainConnectionSocketFactory.INSTANCE)
            .register("https", sslConnectionSocketFactory).build();

    PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(registry);
    if (persistentPool) {
        connManager.setDefaultMaxPerRoute(MAX_CONN_PER_ROUTE);
        connManager.setMaxTotal(MAX_CONN_TOTAL);
    } else {
        connManager.setMaxTotal(1);
    }
    return connManager;
}

From source file:com.thejoshwa.ultrasonic.androidapp.service.ssl.SSLSocketFactory.java

private SSLSocketFactory() {
    super();/*from   w w  w . j  av  a2 s .c  o  m*/
    this.socketfactory = HttpsURLConnection.getDefaultSSLSocketFactory();
    this.hostnameVerifier = null;
    this.nameResolver = null;
}