doc,test: mention Duplex support for TLS
Document and test the existing support for generic Duplex streams in the TLS module. PR-URL: https://github.com/nodejs/node/pull/17599 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
dd2200ecf8
commit
93656f4366
@ -455,7 +455,10 @@ changes:
|
|||||||
description: ALPN options are supported now.
|
description: ALPN options are supported now.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `socket` {net.Socket} An instance of [`net.Socket`][]
|
* `socket` {net.Socket|stream.Duplex}
|
||||||
|
On the server side, any `Duplex` stream. On the client side, any
|
||||||
|
instance of [`net.Socket`][] (for generic `Duplex` stream support
|
||||||
|
on the client side, [`tls.connect()`][] must be used).
|
||||||
* `options` {Object}
|
* `options` {Object}
|
||||||
* `isServer`: The SSL/TLS protocol is asymmetrical, TLSSockets must know if
|
* `isServer`: The SSL/TLS protocol is asymmetrical, TLSSockets must know if
|
||||||
they are to behave as a server or a client. If `true` the TLS socket will be
|
they are to behave as a server or a client. If `true` the TLS socket will be
|
||||||
@ -815,10 +818,12 @@ changes:
|
|||||||
* `port` {number} Port the client should connect to.
|
* `port` {number} Port the client should connect to.
|
||||||
* `path` {string} Creates unix socket connection to path. If this option is
|
* `path` {string} Creates unix socket connection to path. If this option is
|
||||||
specified, `host` and `port` are ignored.
|
specified, `host` and `port` are ignored.
|
||||||
* `socket` {net.Socket} Establish secure connection on a given socket rather
|
* `socket` {stream.Duplex} Establish secure connection on a given socket
|
||||||
than creating a new socket. If this option is specified, `path`, `host` and
|
rather than creating a new socket. Typically, this is an instance of
|
||||||
`port` are ignored. Usually, a socket is already connected when passed to
|
[`net.Socket`][], but any `Duplex` stream is allowed.
|
||||||
`tls.connect()`, but it can be connected later. Note that
|
If this option is specified, `path`, `host` and `port` are ignored,
|
||||||
|
except for certificate validation. Usually, a socket is already connected
|
||||||
|
when passed to `tls.connect()`, but it can be connected later. Note that
|
||||||
connection/disconnection/destruction of `socket` is the user's
|
connection/disconnection/destruction of `socket` is the user's
|
||||||
responsibility, calling `tls.connect()` will not cause `net.connect()` to be
|
responsibility, calling `tls.connect()` will not cause `net.connect()` to be
|
||||||
called.
|
called.
|
||||||
|
38
test/parallel/test-tls-generic-stream.js
Normal file
38
test/parallel/test-tls-generic-stream.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
'use strict';
|
||||||
|
const common = require('../common');
|
||||||
|
if (!common.hasCrypto)
|
||||||
|
common.skip('missing crypto');
|
||||||
|
|
||||||
|
const fixtures = require('../common/fixtures');
|
||||||
|
const makeDuplexPair = require('../common/duplexpair');
|
||||||
|
const assert = require('assert');
|
||||||
|
const { TLSSocket, connect } = require('tls');
|
||||||
|
|
||||||
|
const key = fixtures.readKey('agent1-key.pem');
|
||||||
|
const cert = fixtures.readKey('agent1-cert.pem');
|
||||||
|
const ca = fixtures.readKey('ca1-cert.pem');
|
||||||
|
|
||||||
|
const { clientSide, serverSide } = makeDuplexPair();
|
||||||
|
|
||||||
|
const clientTLS = connect({
|
||||||
|
socket: clientSide,
|
||||||
|
ca,
|
||||||
|
host: 'agent1' // Hostname from certificate
|
||||||
|
});
|
||||||
|
const serverTLS = new TLSSocket(serverSide, {
|
||||||
|
isServer: true,
|
||||||
|
key,
|
||||||
|
cert,
|
||||||
|
ca
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(clientTLS.connecting, false);
|
||||||
|
assert.strictEqual(serverTLS.connecting, false);
|
||||||
|
|
||||||
|
clientTLS.on('secureConnect', common.mustCall(() => {
|
||||||
|
clientTLS.write('foobar', common.mustCall(() => {
|
||||||
|
assert.strictEqual(serverTLS.read().toString(), 'foobar');
|
||||||
|
assert.strictEqual(clientTLS._handle.writeQueueSize, 0);
|
||||||
|
}));
|
||||||
|
assert.ok(clientTLS._handle.writeQueueSize > 0);
|
||||||
|
}));
|
@ -49,6 +49,7 @@ const typeMap = {
|
|||||||
'Stream': 'stream.html#stream_stream',
|
'Stream': 'stream.html#stream_stream',
|
||||||
'stream.Readable': 'stream.html#stream_class_stream_readable',
|
'stream.Readable': 'stream.html#stream_class_stream_readable',
|
||||||
'stream.Writable': 'stream.html#stream_class_stream_writable',
|
'stream.Writable': 'stream.html#stream_class_stream_writable',
|
||||||
|
'stream.Duplex': 'stream.html#stream_class_stream_duplex',
|
||||||
|
|
||||||
'tls.TLSSocket': 'tls.html#tls_class_tls_tlssocket',
|
'tls.TLSSocket': 'tls.html#tls_class_tls_tlssocket',
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user