Skip to content

Commit 4e32770

Browse files
sam-githubitaloacasas
authored andcommitted
tls: new tls.TLSSocket() supports sec ctx options
Add support to new tls.TLSSocket() to create a SecureContext object with all its supported options, in the same way they are supported for all the other APIs that need SecureContext objects. Fix: nodejs#10538 PR-URL: nodejs#11005 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent ecb3a7e commit 4e32770

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

doc/api/tls.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,12 @@ changes:
487487
will be emitted on the socket before establishing a secure communication
488488
* `secureContext`: Optional TLS context object created with
489489
[`tls.createSecureContext()`][]. If a `secureContext` is _not_ provided, one
490-
will be created by calling [`tls.createSecureContext()`][] with no options.
490+
will be created by passing the entire `options` object to
491+
`tls.createSecureContext()`. *Note*: In effect, all
492+
[`tls.createSecureContext()`][] options can be provided, but they will be
493+
_completely ignored_ unless the `secureContext` option is missing.
494+
* ...: Optional [`tls.createSecureContext()`][] options can be provided, see
495+
the `secureContext` option for more information.
491496

492497
Construct a new `tls.TLSSocket` object from an existing TCP socket.
493498

lib/_tls_wrap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ TLSSocket.prototype._wrapHandle = function(wrap) {
351351
// Wrap socket's handle
352352
var context = options.secureContext ||
353353
options.credentials ||
354-
tls.createSecureContext();
354+
tls.createSecureContext(options);
355355
res = tls_wrap.wrap(handle._externalStream,
356356
context.context,
357357
!!options.isServer);

test/parallel/test-tls-socket-default-options.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
const common = require('../common');
33

4-
// Test a directly created TLS socket supports no options, and empty options.
4+
// Test directly created TLS sockets and options.
55

66
const assert = require('assert');
77
const join = require('path').join;
@@ -26,6 +26,16 @@ test({secureContext: tls.createSecureContext({ca: keys.agent1.ca})}, (err) => {
2626
assert.ifError(err);
2727
});
2828

29+
test({ca: keys.agent1.ca}, (err) => {
30+
assert.ifError(err);
31+
});
32+
33+
// Secure context options, like ca, are ignored if a sec ctx is explicitly
34+
// provided.
35+
test({secureContext: tls.createSecureContext(), ca: keys.agent1.ca}, (err) => {
36+
assert.strictEqual(err.message, 'unable to verify the first certificate');
37+
});
38+
2939
function test(client, callback) {
3040
callback = common.mustCall(callback);
3141
connect({

0 commit comments

Comments
 (0)