bdy 1.26.10 → 1.26.11-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/distTs/package.json +2 -2
- package/distTs/src/command/agent/selftest.js +2 -3
- package/distTs/src/index.js +0 -8
- package/distTs/src/sshChannelWindow.js +45 -124
- package/distTs/src/sshKex.js +32 -0
- package/distTs/src/sshKeygen.js +1 -10
- package/distTs/src/tunnel/server/sftp.js +0 -24
- package/distTs/src/tunnel/server/ssh.js +4 -2
- package/distTs/src/tunnel/ssh/client.js +11 -12
- package/node_modules/ssh2/.github/workflows/ci.yml +12 -18
- package/node_modules/ssh2/.github/workflows/lint.yml +2 -2
- package/node_modules/ssh2/README.md +30 -8
- package/node_modules/ssh2/lib/Channel.js +38 -3
- package/node_modules/ssh2/lib/agent.js +3 -101
- package/node_modules/ssh2/lib/client.js +30 -10
- package/node_modules/ssh2/lib/keygen.js +6 -7
- package/node_modules/ssh2/lib/protocol/Protocol.js +3 -1
- package/node_modules/ssh2/lib/protocol/SFTP.js +8 -0
- package/node_modules/ssh2/lib/protocol/constants.js +21 -0
- package/node_modules/ssh2/lib/protocol/crypto/src/binding.cc +33 -32
- package/node_modules/ssh2/lib/protocol/kex.js +122 -0
- package/node_modules/ssh2/lib/protocol/zlib.js +11 -1
- package/node_modules/ssh2/lib/server.js +57 -12
- package/node_modules/ssh2/package.json +9 -6
- package/node_modules/ssh2/test/test-channel-window.js +142 -0
- package/node_modules/ssh2/test/test-destroy.js +97 -0
- package/node_modules/ssh2/test/test-integration-openssh.js +70 -7
- package/node_modules/ssh2/test/test-kex-mlkem.js +211 -0
- package/node_modules/ssh2/test/test-keygen.js +16 -6
- package/node_modules/ssh2/test/test-late-write.js +61 -0
- package/node_modules/ssh2/test/test-misc-client-server.js +29 -0
- package/node_modules/ssh2/test/test-nodelay.js +54 -0
- package/node_modules/ssh2/test/test-protocol-keyparser.js +1 -1
- package/node_modules/ssh2/test/test-sftp.js +33 -0
- package/node_modules/ssh2/test/test-userauth-signature.js +157 -0
- package/package.json +2 -2
- package/node_modules/ssh2/util/build_pagent.bat +0 -2
- package/node_modules/ssh2/util/pagent.c +0 -88
- package/node_modules/ssh2/util/pagent.exe +0 -0
package/distTs/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bdy",
|
|
3
3
|
"preferGlobal": false,
|
|
4
|
-
"version": "1.26.
|
|
4
|
+
"version": "1.26.11-beta",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://buddy.works/docs/cli",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"puppeteer-core": "25.16.0",
|
|
90
90
|
"range-parser": "1.2.1",
|
|
91
91
|
"socket.io-client": "4.8.3",
|
|
92
|
-
"ssh2": "1.17.0",
|
|
92
|
+
"ssh2": "npm:@buddy-works/ssh2@1.17.0-pq.1",
|
|
93
93
|
"tar-stream": "3.2.0",
|
|
94
94
|
"terminal-kit": "3.1.2",
|
|
95
95
|
"undici": "8.12.3",
|
|
@@ -23,9 +23,8 @@ commandAgentSelftest.action(async () => {
|
|
|
23
23
|
// here, so the version could be lost before it is flushed.
|
|
24
24
|
output_1.default.data((0, utils_1.getVersion)());
|
|
25
25
|
// The window ssh2 will really advertise, measured inside the artifact that ships - see
|
|
26
|
-
// effectiveChannelWindow(). build.sh fails a release whose binary does not say 8388608
|
|
27
|
-
//
|
|
28
|
-
// so the ordering guard in sshChannelWindow.ts cannot see a violation there.
|
|
26
|
+
// effectiveChannelWindow(). build.sh fails a release whose binary does not say 8388608:
|
|
27
|
+
// the check that the ssh2 bundled into it is the one that takes the option.
|
|
29
28
|
//
|
|
30
29
|
// Printed, not enforced: an agent that would run at ssh2's 2 MB is slower, not broken,
|
|
31
30
|
// and refusing the update over it would keep a fleet on an older binary for a knob.
|
package/distTs/src/index.js
CHANGED
|
@@ -3,17 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
// FIRST, and it has to stay first: it raises the ssh2 channel window, and ssh2 reads that constant
|
|
7
|
-
// once, when it is loaded. Any import above this line that reaches ssh2 would pin the window at
|
|
8
|
-
// ssh2's 2MB default and cap every upload through a tunnel. See sshChannelWindow.ts.
|
|
9
|
-
const sshChannelWindow_1 = require("./sshChannelWindow");
|
|
10
6
|
const output_1 = __importDefault(require("./output"));
|
|
11
7
|
const logger_1 = __importDefault(require("./logger"));
|
|
12
8
|
const stream_1 = __importDefault(require("stream"));
|
|
13
|
-
if (!sshChannelWindow_1.sshChannelWindow.applied) {
|
|
14
|
-
// Not fatal: uploads through a tunnel just keep ssh2's 2MB-per-round-trip ceiling.
|
|
15
|
-
logger_1.default.debug(`SSH channel window unchanged - ${sshChannelWindow_1.sshChannelWindow.reason}`);
|
|
16
|
-
}
|
|
17
9
|
output_1.default.muteNodeWarnings();
|
|
18
10
|
stream_1.default.setDefaultHighWaterMark(false, 65536);
|
|
19
11
|
process.title = 'bdy';
|
|
@@ -1,146 +1,67 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.effectiveChannelWindow = exports.requireSsh2 = exports.
|
|
4
|
-
// The SSH channel window
|
|
3
|
+
exports.effectiveChannelWindow = exports.requireSsh2 = exports.SSH_CHANNEL_OPTIONS = void 0;
|
|
4
|
+
// The SSH channel window of every ssh2 client and server this process makes.
|
|
5
5
|
//
|
|
6
|
-
// Throughput over one SSH channel is window/RTT, and ssh2 ships a 2 MB window
|
|
7
|
-
//
|
|
8
|
-
//
|
|
6
|
+
// Throughput over one SSH channel is window/RTT, and ssh2 ships a 2 MB window. The agent is the
|
|
7
|
+
// RECEIVING end of an upload - data flows worker -> agent - so it is this side's window that decides
|
|
8
|
+
// how fast anything can be uploaded through a tunnel.
|
|
9
9
|
//
|
|
10
|
-
// Measured
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
// Those numbers predate the refill below being fixed, when the raise only applied to the first burst
|
|
17
|
-
// and the steady-state window was ssh2's 2 MB whatever this said. With the refill honoured, one channel
|
|
18
|
-
// through raw ssh2 does 15.8 MB/s on 2 MB, 30.0 on 4 MB and 59.0 on 8 MB at 60 ms RTT (7.5, 15.2 and
|
|
19
|
-
// 30.1 at 200 ms) - linear in window/RTT, and 8 MB is where a 200 ms link clears the ~19 MB/s an
|
|
20
|
-
// untunneled sftp does. See worker/src/ssh2.js, which carries the same constant and the full set.
|
|
10
|
+
// Measured on one channel through raw ssh2: 15.8 MB/s on 2 MB, 30.0 on 4 MB and 59.0 on 8 MB at
|
|
11
|
+
// 60 ms RTT (7.5, 15.2 and 30.1 at 200 ms) - linear in window/RTT, and 8 MB is where a 200 ms link
|
|
12
|
+
// clears the ~19 MB/s an untunneled OpenSSH sftp does. Past that the inner SSH is the ceiling and
|
|
13
|
+
// there is nothing left to win. Raising it on the WORKER alone changes nothing at all (measured), so
|
|
14
|
+
// the two ends carry the same number: see worker/src/sshChannelWindow.js, which has the full set.
|
|
21
15
|
//
|
|
22
16
|
// Memory: a receive window only becomes resident when the consumer is slower than the sender, bounded
|
|
23
17
|
// by the window per busy channel - measured at 15.6 MB of RSS per SATURATED channel on 8 MB against
|
|
24
18
|
// 9.8 MB on 2 MB. On an agent that is a handful of channels on one machine, so there is no knob here -
|
|
25
19
|
// unlike the worker, which multiplies it by every concurrent transfer on an edge and reads
|
|
26
20
|
// SSH_CHANNEL_WINDOW for exactly that reason.
|
|
27
|
-
const SSH_CHANNEL_WINDOW = 8 * 1024 * 1024;
|
|
28
|
-
// Why a mutation rather than a patched dependency: client.js and server.js read these two constants
|
|
29
|
-
// ONCE, by destructuring lib/Channel.js at module load, so replacing them before ssh2 is first
|
|
30
|
-
// required is enough. And ssh2 is a bundleDependency published straight out of node_modules with
|
|
31
|
-
// `npm ci --ignore-scripts`, so a patch step would be one forgotten command away from silently
|
|
32
|
-
// shipping the 2 MB default - whereas this is source, and it travels with the build.
|
|
33
|
-
//
|
|
34
|
-
// Imported FIRST in src/index.ts, which is the only entry point (bin/cli.js requires it) and already
|
|
35
|
-
// the home of process-wide setup like stream.setDefaultHighWaterMark. Requiring only Channel.js here
|
|
36
|
-
// does not pull in client.js or server.js, so the constants are still unread at this point.
|
|
37
21
|
//
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// means a new module started importing ssh2 above this line - the symptom would otherwise be
|
|
52
|
-
// nothing but slower uploads.
|
|
53
|
-
//
|
|
54
|
-
// Only asked where there is a cache to ask: the released binary is a rollup bundle with its own
|
|
55
|
-
// require shim, where `require.cache` is undefined and reading it threw - which took the window
|
|
56
|
-
// raise with it in every build we ship (1.24.3 and 1.24.4 both run on ssh2's 2 MB) and, worse,
|
|
57
|
-
// made src/index.ts log at startup. In a bundle the load order is the one this file sets, so
|
|
58
|
-
// there is nothing to detect: go straight to the mutation.
|
|
59
|
-
const cache = require.cache;
|
|
60
|
-
if (cache &&
|
|
61
|
-
Object.keys(cache).some((f) => f.includes(`ssh2${'/'}lib${'/'}client.js`))) {
|
|
62
|
-
exports.sshChannelWindow.reason = 'ssh2 was already loaded, so its constants had been read';
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const channel = require('ssh2/lib/Channel.js');
|
|
66
|
-
if (typeof channel.MAX_WINDOW !== 'number' ||
|
|
67
|
-
typeof channel.WINDOW_THRESHOLD !== 'number' ||
|
|
68
|
-
typeof channel.windowAdjust !== 'function') {
|
|
69
|
-
exports.sshChannelWindow.reason = 'ssh2 no longer exposes MAX_WINDOW/WINDOW_THRESHOLD/windowAdjust';
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if (SSH_CHANNEL_WINDOW < channel.MAX_WINDOW) {
|
|
73
|
-
exports.sshChannelWindow.reason = `ssh2 already defaults to ${channel.MAX_WINDOW} bytes`;
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
channel.MAX_WINDOW = SSH_CHANNEL_WINDOW;
|
|
77
|
-
// ssh2 tops the window up once half of it is spent. Left at its own 1 MB it would top up only in
|
|
78
|
-
// the last eighth of an 8 MB window, which is exactly when a fast sender runs dry.
|
|
79
|
-
channel.WINDOW_THRESHOLD = Math.floor(SSH_CHANNEL_WINDOW / 2);
|
|
80
|
-
// And the refill itself, which is where the two constants above stopped being worth anything.
|
|
81
|
-
// client.js and server.js destructure `windowAdjust` from here, but the copy inside Channel.js
|
|
82
|
-
// closes over ITS OWN 2 MB const, so it refilled to 2 MB whatever these two say: measured on a
|
|
83
|
-
// 60 MB transfer, the window opened at 8 MB and every refill after it was 32 KB back up to 2 MB
|
|
84
|
-
// - 1665 window-adjust packets where 14 would do, and a steady-state window of 2 MB. So the raise
|
|
85
|
-
// only ever bought the first burst. Three lines, ssh2's own (Channel.js windowAdjust), with the
|
|
86
|
-
// window read from here - and, like the constants, it has to be in place before client.js
|
|
87
|
-
// destructures it. What still tops up to 2 MB is Channel.js's internal call on the drain path;
|
|
88
|
-
// the next arriving packet brings the window back to full through this one.
|
|
89
|
-
//
|
|
90
|
-
// worker/src/ssh2.js holds the same three lines for the edge, and has the same tests: a window
|
|
91
|
-
// raised on one end alone changes nothing measurable, so an ssh2 bump has to move both.
|
|
92
|
-
const refill = (self) => {
|
|
93
|
-
if (self.outgoing.state === 'closed')
|
|
94
|
-
return;
|
|
95
|
-
const amt = SSH_CHANNEL_WINDOW - self.incoming.window;
|
|
96
|
-
if (amt <= 0)
|
|
97
|
-
return;
|
|
98
|
-
self.incoming.window += amt;
|
|
99
|
-
self._client._protocol.channelWindowAdjust(self.outgoing.id, amt);
|
|
100
|
-
};
|
|
101
|
-
channel.windowAdjust = refill;
|
|
102
|
-
// Read back rather than assume. A bundler that hands consumers a copy of these exports, a frozen
|
|
103
|
-
// module, an ssh2 that redefines them as getters - all of that would leave the three assignments
|
|
104
|
-
// above doing nothing, and `applied: true` would then be a claim nobody checked. What this still
|
|
105
|
-
// cannot see is whether client.js had already destructured them; that is what
|
|
106
|
-
// effectiveChannelWindow() is for, and what the build gate runs on the shipped binary.
|
|
107
|
-
if (channel.MAX_WINDOW !== SSH_CHANNEL_WINDOW ||
|
|
108
|
-
channel.WINDOW_THRESHOLD !== Math.floor(SSH_CHANNEL_WINDOW / 2) ||
|
|
109
|
-
channel.windowAdjust !== refill) {
|
|
110
|
-
exports.sshChannelWindow.reason = 'ssh2 kept its own constants, the assignment did not take';
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
exports.sshChannelWindow.applied = true;
|
|
114
|
-
}
|
|
115
|
-
catch (err) {
|
|
116
|
-
// ssh2 moved, or is not resolvable from here: keep the tunnel working on ssh2's defaults rather
|
|
117
|
-
// than failing to start over a throughput knob. Recorded rather than swallowed - the symptom is
|
|
118
|
-
// otherwise nothing but slower uploads, which is how this cost went unnoticed in the first place.
|
|
119
|
-
exports.sshChannelWindow.reason = `${err?.message || err}`;
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
applyChannelWindow();
|
|
123
|
-
// The only route to ssh2 in src/, so the window above is always in place before client.js and
|
|
124
|
-
// server.js destructure the constants - eslint refuses `import ... from 'ssh2'` and `require('ssh2')`
|
|
125
|
-
// everywhere else (type-only imports are fine, they carry no runtime load). Kept lazy on purpose:
|
|
126
|
-
// requiring ssh2 costs ~70 ms of native binding and protocol module loading, and most commands never
|
|
127
|
-
// open a channel - `bdy --version` should not pay for one.
|
|
22
|
+
// It is the `channelWindow` option of @buddy-works/ssh2, which also tops the window up to this size.
|
|
23
|
+
// With the original ssh2 it was a module constant that this file replaced before ssh2 was first
|
|
24
|
+
// loaded - an ordering that broke silently in a bundle and shipped 1.24.3 and 1.24.4 on 2 MB - and
|
|
25
|
+
// ssh2's refill went back to 2 MB whatever the constant said.
|
|
26
|
+
const SSH_CHANNEL_WINDOW = 8 * 1024 * 1024;
|
|
27
|
+
// What the tunnel client (tunnel/ssh/client.ts) and the agent's SSH server (tunnel/server/ssh.ts)
|
|
28
|
+
// spread into their ssh2 config. One object rather than the number repeated, so the probe below
|
|
29
|
+
// measures what those two really pass and not a copy of it.
|
|
30
|
+
exports.SSH_CHANNEL_OPTIONS = { channelWindow: SSH_CHANNEL_WINDOW };
|
|
31
|
+
// The only route to ssh2 in src/, and lazy on purpose: requiring ssh2 costs ~70 ms of native binding
|
|
32
|
+
// and protocol module loading, and most commands never open a channel - `bdy --version` should not
|
|
33
|
+
// pay for one. eslint refuses `import ... from 'ssh2'` and `require('ssh2')` everywhere else
|
|
34
|
+
// (type-only imports are fine, they carry no runtime load).
|
|
128
35
|
const requireSsh2 = () => require('ssh2');
|
|
129
36
|
exports.requireSsh2 = requireSsh2;
|
|
130
|
-
//
|
|
131
|
-
//
|
|
132
|
-
//
|
|
133
|
-
//
|
|
37
|
+
// The window a client made with SSH_CHANNEL_OPTIONS announces when it opens a channel - measured,
|
|
38
|
+
// not read back from the constant. `agent selftest` prints it and build.sh fails the release if the
|
|
39
|
+
// binary it just built does not say 8388608: that is the check that the ssh2 inside the artifact is
|
|
40
|
+
// the one that takes the option, and that it still does.
|
|
134
41
|
//
|
|
135
|
-
//
|
|
136
|
-
//
|
|
137
|
-
//
|
|
42
|
+
// No socket, no server and no I/O: connect() is given a stream that swallows what is written and
|
|
43
|
+
// never has anything to read, which is enough for it to take the option, and openChannel() then
|
|
44
|
+
// passes the window to a stubbed protocol. Not a PassThrough: that hands the client its own
|
|
45
|
+
// handshake back, which it answers by closing the stream under the stubs.
|
|
138
46
|
const effectiveChannelWindow = () => {
|
|
139
47
|
try {
|
|
140
48
|
const { Client } = (0, exports.requireSsh2)();
|
|
49
|
+
const { Duplex } = require('node:stream');
|
|
141
50
|
const client = new Client();
|
|
51
|
+
client.on('error', () => { });
|
|
52
|
+
client.connect({
|
|
53
|
+
...exports.SSH_CHANNEL_OPTIONS,
|
|
54
|
+
sock: new Duplex({
|
|
55
|
+
read() { },
|
|
56
|
+
write(_chunk, _encoding, done) {
|
|
57
|
+
done();
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
|
+
username: 'window-probe',
|
|
61
|
+
readyTimeout: 0,
|
|
62
|
+
});
|
|
142
63
|
let captured = 0;
|
|
143
|
-
// The shape ssh2's isWritable() asks for (lib/utils.js), and nothing more
|
|
64
|
+
// The shape ssh2's isWritable() asks for (lib/utils.js), and nothing more
|
|
144
65
|
client._sock = { writable: true, _readableState: { ended: false } };
|
|
145
66
|
client._chanMgr = { add: () => 0 };
|
|
146
67
|
client._protocol = {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.withPqKex = exports.hasPqKex = exports.SSH_KEX_PQ = void 0;
|
|
7
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
8
|
+
// The post-quantum hybrid key exchange of @buddy-works/ssh2 (ML-KEM-768 with X25519), which OpenSSH
|
|
9
|
+
// has since 9.9 and prefers since 10.0.
|
|
10
|
+
exports.SSH_KEX_PQ = 'mlkem768x25519-sha256';
|
|
11
|
+
let supported;
|
|
12
|
+
// Whether this node can do it: ML-KEM needs a node built against OpenSSL 3.5+. ssh2 does not offer
|
|
13
|
+
// the exchange where it cannot, and it throws on a list that names an algorithm it does not have -
|
|
14
|
+
// so a list of our own may only name this one after asking.
|
|
15
|
+
const hasPqKex = () => {
|
|
16
|
+
if (supported === undefined) {
|
|
17
|
+
try {
|
|
18
|
+
node_crypto_1.default.generateKeyPairSync('ml-kem-768');
|
|
19
|
+
supported =
|
|
20
|
+
typeof node_crypto_1.default.encapsulate === 'function';
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
supported = false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return supported;
|
|
27
|
+
};
|
|
28
|
+
exports.hasPqKex = hasPqKex;
|
|
29
|
+
// `kex` with the post-quantum exchange put first where this node has it. The classical ones stay:
|
|
30
|
+
// a peer without it - an older worker or agent, an OpenSSH before 9.9 - settles on one of those.
|
|
31
|
+
const withPqKex = (kex) => (0, exports.hasPqKex)() ? [exports.SSH_KEX_PQ, ...kex] : kex;
|
|
32
|
+
exports.withPqKex = withPqKex;
|
package/distTs/src/sshKeygen.js
CHANGED
|
@@ -5,14 +5,5 @@ const sshChannelWindow_1 = require("./sshChannelWindow");
|
|
|
5
5
|
// ssh2's own parser is the one ssh2.Server runs on the key, so this is the exact check that would fail later.
|
|
6
6
|
const isSshHostKeyValid = (key) => !!key && !((0, sshChannelWindow_1.requireSsh2)().utils.parseKey(key) instanceof Error);
|
|
7
7
|
exports.isSshHostKeyValid = isSshHostKeyValid;
|
|
8
|
-
|
|
9
|
-
// BIT STRING padding, so ~1 in 256 keys (public key starting with 0x00) cannot be parsed back.
|
|
10
|
-
const createSshHostKey = () => {
|
|
11
|
-
const Ssh2 = (0, sshChannelWindow_1.requireSsh2)();
|
|
12
|
-
for (;;) {
|
|
13
|
-
const keys = Ssh2.utils.generateKeyPairSync('ed25519', {});
|
|
14
|
-
if ((0, exports.isSshHostKeyValid)(keys.private))
|
|
15
|
-
return keys.private;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
8
|
+
const createSshHostKey = () => (0, sshChannelWindow_1.requireSsh2)().utils.generateKeyPairSync('ed25519', {}).private;
|
|
18
9
|
exports.createSshHostKey = createSshHostKey;
|
|
@@ -79,30 +79,6 @@ class ServerSftp {
|
|
|
79
79
|
this.sftp = sftp;
|
|
80
80
|
this.home = (0, node_os_1.homedir)();
|
|
81
81
|
this.isWindows = (0, utils_1.isWindows)();
|
|
82
|
-
// fix for sftp/scp exit status -1: send exit-status and EOF before channel close
|
|
83
|
-
// https://github.com/mscdex/ssh2/pull/1492
|
|
84
|
-
const s = sftp;
|
|
85
|
-
const origDestroy = s.destroy.bind(s);
|
|
86
|
-
s.destroy = () => {
|
|
87
|
-
try {
|
|
88
|
-
if (s.outgoing?.state === 'open') {
|
|
89
|
-
s._protocol.exitStatus(s.outgoing.id, 0);
|
|
90
|
-
s._protocol.channelEOF(s.outgoing.id);
|
|
91
|
-
}
|
|
92
|
-
// origDestroy() inside the try, not after it: it sends CHANNEL_CLOSE, and a peer that
|
|
93
|
-
// simply vanished leaves the channel 'open' while ssh2 has already torn the connection
|
|
94
|
-
// down (Protocol.cleanup on socket close). With zlib@openssh.com negotiated - which the
|
|
95
|
-
// java client on the other end of a deployment always picks - that write reaches a
|
|
96
|
-
// destroyed zlib and throws 'Invalid Zlib instance' out of ZlibPacketWriter.finalize.
|
|
97
|
-
// It escaped from inside a 'close' handler, so it took down the whole tunnel and, past
|
|
98
|
-
// the agent's uncaughtException hook, the process with it. There is nothing to salvage
|
|
99
|
-
// by letting it out: the channel this belongs to is already gone.
|
|
100
|
-
return origDestroy();
|
|
101
|
-
}
|
|
102
|
-
catch {
|
|
103
|
-
return undefined;
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
82
|
this.sftp.on('OPEN', (reqId, fileName, flags, attrs) => this.open(reqId, fileName, flags, attrs));
|
|
107
83
|
this.sftp.on('READ', (reqId, handle, offset, length) => this.read(reqId, handle, offset, length));
|
|
108
84
|
this.sftp.on('WRITE', (reqId, handle, offset, data) => this.write(reqId, handle, offset, data));
|
|
@@ -47,6 +47,7 @@ const node_stream_1 = __importStar(require("node:stream"));
|
|
|
47
47
|
const promises_1 = require("node:stream/promises");
|
|
48
48
|
const utils_1 = require("../../utils");
|
|
49
49
|
const sshChannelWindow_1 = require("../../sshChannelWindow");
|
|
50
|
+
const sshKex_1 = require("../../sshKex");
|
|
50
51
|
// The window is applied by the module this comes from, so ssh2 cannot be reached before it ran
|
|
51
52
|
const ssh2 = (0, sshChannelWindow_1.requireSsh2)();
|
|
52
53
|
// The writing end of a process's stdin, for pipeline() from the client's session. It is a sink of
|
|
@@ -122,11 +123,12 @@ class ServerSsh extends events_1.default {
|
|
|
122
123
|
this.login = login;
|
|
123
124
|
this.password = password;
|
|
124
125
|
this.server = new ssh2.Server({
|
|
126
|
+
...sshChannelWindow_1.SSH_CHANNEL_OPTIONS,
|
|
125
127
|
hostKeys: [hostKey],
|
|
126
128
|
highWaterMark: 65536,
|
|
127
129
|
ident: 'SSH-2.0-Buddy',
|
|
128
130
|
algorithms: {
|
|
129
|
-
kex: [
|
|
131
|
+
kex: (0, sshKex_1.withPqKex)([
|
|
130
132
|
'curve25519-sha256',
|
|
131
133
|
'curve25519-sha256@libssh.org',
|
|
132
134
|
'ecdh-sha2-nistp256',
|
|
@@ -136,7 +138,7 @@ class ServerSsh extends events_1.default {
|
|
|
136
138
|
'diffie-hellman-group14-sha256',
|
|
137
139
|
'diffie-hellman-group16-sha512',
|
|
138
140
|
'diffie-hellman-group18-sha512',
|
|
139
|
-
],
|
|
141
|
+
]),
|
|
140
142
|
cipher: [
|
|
141
143
|
'chacha20-poly1305@openssh.com',
|
|
142
144
|
'aes256-gcm@openssh.com',
|
|
@@ -9,10 +9,8 @@ const texts_1 = require("../../texts");
|
|
|
9
9
|
const workerHostKey_1 = require("./workerHostKey");
|
|
10
10
|
const utils_1 = require("../../utils");
|
|
11
11
|
const sshChannelWindow_1 = require("../../sshChannelWindow");
|
|
12
|
+
const sshKex_1 = require("../../sshKex");
|
|
12
13
|
const tunnel_1 = require("../../types/tunnel");
|
|
13
|
-
// Through sshChannelWindow, never straight from 'ssh2': the window is applied when that module is
|
|
14
|
-
// imported, so client.js cannot read the constants before it - the placement of this line has
|
|
15
|
-
// nothing to do with it, imports hoist above it either way. eslint enforces the route.
|
|
16
14
|
const ssh2 = (0, sshChannelWindow_1.requireSsh2)();
|
|
17
15
|
class SshClient extends events_1.default {
|
|
18
16
|
ip;
|
|
@@ -72,14 +70,17 @@ class SshClient extends events_1.default {
|
|
|
72
70
|
}
|
|
73
71
|
reject(err);
|
|
74
72
|
});
|
|
75
|
-
const client = this.client;
|
|
76
73
|
try {
|
|
77
74
|
this.client.connect({
|
|
75
|
+
...sshChannelWindow_1.SSH_CHANNEL_OPTIONS,
|
|
78
76
|
algorithms: {
|
|
79
77
|
cipher: ['aes256-gcm@openssh.com'],
|
|
80
78
|
compress: ['none'],
|
|
81
79
|
hmac: ['hmac-sha2-256-etm@openssh.com'],
|
|
82
|
-
|
|
80
|
+
// Post-quantum where this node and the worker both have it. ecdh-sha2-nistp256 stays
|
|
81
|
+
// for a worker that does not: it was the only one this list had, so every worker
|
|
82
|
+
// deployed before the post-quantum exchange takes it.
|
|
83
|
+
kex: (0, sshKex_1.withPqKex)(['ecdh-sha2-nistp256']),
|
|
83
84
|
},
|
|
84
85
|
keepaliveInterval: 10000,
|
|
85
86
|
// Capability advertisement, read by the worker off info.header at connection time. An
|
|
@@ -90,16 +91,14 @@ class SshClient extends events_1.default {
|
|
|
90
91
|
username: this.username,
|
|
91
92
|
password: this.password,
|
|
92
93
|
// Before the password goes anywhere: the server has to prove it is the worker the manager
|
|
93
|
-
// deployed on this address (workerHostKey.ts).
|
|
94
|
-
//
|
|
95
|
-
hostVerifier: (key) => {
|
|
96
|
-
const
|
|
97
|
-
._protocol?._remoteIdentRaw;
|
|
98
|
-
const ok = (0, workerHostKey_1.verifyWorkerHostKey)(this.ip, key, identRaw);
|
|
94
|
+
// deployed on this address (workerHostKey.ts). The server's identification line comes
|
|
95
|
+
// with the key (@buddy-works/ssh2), as `info.header`.
|
|
96
|
+
hostVerifier: ((key, _verify, info) => {
|
|
97
|
+
const ok = (0, workerHostKey_1.verifyWorkerHostKey)(this.ip, key, info?.header?.identRaw);
|
|
99
98
|
if (!ok)
|
|
100
99
|
logger_1.default.error((0, texts_1.LOG_WORKER_HOST_KEY_REJECTED)(this.ip, this.port));
|
|
101
100
|
return ok;
|
|
102
|
-
},
|
|
101
|
+
}),
|
|
103
102
|
});
|
|
104
103
|
// ssh2 only forwards setNoDelay to a socket it already has, and connect() is what creates
|
|
105
104
|
// it - called before connect() this was a silent no-op, leaving Nagle on the tunnel. With
|
|
@@ -15,27 +15,19 @@ jobs:
|
|
|
15
15
|
strategy:
|
|
16
16
|
fail-fast: false
|
|
17
17
|
matrix:
|
|
18
|
-
node-version: [
|
|
18
|
+
node-version: [16.x, 18.x, 20.x, 22.x, 24.x, 24.x, 26.x]
|
|
19
19
|
steps:
|
|
20
|
-
- uses: actions/checkout@
|
|
20
|
+
- uses: actions/checkout@v6
|
|
21
21
|
with:
|
|
22
22
|
persist-credentials: false
|
|
23
23
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
24
|
-
uses: actions/setup-node@
|
|
24
|
+
uses: actions/setup-node@v6
|
|
25
25
|
with:
|
|
26
26
|
node-version: ${{ matrix.node-version }}
|
|
27
27
|
- name: Check Node.js version
|
|
28
28
|
run: node -pe process.versions
|
|
29
29
|
- name: Check npm version
|
|
30
30
|
run: npm -v
|
|
31
|
-
- name: Install Python 2.7 (node <16.x)
|
|
32
|
-
if: ${{ contains(fromJSON('["10.16.0", "10.x", "12.x", "14.x"]'), matrix.node-version) }}
|
|
33
|
-
uses: LizardByte/setup-python-action@v2024.1105.190605
|
|
34
|
-
with:
|
|
35
|
-
python-version: '2.7'
|
|
36
|
-
- name: Use Python 2.7 (node <16.x)
|
|
37
|
-
if: ${{ contains(fromJSON('["10.16.0", "10.x", "12.x", "14.x"]'), matrix.node-version) }}
|
|
38
|
-
run: echo "PYTHON=$(which python2.7)" >> "$GITHUB_ENV"
|
|
39
31
|
- name: Install module
|
|
40
32
|
run: npm install
|
|
41
33
|
- name: Run tests
|
|
@@ -45,13 +37,13 @@ jobs:
|
|
|
45
37
|
strategy:
|
|
46
38
|
fail-fast: false
|
|
47
39
|
matrix:
|
|
48
|
-
node-version: [16.x, 18.x, 20.x, 22.x, 24.x]
|
|
40
|
+
node-version: [16.x, 18.x, 20.x, 22.x, 24.x, 26.x]
|
|
49
41
|
steps:
|
|
50
|
-
- uses: actions/checkout@
|
|
42
|
+
- uses: actions/checkout@v6
|
|
51
43
|
with:
|
|
52
44
|
persist-credentials: false
|
|
53
45
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
54
|
-
uses: actions/setup-node@
|
|
46
|
+
uses: actions/setup-node@v6
|
|
55
47
|
with:
|
|
56
48
|
node-version: ${{ matrix.node-version }}
|
|
57
49
|
- name: Install Python 3.10
|
|
@@ -69,7 +61,7 @@ jobs:
|
|
|
69
61
|
tests-macos-homebrew:
|
|
70
62
|
runs-on: macos-latest
|
|
71
63
|
steps:
|
|
72
|
-
- uses: actions/checkout@
|
|
64
|
+
- uses: actions/checkout@v6
|
|
73
65
|
with:
|
|
74
66
|
persist-credentials: false
|
|
75
67
|
- name: Use Node.js (latest)
|
|
@@ -91,19 +83,21 @@ jobs:
|
|
|
91
83
|
strategy:
|
|
92
84
|
fail-fast: false
|
|
93
85
|
matrix:
|
|
94
|
-
node-version: [16.x, 18.x, 20.x, 22.x, 24.x]
|
|
86
|
+
node-version: [16.x, 18.x, 20.x, 22.x, 24.x, 26.x]
|
|
95
87
|
steps:
|
|
96
|
-
- uses: actions/checkout@
|
|
88
|
+
- uses: actions/checkout@v6
|
|
97
89
|
with:
|
|
98
90
|
persist-credentials: false
|
|
99
91
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
100
|
-
uses: actions/setup-node@
|
|
92
|
+
uses: actions/setup-node@v6
|
|
101
93
|
with:
|
|
102
94
|
node-version: ${{ matrix.node-version }}
|
|
103
95
|
- name: Check Node.js version
|
|
104
96
|
run: node -pe process.versions
|
|
105
97
|
- name: Check npm version
|
|
106
98
|
run: npm -v
|
|
99
|
+
- name: Install setuptools (for distutils compat)
|
|
100
|
+
run: pip install setuptools
|
|
107
101
|
- name: Install module
|
|
108
102
|
run: npm install
|
|
109
103
|
- name: Run tests
|
|
@@ -6,7 +6,7 @@ on:
|
|
|
6
6
|
branches: [ master ]
|
|
7
7
|
|
|
8
8
|
env:
|
|
9
|
-
NODE_VERSION:
|
|
9
|
+
NODE_VERSION: 22.x
|
|
10
10
|
|
|
11
11
|
jobs:
|
|
12
12
|
lint-js:
|
|
@@ -22,6 +22,6 @@ jobs:
|
|
|
22
22
|
- name: Check Node.js version
|
|
23
23
|
run: node -pe process.versions
|
|
24
24
|
- name: Install ESLint + ESLint configs/plugins
|
|
25
|
-
run: npm install --
|
|
25
|
+
run: npm install --omit=prod --include=dev --ignore-scripts
|
|
26
26
|
- name: Lint files
|
|
27
27
|
run: npm run lint
|