gpt4 book ai didi

java - 如何获取 HiveMQ 客户端中使用的密码套件?

转载 作者:行者123 更新时间:2023-11-30 05:35:01 29 4
gpt4 key购买 nike

我将 HiveMQ 服务器配置为识别 TLS 并创建了 TLS 通信。我想打印出正在使用的密码套件。我已经使用了 getSslConfig() 但我最终得到了它作为输出:

可选[com.hivemq.client.internal.mqtt.MqttClientSslConfigImpl@2710]

我知道 MqttClientSslConfig.java 中有一个 getCipherSuites() 方法,但我一直无法找到使用它的方法。作为后续,我将如何指定使用特定的密码套件?到目前为止,我只是使用默认的,如下所示:

代码(如何指定特定的密码套件?):

Mqtt5BlockingClient subscriber = Mqtt5Client.builder()
.identifier(UUID.randomUUID().toString()) // the unique identifier of the MQTT client. The ID is randomly generated between
.serverHost("localhost") // the host name or IP address of the MQTT server. Kept it localhost for testing. localhost is default if not specified.
.serverPort(8883) // specifies the port of the server
.addConnectedListener(context -> ClientConnectionRetreiver.printConnected("Subscriber1")) // prints a string that the client is connected
.addDisconnectedListener(context -> ClientConnectionRetreiver.printDisconnected("Subscriber1")) // prints a string that the client is disconnected
.sslWithDefaultConfig() // << How can I specify a particular cipher suite?
.buildBlocking(); // creates the client builder

代码(我如何尝试获取 SSL 配置):

Mqtt5ClientConfig clientConfig = client.getConfig();
System.out.println(" Ssl Configuration: " + clientConfig.getSslConfig());

最佳答案

您可以像这样配置特定的密码套件:

Mqtt5Client.builder()
...
.sslConfig()
.cipherSuites(Arrays.asList("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"))
.applySslConfig()
...

getSslConfig 返回一个Optional。因此,要获取密码套件:

client.getConfig().getSslConfig().get().getCipherSuites()

关于java - 如何获取 HiveMQ 客户端中使用的密码套件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56826649/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com