Search in sources :

Example 91 with SSLSocketFactory

use of javax.net.ssl.SSLSocketFactory in project ecf by eclipse.

the class Activator method getSSLSocketFactory.

public synchronized SSLSocketFactory getSSLSocketFactory() {
    if (sslSocketFactoryTracker == null) {
        sslSocketFactoryTracker = new ServiceTracker(this.context, SSLSocketFactory.class.getName(), null);
        sslSocketFactoryTracker.open();
    }
    return (SSLSocketFactory) sslSocketFactoryTracker.getService();
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) SSLSocketFactory(javax.net.ssl.SSLSocketFactory)

Example 92 with SSLSocketFactory

use of javax.net.ssl.SSLSocketFactory in project ecf by eclipse.

the class SSLClient method createSocket.

private Socket createSocket(String host, int port, int timeout) throws IOException {
    SSLSocketFactory socketFactory = ProviderPlugin.getDefault().getSSLSocketFactory();
    if (socketFactory == null)
        // $NON-NLS-1$ //$NON-NLS-2$
        throw new IOException("Cannot get SSLSocketFactory to create SSLSocket for host=" + host + ",port=" + port);
    Socket s = socketFactory.createSocket();
    s.connect(new InetSocketAddress(host, port), timeout);
    return s;
}
Also used : SSLSocketFactory(javax.net.ssl.SSLSocketFactory)

Example 93 with SSLSocketFactory

use of javax.net.ssl.SSLSocketFactory in project http2client-benchmark by networknt.

the class OkHttpClientExample method getUnsafeOkHttpClient.

// http://stackoverflow.com/questions/25509296/trusting-all-certificates-with-okhttp
private static OkHttpClient getUnsafeOkHttpClient() {
    try {
        // Install the all-trusting trust manager
        final SSLContext sslContext = SSLContext.getInstance("SSL");
        sslContext.init(null, TRUST_ALL_CERTS, new java.security.SecureRandom());
        // Create an ssl socket factory with our all-trusting manager
        final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
        OkHttpClient okHttpClient = new OkHttpClient();
        okHttpClient.newBuilder().sslSocketFactory(sslSocketFactory).hostnameVerifier((hostname, session) -> true);
        return okHttpClient;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : SSLContext(javax.net.ssl.SSLContext) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) IOException(java.io.IOException)

Example 94 with SSLSocketFactory

use of javax.net.ssl.SSLSocketFactory in project cosmic by MissionCriticalCloud.

the class SecureSSLSocketFactory method createSocket.

@Override
public Socket createSocket(final InetAddress address, final int port, final InetAddress localAddress, final int localPort) throws IOException {
    final SSLSocketFactory factory = this._sslContext.getSocketFactory();
    final Socket socket = factory.createSocket(address, port, localAddress, localPort);
    if (socket instanceof SSLSocket) {
        ((SSLSocket) socket).setEnabledProtocols(SSLUtils.getSupportedProtocols(((SSLSocket) socket).getEnabledProtocols()));
    }
    return socket;
}
Also used : SSLSocket(javax.net.ssl.SSLSocket) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) Socket(java.net.Socket) SSLSocket(javax.net.ssl.SSLSocket)

Example 95 with SSLSocketFactory

use of javax.net.ssl.SSLSocketFactory in project cosmic by MissionCriticalCloud.

the class SecureSSLSocketFactory method createSocket.

@Override
public Socket createSocket(final String host, final int port) throws IOException, UnknownHostException {
    final SSLSocketFactory factory = _sslContext.getSocketFactory();
    final Socket socket = factory.createSocket(host, port);
    if (socket instanceof SSLSocket) {
        ((SSLSocket) socket).setEnabledProtocols(SSLUtils.getSupportedProtocols(((SSLSocket) socket).getEnabledProtocols()));
    }
    return socket;
}
Also used : SSLSocket(javax.net.ssl.SSLSocket) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) Socket(java.net.Socket) SSLSocket(javax.net.ssl.SSLSocket)

Aggregations

SSLSocketFactory (javax.net.ssl.SSLSocketFactory)403 SSLContext (javax.net.ssl.SSLContext)150 SSLSocket (javax.net.ssl.SSLSocket)134 IOException (java.io.IOException)106 X509TrustManager (javax.net.ssl.X509TrustManager)69 Socket (java.net.Socket)63 TrustManager (javax.net.ssl.TrustManager)56 HostnameVerifier (javax.net.ssl.HostnameVerifier)49 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)48 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)48 Test (org.junit.Test)46 KeyManagementException (java.security.KeyManagementException)45 URL (java.net.URL)41 CertificateException (java.security.cert.CertificateException)39 OkHttpClient (okhttp3.OkHttpClient)39 OutputStream (java.io.OutputStream)35 InputStream (java.io.InputStream)34 X509Certificate (java.security.cert.X509Certificate)34 SSLSession (javax.net.ssl.SSLSession)30 InetSocketAddress (java.net.InetSocketAddress)29