Skip to content

Commit 359de5c

Browse files
sam-githubandrew749
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/node#10538 PR-URL: nodejs/node#11005 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent e70d959 commit 359de5c

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
@@ -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

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ TLSSocket.prototype._wrapHandle = function(wrap) {
355355
// Wrap socket's handle
356356
var context = options.secureContext ||
357357
options.credentials ||
358-
tls.createSecureContext();
358+
tls.createSecureContext(options);
359359
res = tls_wrap.wrap(handle._externalStream,
360360
context.context,
361361
!!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)