在Netty使用中TLSv1.3

何德海發表於2021-01-05

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的一個重要區別是它縮短了握手時間。

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.

相關文章