I'm trying to switch all my communication in a secure way, and the websocket is a realy big deal for me.
I using mosquitto in backend to serve data, and I want handle wss connection. unfortunatly, all my connection failed with the
WebSocket connection to 'wss://192.168.x.PORT/mqtt' failed
Here is my mosquitto config file :
user daemon
#Standart port for encrypted MQTT
listener 8883
protocol mqtt
# cafile /etc/mosquitto/tls/ca/ca.crt
# certfile /etc/mosquitto/tls/broker/broker.crt
# keyfile /etc/mosquitto/tls/broker/broker.key
# require_certificate true
#old port encrypted in case
listener 1883
protocol mqtt
# cafile /etc/mosquitto/tls/ca/ca.crt
# certfile /etc/mosquitto/tls/broker/broker.crt
# keyfile /etc/mosquitto/tls/broker/broker.key
#require_certificate true
listener 9001
protocol websockets
cafile /etc/mosquitto/tls/m2mqtt_ca.crt
certfile /etc/mosquitto/tls/borker/m2mqtt_srv.crt
keyfile /etc/mosquitto/tls/borker/m2mqtt_srv.key
tls_version tlsv1.2
allow_anonymous true
require_certificate false
The browser connect to the port 9001 and my local server who bring data connected on localhost:8883
Here is the mosquitto logs :
1970-02-26_21:59:53.65784 4917593: mosquitto version 1.4.14 (build date 2021-12-16 14:48:43+0100) starting
1970-02-26_21:59:53.65949 4917593: Config loaded from /etc/mosquitto/mosquitto.conf.
1970-02-26_21:59:53.68685 4917593: Opening ipv4 listen socket on port 8883.
1970-02-26_21:59:53.69108 4917593: Opening ipv6 listen socket on port 8883.
1970-02-26_21:59:53.69356 4917593: Opening ipv4 listen socket on port 1883.
1970-02-26_21:59:53.69875 4917593: Opening ipv6 listen socket on port 1883.
1970-02-26_21:59:53.71940 4917593: Opening websockets listen socket on port 9001.
1970-02-26_22:00:08.62160 4917608: New connection from 127.0.0.1 on port 8883.
1970-02-26_22:00:08.63007 4917608: New client connected from 127.0.0.1 as butler (c1, k0).
1970-02-26_22:00:08.63265 4917608: Sending CONNACK to butler (0, 0)
1970-02-26_22:00:08.65672 4917608: Received SUBSCRIBE from butler
1970-02-26_22:00:08.65681 4917608: butler/settings/set (QoS 0)
1970-02-26_22:00:08.65685 4917608: butler 0 butler/settings/set
1970-02-26_22:00:08.65688 4917608: Sending SUBACK to butler
1970-02-26_22:00:08.66205 4917608: Received PUBLISH from butler (d0, q0, r1, m0, 'butler/version', ... (7 bytes))
1970-02-26_22:00:08.69587 4917608: Received PUBLISH from butler (d0, q0, r0, m0, 'butler/settings', ... (573 bytes))
1970-02-26_22:00:09.19902 4917609: Received PUBLISH from butler (d0, q0, r0, m0, 'butler/settings', ... (28373 bytes))
1970-02-26_22:00:09.21120 4917609: Received PUBLISH from butler (d0, q0, r0, m0, 'butler/settings', ... (43 bytes))
1970-02-26_22:00:09.21305 4917609: Received PUBLISH from butler (d0, q0, r0, m0, 'butler/settings', ... (67 bytes))
1970-02-26_22:00:09.21504 4917609: Received PUBLISH from butler (d0, q0, r0, m0, 'butler/settings', ... (83 bytes))
Here is my js code to connect to the websocket :
ClientImpl.prototype._doConnect = function(wsurl) {
// When the socket is open, this client will send the CONNECT WireMessage using the saved parameters.
this.connectOptions.useSSL = true;
if (this.connectOptions.useSSL) {
var uriParts = wsurl.split(":");
uriParts[0] = "wss";
wsurl = uriParts.join(":");
}
this._wsuri = wsurl;
this.connected = false;
const options = {
rejectUnauthorized: false
}
if (this.connectOptions.mqttVersion < 4) {
this.socket = new WebSocket(wsurl, ["mqttv3.1"], options);
} else {
this.socket = new WebSocket(wsurl, ["mqtt"], options);
}
}
EDIT
I check in wireshark, the connection (SYN,ACK) done the job, but the client hello in tls failed...
Sorry I cant convert in text mode
EDIT 2
I worked on my problem and I made a ws connection to mosquitto (I enable the network.websocket.allowInsecureFromHTTPS parameter in firefox) and it works ! So i identify the problem : mosquitto doesn't activate wss... I change the config file also
How can I fix this ? Thanks in advance !