Skip to content

Commit e6f6888

Browse files
committed
Accept the ciphers property in connection ssl option
closes mysqljs#1185
1 parent 4aa1094 commit e6f6888

File tree

5 files changed

+88
-9
lines changed

5 files changed

+88
-9
lines changed

Changes.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ you spot any mistakes.
66

77
## HEAD
88

9+
* Accept the `ciphers` property in connection `ssl` option #1185
910
* Fix bad timezone conversion from `Date` to string for certain times #1045 #1155
1011

1112
## v2.8.0 (2015-07-13)

lib/Connection.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,11 @@ if (tls.TLSSocket) {
278278
// 0.11+ environment
279279
Connection.prototype._startTLS = function _startTLS(onSecure) {
280280
var secureContext = tls.createSecureContext({
281-
key : this.config.ssl.key,
281+
ca : this.config.ssl.ca,
282282
cert : this.config.ssl.cert,
283-
passphrase : this.config.ssl.passphrase,
284-
ca : this.config.ssl.ca
283+
ciphers : this.config.ssl.ciphers,
284+
key : this.config.ssl.key,
285+
passphrase : this.config.ssl.passphrase
285286
});
286287

287288
// "unpipe"
@@ -319,10 +320,11 @@ if (tls.TLSSocket) {
319320
// _socket <-> securePair.encrypted <-> securePair.cleartext <-> _protocol
320321

321322
var credentials = Crypto.createCredentials({
322-
key : this.config.ssl.key,
323+
ca : this.config.ssl.ca,
323324
cert : this.config.ssl.cert,
324-
passphrase : this.config.ssl.passphrase,
325-
ca : this.config.ssl.ca
325+
ciphers : this.config.ssl.ciphers,
326+
key : this.config.ssl.key,
327+
passphrase : this.config.ssl.passphrase
326328
});
327329

328330
var rejectUnauthorized = this.config.ssl.rejectUnauthorized;

test/FakeServer.js

+44
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ function FakeConnection(socket) {
5656
EventEmitter.call(this);
5757

5858
this._socket = socket;
59+
this._ssl = null;
5960
this._stream = socket;
6061
this._parser = new Parser({onPacket: this._parsePacket.bind(this)});
6162

@@ -206,6 +207,39 @@ FakeConnection.prototype._handleQueryPacket = function _handleQueryPacket(packet
206207
return;
207208
}
208209

210+
if ((match = /^SHOW STATUS LIKE 'Ssl_cipher';?$/i.exec(sql))) {
211+
this._sendPacket(new Packets.ResultSetHeaderPacket({
212+
fieldCount: 2
213+
}));
214+
215+
this._sendPacket(new Packets.FieldPacket({
216+
catalog : 'def',
217+
charsetNr : Charsets.UTF8_GENERAL_CI,
218+
name : 'Variable_name',
219+
protocol41 : true,
220+
type : Types.VARCHAR
221+
}));
222+
223+
this._sendPacket(new Packets.FieldPacket({
224+
catalog : 'def',
225+
charsetNr : Charsets.UTF8_GENERAL_CI,
226+
name : 'Value',
227+
protocol41 : true,
228+
type : Types.VARCHAR
229+
}));
230+
231+
this._sendPacket(new Packets.EofPacket());
232+
233+
var writer = new PacketWriter();
234+
writer.writeLengthCodedString('Ssl_cipher');
235+
writer.writeLengthCodedString(this._ssl ? this._ssl.getCurrentCipher().name : '');
236+
this._stream.write(writer.toBuffer(this._parser));
237+
238+
this._sendPacket(new Packets.EofPacket());
239+
this._parser.resetPacketNumber();
240+
return;
241+
}
242+
209243
if (/INVALID/i.test(sql)) {
210244
this._sendPacket(new Packets.ErrorPacket({
211245
errno : Errors.ER_PARSE_ERROR,
@@ -408,6 +442,11 @@ if (tls.TLSSocket) {
408442
secureSocket.on('data', this._handleData.bind(this));
409443
this._stream = secureSocket;
410444

445+
var conn = this;
446+
secureSocket.on('secure', function () {
447+
conn._ssl = this.ssl;
448+
});
449+
411450
// resume
412451
var parser = this._parser;
413452
process.nextTick(function() {
@@ -432,6 +471,11 @@ if (tls.TLSSocket) {
432471
securePair.cleartext.on('data', this._handleData.bind(this));
433472
securePair.encrypted.pipe(this._socket);
434473

474+
var conn = this;
475+
securePair.on('secure', function () {
476+
conn._ssl = this.ssl;
477+
});
478+
435479
// resume
436480
var parser = this._parser;
437481
process.nextTick(function() {

test/common.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,10 @@ common.getTestConfig = function(config) {
135135

136136
common.getSSLConfig = function() {
137137
return {
138-
ca : fs.readFileSync(path.join(common.fixtures, 'server.crt'), 'ascii'),
139-
cert : fs.readFileSync(path.join(common.fixtures, 'server.crt'), 'ascii'),
140-
key : fs.readFileSync(path.join(common.fixtures, 'server.key'), 'ascii')
138+
ca : fs.readFileSync(path.join(common.fixtures, 'server.crt'), 'ascii'),
139+
cert : fs.readFileSync(path.join(common.fixtures, 'server.crt'), 'ascii'),
140+
ciphers : 'ECDHE-RSA-AES128-SHA256:AES128-GCM-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH',
141+
key : fs.readFileSync(path.join(common.fixtures, 'server.key'), 'ascii')
141142
};
142143
};
143144

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var assert = require('assert');
2+
var common = require('../../common');
3+
var connection = common.createConnection({
4+
port : common.fakeServerPort,
5+
ssl : {
6+
ca : common.getSSLConfig().ca,
7+
ciphers : 'RC4-SHA'
8+
}
9+
});
10+
11+
var server = common.createFakeServer();
12+
13+
server.listen(common.fakeServerPort, function (err) {
14+
assert.ifError(err);
15+
16+
connection.query('SHOW STATUS LIKE \'Ssl_cipher\';', function (err, rows) {
17+
assert.ifError(err);
18+
assert.equal(rows.length, 1);
19+
assert.equal(rows[0].Variable_name, 'Ssl_cipher');
20+
assert.equal(rows[0].Value, 'RC4-SHA');
21+
22+
connection.destroy();
23+
server.destroy();
24+
});
25+
});
26+
27+
server.on('connection', function (incomingConnection) {
28+
incomingConnection.handshake({
29+
serverCapabilities1: common.ClientConstants.CLIENT_SSL
30+
});
31+
});

0 commit comments

Comments
 (0)