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.fatwire.dta.sscrawler.EasySSLProtocolSocketFactory.java

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

From source file:org.sana.net.http.ssl.EasySSLSocketFactory.java

private static SSLContext createEasySSLContext(TrustManager manager) throws IOException {
    try {/*from   www.j  ava  2 s.  c om*/
        SSLContext context = SSLContext.getInstance("TLS");
        context.init(null, new TrustManager[] { manager }, null);
        return context;
    } catch (Exception e) {
        throw new IOException(e.getMessage());
    }
}

From source file:oracle.custom.ui.utils.ServerUtils.java

public static SSLContext getContext() throws NoSuchAlgorithmException, KeyManagementException {
    TrustManager tms[] = new TrustManager[] { new X509TrustManager() {
        @Override/*  w  w  w.  j  a v  a2  s  . co  m*/
        public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {

        }

        @Override
        public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {

        }

        @Override
        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    } };

    SSLContext context = SSLContext.getInstance("TLS");
    context.init(null, tms, new SecureRandom());
    return context;
}

From source file:au.edu.monash.merc.capture.util.httpclient.ssl.EasyIgnoreSSLProtocolSocketFactory.java

private static SSLContext createEasySSLContext() {
    try {//from  w  w  w. ja v  a2 s .c om
        SSLContext context = SSLContext.getInstance("SSL");
        context.init(null, new TrustManager[] { (TrustManager) new DefaultEasyX509TrustManager() },
                new SecureRandom());
        return context;
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        throw new HttpClientError(e.toString());
    }
}

From source file:au.edu.monash.merc.capture.util.httpclient.ssl.EasySSLProtocolSocketFactory.java

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

From source file:com.googlecode.spektom.gcsearch.utils.EasySSLProtocolSocketFactory.java

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

From source file:test.TestFinal.java

public static JerseyClient getJerseyClient(boolean isSSL) {
    ClientBuilder clientBuilder = JerseyClientBuilder.newBuilder().register(MultiPartFeature.class);

    // Create a secure JerseyClient
    if (isSSL) {//from w  ww. java  2 s.  c o m
        try {
            HostnameVerifier verifier = new HostnameVerifier() {
                public boolean verify(String hostname, SSLSession session) {
                    return true;
                }
            };

            TrustManager[] tm = new TrustManager[] { new X509TrustManager() {

                public X509Certificate[] getAcceptedIssuers() {
                    return null;
                }

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

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

            SSLContext sslContext = sslContext = SSLContext.getInstance("SSL");

            sslContext.init(null, tm, new SecureRandom());

            clientBuilder.sslContext(sslContext).hostnameVerifier(verifier);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (KeyManagementException e) {
            e.printStackTrace();
        }
    }

    return (JerseyClient) clientBuilder.build().register(JacksonJsonProvider.class);
}

From source file:eu.alefzero.owncloud.authenticator.EasySSLSocketFactory.java

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

From source file:cn.dacas.emmclient.security.ssl.EasySSLSocketFactory.java

private static SSLContext createIgnoreSSLContext() throws IOException {
    try {//from   w  ww  .j  a va  2 s  .c o m
        SSLContext context = SSLContext.getInstance("TLS");
        context.init(null, new TrustManager[] { new IgnoreCertTrustManager() }, null);
        return context;
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException(e.getMessage());
    }
}

From source file:eu.eco2clouds.api.bonfire.client.rest.RestClient.java

private static void enableSSLUnsecureTrustStore() {
    try {/*from w  w  w . j  a  v a 2 s  .c  o  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());
    }
}