1
1
package org .logstash .plugins .inputs .http .util ;
2
2
3
3
import io .netty .buffer .ByteBufAllocator ;
4
+ import io .netty .channel .socket .SocketChannel ;
4
5
import io .netty .handler .ssl .SslContext ;
5
6
import io .netty .handler .ssl .SslHandler ;
6
7
import org .apache .logging .log4j .LogManager ;
7
8
import org .apache .logging .log4j .Logger ;
8
9
9
10
import javax .net .ssl .SSLEngine ;
11
+ import javax .net .ssl .SSLParameters ;
12
+ import java .net .InetSocketAddress ;
10
13
import java .util .Arrays ;
11
14
12
15
public class SslHandlerProvider {
@@ -28,14 +31,20 @@ public SslHandlerProvider(SslContext sslContext) {
28
31
this .sslContext = sslContext ;
29
32
}
30
33
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 );
32
39
33
- SslHandler sslHandler = sslContext .newHandler (bufferAllocator );
34
-
35
- SSLEngine engine = sslHandler .engine ();
40
+ final SSLEngine engine = sslHandler .engine ();
36
41
engine .setEnabledProtocols (protocols );
37
42
engine .setUseClientMode (false );
38
43
44
+ final SSLParameters sslParameters = engine .getSSLParameters ();
45
+ sslParameters .setEndpointIdentificationAlgorithm ("HTTPS" );
46
+ engine .setSSLParameters (sslParameters );
47
+
39
48
if (verifyMode == SslClientVerifyMode .FORCE_PEER ) {
40
49
// Explicitly require a client certificate
41
50
engine .setNeedClientAuth (true );
0 commit comments