使用 TLSv1.3 时是否可以为 TLS 连接设置密码套件?

Is it possible to set the set cipher suite for a TLS connection when using TLSv1.3?

我正在开发一个应用程序,我要在两个设备之间建立 TLS 连接。我正在使用 TLSv1.3,但是当我尝试像这样设置密码套件时:

String[] protocolCHACHA = new String[1];
protocolCHACHA[0]= "TLS_CHACHA20_POLY1305_SHA256";

String [] tlsVersion = new String[1];
tlsVersion [0] = "TLSv1.3";

SSLServerSocket serverSocket = (SSLServerSocket) serverSSLContext.getServerSocketFactory().createServerSocket(0);
serverSocket.setEnabledProtocols(tlsVersion);   
serverSocket.setEnabledCipherSuites(protocolCHACHA);

我得到一个javax.net.ssl.SSLHandshakeException

   2021-05-05 11:40:19.131 2932-15842/com.example.testaware W/System.err: javax.net.ssl.SSLHandshakeException: Handshake failed
2021-05-05 11:40:19.131 2932-15842/com.example.testaware W/System.err:     at com.android.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(ConscryptFileDescriptorSocket.java:305)
2021-05-05 11:40:19.131 2932-15842/com.example.testaware W/System.err:     at com.android.org.conscrypt.ConscryptFileDescriptorSocket.waitForHandshake(ConscryptFileDescriptorSocket.java:510)
2021-05-05 11:40:19.131 2932-15842/com.example.testaware W/System.err:     at com.android.org.conscrypt.ConscryptFileDescriptorSocket.getInputStream(ConscryptFileDescriptorSocket.java:473)
2021-05-05 11:40:19.131 2932-15842/com.example.testaware W/System.err:     at com.example.testaware.AppServer.lambda$new[=11=]$AppServer(AppServer.java:124)
2021-05-05 11:40:19.131 2932-15842/com.example.testaware W/System.err:     at com.example.testaware.-$$Lambda$AppServer$vHnVsGrXrL1ybKsPtFi9r-AJTKQ.run(Unknown Source:8)
2021-05-05 11:40:19.131 2932-15842/com.example.testaware W/System.err:     at java.lang.Thread.run(Thread.java:919)
2021-05-05 11:40:19.131 2932-15842/com.example.testaware W/System.err: Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x7282fc4908: Failure in SSL library, usually a protocol error
2021-05-05 11:40:19.131 2932-15842/com.example.testaware W/System.err: error:100000ae:SSL routines:OPENSSL_internal:NO_CERTIFICATE_SET (external/boringssl/src/ssl/tls13_server.cc:689 0x7278a83e6b:0x00000000)
2021-05-05 11:40:19.131 2932-15842/com.example.testaware W/System.err:     at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
2021-05-05 11:40:19.131 2932-15842/com.example.testaware W/System.err:     at com.android.org.conscrypt.NativeSsl.doHandshake(NativeSsl.java:387)
2021-05-05 11:40:19.131 2932-15842/com.example.testaware W/System.err:     at com.android.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(ConscryptFileDescriptorSocket.java:234)
2021-05-05 11:40:19.131 2932-15842/com.example.testaware W/System.err:  ... 5 more

有人知道为什么吗?无法决定使用哪个密码套件吗?如果我删除 serverSocket.setEnabledCipherSuites(protocolCHACHA); 我没有异常。

根据 Conscrypt 的 Capabilities 文档,

The TLS 1.3 cipher suites cannot be customized; they are always enabled when TLS 1.3 is enabled, and any attempt to disable them via a call to setEnabledCipherSuites() is ignored.

虽然,我实际上是通过谷歌搜索我收到的相同“NO_CERTIFICATE_SET”错误消息找到了这个线程。我的代码也试图设置密码,所以我认为你刚刚解决了我的问题。