Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Enable connections to secure MQTT brokers #87

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ldstein
Copy link
Contributor

@ldstein ldstein commented Jan 10, 2014

This PR adds support for connecting to a MQTT broker which requires SSL/TLS authentication.

Also a bump of async_bench to allow dev-dependencies to install in a Windows environment.

Pretty much addresses issue #78

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.07%) when pulling 7b4da72 on ldstein:master into 1a7f48d on mcollina:master.

@mcollina
Copy link
Collaborator

@ldstein I'm slightly against this. MQTT.js is going to deprecate the old SSL API in v0.4.0 and remove 'keyPath' and 'certPath' in favor of buffers.
mqttjs/MQTT.js#145
That PR is missing the 'client' part -- the server has already been done. If you help with that, we can merge and release MQTT.js 0.4.0.

@adamvr is it ok for you?

@ldstein Can you please add test for this in any case?

@mcollina
Copy link
Collaborator

Ouch, this is really really old. However, I should get it in. Anybody that would like to update it to v2?

This would need to be updated to MQTT.js v1.x.

@ldstein
Copy link
Contributor Author

ldstein commented Feb 15, 2019

Happy 2019. I believe this PR can be safely closed :)

For anyone reading this, below is an example to connect to a secure MQTT broker configured with a certificate derived from a self-signed CA (tested with ascoltatori 4.3.0):

const mqtt        = require('mqtt');
const ascoltatori = require('ascoltatori');
const fs          = require('fs');

const settings = 
{
    type: 'mqtt',
    json: true,
    mqtt: mqtt,
    url : 'mqtts://localhost:8883',
    // Plus any additional required TLS configuration
    // as described by https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options
    ca  : [fs.readFileSync('certs/ca.crt')]
};

ascoltatori.build(settings, function(err, ascoltatore)
{
    if (err)
        return console.error(err);

    ascoltatore.subscribe('test', console.log);
    ascoltatore.publish  ('test', 'Hello world');
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants