You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2018/11/22 09:21:15 UTC
[4/4] httpcomponents-core git commit: Added optional dependency on
conscrypt-openjdk-uber 1.4.1;
support for advanced TLS functions (such as ALPN extension) on Java 1.7 and
Java 1.8 through Conscrypt TLS library
Added optional dependency on conscrypt-openjdk-uber 1.4.1; support for advanced TLS functions (such as ALPN extension) on Java 1.7 and Java 1.8 through Conscrypt TLS library
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/f322f5ad
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/f322f5ad
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/f322f5ad
Branch: refs/heads/master
Commit: f322f5add27c7c7697c1419eccb22506a30daea8
Parents: adcaa9f
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Wed Nov 21 18:40:59 2018 +0100
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Thu Nov 22 10:01:13 2018 +0100
----------------------------------------------------------------------
httpcore5-h2/pom.xml | 6 +
.../Http2ConscriptRequestExecutionExample.java | 163 +++++++++++++++++++
.../http2/ssl/ConscryptClientTlsStrategy.java | 104 ++++++++++++
.../http2/ssl/ConscryptServerTlsStrategy.java | 113 +++++++++++++
.../hc/core5/http2/ssl/ConscryptSupport.java | 89 ++++++++++
.../apache/hc/core5/http2/ssl/H2TlsSupport.java | 29 ++--
pom.xml | 6 +
7 files changed, 495 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f322f5ad/httpcore5-h2/pom.xml
----------------------------------------------------------------------
diff --git a/httpcore5-h2/pom.xml b/httpcore5-h2/pom.xml
index 1e82751..5a75b94 100644
--- a/httpcore5-h2/pom.xml
+++ b/httpcore5-h2/pom.xml
@@ -44,6 +44,12 @@
<scope>compile</scope>
</dependency>
<dependency>
+ <groupId>org.conscrypt</groupId>
+ <artifactId>conscrypt-openjdk-uber</artifactId>
+ <scope>compile</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f322f5ad/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2ConscriptRequestExecutionExample.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2ConscriptRequestExecutionExample.java b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2ConscriptRequestExecutionExample.java
new file mode 100644
index 0000000..82585c8
--- /dev/null
+++ b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2ConscriptRequestExecutionExample.java
@@ -0,0 +1,163 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http.examples;
+
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Future;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpConnection;
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.Message;
+import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncRequester;
+import org.apache.hc.core5.http.nio.AsyncClientEndpoint;
+import org.apache.hc.core5.http.nio.BasicRequestProducer;
+import org.apache.hc.core5.http.nio.BasicResponseConsumer;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
+import org.apache.hc.core5.http2.config.H2Config;
+import org.apache.hc.core5.http2.frame.RawFrame;
+import org.apache.hc.core5.http2.impl.nio.Http2StreamListener;
+import org.apache.hc.core5.http2.impl.nio.bootstrap.H2RequesterBootstrap;
+import org.apache.hc.core5.http2.ssl.ConscryptClientTlsStrategy;
+import org.apache.hc.core5.io.CloseMode;
+import org.apache.hc.core5.ssl.SSLContexts;
+import org.apache.hc.core5.util.Timeout;
+import org.conscrypt.Conscrypt;
+
+/**
+ * This example demonstrates how to execute HTTP/2 requests over TLS connections
+ * with Java 1.7 or Java 1.8 and Conscrypt TLS library
+ */
+public class Http2ConscriptRequestExecutionExample {
+
+ public final static void main(final String[] args) throws Exception {
+
+ // Create and start requester
+ H2Config h2Config = H2Config.custom()
+ .setPushEnabled(false)
+ .build();
+
+ final SSLContext sslContext = SSLContexts.custom()
+ .setProvider(Conscrypt.newProvider())
+ .build();
+
+ final HttpAsyncRequester requester = H2RequesterBootstrap.bootstrap()
+ .setH2Config(h2Config)
+ .setTlsStrategy(new ConscryptClientTlsStrategy(sslContext))
+ .setStreamListener(new Http2StreamListener() {
+
+ @Override
+ public void onHeaderInput(final HttpConnection connection, final int streamId, final List<? extends Header> headers) {
+ for (int i = 0; i < headers.size(); i++) {
+ System.out.println(connection.getRemoteAddress() + " (" + streamId + ") << " + headers.get(i));
+ }
+ }
+
+ @Override
+ public void onHeaderOutput(final HttpConnection connection, final int streamId, final List<? extends Header> headers) {
+ for (int i = 0; i < headers.size(); i++) {
+ System.out.println(connection.getRemoteAddress() + " (" + streamId + ") >> " + headers.get(i));
+ }
+ }
+
+ @Override
+ public void onFrameInput(final HttpConnection connection, final int streamId, final RawFrame frame) {
+ }
+
+ @Override
+ public void onFrameOutput(final HttpConnection connection, final int streamId, final RawFrame frame) {
+ }
+
+ @Override
+ public void onInputFlowControl(final HttpConnection connection, final int streamId, final int delta, final int actualSize) {
+ }
+
+ @Override
+ public void onOutputFlowControl(final HttpConnection connection, final int streamId, final int delta, final int actualSize) {
+ }
+
+ })
+ .create();
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ @Override
+ public void run() {
+ System.out.println("HTTP requester shutting down");
+ requester.close(CloseMode.GRACEFUL);
+ }
+ });
+ requester.start();
+
+ HttpHost target = new HttpHost("https", "nghttp2.org", 443);
+ String[] requestUris = new String[] {"/httpbin/ip", "/httpbin/user-agent", "/httpbin/headers"};
+
+ final CountDownLatch latch = new CountDownLatch(requestUris.length);
+ for (final String requestUri: requestUris) {
+ final Future<AsyncClientEndpoint> future = requester.connect(target, Timeout.ofDays(5));
+ final AsyncClientEndpoint clientEndpoint = future.get();
+ clientEndpoint.execute(
+ new BasicRequestProducer("GET", target, requestUri),
+ new BasicResponseConsumer<>(new StringAsyncEntityConsumer()),
+ new FutureCallback<Message<HttpResponse, String>>() {
+
+ @Override
+ public void completed(final Message<HttpResponse, String> message) {
+ clientEndpoint.releaseAndReuse();
+ HttpResponse response = message.getHead();
+ String body = message.getBody();
+ System.out.println(requestUri + "->" + response.getCode() + " " + response.getVersion());
+ System.out.println(body);
+ latch.countDown();
+ }
+
+ @Override
+ public void failed(final Exception ex) {
+ clientEndpoint.releaseAndDiscard();
+ System.out.println(requestUri + "->" + ex);
+ latch.countDown();
+ }
+
+ @Override
+ public void cancelled() {
+ clientEndpoint.releaseAndDiscard();
+ System.out.println(requestUri + " cancelled");
+ latch.countDown();
+ }
+
+ });
+ }
+
+ latch.await();
+ System.out.println("Shutting down I/O reactor");
+ requester.initiateShutdown();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f322f5ad/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptClientTlsStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptClientTlsStrategy.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptClientTlsStrategy.java
new file mode 100644
index 0000000..1c701e2
--- /dev/null
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptClientTlsStrategy.java
@@ -0,0 +1,104 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http2.ssl;
+
+import java.net.SocketAddress;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.URIScheme;
+import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
+import org.apache.hc.core5.reactor.ssl.SSLBufferMode;
+import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
+import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
+import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * Basic client-side implementation of {@link TlsStrategy} that upgrades to TLS for all endpoints
+ * with {@code HTTPS} scheme.
+ *
+ * @since 5.0
+ */
+public class ConscryptClientTlsStrategy implements TlsStrategy {
+
+ private final SSLContext sslContext;
+ private final SSLBufferMode sslBufferMode;
+ private final SSLSessionInitializer initializer;
+ private final SSLSessionVerifier verifier;
+
+ public ConscryptClientTlsStrategy(
+ final SSLContext sslContext,
+ final SSLBufferMode sslBufferMode,
+ final SSLSessionInitializer initializer,
+ final SSLSessionVerifier verifier) {
+ this.sslContext = Args.notNull(sslContext, "SSL context");
+ this.sslBufferMode = sslBufferMode;
+ this.initializer = initializer;
+ this.verifier = verifier;
+ }
+
+ public ConscryptClientTlsStrategy(
+ final SSLContext sslContext,
+ final SSLSessionInitializer initializer,
+ final SSLSessionVerifier verifier) {
+ this(sslContext, null, initializer, verifier);
+ }
+
+ public ConscryptClientTlsStrategy(
+ final SSLContext sslContext,
+ final SSLSessionVerifier verifier) {
+ this(sslContext, null, null, verifier);
+ }
+
+ public ConscryptClientTlsStrategy(final SSLContext sslContext) {
+ this(sslContext, null, null, null);
+ }
+
+ @Override
+ public boolean upgrade(
+ final TransportSecurityLayer tlsSession,
+ final HttpHost host,
+ final SocketAddress localAddress,
+ final SocketAddress remoteAddress,
+ final Object attachment) {
+ final String scheme = host != null ? host.getSchemeName() : null;
+ if (URIScheme.HTTPS.same(scheme)) {
+ tlsSession.startTls(
+ sslContext,
+ host,
+ sslBufferMode,
+ ConscryptSupport.initialize(attachment, initializer),
+ ConscryptSupport.verify(verifier));
+ return true;
+ }
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f322f5ad/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptServerTlsStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptServerTlsStrategy.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptServerTlsStrategy.java
new file mode 100644
index 0000000..1cea2cb
--- /dev/null
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptServerTlsStrategy.java
@@ -0,0 +1,113 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http2.ssl;
+
+import java.net.SocketAddress;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.nio.ssl.FixedPortStrategy;
+import org.apache.hc.core5.http.nio.ssl.SecurePortStrategy;
+import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
+import org.apache.hc.core5.reactor.ssl.SSLBufferMode;
+import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
+import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
+import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * Basic side-side implementation of {@link TlsStrategy} that upgrades to TLS for endpoints
+ * with the specified local ports.
+ *
+ * @since 5.0
+ */
+public class ConscryptServerTlsStrategy implements TlsStrategy {
+
+ private final SSLContext sslContext;
+ private final SecurePortStrategy securePortStrategy;
+ private final SSLBufferMode sslBufferMode;
+ private final SSLSessionInitializer initializer;
+ private final SSLSessionVerifier verifier;
+
+ public ConscryptServerTlsStrategy(
+ final SSLContext sslContext,
+ final SecurePortStrategy securePortStrategy,
+ final SSLBufferMode sslBufferMode,
+ final SSLSessionInitializer initializer,
+ final SSLSessionVerifier verifier) {
+ this.sslContext = Args.notNull(sslContext, "SSL context");
+ this.securePortStrategy = securePortStrategy;
+ this.sslBufferMode = sslBufferMode;
+ this.initializer = initializer;
+ this.verifier = verifier;
+ }
+
+ public ConscryptServerTlsStrategy(
+ final SSLContext sslContext,
+ final SecurePortStrategy securePortStrategy,
+ final SSLSessionInitializer initializer,
+ final SSLSessionVerifier verifier) {
+ this(sslContext, securePortStrategy, null, initializer, verifier);
+ }
+
+ public ConscryptServerTlsStrategy(
+ final SSLContext sslContext,
+ final SecurePortStrategy securePortStrategy,
+ final SSLSessionVerifier verifier) {
+ this(sslContext, securePortStrategy, null, null, verifier);
+ }
+
+ public ConscryptServerTlsStrategy(final SSLContext sslContext, final SecurePortStrategy securePortStrategy) {
+ this(sslContext, securePortStrategy, null, null, null);
+ }
+
+ public ConscryptServerTlsStrategy(final SSLContext sslContext, final int... securePorts) {
+ this(sslContext, new FixedPortStrategy(securePorts));
+ }
+
+ @Override
+ public boolean upgrade(
+ final TransportSecurityLayer tlsSession,
+ final HttpHost host,
+ final SocketAddress localAddress,
+ final SocketAddress remoteAddress,
+ final Object attachment) {
+ if (securePortStrategy != null && securePortStrategy.isSecure(localAddress)) {
+ tlsSession.startTls(
+ sslContext,
+ host,
+ sslBufferMode,
+ ConscryptSupport.initialize(attachment, initializer),
+ ConscryptSupport.verify(verifier));
+ return true;
+ }
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f322f5ad/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptSupport.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptSupport.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptSupport.java
new file mode 100644
index 0000000..e1a9b9d
--- /dev/null
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ConscryptSupport.java
@@ -0,0 +1,89 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http2.ssl;
+
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLParameters;
+
+import org.apache.hc.core5.net.NamedEndpoint;
+import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
+import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
+import org.apache.hc.core5.reactor.ssl.TlsDetails;
+import org.conscrypt.Conscrypt;
+
+/**
+ * Conscrypt TLS support methods
+ *
+ * @since 5.0
+ */
+public final class ConscryptSupport {
+
+ public static SSLSessionInitializer initialize(
+ final Object attachment,
+ final SSLSessionInitializer initializer) {
+ return new SSLSessionInitializer() {
+
+ @Override
+ public void initialize(final NamedEndpoint endpoint, final SSLEngine sslEngine) {
+ final SSLParameters sslParameters = sslEngine.getSSLParameters();
+ sslParameters.setProtocols(H2TlsSupport.excludeBlacklistedProtocols(sslParameters.getProtocols()));
+ sslParameters.setCipherSuites(H2TlsSupport.excludeBlacklistedCiphers(sslParameters.getCipherSuites()));
+ H2TlsSupport.setEnableRetransmissions(sslParameters, false);
+ final String[] appProtocols = H2TlsSupport.selectApplicationProtocols(attachment);
+ if (Conscrypt.isConscrypt(sslEngine)) {
+ sslEngine.setSSLParameters(sslParameters);
+ Conscrypt.setApplicationProtocols(sslEngine, appProtocols);
+ } else {
+ H2TlsSupport.setApplicationProtocols(sslParameters, appProtocols);
+ sslEngine.setSSLParameters(sslParameters);
+ }
+ if (initializer != null) {
+ initialize(endpoint, sslEngine);
+ }
+ }
+
+ };
+ }
+
+ public static SSLSessionVerifier verify(final SSLSessionVerifier verifier) {
+ return new SSLSessionVerifier() {
+
+ @Override
+ public TlsDetails verify(final NamedEndpoint endpoint, final SSLEngine sslEngine) throws SSLException {
+ TlsDetails tlsDetails = verifier != null ? verifier.verify(endpoint, sslEngine) : null;
+ if (tlsDetails == null && Conscrypt.isConscrypt(sslEngine)) {
+ tlsDetails = new TlsDetails(sslEngine.getSession(), Conscrypt.getApplicationProtocol(sslEngine));
+ }
+ return tlsDetails;
+ }
+
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f322f5ad/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
index e9443eb..df9f49a 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
@@ -374,6 +374,19 @@ public final class H2TlsSupport {
ReflectionSupport.callSetter(sslParameters, "ApplicationProtocols", String[].class, values);
}
+ public static String[] selectApplicationProtocols(final Object attachment) {
+ final HttpVersionPolicy versionPolicy = attachment instanceof HttpVersionPolicy ?
+ (HttpVersionPolicy) attachment : HttpVersionPolicy.NEGOTIATE;
+ switch (versionPolicy) {
+ case FORCE_HTTP_1:
+ return new String[] { ApplicationProtocols.HTTP_1_1.id };
+ case FORCE_HTTP_2:
+ return new String[] { ApplicationProtocols.HTTP_2.id };
+ default:
+ return new String[] { ApplicationProtocols.HTTP_2.id, ApplicationProtocols.HTTP_1_1.id };
+ }
+ }
+
public static SSLSessionInitializer enforceRequirements(
final Object attachment,
final SSLSessionInitializer initializer) {
@@ -385,21 +398,7 @@ public final class H2TlsSupport {
sslParameters.setProtocols(excludeBlacklistedProtocols(sslParameters.getProtocols()));
sslParameters.setCipherSuites(excludeBlacklistedCiphers(sslParameters.getCipherSuites()));
setEnableRetransmissions(sslParameters, false);
- final HttpVersionPolicy versionPolicy = attachment instanceof HttpVersionPolicy ?
- (HttpVersionPolicy) attachment : HttpVersionPolicy.NEGOTIATE;
- final String[] appProtocols;
- switch (versionPolicy) {
- case FORCE_HTTP_1:
- appProtocols = new String[] { ApplicationProtocols.HTTP_1_1.id };
- break;
- case FORCE_HTTP_2:
- appProtocols = new String[] { ApplicationProtocols.HTTP_2.id };
- break;
- default:
- appProtocols = new String[] { ApplicationProtocols.HTTP_2.id, ApplicationProtocols.HTTP_1_1.id };
- break;
- }
- setApplicationProtocols(sslParameters, appProtocols);
+ setApplicationProtocols(sslParameters, selectApplicationProtocols(attachment));
sslEngine.setSSLParameters(sslParameters);
if (initializer != null) {
initializer.initialize(endpoint, sslEngine);
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f322f5ad/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 89de9fb..5a2a96c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -77,6 +77,7 @@
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
+ <conscrypt.version>1.4.1</conscrypt.version>
<junit.version>4.12</junit.version>
<mockito.version>2.23.0</mockito.version>
<slf4j.version>1.7.25</slf4j.version>
@@ -86,6 +87,11 @@
<dependencyManagement>
<dependencies>
<dependency>
+ <groupId>org.conscrypt</groupId>
+ <artifactId>conscrypt-openjdk-uber</artifactId>
+ <version>${conscrypt.version}</version>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>