-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,10 +65,17 @@ Connection.prototype.connect = function(cb) { | |
: Net.createConnection(this.config); | ||
|
||
// Node v0.10+ Switch socket into "old mode" (Streams2) | ||
this._socket.on("data",function() {}); | ||
|
||
this._socket.pipe(this._protocol); | ||
this._protocol.pipe(this._socket); | ||
//this._socket.on("data",function() {}); | ||
|
||
//this._socket.pipe(this._protocol); | ||
//this._protocol.pipe(this._socket); | ||
var connection = this; | ||
this._protocol.on('data', function(data) { | ||
connection._socket.write(data); | ||
}); | ||
this._socket.on('data', function(data) { | ||
connection._protocol.write(data); | ||
}); | ||
|
||
this._socket.on('error', this._handleNetworkError.bind(this)); | ||
this._socket.on('connect', this._handleProtocolConnect.bind(this)); | ||
|
@@ -200,6 +207,49 @@ Connection.prototype.format = function(sql, values) { | |
return SqlString.format(sql, values, this.config.stringifyObjects, this.config.timezone); | ||
}; | ||
|
||
|
||
Connection.prototype._startTLS = function(onSecure) { | ||
|
||
var crypto = require('crypto'); | ||
var tls = require('tls'); | ||
var sslProfiles, sslProfileName; | ||
if (typeof this.config.ssl == 'string') { | ||
sslProfileName = this.config.ssl; | ||
sslProfiles = require('../fixtures/ssl-profiles.json'); | ||
this.config.ssl = sslProfiles[this.config.ssl]; | ||
if (!this.config.ssl) | ||
throw new Error('Unknown SSL profile for ' + sslProfileName); | ||
} | ||
|
||
// before TLS: | ||
// _socket <-> _protocol | ||
// after: | ||
// _socket <-> securePair.encrypted <-> securePair.cleartext <-> _protocol | ||
|
||
var credentials = crypto.createCredentials({ | ||
key: this.config.ssl.key, | ||
cert: this.config.ssl.cert, | ||
passphrase: this.config.ssl.passphrase, | ||
ca: this.config.ssl.ca | ||
}); | ||
|
||
var securePair = tls.createSecurePair(credentials, false); | ||
|
||
securePair.encrypted.pipe(this._socket); | ||
securePair.cleartext.pipe(this._protocol); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
sidorares
Author
Member
|
||
|
||
// TODO: change to unpipe/pipe (does not work for some reason. Streams1/2 conflict?) | ||
this._socket.removeAllListeners('data'); | ||
this._protocol.removeAllListeners('data'); | ||
this._socket.on('data', function(data) { | ||
securePair.encrypted.write(data); | ||
}); | ||
this._protocol.on('data', function(data) { | ||
securePair.cleartext.write(data); | ||
}); | ||
securePair.on('secure', onSecure); | ||
}; | ||
|
||
Connection.prototype._handleConnectTimeout = function() { | ||
if (this._socket) { | ||
this._socket.setTimeout(0); | ||
|
createSecurePair is deprecated in v0.11.x.
You're probably better off just doing something like this for v0.10+ instead: