1

我知道可以使用全局属性强制执行特定的 TLS 版本,如下所示:

  • 带代码:System.setProperty("jdk.tls.client.protocols", "TLSv1.2");
  • 或从命令行:java -Djdk.tls.client.protocols=TLSv1.2 ...

有没有办法在每个上下文/引擎的 SSL 基础上更精细地做到这一点?例如,如果我想阻止在特定上下文中使用 TLSv1.3,并且只允许最高 TLSv1.2 的协议,该怎么办?

我以为是这样的:

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
...
var sslContext = SSLContext.getInstance("TLSv1.2");
var sslEngine = sslContext.createSSLEngine();
...

但我的测试仍然显示 TLSv1.3 在 SSL 握手阶段蔓延。事实上,Java 16+ java doc 解释说“协议”参数保证提供者支持请求的 TLS 版本,但不一定限制提供者更高:

SSLContext.getProtocol(String protocol);

文档:

protocol – the standard name of the requested protocol. See the SSLContext section in the Java Security Standard Algorithm Names Specification for information about standard protocol names.

PS:我在这里找到了更接近我需要回答的内容: SSLContext.getInstance("TLS") 是否也支持 TLS v1.1 和 TLS v1.2?

To use TLSv1.2 try to use below code:
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(null, null, null);

假设答案是正确的(我认为不是),但是我确实想从特定的信任库和密钥库管理器初始化我的上下文,传递 NULL 对我来说是不可接受的。

4

0 回答 0