tls: native bidirectional TLS bridge for kernel-adjacent forwarding (TUN/VPN/proxy workloads)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 30/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- javascript, node.js
- 领域
- backend, networking, security
调研方向
先阅读 src/crypto/crypto_tls.cc 中 TLSWrap::ClearOut()、EncOut() 和 DoWrite() 附近的代码,然后检查 test-tls-onread-static-buffer.js。该提案需要维护者就 API、fd 所有权、线程处理和生命周期行为达成一致。完成的标准是:达成一致的测试和基准测试能够证明双向 TLS 转发无需按 chunk 处理 JavaScript payload。
由索引模型根据 Issue 内容生成。
描述
What is the problem this feature will solve?
Node’s TLSSocket is designed for application-level stream I/O: cleartext is delivered to JavaScript via the streams API ('data', read(), backpressure via pause()/drain). For high-throughput, full-duplex, kernel-adjacent forwarding (TUN/TAP tunnels, VPN bridges, L3 proxies), users must implement a JS pump between a native fd and a TLSSocket.
That pattern degrades badly in practice:
- Per-chunk V8 boundary — TLSWrap::ClearOut() reads via SSL_read, copies into an allocated buffer, and EmitRead() into JS (src/crypto/crypto_tls.cc, kClearOutChunkSize = 16384).
- Extra event-loop turns — sync underlying writes are deferred with SetImmediate before WriteWrap::Done() (EncOut() / empty DoWrite() paths).
- Dual backpressure — the app must coordinate pause/resume between two independent stream endpoints (e.g. TUN poll + TLS socket) in JavaScript.
- No framing help — TLS is a byte stream; L3 frames (e.g. IPv6 packets) often require reassembly across multiple reads in userland.
- Real-world impact: projects doing iOS CoreDevice / CDTunnel-style forwarding (e.g. Appium appium-ios-tuntap) had to leave Node TLS entirely and implement OpenSSL forwarding in a native addon with dedicated blocking I/O threads — duplicating logic that conceptually belongs next to TLSWrap.
The stream API remains correct for HTTP, RPC, etc.; this gap is specifically for payload forwarding where JS should never see the bytes.
What is the feature you are proposing to solve the problem?
Add a first-class native TLS bridge API that pumps cleartext between an encrypted TCP (or pipe) stream and another native I/O endpoint without surfacing payload data to JavaScript.
Proposed API (sketch):
import tls from 'node:tls';
import net from 'node:net';
const tcp = net.connect({ port });
const bridge = tls.createBridge({
socket: tcp, // existing net.Socket / fd
sink: tunFd, // numeric fd or native handle (TUN, pipe, etc.)
credentials: { cert, key }, // or secureContext / PSK options
direction: 'duplex', // 'duplex' | 'encrypt-only' | 'decrypt-only'
onError(err) { /* lifecycle */ },
onClose() { /* cleanup */ },
});
await bridge.handshake(); // or auto on first I/O
bridge.start();
bridge.stop();
Implementation outline (in core, built on existing TLSWrap):
- Reuse TLSWrap + OpenSSL session setup (lockdown cert, TLS-PSK, etc.) — same crypto as tls.connect().
- Run the hot loop in native code (dedicated per-connection thread or integrated read/write cycle in TLSWrap), analogous to ClearIn → ClearOut → EncOut but wired directly to the sink fd instead of EmitRead/DoWrite.
- JavaScript receives only: handshake result, errors, close — not per-packet callbacks.
- Support dup()/fd ownership semantics documented clearly (who closes what).
Success criteria:
- Sustained bidirectional TLS 1.2 forwarding at path-MTU record sizes without per-chunk JS allocation.
p99 latency and CPU use materially better than an equivalent socket.on('data') ↔ tun.write() pump. - Add-on authors (TUN, userspace VPN, transparent proxies) can delete custom OpenSSL pthread forwarders.
What alternatives have you considered?
- Stay on TLSSocket + streams — Correct for apps, insufficient for tunnel workloads; requires JS pump and suffers the costs above. This is what forced native-addon workarounds today.
- socket.on('data') + onread static buffer — Helps TCP; TLSWrap::ClearOut() still copies before JS (test-tls-onread-static-buffer.js covers TCP onread, not a TLS zero-copy path). Does not remove the V8 boundary for cleartext payload.
- Third-party native addons (custom OpenSSL in N-API) — Works (proven in production) but duplicates TLSWrap session management, cert/PSK handling, and security updates. Every VPN/tunnel project reinvents the same forwarder.
- node:quic patterns — QUIC has native stream handling oriented toward protocol I/O; CDTunnel / lockdown TLS 1.2 over TCP is a different stack and not a drop-in substitute.
- Document “don’t use TLS for this” only — Honest but pushes ecosystem fragmentation; a small, targeted tls.createBridge() (or similar) keeps advanced use cases on supported Node APIs.
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 38.4k
- 平均合并
- 4 天 10 小时
- 30 天内合并 PR
- 276
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
nodejs/node 的其他 Issue
-
doc
难度 1/5 1 小时以内 新手友好度 90/100
维护者通常 1 天内回复
-
doc
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
build
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
nodejs/node#65994 · 2 条评论 · 2 个 reaction ·
维护者通常 1 天内回复
-
feature request
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
keyxmakerx/Chronicle#967 ·
维护者通常 1 天内回复
-
good first issue hacktoberfest
难度 1/5 1 小时以内 新手友好度 92/100
维护者通常 1 天内回复
-
external-issue to-triage
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
LearningCircuit/local-deep-research#7067 ·
维护者通常 1 天内回复