Connecting using TLS and Node JS via mqtt.js

6,399 views
Skip to first unread message

enco...@gmail.com

unread,
Mar 2, 2016, 3:56:31 PM3/2/16
to emqtt
var connectOptions = {
   
host: "192.168.1.76",
   
port: 8883,
   
protocol: "mqtts",
   
keepalive: 10,
   
clientId: serverUID,
   
protocolId: "MQTT",
   
protocolVersion: 4,
   
clean: true,
   
reconnectPeriod: 2000,
   
connectTimeout: 2000,
   
key: fs.readFileSync("./keys/key.pem"),
   
cert: fs.readFileSync("./keys/cert.pem"),
   
rejectUnauthorized: false,
};

var client = mqtt.connect(connectOptions);




 {mqtts, 8883, [
            %% Size of acceptor pool
            {acceptors, 16},

            %% Maximum number of concurrent clients
            {max_clients, 512},

            %% Socket Access Control
            {access, [{allow, all}]},

            %% SSL certificate and key files
            {ssl, [{certfile, "etc/ssl/crt.pem"},
                   {keyfile,  "etc/ssl/key.pem"}]},

            %% Socket Options
            {sockopts, [
                {backlog, 1024}
                %{buffer, 4096},
            ]}
        ]},
        %% WebSocket over HTTPS Listener
        {https, 8083, [
          %% Size of acceptor pool
          {acceptors, 4},
          %% Maximum number of concurrent clients
          {max_clients, 512},
          %% Socket Access Control
          {access, [{allow, all}]},
          %% SSL certificate and key files
          {ssl, [{certfile, "etc/ssl/crt.pem"},
                 {keyfile,  "etc/ssl/key.pem"}]},
          %% Socket Options
          {sockopts, [
              %{buffer, 4096},
              {backlog, 1024}
          ]}
        ]}




I am using self-signed certificates and have already verified that valid communication using a node js server and client using the same certificates and keys.  However, I cannot connect to the emqttd broker via TLS.  I don't receive an error message in my node app or see any errors in the emqttd logs.  Does anyone have any experience with Node JS and emqttd using TLS?  I have no trouble using TCP.  

saha....@gmail.com

unread,
Mar 6, 2017, 7:43:22 PM3/6/17
to emqtt
It might help if you take a look at the page: https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-the-mosquitto-mqtt-messaging-broker-on-ubuntu-16-04
There he clearly specifies how he connects using:

  • mosquitto_pub -h mqtt.example.com -t test -m "hello again" -p 8883 --capath /etc/ssl/certs/ -u "sammy" -P "password"


And this works from a remote server as well. It means even for cert based authentication the username/password needs to be provided for mqtt.
Now please try to follow this pointer. Incase if you have already solved the problem would like to know how. 

regards.

Viswadeep V

unread,
Jun 30, 2023, 10:27:33 AM6/30/23
to emqtt
Were you able to successfully connect.. I am not getting any error either but no data as well..
Reply all
Reply to author
Forward
0 new messages