Comparing version 2.0.1 to 2.1.0
@@ -9,2 +9,9 @@ # Changes | ||
## v2.1.0 (2014-02-20) | ||
* crypto.createHash fix for node.js < 11 #735 | ||
* Add `connectTimeout` option to specify a timeout for establishing a connection #726 | ||
* SSL support #481 | ||
## v2.0.1 | ||
@@ -141,3 +148,3 @@ | ||
and also make the charset user configurable. | ||
* Fix BLOB type casting for `TINY_BLOG`, `MEDIUM_BLOB` and `LONG_BLOB`. | ||
* Fix BLOB type casting for `TINY_BLOB`, `MEDIUM_BLOB` and `LONG_BLOB`. | ||
* Add support for sending and receiving large (> 16 MB) packets. | ||
@@ -144,0 +151,0 @@ |
@@ -0,0 +0,0 @@ var Connection = require('./lib/Connection'); |
@@ -67,8 +67,16 @@ var Net = require('net'); | ||
// Node v0.10+ Switch socket into "old mode" (Streams2) | ||
this._socket.on("data",function() {}); | ||
var connection = this; | ||
this._protocol.on('data', function(data) { | ||
connection._socket.write(data); | ||
}); | ||
this._socket.on('data', function(data) { | ||
connection._protocol.write(data); | ||
}); | ||
this._protocol.on('end', function() { | ||
connection._socket.end() | ||
}); | ||
this._socket.on('end', function(err) { | ||
connection._protocol.end(); | ||
}); | ||
this._socket.pipe(this._protocol); | ||
this._protocol.pipe(this._socket); | ||
this._socket.on('error', this._handleNetworkError.bind(this)); | ||
@@ -80,2 +88,11 @@ this._socket.on('connect', this._handleProtocolConnect.bind(this)); | ||
this._protocol.on('end', this._handleProtocolEnd.bind(this)); | ||
if (this.config.connectTimeout) { | ||
var handleConnectTimeout = this._handleConnectTimeout.bind(this); | ||
this._socket.setTimeout(this.config.connectTimeout, handleConnectTimeout); | ||
this._socket.once('connect', function() { | ||
this.setTimeout(0, handleConnectTimeout); | ||
}); | ||
} | ||
} | ||
@@ -196,2 +213,59 @@ | ||
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); | ||
// 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); | ||
this._socket.destroy(); | ||
} | ||
var err = new Error('connect ETIMEDOUT'); | ||
err.errorno = 'ETIMEDOUT'; | ||
err.code = 'ETIMEDOUT'; | ||
err.syscall = 'connect'; | ||
this._handleNetworkError(err); | ||
}; | ||
Connection.prototype._handleNetworkError = function(err) { | ||
@@ -198,0 +272,0 @@ this._protocol.handleNetworkError(err); |
@@ -18,2 +18,3 @@ var urlParse = require('url').parse; | ||
this.database = options.database; | ||
this.connectTimeout = options.connectTimeout || undefined; | ||
this.insecureAuth = options.insecureAuth || false; | ||
@@ -30,2 +31,3 @@ this.supportBigNumbers = options.supportBigNumbers || false; | ||
this.pool = options.pool || undefined; | ||
this.ssl = options.ssl || undefined; | ||
this.multipleStatements = options.multipleStatements || false; | ||
@@ -32,0 +34,0 @@ this.typeCast = (options.typeCast === undefined) |
@@ -0,0 +0,0 @@ var mysql = require('../'); |
@@ -0,0 +0,0 @@ |
@@ -0,0 +0,0 @@ var inherits = require('util').inherits |
@@ -5,8 +5,19 @@ var Buffer = require('buffer').Buffer; | ||
function sha1(msg) { | ||
var hash = Crypto.createHash('sha1'); | ||
hash.update(msg); | ||
// hash.digest() does not output buffers yet | ||
return hash.digest('binary'); | ||
}; | ||
var sha1; | ||
if (Number(process.version.match(/^v\d+\.(\d+)/)[1]) >= 10){ | ||
sha1 = function(msg) { | ||
var hash = Crypto.createHash('sha1'); | ||
hash.setEncoding('binary'); | ||
hash.write(msg); | ||
hash.end(); | ||
return hash.read(); | ||
} | ||
} else { | ||
sha1 = function(msg) { | ||
var hash = Crypto.createHash('sha1'); | ||
hash.update(msg); | ||
// hash.digest() does not output buffers yet | ||
return hash.digest('binary'); | ||
} | ||
} | ||
Auth.sha1 = sha1; | ||
@@ -13,0 +24,0 @@ |
@@ -0,0 +0,0 @@ exports.BIG5_CHINESE_CI = 1; |
@@ -0,0 +0,0 @@ // Manually extracted from mysql-5.5.23/include/mysql_com.h |
@@ -0,0 +0,0 @@ // Generated by generate-error-constants.js, do not modify by hand |
@@ -0,0 +0,0 @@ // Manually extracted from mysql-5.5.23/include/mysql_com.h |
@@ -0,0 +0,0 @@ // Manually extracted from mysql-5.5.23/include/mysql_com.h |
@@ -0,0 +0,0 @@ // Manually extracted from mysql-5.5.23/include/mysql_com.h |
@@ -0,0 +0,0 @@ module.exports = PacketHeader; |
@@ -0,0 +0,0 @@ module.exports = ClientAuthenticationPacket; |
@@ -0,0 +0,0 @@ module.exports = ComChangeUserPacket; |
@@ -0,0 +0,0 @@ module.exports = ComPingPacket; |
@@ -0,0 +0,0 @@ module.exports = ComQueryPacket; |
@@ -0,0 +0,0 @@ module.exports = ComQuitPacket; |
@@ -0,0 +0,0 @@ module.exports = ComStatisticsPacket; |
@@ -0,0 +0,0 @@ module.exports = EmptyPacket; |
@@ -0,0 +0,0 @@ module.exports = EofPacket; |
@@ -0,0 +0,0 @@ module.exports = ErrorPacket; |
@@ -0,0 +0,0 @@ var Types = require('../constants/types'); |
@@ -0,0 +0,0 @@ module.exports = FieldPacket; |
@@ -0,0 +0,0 @@ module.exports = HandshakeInitializationPacket; |
@@ -0,0 +0,0 @@ var Elements = module.exports = require('require-all')({ |
@@ -0,0 +0,0 @@ module.exports = LocalDataFilePacket; |
@@ -0,0 +0,0 @@ module.exports = OkPacket; |
@@ -0,0 +0,0 @@ module.exports = OldPasswordPacket; |
@@ -0,0 +0,0 @@ module.exports = ResultSetHeaderPacket; |
@@ -0,0 +0,0 @@ var Types = require('../constants/types'); |
@@ -0,0 +0,0 @@ module.exports = StatisticsPacket; |
@@ -0,0 +0,0 @@ module.exports = UseOldPasswordPacket; |
@@ -0,0 +0,0 @@ var BIT_16 = Math.pow(2, 16); |
@@ -0,0 +0,0 @@ var MAX_PACKET_LENGTH = Math.pow(2, 24) - 1; |
@@ -125,2 +125,7 @@ var Parser = require('./Parser'); | ||
self._dequeue(); | ||
}) | ||
.on('start-tls', function() { | ||
self._connection._startTLS(function() { | ||
sequence._tlsUpgradeCompleteHandler(); | ||
}) | ||
}); | ||
@@ -127,0 +132,0 @@ |
@@ -0,0 +0,0 @@ module.exports = ResultSet; |
@@ -0,0 +0,0 @@ var Sequence = require('./Sequence'); |
@@ -1,5 +0,6 @@ | ||
var Sequence = require('./Sequence'); | ||
var Util = require('util'); | ||
var Packets = require('../packets'); | ||
var Auth = require('../Auth'); | ||
var Sequence = require('./Sequence'); | ||
var Util = require('util'); | ||
var Packets = require('../packets'); | ||
var Auth = require('../Auth'); | ||
var ClientConstants = require('../constants/client'); | ||
@@ -34,2 +35,25 @@ module.exports = Handshake; | ||
var serverSSLSupport = packet.serverCapabilities1 & ClientConstants.CLIENT_SSL; | ||
if (this._config.ssl) { | ||
if (!serverSSLSupport) | ||
throw new Error('Server does not support secure connnection'); | ||
this._config.clientFlags |= ClientConstants.CLIENT_SSL; | ||
this.emit('packet', new Packets.SSLRequestPacket({ | ||
clientFlags : this._config.clientFlags, | ||
maxPacketSize : this._config.maxPacketSize, | ||
charsetNumber : this._config.charsetNumber | ||
})); | ||
this.emit('start-tls'); | ||
} else { | ||
this._sendCredentials(); | ||
} | ||
}; | ||
Handshake.prototype._tlsUpgradeCompleteHandler = function() { | ||
this._sendCredentials(); | ||
}; | ||
Handshake.prototype._sendCredentials = function(serverHello) { | ||
var packet = this._handshakeInitializationPacket; | ||
this.emit('packet', new Packets.ClientAuthenticationPacket({ | ||
@@ -36,0 +60,0 @@ clientFlags : this._config.clientFlags, |
@@ -0,0 +0,0 @@ var Elements = module.exports = require('require-all')({ |
@@ -0,0 +0,0 @@ var Sequence = require('./Sequence'); |
@@ -0,0 +0,0 @@ var Sequence = require('./Sequence'); |
@@ -0,0 +0,0 @@ var Sequence = require('./Sequence'); |
@@ -0,0 +0,0 @@ var Util = require('util'); |
@@ -0,0 +0,0 @@ var Sequence = require('./Sequence'); |
@@ -0,0 +0,0 @@ var SqlString = exports; |
@@ -5,3 +5,3 @@ { | ||
"description": "A node.js driver for mysql. It is written in JavaScript, does not require compiling, and is 100% MIT licensed.", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"homepage": "https://github.com/felixge/node-mysql", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -143,2 +143,4 @@ # node-mysql | ||
* `timezone`: The timezone used to store local dates. (Default: `'local'`) | ||
* `connectTimeout`: The milliseconds before a timeout occurs during the initial connection | ||
to the MySQL server. (Default: no timeout) | ||
* `stringifyObjects`: Stringify objects instead of converting to values. See | ||
@@ -169,3 +171,6 @@ issue [#501](https://github.com/felixge/node-mysql/issues/501). (Default: `'false'`) | ||
also possible to blacklist default ones. For more information, check [Connection Flags](#connection-flags). | ||
* `ssl`: object with ssl parameters ( same format as [crypto.createCredentials](http://nodejs.org/api/crypto.html#crypto_crypto_createcredentials_details) argument ) | ||
or a string containing name of ssl profile. Currently only 'Amazon RDS' profile is bundled, containing CA from https://rds.amazonaws.com/doc/rds-ssl-ca-cert.pem | ||
In addition to passing these options as an object, you can also use a url | ||
@@ -268,4 +273,2 @@ string. For example: | ||
* `createConnection`: The function to use to create the connection. (Default: | ||
`mysql.createConnection`) | ||
* `waitForConnections`: Determines the pool's action when no connections are | ||
@@ -272,0 +275,0 @@ available and the limit has been reached. If `true`, the pool will queue the |
@@ -0,0 +0,0 @@ #!/usr/bin/env node |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
193320
59
3787
1039
3