如何获取 HiveMQ Client 中使用的密码套件?
How to get the cipher suite being used in HiveMQ Client?
我将 HiveMQ 服务器配置为识别 TLS 并创建了 TLS 通信。我想打印出正在使用的密码套件。我使用了 getSslConfig() 但我最终将其作为输出:
Optional[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
returns一个Optional
。所以要获得密码套件:
client.getConfig().getSslConfig().get().getCipherSuites()
我将 HiveMQ 服务器配置为识别 TLS 并创建了 TLS 通信。我想打印出正在使用的密码套件。我使用了 getSslConfig() 但我最终将其作为输出:
Optional[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
returns一个Optional
。所以要获得密码套件:
client.getConfig().getSslConfig().get().getCipherSuites()