From f7d357312fa634431aa4af180691cb12efacd902 Mon Sep 17 00:00:00 2001 From: Aayush Atharva Date: Fri, 10 Jan 2020 21:04:06 +0530 Subject: [PATCH] Add TLS SNI Extension in HTTP/2 Client request. (#9937) Motivation: Since "Http2ClientInitializer" creates a new SSLContext Handler without specifying Host, Netty does not add SNI Extension in TLS Client Hello request and the request fails if the server uses SNI to establish TLS Connection. Modification: Specified Host while creating a new SSLContext Handler in "Http2ClientInitializer". Result: Netty adds SNI Extension of the Host Specified in new SSLContext Handler and sends it with TLS Client Hello request. Fixes #9815. --- .../http2/helloworld/client/Http2ClientInitializer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/example/src/main/java/io/netty/example/http2/helloworld/client/Http2ClientInitializer.java b/example/src/main/java/io/netty/example/http2/helloworld/client/Http2ClientInitializer.java index 0fd36416cb4..f4fa9d20105 100644 --- a/example/src/main/java/io/netty/example/http2/helloworld/client/Http2ClientInitializer.java +++ b/example/src/main/java/io/netty/example/http2/helloworld/client/Http2ClientInitializer.java @@ -98,7 +98,8 @@ protected void configureEndOfPipeline(ChannelPipeline pipeline) { */ private void configureSsl(SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); - pipeline.addLast(sslCtx.newHandler(ch.alloc())); + // Specify Host in SSLContext New Handler to add TLS SNI Extension + pipeline.addLast(sslCtx.newHandler(ch.alloc(), Http2Client.HOST, Http2Client.PORT)); // We must wait for the handshake to finish and the protocol to be negotiated before configuring // the HTTP/2 components of the pipeline. pipeline.addLast(new ApplicationProtocolNegotiationHandler("") {