2017-03-07 130 views
0

我的Netty应用程序在JDK1.8上作为TCP套接字服务器运行。 JDK 1.8支持TLS 1.0,TLS 1.1和TLS 1.2。如何强制netty服务器通过TLS 1.2进行通信?

我们希望在服务器端通过TLSv1.2强制实现TCP服务器和客户端之间的通信(不需要使用低层协议)。

下面的代码片段:

{ 
KeyStore ks = KeyStore.getInstance("JKS"); 
     ks.load(new FileInputStream("JKS location"), "password"); 
     KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); 
     kmf.init(ks, "password".toCharArray()); 
     SslContext sslContext = SslContextBuilder.forServer(kmf).build(); 
     pipeline.addLast(sslContext.newHandler(socketChannel.alloc())); 
} 

我们怎么能强制网状服务器通过仅TLS1.2协议进行通信?

回答

1

只需正确配置的SSLEngine:

SslHandler handler = sslContext.newHandler(socketChannel.alloc()); 
handler.engine().setEnabledProtocols(new String[] {"TLSv1.2"}); 
... 
+0

感谢诺曼。这是按预期工作的。 –

相关问题