| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8e7ac25 commit e021fb7
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -465,7 +465,10 @@ connection is open. | |||
| 465 | 465 | added: v0.11.4 | |
| 466 | 466 | --> | |
| 467 | 467 | ||
| 468 | - * `socket` {net.Socket} An instance of [`net.Socket`][] | ||
| 468 | + * `socket` {net.Socket|stream.Duplex} | ||
| 469 | + On the server side, any `Duplex` stream. On the client side, any | ||
| 470 | + instance of [`net.Socket`][] (for generic `Duplex` stream support | ||
| 471 | + on the client side, [`tls.connect()`][] must be used). | ||
| 469 | 472 | * `options` {Object} | |
| 470 | 473 | * `isServer`: The SSL/TLS protocol is asymmetrical, TLSSockets must know if | |
| 471 | 474 | they are to behave as a server or a client. If `true` the TLS socket will be | |
@@ -788,10 +791,12 @@ changes: | |||
| 788 | 791 | * `port` {number} Port the client should connect to. | |
| 789 | 792 | * `path` {string} Creates unix socket connection to path. If this option is | |
| 790 | 793 | specified, `host` and `port` are ignored. | |
| 791 | - * `socket` {net.Socket} Establish secure connection on a given socket rather | ||
| 792 | - than creating a new socket. If this option is specified, `path`, `host` and | ||
| 793 | - `port` are ignored. Usually, a socket is already connected when passed to | ||
| 794 | - `tls.connect()`, but it can be connected later. Note that | ||
| 794 | + * `socket` {stream.Duplex} Establish secure connection on a given socket | ||
| 795 | + rather than creating a new socket. Typically, this is an instance of | ||
| 796 | + [`net.Socket`][], but any `Duplex` stream is allowed. | ||
| 797 | + If this option is specified, `path`, `host` and `port` are ignored, | ||
| 798 | + except for certificate validation. Usually, a socket is already connected | ||
| 799 | + when passed to `tls.connect()`, but it can be connected later. Note that | ||
| 795 | 800 | connection/disconnection/destruction of `socket` is the user's | |
| 796 | 801 | responsibility, calling `tls.connect()` will not cause `net.connect()` to be | |
| 797 | 802 | called. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,38 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + if (!common.hasCrypto) | ||
| 4 | + common.skip('missing crypto'); | ||
| 5 | + | ||
| 6 | + const fixtures = require('../common/fixtures'); | ||
| 7 | + const makeDuplexPair = require('../common/duplexpair'); | ||
| 8 | + const assert = require('assert'); | ||
| 9 | + const { TLSSocket, connect } = require('tls'); | ||
| 10 | + | ||
| 11 | + const key = fixtures.readKey('agent1-key.pem'); | ||
| 12 | + const cert = fixtures.readKey('agent1-cert.pem'); | ||
| 13 | + const ca = fixtures.readKey('ca1-cert.pem'); | ||
| 14 | + | ||
| 15 | + const { clientSide, serverSide } = makeDuplexPair(); | ||
| 16 | + | ||
| 17 | + const clientTLS = connect({ | ||
| 18 | + socket: clientSide, | ||
| 19 | + ca, | ||
| 20 | + host: 'agent1' // Hostname from certificate | ||
| 21 | + }); | ||
| 22 | + const serverTLS = new TLSSocket(serverSide, { | ||
| 23 | + isServer: true, | ||
| 24 | + key, | ||
| 25 | + cert, | ||
| 26 | + ca | ||
| 27 | + }); | ||
| 28 | + | ||
| 29 | + assert.strictEqual(clientTLS.connecting, false); | ||
| 30 | + assert.strictEqual(serverTLS.connecting, false); | ||
| 31 | + | ||
| 32 | + clientTLS.on('secureConnect', common.mustCall(() => { | ||
| 33 | + clientTLS.write('foobar', common.mustCall(() => { | ||
| 34 | + assert.strictEqual(serverTLS.read().toString(), 'foobar'); | ||
| 35 | + assert.strictEqual(clientTLS._handle.writeQueueSize, 0); | ||
| 36 | + })); | ||
| 37 | + assert.ok(clientTLS._handle.writeQueueSize > 0); | ||
| 38 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,7 @@ const typeMap = { | |||
| 26 | 26 | 'Stream': 'stream.html#stream_stream', | |
| 27 | 27 | 'stream.Writable': 'stream.html#stream_class_stream_writable', | |
| 28 | 28 | 'stream.Readable': 'stream.html#stream_class_stream_readable', | |
| 29 | + 'stream.Duplex': 'stream.html#stream_class_stream_duplex', | ||
| 29 | 30 | 'ChildProcess': 'child_process.html#child_process_class_childprocess', | |
| 30 | 31 | 'cluster.Worker': 'cluster.html#cluster_class_worker', | |
| 31 | 32 | 'dgram.Socket': 'dgram.html#dgram_class_dgram_socket', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments