Example usage for javax.net.ssl SSLContext getSocketFactory

List of usage examples for javax.net.ssl SSLContext getSocketFactory

Introduction

In this page you can find the example usage for javax.net.ssl SSLContext getSocketFactory.

Prototype

public final SSLSocketFactory getSocketFactory() 

Source Link

Document

Returns a SocketFactory object for this context.

Usage

From source file:net.networksaremadeofstring.rhybudd.TrustAllSSLSocketFactory.java

public TrustAllSSLSocketFactory()
        throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException {
    super(null);//  w  ww .  ja v  a 2s  . co m
    try {
        SSLContext sslcontext = SSLContext.getInstance("TLS");
        sslcontext.init(null, new TrustManager[] { new TrustAllManager() }, null);
        factory = sslcontext.getSocketFactory();
        setHostnameVerifier(new AllowAllHostnameVerifier());
    } catch (Exception ex) {

    }
}

From source file:com.wiyun.engine.network.TrustAllSSLSocketFactory.java

public TrustAllSSLSocketFactory()
        throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException {
    super(null);/* w w w . j  a  v a2s  .  c  o  m*/
    try {
        SSLContext sslcontext = SSLContext.getInstance("TLS");
        sslcontext.init(null, new TrustManager[] { new TrustAllManager() }, null);
        factory = sslcontext.getSocketFactory();
        setHostnameVerifier(new AllowAllHostnameVerifier());
    } catch (Exception ex) {
    }
}

From source file:org.jsnap.request.SSLSocketFactory.java

private SSLSocketFactory(boolean trustAll) {
    sf = null;//from   w  w w  .  j  a va  2s  .c  o  m
    if (trustAll) {
        // Create a trust manager that does not validate certificate chains.
        TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }

            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            }

            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            }
        } };
        try {
            SSLContext sc = SSLContext.getInstance("SSL");
            sc.init(null, trustAllCerts, null);
            sf = sc.getSocketFactory();
        } catch (NoSuchAlgorithmException e) {
            Logger.getLogger(SSLSocketFactory.class).log(Level.WARN, "Unable to instantiate SSLSocketFactory",
                    e);
        } catch (KeyManagementException e) {
            Logger.getLogger(SSLSocketFactory.class).log(Level.WARN, "Unable to instantiate SSLSocketFactory",
                    e);
        }
    } else {
        try {
            SSLContext sc = SSLContext.getInstance("SSL");
            sc.init(null, null, null);
            sf = sc.getSocketFactory();
        } catch (NoSuchAlgorithmException e) {
            Logger.getLogger(SSLSocketFactory.class).log(Level.WARN, "Unable to instantiate SSLSocketFactory",
                    e);
        } catch (KeyManagementException e) {
            Logger.getLogger(SSLSocketFactory.class).log(Level.WARN, "Unable to instantiate SSLSocketFactory",
                    e);
        }
    }
}

From source file:org.addhen.smssync.net.ssl.TrustedSocketFactory.java

public TrustedSocketFactory(String host, boolean secure)
        throws NoSuchAlgorithmException, KeyManagementException {
    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, new TrustManager[] { TrustManagerFactory.get(host, secure) }, new SecureRandom());
    mSocketFactory = sslContext.getSocketFactory();
    mSchemeSocketFactory = org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory();
    mSchemeSocketFactory//from   ww  w  .  j  a  v  a 2  s. c  o m
            .setHostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
}

From source file:ezbake.deployer.publishers.SecurityServiceClient.java

protected HttpsURLConnection openUrlConnection(URL endpoint) throws IOException, SSLContextException {

    SSLContext sslContext = EzSSL.getSSLContext(config.getEzConfiguration());

    HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
    HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
        @Override//from  w  w w .j a v a  2s  . c  o m
        public boolean verify(String s, SSLSession sslSession) {
            return true;
        }
    });
    return (HttpsURLConnection) endpoint.openConnection();
}

From source file:com.cloud.network.bigswitch.TrustingProtocolSocketFactory.java

public TrustingProtocolSocketFactory() throws IOException {
    // Create a trust manager that does not validate certificate chains
    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
        @Override/* w ww  .j a va  2s.c o  m*/
        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }

        @Override
        public void checkClientTrusted(X509Certificate[] certs, String authType) {
            // Trust always
        }

        @Override
        public void checkServerTrusted(X509Certificate[] certs, String authType) {
            // Trust always
        }
    } };

    try {
        // Install the all-trusting trust manager
        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        ssf = sc.getSocketFactory();
    } catch (KeyManagementException e) {
        throw new IOException(e);
    } catch (NoSuchAlgorithmException e) {
        throw new IOException(e);
    }
}

From source file:org.pluroid.pluroium.HttpClientFactory.java

/**
 * Constructor//  w  w  w .ja  v a2 s  .  com
 */
public MySSLSocketFactory() {
    if (m_sslSocketFactory == null) {
        try {
            SSLContext sc = SSLContext.getInstance("TLS");
            sc.init(null, null, null);
            m_sslSocketFactory = sc.getSocketFactory();
        } catch (Exception ex) {
        }
    }
}

From source file:com.apporiented.hermesftp.cmd.impl.FtpCmdAuth.java

private SSLSocket createSslSocket() throws IOException {
    String clientHost = getCtx().getClientSocket().getInetAddress().getHostAddress();
    SSLContext sslContext = getCtx().getOptions().getSslContext();
    SSLSocketFactory factory = sslContext.getSocketFactory();
    SSLSocket sslSocket = (SSLSocket) factory.createSocket(getCtx().getClientSocket(), clientHost,
            getCtx().getOptions().getFtpPort(), true);
    sslSocket.setUseClientMode(false);// ww w  .j a  v a2  s  .  c om
    sslSocket.addHandshakeCompletedListener(this);
    enableCipherSuites(sslSocket);
    log.info("Enabled cipher suites (explicit SSL): "
            + StringUtils.arrayToCommaDelimitedString(sslSocket.getEnabledCipherSuites()));
    return sslSocket;
}

From source file:com.collabnet.svnedge.net.SslProtocolSocketFactory.java

private SslProtocolSocketFactory() {
    try {/*  w  ww  .j a va2s. c  om*/
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, new TrustManager[] { new TrustAllTrustManager() }, null);
        this.socketFactory = sslContext.getSocketFactory();
    } catch (Exception e) {
        log(0, "Could not initialize SSL context", e);
    }
}

From source file:org.keycloak.truststore.JSSETruststoreConfigurator.java

public javax.net.ssl.SSLSocketFactory getSSLSocketFactory() {
    if (provider == null) {
        return null;
    }//from w w w  . j  av a  2  s . c  om

    if (sslFactory == null) {
        synchronized (this) {
            if (sslFactory == null) {
                try {
                    SSLContext sslctx = SSLContext.getInstance("TLS");
                    sslctx.init(null, getTrustManagers(), null);
                    sslFactory = sslctx.getSocketFactory();
                } catch (Exception e) {
                    throw new RuntimeException("Failed to initialize SSLContext: ", e);
                }
            }
        }
    }
    return sslFactory;
}