Example usage for javax.net.ssl SSLContext getDefault

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

Introduction

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

Prototype

public static SSLContext getDefault() throws NoSuchAlgorithmException 

Source Link

Document

Returns the default SSL context.

Usage

From source file:Main.java

/**
 * Returns the ciphers preferred to use during tests. They may be chosen because they are widely
 * available or because they are fast. There is no requirement that they provide confidentiality
 * or integrity.//from   w  ww . ja  va 2s.  c o  m
 */
public static List<String> preferredCiphers() {
    String[] ciphers;
    try {
        ciphers = SSLContext.getDefault().getDefaultSSLParameters().getCipherSuites();
    } catch (NoSuchAlgorithmException ex) {
        throw new RuntimeException(ex);
    }
    List<String> ciphersMinusGcm = new ArrayList<String>();
    for (String cipher : ciphers) {
        // The GCM implementation in Java is _very_ slow (~1 MB/s)
        if (cipher.contains("_GCM_")) {
            continue;
        }
        ciphersMinusGcm.add(cipher);
    }
    return Collections.unmodifiableList(ciphersMinusGcm);
}

From source file:com.cloudhopper.httpclient.util.SchemeFactory.java

static public Scheme createHttpsScheme() throws NoSuchAlgorithmException {
    SSLSocketFactory socketFactory = new SSLSocketFactory(SSLContext.getDefault());
    return new Scheme("https", socketFactory, 443);
}

From source file:OkHttpEngine.java

@Override
public ResponseEntity<String> submit(JCurlRequestOptions requestOptions) throws Exception {
    OkHttpClient client = new OkHttpClient.Builder().connectTimeout(2000, TimeUnit.MILLISECONDS)
            .sslSocketFactory(SSLContext.getDefault().getSocketFactory()).followSslRedirects(true).build();

    ResponseEntity<String> responseEntity = null;

    for (int i = 0; i < requestOptions.getCount(); i++) {
        final Request.Builder requestBuilder = new Request.Builder().url(requestOptions.getUrl())
                .headers(Headers.of(requestOptions.getHeaderMap())).get();
        Request request = requestBuilder.build();

        System.out.println("\nSending 'GET' request to URL : " + requestOptions.getUrl());
        Response response = client.newCall(request).execute();

        int responseCode = response.code();
        System.out.println("Response Code : " + responseCode);

        final InputStream is = response.body().byteStream();
        String responseContent = IOUtils.toString(is);
        is.close();//from w  w w  .  j a  va  2 s . c o  m

        //print result
        System.out.println(responseContent);

        responseEntity = new ResponseEntity<String>(responseContent, HttpStatus.valueOf(responseCode));
    }
    return responseEntity;
}

From source file:JettyEngine.java

@Override
public ResponseEntity<String> submit(JCurlRequestOptions requestOptions) throws Exception {

    final SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setSslContext(SSLContext.getDefault());
    HttpClient httpClient = new HttpClient(sslContextFactory);
    // Configure HttpClient here
    httpClient.start();/*from   ww w . j ava  2 s  .co m*/

    ResponseEntity<String> responseEntity = null;

    for (int i = 0; i < requestOptions.getCount(); i++) {
        final Request request = httpClient.newRequest(requestOptions.getUrl());

        for (Map.Entry<String, String> e : requestOptions.getHeaderMap().entrySet()) {
            request.header(e.getKey(), e.getValue());
        }

        System.out.println("\nSending 'GET' request to URL : " + requestOptions.getUrl());
        final ContentResponse response = request.send();

        int responseCode = response.getStatus();
        System.out.println("Response Code : " + responseCode);

        String responseContent = IOUtils.toString(response.getContent(), "utf-8");

        //print result
        System.out.println(responseContent);

        responseEntity = new ResponseEntity<String>(responseContent, HttpStatus.valueOf(responseCode));
    }

    httpClient.stop();
    return responseEntity;
}

From source file:com.netflix.http4.ssl.KeyStoreAwareSocketFactory.java

public KeyStoreAwareSocketFactory(X509HostnameVerifier hostnameVerifier)
        throws NoSuchAlgorithmException, KeyStoreException {
    super(SSLContext.getDefault(), hostnameVerifier);

    this.keyStore = null;
    this.trustStore = null;
}

From source file:net.acesinc.data.json.generator.log.HttpPostLogger.java

public HttpPostLogger(Map<String, Object> props) throws NoSuchAlgorithmException {
    this.url = (String) props.get(URL_PROP_NAME);
    SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory(SSLContext.getDefault(),
            new NoopHostnameVerifier());
    this.httpClient = HttpClientBuilder.create().setSSLSocketFactory(sf).build();
}

From source file:securitytools.common.http.HttpClientFactory.java

public static CloseableHttpClient build(ClientConfiguration clientConfiguration)
        throws NoSuchAlgorithmException {
    HttpClientBuilder builder = HttpClients.custom();

    // Certificate Validation
    if (clientConfiguration.isCertificateValidationEnabled()) {
        builder.setSSLSocketFactory(new SSLConnectionSocketFactory(SSLContext.getDefault(),
                SSLConnectionSocketFactory.STRICT_HOSTNAME_VERIFIER));
    } else {/*from w w  w .  j a v  a  2 s .c o  m*/
        // Disable
        builder.setSSLSocketFactory(new TrustingSSLConnectionSocketFactory());
    }

    // Timeouts
    RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
    requestConfigBuilder.setConnectTimeout(clientConfiguration.getConnectionTimeout());
    requestConfigBuilder.setConnectionRequestTimeout(clientConfiguration.getConnectionTimeout());
    requestConfigBuilder.setSocketTimeout(clientConfiguration.getSocketTimeout());
    builder.setDefaultRequestConfig(requestConfigBuilder.build());

    // User Agent
    builder.setUserAgent(clientConfiguration.getUserAgent());

    // Proxy
    if (clientConfiguration.getProxyHost() != null) {
        builder.setProxy(clientConfiguration.getProxyHost());
    }

    return builder.build();
}

From source file:com.netflix.http4.ssl.KeyStoreAwareSocketFactory.java

public KeyStoreAwareSocketFactory(final AbstractSslContextFactory abstractFactory)
        throws ClientSslSocketFactoryException, NoSuchAlgorithmException {
    super(abstractFactory == null ? SSLContext.getDefault() : abstractFactory.getSSLContext());

    if (abstractFactory == null) {
        this.keyStore = null;
        this.trustStore = null;
    } else {/* w  ww.  j a  v a2  s . co m*/
        this.keyStore = abstractFactory.getKeyStore();
        this.trustStore = abstractFactory.getTrustStore();
    }
}

From source file:org.eclipse.thym.core.engine.internal.cordova.NpmBasedEngineRepoProvider.java

private InputStream getRemoteJSonStream(String url) throws IOException {
    try {/*ww  w .  jav a  2 s . c  o m*/
        // SSLSocketFactory to patch HTTPClient's that are earlier than 4.3.2
        // to enable SNI support.
        SSLSocketFactory factory = new SSLSocketFactory(SSLContext.getDefault()) {
            @Override
            public Socket createSocket() throws IOException {
                return SocketFactory.getDefault().createSocket();
            }

            @Override
            public Socket createSocket(HttpParams params) throws IOException {
                return SocketFactory.getDefault().createSocket();
            }
        };
        DefaultHttpClient client = new DefaultHttpClient();
        HttpUtil.setupProxy(client);
        client.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 443, factory));
        HttpGet get = new HttpGet(url);
        HttpResponse response = client.execute(get);
        HttpEntity entity = response.getEntity();
        return entity.getContent();
    } catch (NoSuchAlgorithmException e) {
        HybridCore.log(IStatus.ERROR, "Error creating the SSL Factory ", e);
    }
    return null;
}

From source file:com.netflix.http4.ssl.KeyStoreAwareSocketFactory.java

public KeyStoreAwareSocketFactory(final AbstractSslContextFactory abstractFactory,
        X509HostnameVerifier hostnameVerifier)
        throws ClientSslSocketFactoryException, NoSuchAlgorithmException {
    super(abstractFactory == null ? SSLContext.getDefault() : abstractFactory.getSSLContext(),
            hostnameVerifier);/* w  ww .ja v  a  2s  . c  o m*/

    if (abstractFactory == null) {
        this.keyStore = null;
        this.trustStore = null;
    } else {
        this.keyStore = abstractFactory.getKeyStore();
        this.trustStore = abstractFactory.getTrustStore();
    }
}