Add secure method to tcp socket for firefox

Adding a secure method to tcp socket for firefox.

Firefox sockets can be upgraded to TLS using by calling nsISocketTransportService.createTransport with type 'starttls' and the same hostname and port as an existing insecure tcp socket.  Documentation is here: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsISocketTransportService#createTransport()

I've tested this in my own firefox addon and am able to log into Facebook XMPP using the starttls flow and get my friends list, however I'm not sure how to update the tests in freedom-for-firefox (they already have 1 failure, and when I add my own test that I try to intentionally make fail I don't get a 2nd error).
seems worth a comment.


On Tue, Aug 12, 2014 at 8:51 AM, dborkan <notifications@github.com> wrote:

> In providers/tcp_socket.js:
>
> > +  this.port = port;
> > +  continuation();
> > +};
> > +
> > +// TODO: handle failures.
> > +Socket_firefox.prototype.secure = function(continuation) {
> > +  if (!this.hostname || !this.port || !this.clientSocket) {
> > +    continuation(undefined, {
> > +      "errcode": "SOCKET_NOT_CONNECTED",
> > +      "message": "Cannot Secure Not Connected Socket"
> > +    });
> > +    return;
> > +  }
> > +  this.clientSocket = new ClientSocket();
> > +  this.clientSocket.setOnDataListener(this._onData.bind(this));
> > +  this.clientSocket.connect(this.hostname, this.port, true);
>
> It continues the existing TCP session. The firefox API is weird and unlike
> in Chrome you don't get a unique socket identifier which you can upgrade to
> TLS, nor is there a socket object with any upgradeToTls method. Instead it
> appears to keep a mapping from hostname/port to a socket which can be
> upgraded to tls by creating a new nsISocketTransport object (not
> necessarily the same as creating a new connection) with type 'starttls'.
>
> We will need to test this in the future and make sure it doesn't result in
> weird race conditions if we have 2 pieces of code both trying to connect to
> the same hostname/port and do a starttls flow (e.g. if there are 2
> instances of a GTalk social provider that are both trying to connect to
> GTalk at the same time with different logins)
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/freedomjs/freedom-for-firefox/pull/12/files#r16121843>
> .
>