List of usage examples for org.apache.http.ssl SSLContexts createDefault
public static SSLContext createDefault() throws SSLInitializationException
From source file:com.joyent.manta.http.MantaSSLConnectionSocketFactory.java
/** * @return reference to SSL Context */ private static SSLContext buildContext() { return SSLContexts.createDefault(); }
From source file:org.aevans.goat.net.SSLStrategyGetter.java
public static SchemeIOSessionStrategy getSchemeIOSessionStrategy() { DefaultHostnameVerifier hostnameVerifier = new DefaultHostnameVerifier( PublicSuffixMatcherLoader.getDefault()); SchemeIOSessionStrategy sioss = new SchemeIOSessionStrategy() { @Override/* w w w. ja v a 2 s. c om*/ public boolean isLayeringRequired() { return true; } @Override public IOSession upgrade(final HttpHost host, final IOSession iosession) throws IOException { SSLSetupHandler handler = new SSLSetupHandler() { @Override public void initalize(SSLEngine sslengine) throws SSLException { } @Override public void verify(IOSession iosession, SSLSession sslsession) throws SSLException { if (!hostnameVerifier.verify(host.getHostName(), sslsession)) { final java.security.cert.Certificate[] certs = sslsession.getPeerCertificates(); final X509Certificate x509 = (X509Certificate) certs[0]; final X500Principal x500Principal = x509.getSubjectX500Principal(); throw new SSLPeerUnverifiedException("Host name '" + host.getHostName() + "' does not match " + "the certificate subject provided by the peer (" + x500Principal.toString() + ")"); } } }; SSLBufferManagementStrategy sslbm = new ReleasableSSLBufferManagementStrategy(); SSLIOSession ssio = new SSLIOSession(iosession, SSLMode.CLIENT, host, SSLContexts.createDefault(), handler, sslbm); iosession.setAttribute(SSLIOSession.SESSION_KEY, ssio); ssio.initialize(); return ssio; } }; return sioss; }
From source file:com.mirth.connect.util.MirthSSLUtil.java
public static String[] getSupportedHttpsProtocols() { return SSLContexts.createDefault().getSupportedSSLParameters().getProtocols(); }
From source file:com.mirth.connect.util.MirthSSLUtil.java
public static String[] getSupportedHttpsCipherSuites() { return SSLContexts.createDefault().getSupportedSSLParameters().getCipherSuites(); }
From source file:org.nekorp.workflow.desktop.rest.util.RestTemplateFactory.java
@PostConstruct public void init() { targetHost = new HttpHost(host, port, protocol); //connectionPool = new PoolingHttpClientConnectionManager(); //connectionPool.setDefaultMaxPerRoute(10); //connectionPool.setMaxTotal(20); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(username, password)); //wildcard ssl certificate SSLContext sslContext = SSLContexts.createDefault(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider) //.setConnectionManager(connectionPool) .setSSLSocketFactory(sslsf).build(); // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local // auth cache BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); // Add AuthCache to the execution context HttpClientContext localContext = HttpClientContext.create(); localContext.setAuthCache(authCache); HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactoryBasicAuth( httpclient, localContext);// w w w . java 2s.c o m this.template = new RestTemplate(); template.getMessageConverters().add(new BufferedImageHttpMessageConverter()); template.setRequestFactory(factory); }
From source file:org.elasticsearch.xpack.ssl.SSLClientAuthTests.java
public void testThatHttpFailsWithoutSslClientAuth() throws IOException { SSLIOSessionStrategy sessionStrategy = new SSLIOSessionStrategy(SSLContexts.createDefault(), NoopHostnameVerifier.INSTANCE); try (RestClient restClient = createRestClient( httpClientBuilder -> httpClientBuilder.setSSLStrategy(sessionStrategy), "https")) { restClient.performRequest("GET", "/"); fail("Expected SSLHandshakeException"); } catch (IOException e) { Throwable t = ExceptionsHelper.unwrap(e, CertPathBuilderException.class); assertThat(t, instanceOf(CertPathBuilderException.class)); assertThat(t.getMessage(),/*from w w w. jav a2 s .c o m*/ containsString("unable to find valid certification path to requested target")); } }
From source file:com.mirth.connect.util.MirthSSLUtil.java
public static String[] getEnabledHttpsProtocols(String[] requestedProtocols) { logger.debug("Requested SSL protocols: " + Arrays.toString(requestedProtocols)); SSLContext sslContext = SSLContexts.createDefault(); String[] supportedProtocols = sslContext.getSupportedSSLParameters().getProtocols(); Set<String> enabledProtocols = new LinkedHashSet<String>(); for (String protocol : requestedProtocols) { if (ArrayUtils.contains(supportedProtocols, protocol)) { enabledProtocols.add(protocol); }//from www . j a va 2 s. c o m } logger.debug("Enabled SSL protocols: " + String.valueOf(enabledProtocols)); return enabledProtocols.toArray(new String[enabledProtocols.size()]); }
From source file:com.mirth.connect.util.MirthSSLUtil.java
public static String[] getEnabledHttpsCipherSuites(String[] requestedCipherSuites) { logger.debug("Requested SSL cipher suites: " + Arrays.toString(requestedCipherSuites)); SSLContext sslContext = SSLContexts.createDefault(); String[] supportedCipherSuites = sslContext.getSupportedSSLParameters().getCipherSuites(); Set<String> enabledCipherSuites = new LinkedHashSet<String>(); for (String cipherSuite : requestedCipherSuites) { if (ArrayUtils.contains(supportedCipherSuites, cipherSuite)) { enabledCipherSuites.add(cipherSuite); }//from w w w.ja va2 s . c o m } logger.debug("Enabled SSL cipher suites: " + String.valueOf(enabledCipherSuites)); return enabledCipherSuites.toArray(new String[enabledCipherSuites.size()]); }
From source file:microsoft.exchange.webservices.data.core.EwsSSLProtocolSocketFactory.java
/** * Create SSL context and initialize it using specific trust manager. * * @param trustManager trust manager/*from w w w .j ava2s . co m*/ * @return initialized SSL context * @throws GeneralSecurityException on security error */ public static SSLContext createSslContext(TrustManager trustManager) throws GeneralSecurityException { EwsX509TrustManager x509TrustManager = new EwsX509TrustManager(null, trustManager); SSLContext sslContext = SSLContexts.createDefault(); sslContext.init(null, new TrustManager[] { x509TrustManager }, null); return sslContext; }
From source file:org.jboss.as.test.integration.management.http.HttpGenericOperationUnitTestCase.java
private static CloseableHttpClient createHttpClient(String host, int port, String username, String password) { try {//from w ww . j a v a 2 s .com SSLContext sslContext = SSLContexts.createDefault(); SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("https", sslConnectionSocketFactory) .register("http", PlainConnectionSocketFactory.getSocketFactory()).build(); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(host, port, MANAGEMENT_REALM, AuthSchemes.DIGEST), new UsernamePasswordCredentials(username, password)); PoolingHttpClientConnectionManager connectionPool = new PoolingHttpClientConnectionManager(registry); HttpClientBuilder.create().setConnectionManager(connectionPool).build(); return HttpClientBuilder.create().setConnectionManager(connectionPool) .setRetryHandler(new StandardHttpRequestRetryHandler(5, true)) .setDefaultCredentialsProvider(credsProvider).build(); } catch (Exception e) { throw new RuntimeException(e); } }