title: Node.js & Socket.io: Self-signed certificates for a secure websocket connection
body: <p>I've been running across the internet looking for a straight forward answer, but most solutions involve using Express and serving HTTP content for secure connections. I'm more interested in a secure web socket connection (<strong>wss</strong>) for Node.js and socket.io</p>
  
  <p>I don't use Node.js for HTTP requests. I use the socket.io module that works with Node.js to deliver messages in real time to my applications. I only use node for the web socket connection.</p>
  
  <p>I'll explain breifly what my setup is. I use Django as my HTTP backend. Users make a request to Django, Django forwards the contents of that request to Redis, Node.js listens in on one of Redis' channels, it processes the contents and sends the message to the appropriate recipient.</p>
  
  <p>Pretty simple and straight forward. Everything works fine. But I'm afraid that the websocket connection to Node.js is unsecure. When Node.js sends a message to the recipient, I don't want anyone snooping in between and intercepting the message. I would like to make sure my users feel safe and trust the service I have built for them.</p>
  
  <p>I looked into self-signed certificates and certificates from a CA. Both provide the same level of security. Since I am only using Node.js for socket.io and not serving HTTP content, a self-signed certificate will work absolutely fine (the service I have built is for mobile, not for browsers!)</p>
  
  <p>Below is my implentation of socket.io:</p>
  
  <pre><code>var io = require('socket.io').listen(8000);
  var redis = require('socket.io/node_modules/redis')
  var redisChannelConnection = redis.createClient(6000, "12.345.678.9");
  var redisServer = redis.createClient(6000, "23.456.789.1");
  
  // Subscribe to Redis Channel
  redisChannelConnection.subscribe('messages');
  
  io.sockets.on('connection', function (socket) {
       socket.emit('message', 'Hello World');
       }
  </code></pre>
  
  <p>I have just written up a simple connection function so far. It works as a normal websocket connection. But I would like to make it a <strong>secure websocket connection</strong>. How many I go about doing this?</p>
  
  <p>Thank you for your help.</p>