From 152b491da5eec05dfbbcf64eae2f78fa0922d22b Mon Sep 17 00:00:00 2001 From: clatko Date: Tue, 13 Nov 2018 17:02:32 -0800 Subject: [PATCH 1/3] allow for sni enabled endpoints re issue #337 --- .../netty/http/LoadBalancingHttpClient.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ribbon-transport/src/main/java/com/netflix/ribbon/transport/netty/http/LoadBalancingHttpClient.java b/ribbon-transport/src/main/java/com/netflix/ribbon/transport/netty/http/LoadBalancingHttpClient.java index f21244c3..da279c88 100644 --- a/ribbon-transport/src/main/java/com/netflix/ribbon/transport/netty/http/LoadBalancingHttpClient.java +++ b/ribbon-transport/src/main/java/com/netflix/ribbon/transport/netty/http/LoadBalancingHttpClient.java @@ -38,8 +38,12 @@ import io.reactivex.netty.protocol.http.client.HttpClientResponse; import io.reactivex.netty.servo.http.HttpClientListener; +import java.net.MalformedURLException; import java.net.URI; +import java.net.URL; import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; @@ -48,7 +52,10 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import javax.net.ssl.SNIHostName; +import javax.net.ssl.SNIServerName; import javax.net.ssl.SSLEngine; +import javax.net.ssl.SSLParameters; import rx.Observable; import rx.functions.Func1; @@ -511,6 +518,23 @@ protected HttpClient createRxClient(Server server) { @Override public SSLEngine createSSLEngine(ByteBufAllocator allocator) { SSLEngine myEngine = super.createSSLEngine(allocator); + + URL url = null; + if(null!=getRxClients()) { + try { + Server server = getRxClients().entrySet().iterator().next().getKey(); + url = new URL(server.getScheme() + "://" + server.getHost()); + + SSLParameters sslParameters = new SSLParameters(); + List sniServerNames = new ArrayList<>(); + sniServerNames.add(new SNIHostName(url.getHost())); + sslParameters.setServerNames(sniServerNames); + myEngine.setSSLParameters(sslParameters); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + } + myEngine.setUseClientMode(true); return myEngine; } From 83fb597c323ca218e12463a71c59e01f46161adf Mon Sep 17 00:00:00 2001 From: clatko Date: Wed, 26 Dec 2018 14:56:49 -0800 Subject: [PATCH 2/3] add logger; allow for multiple hosts to be sent via sni --- .../netty/http/LoadBalancingHttpClient.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ribbon-transport/src/main/java/com/netflix/ribbon/transport/netty/http/LoadBalancingHttpClient.java b/ribbon-transport/src/main/java/com/netflix/ribbon/transport/netty/http/LoadBalancingHttpClient.java index da279c88..ce96a890 100644 --- a/ribbon-transport/src/main/java/com/netflix/ribbon/transport/netty/http/LoadBalancingHttpClient.java +++ b/ribbon-transport/src/main/java/com/netflix/ribbon/transport/netty/http/LoadBalancingHttpClient.java @@ -91,7 +91,7 @@ public class LoadBalancingHttpClient extends LoadBalancingRxClientWithPool implements HttpClient { private static final HttpClientConfig DEFAULT_RX_CONFIG = HttpClientConfig.Builder.newDefaultConfig(); - + private static final Logger logger = LoggerFactory.getLogger(LoadBalancingRxClient.class); private final String requestIdHeaderName; private final HttpRequestIdProvider requestIdProvider; private final List, HttpClientResponse>> listeners; @@ -522,16 +522,16 @@ public SSLEngine createSSLEngine(ByteBufAllocator allocator) { URL url = null; if(null!=getRxClients()) { try { - Server server = getRxClients().entrySet().iterator().next().getKey(); - url = new URL(server.getScheme() + "://" + server.getHost()); - SSLParameters sslParameters = new SSLParameters(); List sniServerNames = new ArrayList<>(); - sniServerNames.add(new SNIHostName(url.getHost())); + for(Server server: getRxClients().keySet()) { + url = new URL(server.getScheme() + "://" + server.getHost()); + sniServerNames.add(new SNIHostName(url.getHost())); + } sslParameters.setServerNames(sniServerNames); myEngine.setSSLParameters(sslParameters); } catch (MalformedURLException e) { - e.printStackTrace(); + logger.error("MalformedURL: " + url.toString()); } } From 35d53b7e3815efee34b6828e0c294fb4195a1da2 Mon Sep 17 00:00:00 2001 From: clatko Date: Tue, 8 Jan 2019 14:19:38 -0800 Subject: [PATCH 3/3] fix logger --- .../ribbon/transport/netty/http/LoadBalancingHttpClient.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ribbon-transport/src/main/java/com/netflix/ribbon/transport/netty/http/LoadBalancingHttpClient.java b/ribbon-transport/src/main/java/com/netflix/ribbon/transport/netty/http/LoadBalancingHttpClient.java index ce96a890..2d7eb4e3 100644 --- a/ribbon-transport/src/main/java/com/netflix/ribbon/transport/netty/http/LoadBalancingHttpClient.java +++ b/ribbon-transport/src/main/java/com/netflix/ribbon/transport/netty/http/LoadBalancingHttpClient.java @@ -57,6 +57,9 @@ import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLParameters; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import rx.Observable; import rx.functions.Func1; import rx.functions.Func2; @@ -91,7 +94,7 @@ public class LoadBalancingHttpClient extends LoadBalancingRxClientWithPool implements HttpClient { private static final HttpClientConfig DEFAULT_RX_CONFIG = HttpClientConfig.Builder.newDefaultConfig(); - private static final Logger logger = LoggerFactory.getLogger(LoadBalancingRxClient.class); + private static final Logger logger = LoggerFactory.getLogger(LoadBalancingHttpClient.class); private final String requestIdHeaderName; private final HttpRequestIdProvider requestIdProvider; private final List, HttpClientResponse>> listeners;