B4J Question [B4X] jMQTT - TLS with self signed certificates

JDR

Member
Hello

I want to use an encryptes MQTT connection in all my B4J projects.
My local Mosquitto MQTT broker has been configured to use TLS with a server and client certificate, both self signed, but there is no option in the library to parse the certificate to setup the connection.
I followed this tutorial in order to accept self signed certificate with the TrustAll method that was provided there, but no succes.
I also configured Mosquitto with the following line require_certificate false that I got from this tutorial, but that also didn't help.

The application itselfs does not make a correct connection to the broker, not even a failed connection was found in the Mosquitto log files.

The only log message I receive from jMQTT is this:

B4X:
Waiting for debugger to connect...
shell switching to alternate port: 9054
shell switching to alternate port: 9055
Program started.
13/07/2022 12:15:14 Succesfully connected to MQTTBROKER mosquitto-mqtt-001
Logging disabled
13/07/2022 12:15:15 Connection to MQTTBROKER is false
13/07/2022 12:15:15 Error message: java.io.EOFException$
(EOFException) java.io.EOFException
13/07/2022 12:15:20 Trying to reconnect to MQTT broker mosquitto-mqtt-001
13/07/2022 12:15:20 Succesfully connected to MQTTBROKER mosquitto-mqtt-001
13/07/2022 12:15:21 Connection to MQTTBROKER is false
13/07/2022 12:15:21 Error message: java.io.EOFException$
(EOFException) java.io.EOFException

I provided the MQTTConnector module as an attachment of this post.
All the variables from the connection are parsed out of a config file.

Can somebody help me further with this?

Thank you in advance!
 

Attachments

  • MqttConnector.bas
    4.5 KB · Views: 243
Last edited:

MicroDrie

Well-Known Member
Licensed User
Longtime User
13/07/2022 12:15:15 Error message: java.io.EOFException$
(EOFException) java.io.EOFException
I don't think someone can help you with the Java End Off File error without the main program code, and further I don't think it has anything to do with the MQTT. It look to me that it has to do something with writing and read back the file content of your config file. The best advice is to single step to the subroutine that reads your config file and look when the error arise.

Update perhaps its handy to write your config file as a JSON file and get the required program code from JSON Tree Example
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
...and.. some info for general configuration and config of mosquito...


caution with: per_listener_settings [ true | false ]

If it is "true" then you must do that i ve said in post #4 - every port will have different configuration in the same config...
 
Upvote 0

JDR

Member
I don't think someone can help you with the Java End Off File error without the main program code, and further I don't think it has anything to do with the MQTT. It look to me that it has to do something with writing and read back the file content of your config file. The best advice is to single step to the subroutine that reads your config file and look when the error arise.

Update perhaps its handy to write your config file as a JSON file and get the required program code from JSON Tree Example

Hi

Thank you or your reply.
I uploaded my main code as well.
The config file is not written in JSON, just plain config file.
With a normal unencrypted tcp connection to the broker everything works perfectly.


I know how to configure my Mosquitto mqtt broker with tls certificates.
But in my use case, I use self-signed certificates because the broker doesn't need to be reached from the internet.

The problem I'm concerning is that the jMQTT library support TLS, but I couldn't find how I could import a certificate in order to create a secure connection with my broker.
I did it before in Pyhton and Micropython with the paho-mqtt library.
From other forum posts and documentation I noticed that the jMQTT library is based on the paho-mqtt library.
I was wondering how the TLS implementation for MQTT can be used in B4J programs.

Can somebody help me further with this?

Thank you in advance!
 

Attachments

  • main.bas
    1.8 KB · Views: 208
Upvote 0
Top