GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — tls: add tlsSocket.socket, to access the raw stream beneath TLS · nodejs/node@ad94073

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • tls.md
  • lib/internal/tls
    • wrap.js
  • test/parallel
    • test-tls-socket-underlying-socket.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/tls.md‎

Copy file name to clipboardExpand all lines: doc/api/tls.md
+23Lines changed: 23 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,27 @@ and their processing can be delayed due to packet loss or reordering. However,
16681668
smaller fragments add extra TLS framing bytes and CPU overhead, which may
16691669
decrease overall server throughput.
16701670

1671+
### `tlsSocket.socket`
1672+
1673+
<!-- YAML
1674+
added: REPLACEME
1675+
-->
1676+
1677+
* Type: {net.Socket|stream.Duplex|null}
1678+
1679+
The underlying socket or stream that this socket reads and writes TLS data
1680+
through. This is the `socket` passed to [`new tls.TLSSocket()`][] or
1681+
[`tls.connect()`][], or the connection given to a [`tls.Server`][] by its
1682+
`'connection'` event.
1683+
1684+
This is only `null` for client sockets that manage their own connection,
1685+
created by [`tls.connect()`][] with a `port` or `path` rather than a `socket`.
1686+
Connection details such as `remoteAddress` are then available directly on this
1687+
socket. Server sockets always have an underlying socket.
1688+
1689+
This remains available after the socket has been destroyed, for example to
1690+
identify the underlying connection from a [`'tlsClientError'`][] listener.
1691+
16711692
## `tls.checkServerIdentity(hostname, cert)`
16721693

16731694
<!-- YAML
@@ -2583,6 +2604,7 @@ added: v0.11.3
25832604
[`'secureConnect'`]: #event-secureconnect
25842605
[`'secureConnection'`]: #event-secureconnection
25852606
[`'session'`]: #event-session
2607+
[`'tlsClientError'`]: #event-tlsclienterror
25862608
[`--tls-cipher-list`]: cli.md#--tls-cipher-listlist
25872609
[`--use-bundled-ca`]: cli.md#--use-bundled-ca---use-openssl-ca
25882610
[`--use-openssl-ca`]: cli.md#--use-bundled-ca---use-openssl-ca
@@ -2598,6 +2620,7 @@ added: v0.11.3
25982620
[`net.Server`]: net.md#class-netserver
25992621
[`net.Socket`]: net.md#class-netsocket
26002622
[`net.createServer()`]: net.md#netcreateserveroptions-connectionlistener
2623+
[`new tls.TLSSocket()`]: #new-tlstlssocketsocket-options
26012624
[`server.addContext()`]: #serveraddcontexthostname-context
26022625
[`server.getTicketKeys()`]: #servergetticketkeys
26032626
[`server.listen()`]: net.md#serverlisten
Collapse file

‎lib/internal/tls/wrap.js‎

Copy file name to clipboardExpand all lines: lib/internal/tls/wrap.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,8 @@ function TLSSocket(socket, opts) {
708708
// Proxy for API compatibility
709709
this.ssl = this._handle; // C++ TLSWrap object
710710

711+
this.socket = socket ?? null;
712+
711713
this.on('error', this._tlsError);
712714

713715
this._init(socket, wrap);
Collapse file

‎test/parallel/test-tls-socket-underlying-socket.js‎

Copy file name to clipboard
+57Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use strict';
2+
const common = require('../common');
3+
if (!common.hasCrypto)
4+
common.skip('missing crypto');
5+
6+
const assert = require('assert');
7+
const fixtures = require('../common/fixtures');
8+
const net = require('net');
9+
const tls = require('tls');
10+
const { duplexPair } = require('stream');
11+
12+
const key = fixtures.readKey('agent1-key.pem');
13+
const cert = fixtures.readKey('agent1-cert.pem');
14+
15+
// Server sockets over a plain connection expose that net.Socket.
16+
{
17+
const server = tls.createServer({ key, cert });
18+
let rawSocket;
19+
server.prependListener('connection', common.mustCall((socket) => {
20+
rawSocket = socket;
21+
}));
22+
server.on('secureConnection', common.mustCall((tlsSocket) => {
23+
assert.ok(rawSocket instanceof net.Socket);
24+
assert.strictEqual(tlsSocket.socket, rawSocket);
25+
tlsSocket.end();
26+
server.close();
27+
}));
28+
server.listen(0, common.mustCall(() => {
29+
const client = tls.connect({
30+
port: server.address().port,
31+
rejectUnauthorized: false,
32+
}, common.mustCall(() => {
33+
assert.strictEqual(client.socket, null);
34+
client.end();
35+
}));
36+
}));
37+
}
38+
39+
// Server sockets over any other stream expose that stream, and still do after
40+
// a failed handshake has destroyed them.
41+
{
42+
const server = tls.createServer({ key, cert, minVersion: 'TLSv1.3' });
43+
const [serverSide, clientSide] = duplexPair();
44+
server.on('secureConnection', common.mustNotCall());
45+
server.on('tlsClientError', common.mustCall((err, tlsSocket) => {
46+
assert.strictEqual(tlsSocket.socket, serverSide);
47+
setImmediate(common.mustCall(() => {
48+
assert.strictEqual(tlsSocket.destroyed, true);
49+
assert.strictEqual(tlsSocket.socket, serverSide);
50+
}));
51+
}));
52+
server.emit('connection', serverSide);
53+
54+
const client = tls.connect({ socket: clientSide, maxVersion: 'TLSv1.2' });
55+
assert.strictEqual(client.socket, clientSide);
56+
client.on('error', common.mustCall());
57+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.