我将HiveMQ服务器配置为识别TLS,并创建了TLS通信。我想打印出正在使用的密码套件。我使用过getSslConfig(),但最终将其作为输出:
Optional[com.hivemq.client.internal.mqtt.MqttClientSslConfigImpl@2710]
我知道getCipherSuites()
中有一个MqttClientSslConfig.java
方法,但是我还没有找到使用它的方法。作为后续措施,我将如何指定使用特定的密码套件?到目前为止,我一直在使用默认的默认值,就像这样:
代码(如何指定特定的密码套件?):
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());
答案 0 :(得分:1)
您可以像这样配置特定的密码套件:
Mqtt5Client.builder()
...
.sslConfig()
.cipherSuites(Arrays.asList("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"))
.applySslConfig()
...
getSslConfig
返回一个Optional
。因此,要获得密码套件:
client.getConfig().getSslConfig().get().getCipherSuites()