Example usage for javax.net.ssl SSLContext getInstance

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

Introduction

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

Prototype

public static SSLContext getInstance(String protocol) throws NoSuchAlgorithmException 

Source Link

Document

Returns a SSLContext object that implements the specified secure socket protocol.

Usage

From source file:org.datacleaner.util.SecurityUtils.java

/**
 * Removes the certificate checks of HTTPS traffic on a HTTP client. Use
 * with caution!//from w ww .  ja  va2 s  . c om
 * 
 * @param httpClient
 * @throws IllegalStateException
 */
public static void removeSshCertificateChecks(HttpClient httpClient) throws IllegalStateException {
    try {
        // prepare a SSL context which doesn't validate certificates
        final SSLContext sslContext = SSLContext.getInstance("SSL");
        final TrustManager trustManager = new NaiveTrustManager();
        sslContext.init(null, new TrustManager[] { trustManager }, new SecureRandom());
        final SSLSocketFactory schemeSocketFactory = new SSLSocketFactory(sslContext);
        final Scheme sslScheme = new Scheme("https", 443, schemeSocketFactory);

        // try again with a new registry
        final SchemeRegistry registry = httpClient.getConnectionManager().getSchemeRegistry();
        registry.register(sslScheme);
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}

From source file:com.dvdprime.android.app.http.CustomSSLSocketFactory.java

/**
 * Creates a new CustomSSLSocket object.
 * //from  w  ww.j  a  v  a2 s . c  o m
 * @return the SSL context
 * @throws NoSuchAlgorithmException
 *             the no such algorithm exception
 * @throws KeyManagementException
 *             the key management exception
 * @throws KeyStoreException
 *             the key store exception
 */
private static SSLContext createSSLContext()
        throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException {
    SSLContext context = SSLContext.getInstance(SSL_PROTOCOL_NAME);
    context.init(null, new TrustManager[] { new CustomX509TrustManager(null) }, null);
    return context;
}

From source file:com.rackspacecloud.client.cloudfiles.EasySSLSocketFactory.java

private static SSLContext createEasySSLContext()
        throws IOException, NoSuchAlgorithmException, KeyStoreException {
    KeyStore keystore = null;/*from   ww w . java 2s.  c  o  m*/
    EasyX509TrustManager extm = new EasyX509TrustManager(keystore);
    try {
        SSLContext context = SSLContext.getInstance("TLS");
        context.init(null, new TrustManager[] { extm }, null);
        return context;
    } catch (Exception e) {
        throw new IOException(e.getMessage());
    }
}

From source file:com.spokenpic.net.ssl.TrustAllSSLSocketFactory.java

public TrustAllSSLSocketFactory()
        throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException {
    super(null);/*from  w  w w  .j  a v  a2  s  .c om*/
    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:eu.eco2clouds.api.bonfire.client.rest.RestClient.java

private static void enableSSLUnsecureTrustStore() {
    try {/*from w w w  .  j  a  v a 2s .  co  m*/
        SSLContext ctx = SSLContext.getInstance("TLS");
        ctx.init(new KeyManager[0], new TrustManager[] { new DefaultTrustManager() }, new SecureRandom());
        SSLContext.setDefault(ctx);
    } catch (NoSuchAlgorithmException exception) {
        System.out.println("ERROR TRYING TO DISSABLE JAVA SSL SECURITY");
        System.out.println("NO TLS ALGORITHM EXCEPTION");
        System.out.println("EXCEPTION" + exception.getMessage());
    } catch (KeyManagementException exception) {
        System.out.println("ERROR TRYING TO DISSABLE JAVA SSL SECURITY");
        System.out.println("KEY MANAGEMENT CREATION EXCEPTION");
        System.out.println("EXCEPTION" + exception.getMessage());
    }
}

From source file:com.androidinahurry.network.utils.FakeSSLSocketFactory.java

public FakeSSLSocketFactory(KeyStore truststore)
        throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
    super(null);//from   www .  j  a  va2s.  c  om

    try {
        SSLContext context = SSLContext.getInstance("TLS");

        // Create a trust manager that does not validate certificate chains
        // and simply
        // accept all type of certificates
        TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return new java.security.cert.X509Certificate[] {};
            }

            public void checkClientTrusted(X509Certificate[] chain, String authType)
                    throws CertificateException {
            }

            public void checkServerTrusted(X509Certificate[] chain, String authType)
                    throws CertificateException {
            }
        } };

        // Initialize the socket factory
        context.init(null, trustAllCerts, new SecureRandom());
        sslFactory = context.getSocketFactory();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.manning.androidhacks.hack023.net.SimpleSSLSocketFactory.java

private static SSLContext createSimpleSSLContext() throws IOException {
    try {/*from   ww w. j av a 2 s .c  om*/
        SSLContext context = SSLContext.getInstance("TLS");
        context.init(null, new TrustManager[] { new AcceptInvalidX509TrustManager() }, null);
        return context;
    } catch (Exception e) {
        throw new IOException(e.getMessage());
    }
}

From source file:cn.cuizuoli.appranking.http.client.TrustSSLSocketFactoryFactoryBean.java

@Override
public SSLSocketFactory getObject() throws Exception {
    try {/* w w w.  j  av  a  2s  .c o  m*/
        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new SecureRandom());
        return sc.getSocketFactory();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:edu.cmu.cylab.starslinger.exchange.CheckedSSLSocketFactory.java

private static SSLContext createEasySSLContext() throws IOException {
    KeyStore trusted = null;//ww  w. j  a  va  2s .  c  o  m

    try {
        SSLContext context = SSLContext.getInstance("TLS");
        context.init(null, new TrustManager[] { new CheckedX509TrustManager(trusted) }, null);
        return context;

    } catch (KeyManagementException e) {
        throw new IOException(e.getLocalizedMessage());
    } catch (NoSuchAlgorithmException e) {
        throw new IOException(e.getLocalizedMessage());
    } catch (KeyStoreException e) {
        throw new IOException(e.getLocalizedMessage());
    }
}

From source file:pl.bcichecki.rms.client.android.services.clients.restful.https.ssl.SimpleSSLSocketFactory.java

public SimpleSSLSocketFactory(KeyStore truststore)
        throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
    super(truststore);
    sslContext = SSLContext.getInstance("SSL");
    x509TrustManager = new SimpleX509TrustManager();
    sslContext.init(null, new TrustManager[] { x509TrustManager }, new SecureRandom());
}