mcollina / mows

Using MQTT.js in the browser over WebSocket -- Built with browserify!
72 stars 12 forks source link

Support for MOWS over HTTPS #2

Closed ldstein closed 11 years ago

ldstein commented 11 years ago

This patch adds support for secure connections.

It includes a new method, createSecureServer:


var clientHandler = function(client) {
 // Handle client
}

var secureOpts = {
    key:  fs.readFileSync('./secure-test/cert/24485013-my.webserver.com.key'),
    cert: fs.readFileSync('./secure-test/cert/24485013-my.webserver.com.cert')
}

mows.createSecureServer(secureOpts, clientHandler).listen(666);

To create a secure browser client, specify the 'wss' protocol:

// ws is unsecure, wss is secure:
var unsecureClient = mows.createClient(665, 'ws://my.webserver.com');
var secureClient    = mows.createClient(666, 'wss://my.webserver.com');

To create a secure Node client, define a protocol object and pass appropriate certificates, authentication options, etc:


// See http://nodejs.org/api/https.html#https_https_request_options_callback
var secureClientOpts =
{
    protocol:
    {
        ca: fs.readFileSync('./secure-test/cert/24485013-my.webserver.com.cert')
    }
};

var secureClient = mows.createClient(666, 'wss://my.webserver.com', secureClientOpts);
applyEventHandlers(unsecureClient2);
mcollina commented 11 years ago

Why the commit is done with my email? Can you write a unit test similar to the original one to test the behavior? Could you move the examples in a examples/ folder, instead of 'secure-test'? You can use testling to test it in the Browser, too.

ldstein commented 11 years ago

Weird. Not quite sure how your email got associated with my commit and why it's dated as 22 days ago.

I'll fix up my repo, add the unit tests and resubmit the pull request.