Skip to content

Commit 4e6efc1

Browse files
committed
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 bd947de commit 4e6efc1

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

doc/api/tls.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,12 @@ added: v0.11.4
483483
will be emitted on the socket before establishing a secure communication
484484
* `secureContext`: Optional TLS context object created with
485485
[`tls.createSecureContext()`][]. If a `secureContext` is _not_ provided, one
486-
will be created by calling [`tls.createSecureContext()`][] with no options.
486+
will be created by passing the entire `options` object to
487+
`tls.createSecureContext()`. *Note*: In effect, all
488+
[`tls.createSecureContext()`][] options can be provided, but they will be
489+
_completely ignored_ unless the `secureContext` option is missing.
490+
* ...: Optional [`tls.createSecureContext()`][] options can be provided, see
491+
the `secureContext` option for more information.
487492

488493
Construct a new `tls.TLSSocket` object from an existing TCP socket.
489494

lib/_tls_wrap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ TLSSocket.prototype._wrapHandle = function(wrap) {
344344
// Wrap socket's handle
345345
var context = options.secureContext ||
346346
options.credentials ||
347-
tls.createSecureContext();
347+
tls.createSecureContext(options);
348348
res = tls_wrap.wrap(handle._externalStream,
349349
context.context,
350350
!!options.isServer);

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

Lines changed: 11 additions & 1 deletion
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)