11package org .logstash .plugins .inputs .http .util ;
22
33import io .netty .buffer .ByteBufAllocator ;
4+ import io .netty .channel .socket .SocketChannel ;
45import io .netty .handler .ssl .SslContext ;
56import io .netty .handler .ssl .SslHandler ;
67import org .apache .logging .log4j .LogManager ;
78import org .apache .logging .log4j .Logger ;
89
910import javax .net .ssl .SSLEngine ;
11+ import javax .net .ssl .SSLParameters ;
12+ import java .net .InetSocketAddress ;
1013import java .util .Arrays ;
1114
1215public class SslHandlerProvider {
@@ -28,14 +31,20 @@ public SslHandlerProvider(SslContext sslContext) {
2831 this .sslContext = sslContext ;
2932 }
3033
31- public SslHandler getSslHandler (ByteBufAllocator bufferAllocator ) {
34+ public SslHandler getSslHandler (final SocketChannel socketChannel ) {
35+ final InetSocketAddress remoteAddress = socketChannel .remoteAddress ();
36+ final String peerHost = remoteAddress .getHostString ();
37+ final int peerPort = remoteAddress .getPort ();
38+ final SslHandler sslHandler = sslContext .newHandler (socketChannel .alloc (), peerHost , peerPort );
3239
33- SslHandler sslHandler = sslContext .newHandler (bufferAllocator );
34-
35- SSLEngine engine = sslHandler .engine ();
40+ final SSLEngine engine = sslHandler .engine ();
3641 engine .setEnabledProtocols (protocols );
3742 engine .setUseClientMode (false );
3843
44+ final SSLParameters sslParameters = engine .getSSLParameters ();
45+ sslParameters .setEndpointIdentificationAlgorithm ("HTTPS" );
46+ engine .setSSLParameters (sslParameters );
47+
3948 if (verifyMode == SslClientVerifyMode .FORCE_PEER ) {
4049 // Explicitly require a client certificate
4150 engine .setNeedClientAuth (true );
0 commit comments