Example usage for org.apache.http.conn.ssl SSLInitializationException SSLInitializationException

List of usage examples for org.apache.http.conn.ssl SSLInitializationException SSLInitializationException

Introduction

In this page you can find the example usage for org.apache.http.conn.ssl SSLInitializationException SSLInitializationException.

Prototype

public SSLInitializationException(final String message, final Throwable cause) 

Source Link

Usage

From source file:com.ksc.internal.SdkSSLContext.java

/**
 * @see SSLContexts#createDefault()/* ww w  . ja v a  2  s.  c  om*/
 */
public static final SSLContext getPreferredSSLContext(final SecureRandom secureRandom) {
    try {
        final SSLContext sslcontext = SSLContext.getInstance("TLS");
        // http://download.java.net/jdk9/docs/technotes/guides/security/jsse/JSSERefGuide.html
        sslcontext.init(null, null, secureRandom);
        return sslcontext;
    } catch (final NoSuchAlgorithmException ex) {
        throw new SSLInitializationException(ex.getMessage(), ex);
    } catch (final KeyManagementException ex) {
        throw new SSLInitializationException(ex.getMessage(), ex);
    }
}

From source file:de.vanita5.twittnuker.util.net.ssl.TwidereSSLSocketFactory.java

public static LayeredConnectionSocketFactory getSocketFactory(final Context context,
        final boolean ignoreSSLErrors) throws SSLInitializationException {
    try {/*from ww w  . j  ava2  s  .c o m*/
        return new TwidereSSLSocketFactory(context, ignoreSSLErrors);
    } catch (final GeneralSecurityException e) {
        throw new SSLInitializationException("Cannot create socket factory", e);
    }
}

From source file:org.ops4j.pax.url.mvn.internal.HttpClients.java

private static PoolingHttpClientConnectionManager createConnManager(PropertyResolver resolver, String pid) {
    boolean SSL_INSECURE = getBoolean(resolver, "maven.wagon.http.ssl.insecure",
            !getBoolean(resolver, pid + "certificateCheck", false));
    boolean IGNORE_SSL_VALIDITY_DATES = getBoolean(resolver, "maven.wagon.http.ssl.ignore.validity.dates",
            false);//from ww w.  j a  va 2  s  . co  m
    boolean SSL_ALLOW_ALL = getBoolean(resolver, "maven.wagon.http.ssl.allowall",
            !getBoolean(resolver, pid + "certificateCheck", false));
    boolean PERSISTENT_POOL = getBoolean(resolver, "maven.wagon.http.pool", true);
    int MAX_CONN_PER_ROUTE = getInteger(resolver, "maven.wagon.httpconnectionManager.maxPerRoute", 20);
    int MAX_CONN_TOTAL = getInteger(resolver, "maven.wagon.httpconnectionManager.maxTotal", 40);

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

    SSLConnectionSocketFactory sslConnectionSocketFactory;
    if (SSL_INSECURE) {
        try {
            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);
    }

    boolean soKeepAlive = getBoolean(resolver, pid + ServiceConstants.PROPERTY_SOCKET_SO_KEEPALIVE, false);
    int soLinger = getInteger(resolver, pid + ServiceConstants.PROPERTY_SOCKET_SO_LINGER, -1);
    boolean soReuseAddress = getBoolean(resolver, pid + ServiceConstants.PROPERTY_SOCKET_SO_REUSEADDRESS,
            false);
    boolean soTcpNoDelay = getBoolean(resolver, pid + ServiceConstants.PROPERTY_SOCKET_TCP_NODELAY, true);
    //        int soTimeout = getInteger( resolver, pid + ServiceConstants.PROPERTY_SOCKET_SO_TIMEOUT, 0 );
    SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(soKeepAlive) // default false
            .setSoLinger(soLinger) // default -1
            .setSoReuseAddress(soReuseAddress) // default false
            .setTcpNoDelay(soTcpNoDelay) // default true
            .setSoTimeout(0) // default 0, but set in org.apache.http.impl.conn.CPoolProxy.setSocketTimeout()
            // this value is not used
            .build();
    connManager.setDefaultSocketConfig(socketConfig);

    int bufferSize = getInteger(resolver, pid + ServiceConstants.PROPERTY_CONNECTION_BUFFER_SIZE, 8192);
    ConnectionConfig connectionConfig = ConnectionConfig.custom().setBufferSize(bufferSize) // default 8192
            .setFragmentSizeHint(bufferSize) // default 'buffer size'
            .build();
    connManager.setDefaultConnectionConfig(connectionConfig);

    return connManager;
}

From source file:io.wcm.caravan.commons.httpclient.impl.helpers.CertificateLoader.java

/**
 * Creates default SSL context.//from  w  ww  .  j ava2 s . c om
 * @return SSL context
 */
public static SSLContext createDefaultSSlContext() throws SSLInitializationException {
    try {
        final SSLContext sslcontext = SSLContext.getInstance(SSL_CONTEXT_TYPE_DEFAULT);
        sslcontext.init(null, null, null);
        return sslcontext;
    } catch (NoSuchAlgorithmException ex) {
        throw new SSLInitializationException(ex.getMessage(), ex);
    } catch (KeyManagementException ex) {
        throw new SSLInitializationException(ex.getMessage(), ex);
    }
}

From source file:orca.ektorp.client.ContextualSSLSocketFactory.java

/**
 * Obtains default SSL socket factory with an SSL context based on the standard JSSE
 * trust material (<code>cacerts</code> file in the security properties directory).
 * System properties are not taken into consideration.
 *
 * @return default SSL socket factory//w w w  .  ja  v  a2s  . c o m
 */
public static ContextualSSLSocketFactory getSocketFactory() throws SSLInitializationException {
    SSLContext sslcontext;
    try {
        sslcontext = SSLContext.getInstance("TLS");
        sslcontext.init(null, null, null);
        return new ContextualSSLSocketFactory(sslcontext, BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
    } catch (NoSuchAlgorithmException ex) {
        throw new SSLInitializationException(ex.getMessage(), ex);
    } catch (KeyManagementException ex) {
        throw new SSLInitializationException(ex.getMessage(), ex);
    }
}

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 {//  www . j  av  a2 s  .c om
            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 {/*from  w  w  w  .  j  a va 2 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 (persistentPool) {
        connManager.setDefaultMaxPerRoute(MAX_CONN_PER_ROUTE);
        connManager.setMaxTotal(MAX_CONN_TOTAL);
    } else {
        connManager.setMaxTotal(1);
    }
    return connManager;
}

From source file:com.amazonaws.http.HttpClientFactory.java

/**
 * @see SSLContexts#createDefault()//  w w w.j a  v  a2  s . c  o m
 */
public static SSLContext createSSLContext(ClientConfiguration config) throws SSLInitializationException {
    try {
        final SSLContext sslcontext = SSLContext.getInstance("TLS");
        // http://download.java.net/jdk9/docs/technotes/guides/security/jsse/JSSERefGuide.html
        sslcontext.init(null, null, config.getSecureRandom());
        return sslcontext;
    } catch (final NoSuchAlgorithmException ex) {
        throw new SSLInitializationException(ex.getMessage(), ex);
    } catch (final KeyManagementException ex) {
        throw new SSLInitializationException(ex.getMessage(), ex);
    }
}