Example usage for javax.net.ssl SSLContext init

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

Introduction

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

Prototype

public final void init(KeyManager[] km, TrustManager[] tm, SecureRandom random) throws KeyManagementException 

Source Link

Document

Initializes this context.

Usage

From source file:com.trsst.client.AnonymSSLSocketFactory.java

/**
 * Create the SSL Context./*from  w  w w.  j a v a  2s  . co m*/
 * 
 * @return The SSLContext
 */
private static SSLContext createEasySSLContext() {
    try {
        SSLContext context = SSLContext.getInstance("SSL"); //$NON-NLS-1$
        context.init(null, new TrustManager[] { new X509TrustManager() {
            public void checkClientTrusted(X509Certificate[] chain, String authType) {
            }

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

            public X509Certificate[] getAcceptedIssuers() {
                return new X509Certificate[] {};
            }
        } }, null);
        return context;
    } catch (Exception e) {
        throw new HttpClientError(e.toString());
    }
}

From source file:cz.vity.freerapid.plugins.webclient.ssl.EasySSLProtocolSocketFactory.java

private static SSLContext createEasySSLContext() {
    try {//from   w  w  w .  j av a2 s.co m
        SSLContext context = SSLContext.getInstance("SSL");
        context.init(null, new TrustManager[] { new EasyX509TrustManager(null) }, null);
        return context;
    } catch (Exception e) {
        LogUtils.processException(logger, e);
        throw new HttpClientError(e.toString());
    }
}

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

/**
 * Removes the certificate checks of HTTPS traffic on a HTTP client. Use
 * with caution!//from ww w .j  a  v a 2 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.ntsync.android.sync.client.MySSLSocketFactory.java

private static SSLContext createEasySSLContext() throws IOException {
    try {// w  w w . jav a 2 s  .co  m
        SSLContext context = SSLContext.getInstance("TLS");
        context.init(null, new TrustManager[] { new MyX509TrustManager() }, null);
        return context;
    } catch (GeneralSecurityException e) {
        Log.e(TAG, "Init SSLContext failed.", e);
        throw new IOException(e.getMessage());
    }
}

From source file:com.appdynamics.openstack.nova.RestClient.java

static HttpClient httpClientWithTrustManager() throws KeyManagementException, NoSuchAlgorithmException {
    HttpClient httpClient = new DefaultHttpClient();

    httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);

    httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, timeout);

    httpClient.getParams().setParameter("http.connection-manager.max-per-host", 1);

    X509TrustManager tm = new X509TrustManager() {

        @Override//from  www.j  a  v a 2  s .  com
        public X509Certificate[] getAcceptedIssuers() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
            // TODO Auto-generated method stub

        }

        @Override
        public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
            // TODO Auto-generated method stub

        }
    };

    SSLContext ctx = SSLContext.getInstance("TLS");

    ctx.init(null, new TrustManager[] { tm }, null);

    SSLSocketFactory ssf = new SSLSocketFactory(ctx);

    ClientConnectionManager ccm = httpClient.getConnectionManager();

    SchemeRegistry sr = ccm.getSchemeRegistry();

    sr.register(new Scheme("https", ssf, 443)); // Scheme("https", ssf, 443));

    return new DefaultHttpClient(ccm, httpClient.getParams());

}

From source file:org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory.java

private static SSLContext createEasySSLContext() {
    try {/*from   w  ww  . ja va2s . c  o  m*/
        SSLContext context = SSLContext.getInstance("SSL");
        context.init(null, new TrustManager[] { new EasyX509TrustManager(null) }, null);
        return context;
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        throw new RuntimeException(e.toString());
    }
}

From source file:org.apache.falcon.request.BaseRequest.java

public static SSLContext getSslContext() throws Exception {
    SSLContext sslContext = SSLContext.getInstance("SSL");
    sslContext.init(null, new TrustManager[] { TrustManagerUtils.getValidateServerCertificateTrustManager() },
            new SecureRandom());
    return sslContext;
}

From source file:com.bytelightning.opensource.pokerface.HelloWorldScriptTest.java

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    PrevSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
    PrevHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();

    proxy = new PokerFace();
    XMLConfiguration conf = new XMLConfiguration();
    conf.load(ProxySpecificTest.class.getResource("/HelloWorldTestConfig.xml"));
    proxy.config(conf);/*from ww w  .ja v  a2 s. c om*/
    boolean started = proxy.start();
    Assert.assertTrue("Successful proxy start", started);

    SSLContext sc = SSLContext.getInstance("TLS");
    TrustManager[] trustAllCertificates = { new X509TrustAllManager() };
    sc.init(null, trustAllCertificates, new SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
        @Override
        public boolean verify(String hostname, SSLSession session) {
            return true; // Just allow them all.
        }
    });

}

From source file:com.sun.socialsite.util.LeniantSSLProtocolSocketFactory.java

private static SSLContext createLeniantSSLContext() {
    try {//from ww  w.jav a  2  s.c  om
        SSLContext context = SSLContext.getInstance("SSL");
        context.init(null, new TrustManager[] { new LeniantX509TrustManager(null) }, null);
        return context;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new HttpClientError(e.toString());
    }
}

From source file:HttpClient.EasySSLProtocolSocketFactory.java

private static SSLContext createEasySSLContext() {
    try {//from  ww w .j  a  va 2  s . c  o m
        SSLContext context = SSLContext.getInstance("SSL");
        context.init(null, new TrustManager[] { (TrustManager) new EasyX509TrustManager(null) }, null);
        return context;
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        throw new HttpClientError(e.toString());
    }
}