简体   繁体   中英

Connecting to an MQTT broker using TLS with a Pre-shared Key

I am trying to connect to an MQTT broker using a Java console application, with the broker only supporting TLS with a pre-shared key (not SSL or other client certificate file options). I have the following dependencies:

<dependency>
    <groupId>org.eclipse.paho</groupId>
    <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
    <version>1.1.0</version>
</dependency>
<dependency>
    <groupId>org.bouncycastle</groupId>
    <artifactId>bcprov-jdk15on</artifactId>
    <version>1.56</version>
</dependency>

I am using the following page as a starting point: http://www.hivemq.com/blog/mqtt-client-library-encyclopedia-eclipse-paho-java

And they have the following section for an SSL connection:

MqttClient client = new MqttClient("ssl://yourbroker:8883", MqttClient.generateClientId(), new MemoryPersistence());

SSLContext sslContext = SSLContext.getInstance("SSL");
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore keyStore = readKeyStore();
trustManagerFactory.init(keyStore);
sslContext.init(null, trustManagerFactory.getTrustManagers(), new SecureRandom());

MqttConnectOptions options = new MqttConnectOptions();
options.setSocketFactory(sslContext.getSocketFactory());

client.connect(options);

What I really need is a sample that uses TLS with a pre-shared key, I have done quite a bit of searching and can find a TLS PSK sample ( http://tiebing.blogspot.com.au/2013/09/java-bouncy-castle-tls-psk-example.html ) but do not know how to connect the MQTT client to that TLS PSK example.

Any assistance would be greatly appreciated, thanks!

I never found a resolution to this, however using Mosquitto as a broker was a suitable workaround:

Mosquitto

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM