Skip to content

Commit dc9c152

Browse files
Alex Burleydougwilson
Alex Burley
authored andcommitted
Accept the maxVersion and minVersion properties in connection ssl option
fixes #2301 closes #2304
1 parent 281d935 commit dc9c152

7 files changed

+180
-1
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 `maxVersion` and `minVersion` properties in connection `ssl` option #2301 #2304
910
* Support Node.js 14.x
1011
* Support Node.js 15.x
1112
* Support Node.js 16.x

Readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ following options:
280280
* `ciphers`: The ciphers to use to use in the SSL handshake instead of the default ones for Node.js. This
281281
is passed as the `ciphers` option for [`tls.createSecureContext()`] call (or underlying [`crypto.createCredentials()`]
282282
if using Node.js below 0.12).
283+
* `maxVersion`: This is passed as the `maxVersion` option for the underlying [`tls.createSecureContext()`]
284+
call.
285+
* `minVersion`: This is passed as the `minVersion` option for the underlying [`tls.createSecureContext()`]
286+
call.
283287
* `key`: This is passed as the `key` option for [`tls.createSecureContext()`] call (or underlying
284288
[`crypto.createCredentials()`] if using Node.js below 0.12).
285289
* `passphrase`: This is passed as the `passphrase` option for [`tls.createSecureContext()`] call (or

lib/Connection.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ if (tls.TLSSocket) {
306306
});
307307

308308
// cleartext <-> protocol
309-
secureSocket.pipe(connection._protocol);
309+
secureSocket.pipe(connection._protocol, { end: false });
310310
connection._protocol.on('data', function(data) {
311311
secureSocket.write(data);
312312
});
@@ -465,6 +465,8 @@ function createSecureContext (config, cb) {
465465
cert : config.ssl.cert,
466466
ciphers : config.ssl.ciphers,
467467
key : config.ssl.key,
468+
maxVersion : config.ssl.maxVersion,
469+
minVersion : config.ssl.minVersion,
468470
passphrase : config.ssl.passphrase
469471
});
470472
} catch (err) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
var assert = require('assert');
2+
var common = require('../../common');
3+
var tls = require('tls');
4+
5+
if (!tls.createSecureContext) {
6+
common.skipTest('node ' + process.version + ' does not support tls.createSecureContext()');
7+
}
8+
9+
if (!tls.DEFAULT_MAX_VERSION) {
10+
common.skipTest('node ' + process.version + ' does not support tls maxVersion');
11+
}
12+
13+
var server = common.createFakeServer({
14+
ssl: {
15+
maxVersion : tls.DEFAULT_MAX_VERSION,
16+
minVersion : tls.DEFAULT_MAX_VERSION
17+
}
18+
});
19+
20+
server.listen(0, function (err) {
21+
assert.ifError(err);
22+
23+
var connection = common.createConnection({
24+
port : server.port(),
25+
ssl : {
26+
ca : common.getSSLConfig().ca,
27+
maxVersion : tls.DEFAULT_MAX_VERSION
28+
}
29+
});
30+
31+
connection.connect(function (err) {
32+
assert.ifError(err);
33+
connection.destroy();
34+
server.destroy();
35+
});
36+
});
37+
38+
server.on('connection', function (incomingConnection) {
39+
incomingConnection.handshake({
40+
serverCapabilities1: common.ClientConstants.CLIENT_SSL
41+
});
42+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
var assert = require('assert');
2+
var common = require('../../common');
3+
var tls = require('tls');
4+
5+
if (!tls.createSecureContext) {
6+
common.skipTest('node ' + process.version + ' does not support tls.createSecureContext()');
7+
}
8+
9+
if (!tls.DEFAULT_MAX_VERSION) {
10+
common.skipTest('node ' + process.version + ' does not support tls maxVersion');
11+
}
12+
13+
var server = common.createFakeServer({
14+
ssl: {
15+
maxVersion : tls.DEFAULT_MAX_VERSION,
16+
minVersion : tls.DEFAULT_MAX_VERSION
17+
}
18+
});
19+
20+
server.listen(0, function (err) {
21+
assert.ifError(err);
22+
23+
var connection = common.createConnection({
24+
port : server.port(),
25+
ssl : {
26+
ca : common.getSSLConfig().ca,
27+
maxVersion : tls.DEFAULT_MIN_VERSION
28+
}
29+
});
30+
31+
connection.connect(function (err) {
32+
assert.ok(err);
33+
assert.strictEqual(err.code, 'HANDSHAKE_SSL_ERROR');
34+
assert.strictEqual(err.fatal, true);
35+
connection.destroy();
36+
server.destroy();
37+
});
38+
});
39+
40+
server.on('connection', function (incomingConnection) {
41+
incomingConnection.handshake({
42+
serverCapabilities1: common.ClientConstants.CLIENT_SSL
43+
});
44+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
var assert = require('assert');
2+
var common = require('../../common');
3+
var tls = require('tls');
4+
5+
if (!tls.createSecureContext) {
6+
common.skipTest('node ' + process.version + ' does not support tls.createSecureContext()');
7+
}
8+
9+
if (!tls.DEFAULT_MIN_VERSION) {
10+
common.skipTest('node ' + process.version + ' does not support tls minVersion');
11+
}
12+
13+
var server = common.createFakeServer({
14+
ssl: {
15+
maxVersion : tls.DEFAULT_MIN_VERSION,
16+
minVersion : tls.DEFAULT_MIN_VERSION
17+
}
18+
});
19+
20+
server.listen(0, function (err) {
21+
assert.ifError(err);
22+
23+
var connection = common.createConnection({
24+
port : server.port(),
25+
ssl : {
26+
ca : common.getSSLConfig().ca,
27+
minVersion : tls.DEFAULT_MIN_VERSION
28+
}
29+
});
30+
31+
connection.connect(function (err) {
32+
assert.ifError(err);
33+
connection.destroy();
34+
server.destroy();
35+
});
36+
});
37+
38+
server.on('connection', function (incomingConnection) {
39+
incomingConnection.handshake({
40+
serverCapabilities1: common.ClientConstants.CLIENT_SSL
41+
});
42+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
var assert = require('assert');
2+
var common = require('../../common');
3+
var tls = require('tls');
4+
5+
if (!tls.createSecureContext) {
6+
common.skipTest('node ' + process.version + ' does not support tls.createSecureContext()');
7+
}
8+
9+
if (!tls.DEFAULT_MIN_VERSION) {
10+
common.skipTest('node ' + process.version + ' does not support tls minVersion');
11+
}
12+
13+
var server = common.createFakeServer({
14+
ssl: {
15+
maxVersion : tls.DEFAULT_MIN_VERSION,
16+
minVersion : tls.DEFAULT_MIN_VERSION
17+
}
18+
});
19+
20+
server.listen(0, function (err) {
21+
assert.ifError(err);
22+
23+
var connection = common.createConnection({
24+
port : server.port(),
25+
ssl : {
26+
ca : common.getSSLConfig().ca,
27+
minVersion : tls.DEFAULT_MAX_VERSION
28+
}
29+
});
30+
31+
connection.connect(function (err) {
32+
assert.ok(err);
33+
assert.strictEqual(err.code, 'HANDSHAKE_SSL_ERROR');
34+
assert.strictEqual(err.fatal, true);
35+
connection.destroy();
36+
server.destroy();
37+
});
38+
});
39+
40+
server.on('connection', function (incomingConnection) {
41+
incomingConnection.handshake({
42+
serverCapabilities1: common.ClientConstants.CLIENT_SSL
43+
});
44+
});

0 commit comments

Comments
 (0)