GeezerVison is showing github.com — tls: new tls.TLSSocket() supports sec ctx options · nodejs/node@7cad561
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: doc/api/tls.md +6-1Lines changed: 6 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -483,7 +483,12 @@ added: v0.11.4 |
483 | 483 | will be emitted on the socket before establishing a secure communication |
484 | 484 | * `secureContext`: Optional TLS context object created with |
485 | 485 | [`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. |
487 | 492 |
|
488 | 493 | Construct a new `tls.TLSSocket` object from an existing TCP socket. |
489 | 494 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: lib/_tls_wrap.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -355,7 +355,7 @@ TLSSocket.prototype._wrapHandle = function(wrap) { |
355 | 355 | // Wrap socket's handle |
356 | 356 | var context = options.secureContext || |
357 | 357 | options.credentials || |
358 | | - tls.createSecureContext(); |
| 358 | + tls.createSecureContext(options); |
359 | 359 | res = tls_wrap.wrap(handle._externalStream, |
360 | 360 | context.context, |
361 | 361 | !!options.isServer); |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-tls-socket-default-options.js +11-1Lines changed: 11 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | 'use strict'; |
2 | 2 | const common = require('../common'); |
3 | 3 |
|
4 | | -// Test a directly created TLS socket supports no options, and empty options. |
| 4 | +// Test directly created TLS sockets and options. |
5 | 5 |
|
6 | 6 | const assert = require('assert'); |
7 | 7 | const join = require('path').join; |
@@ -26,6 +26,16 @@ test({secureContext: tls.createSecureContext({ca: keys.agent1.ca})}, (err) => { |
26 | 26 | assert.ifError(err); |
27 | 27 | }); |
28 | 28 |
|
| 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 | + |
29 | 39 | function test(client, callback) { |
30 | 40 | callback = common.mustCall(callback); |
31 | 41 | connect({ |
|