在Netty使用中TLSv1.3


1 Why

  TLSv1.3相比TLSv1.2性能更好,安全性更高。

   參考文章:《TLS 1.3 VS TLS 1.2,讓你明白 TLS 1.3 的強大

 

TLS 1.3 與之前的協議有較大差異,主要在於:

  • 支持 0-RTT 數據傳輸,在建立連接時節省了往返時間
  • ServerHello 之后的所有握手消息采取了加密操作,可見明文大大減少
  • 不再允許對加密報文進行壓縮、不再允許雙方發起重協商
  • 引入了新的密鑰協商機制—PSK
  • 廢棄了3DES、RC4、AES-CBC 等加密組件,廢棄了 SHA1、MD5 等哈希算法
  • DSA證書不再允許在 TLS 1.3 中使用

2 How

  關鍵點是版本號,Netty版本使用4.1.54以上,SSL模塊使用boringssl 2.0.34以上。如下所示:

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-all</artifactId>
    <version>4.1.54.Final</version>
</dependency>

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-tcnative-boringssl-static</artifactId>
    <version>2.0.34.Final</version>
</dependency>

 

3 效果確認

Netty日志輸出

io.netty.handler.ssl.SslHandler - [id: 0x35537343, L:/127.0.0.1:26911 - R:/127.0.0.1:9443] HANDSHAKEN: protocol:TLSv1.3 cipher suite:TLS_AES_128_GCM_SHA256

可以看到它用的是TLSv1.3,加密套件為TLS_AES_128_GCM_SHA256

 

Wireshark抓包

image

  可以看到,在第2個報文中就出現了Application Data,這就是0-RTT。TLSv1.3跟TLSv1.2的一個重要區別是它縮短了握手時間。

  需要注意的是,Wireshark要用3.4.2以上的版本,否則可能無法解析TLSv1.3的報文。

4 參考

Netty在github上的相關提交說明: 

Netty 4.1.52-Final version has supported TLSv1.3 as default, refer here for more info

  https://github.com/netty/netty/commit/b1d3aad404a39143da7a86c121d60f35c0d21108

Motiviation:
When TLSv1.3 was introduced almost 2 years ago, it was decided to disable it by default, even when it's supported by the underlying TLS implementation.
TLSv13 is pretty stable now in Java (out of the box in Java 11, OpenJSSE for Java 8, BoringSSL and OpenSSL) and may be enabled by default.
Modifications:
Ensure TLSv13 is enabled by default when the underyling JDK SSLEngine implementation enables it as well
Result:
TLSv1.3 is now enabled by default, so users don't have to explicitly enable it.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM