diff --git a/lib/transport/binary/connection.js b/lib/transport/binary/connection.js index 86ea9493..a870f847 100644 --- a/lib/transport/binary/connection.js +++ b/lib/transport/binary/connection.js @@ -1,6 +1,7 @@ "use strict"; var net = require('net'), + tls = require('tls'), util = require('util'), utils = require('../../utils'), errors = require('../../errors'), @@ -13,6 +14,8 @@ var net = require('net'), function Connection (config) { EventEmitter.call(this); config = config || {}; + this.ssl = config.ssl || false; + this.sslca = config.sslca || ''; this.host = config.host || 'localhost'; this.port = +config.port || 2424; this.socket = null; @@ -126,7 +129,17 @@ Connection.prototype.cancel = function (err) { * @return {Socket} The socket. */ Connection.prototype.createSocket = function () { - var socket = net.createConnection(this.port, this.host); + var socket = null; + if (this.ssl) { + var opts = {}; + if (this.sslca) { + opts.ca = this.sslca; + } + socket = tls.connect(this.port, this.host, opts); + } + else { + socket = net.createConnection(this.port, this.host); + } socket.setNoDelay(true); socket.setMaxListeners(100); return socket; diff --git a/lib/transport/binary/index.js b/lib/transport/binary/index.js index 03d2be66..87844034 100644 --- a/lib/transport/binary/index.js +++ b/lib/transport/binary/index.js @@ -44,6 +44,8 @@ BinaryTransport.prototype.configure = function (config) { this.host = config.host || config.hostname || 'localhost'; this.port = config.port || 2424; + this.ssl = config.ssl || false; + this.sslca = config.sslca || ''; this.username = config.username || 'root'; this.password = config.password || ''; @@ -86,6 +88,8 @@ BinaryTransport.prototype.configureConnection = function () { this.connection = new Connection({ host: this.host, port: this.port, + ssl: this.ssl, + sslca: this.sslca, enableRIDBags: this.enableRIDBags, logger: this.logger, useToken: this.useToken