Monday, 18 June 2012

node.js boilerplate - SSL/TLS with express & socket.io

Introduction
We would like to secure various pages of our node.js boilerplate; we have in place a very crude but functioning login form. This post will demonstrate the steps involved in order to get forms authentication working over a secure channel using SSL/TLS.

Create a certificate using openssl
Follow the steps in the below post in order to create a certificate:

Create certificate using openssl

Security/Certificate options
Simply create the following security options object using the certificates and key created from the above:


Now create a server via nodes http module and pass it the express server; binding the app.


Now change the login form to post via https and if you require socket.io on any of the secured pages (those under https); when you create the socket.io object; connect via https like so:



About
This post is part of a series of posts tagged under node-plates a boilerplate mobile/web application written in node.js, express, socket.io, mongooose, jquery.mobile & html 5.

Github
You can grab this from github ->
https://github.com/AndrewKeig/node-plates

References
/nodejs.org/api

3 comments:

  1. Hi, I've just read this article and there's something I'm not sure if it's a mistake.

    This block:
    var httpsServer = https.createServer(options, app.handle.bind(app)).listen(8443);
    var httpSocketIo = require('socket.io').listen(httpServer );

    Shouldn't it be like this?:
    var httpsServer = https.createServer(options, app.handle.bind(app)).listen(8443);
    var httpsSocketIo = require('socket.io').listen(httpsServer );

    Other than that, thanks, It's a very useful article.

    ReplyDelete
  2. Hey; many thanks; I have updated the Gist....

    ReplyDelete