bdy 1.26.11 → 1.26.13-dev

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.26.11",
4
+ "version": "1.26.13-dev",
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": "npm:@buddy-works/ssh2@1.17.0-pq.1",
92
+ "ssh2": "npm:@buddy-works/ssh2@1.17.0-pq.2",
93
93
  "tar-stream": "3.2.0",
94
94
  "terminal-kit": "3.1.2",
95
95
  "undici": "8.12.3",
@@ -436,14 +436,18 @@ class Agent extends events_1.default {
436
436
  });
437
437
  tunnels.forEach((data) => {
438
438
  let sshHostKey;
439
- if (this.manager)
439
+ let sshHostKeyRsa;
440
+ if (this.manager) {
440
441
  sshHostKey = this.manager.sshHostKey;
442
+ sshHostKeyRsa = this.manager.sshHostKeyRsa;
443
+ }
441
444
  const tunnel = tt.find((tunnel) => data.id === tunnel.id);
442
445
  if (!tunnel) {
443
446
  const TunnelImpl = require('../tunnel/tunnel').default;
444
447
  this.addTunnel(new TunnelImpl({
445
448
  ...data,
446
449
  sshHostKey,
450
+ sshHostKeyRsa,
447
451
  agent: {
448
452
  id: this.id,
449
453
  host: this.host,
@@ -26,6 +26,7 @@ class AgentManagerClass {
26
26
  // actually gone. Anything that must not start in that window checks this.
27
27
  exiting = false;
28
28
  sshHostKey;
29
+ sshHostKeyRsa;
29
30
  agent;
30
31
  ws;
31
32
  server;
@@ -38,6 +39,7 @@ class AgentManagerClass {
38
39
  this.token = null;
39
40
  this.port = null;
40
41
  this.sshHostKey = null;
42
+ this.sshHostKeyRsa = null;
41
43
  this.agent = null;
42
44
  this.server = null;
43
45
  this.ws = null;
@@ -713,7 +715,7 @@ class AgentManagerClass {
713
715
  }
714
716
  let tunnel;
715
717
  try {
716
- tunnel = await getApiBuddy().addTunnel(this.id || '', this.host || '', this.token || '', data, this.sshHostKey || '');
718
+ tunnel = await getApiBuddy().addTunnel(this.id || '', this.host || '', this.token || '', data, this.sshHostKey || '', this.sshHostKeyRsa || undefined);
717
719
  }
718
720
  catch (err) {
719
721
  this.serverError(res, err.message);
@@ -838,19 +840,26 @@ class AgentManagerClass {
838
840
  // load from config
839
841
  const json = this.system.loadNewAgentConfig();
840
842
  this.sshHostKey = json.sshHostKey;
843
+ this.sshHostKeyRsa = json.sshHostKeyRsa;
841
844
  }
842
845
  catch {
843
846
  // save from param
844
847
  }
845
- const { createSshHostKey, isSshHostKeyValid } = require('../sshKeygen');
848
+ const { createSshHostKey, createSshHostKeyRsa, isSshHostKeyValid, } = require('../sshKeygen');
846
849
  if (!isSshHostKeyValid(this.sshHostKey)) {
847
850
  if (this.sshHostKey)
848
851
  logger_1.default.error(texts_1.LOG_AGENT_SSH_HOST_KEY_INVALID);
849
852
  this.sshHostKey = createSshHostKey();
850
853
  }
854
+ // A config from before the RSA key has none: it is added next to the Ed25519 one, which stays
855
+ if (!isSshHostKeyValid(this.sshHostKeyRsa)) {
856
+ if (this.sshHostKeyRsa)
857
+ logger_1.default.error(texts_1.LOG_AGENT_SSH_HOST_KEY_INVALID);
858
+ this.sshHostKeyRsa = createSshHostKeyRsa();
859
+ }
851
860
  try {
852
861
  // resave config
853
- this.system.saveNewAgentConfig(this.sshHostKey || '');
862
+ this.system.saveNewAgentConfig(this.sshHostKey || '', this.sshHostKeyRsa || '');
854
863
  return true;
855
864
  }
856
865
  catch {
@@ -1096,7 +1096,7 @@ class AgentSystem {
1096
1096
  return false;
1097
1097
  }
1098
1098
  }
1099
- saveNewAgentConfig(sshHostKey) {
1099
+ saveNewAgentConfig(sshHostKey, sshHostKeyRsa) {
1100
1100
  try {
1101
1101
  this.clearAgentFiles();
1102
1102
  }
@@ -1107,6 +1107,7 @@ class AgentSystem {
1107
1107
  logger_1.default.info(texts_1.LOG_SAVING_AGENT_LOCAL_CONFIG);
1108
1108
  (0, node_fs_1.writeFileSync)(this.getNewAgentConfigPath(), JSON.stringify({
1109
1109
  sshHostKey,
1110
+ sshHostKeyRsa,
1110
1111
  }), {
1111
1112
  encoding: 'utf-8',
1112
1113
  });
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSshHostKey = exports.isSshHostKeyValid = void 0;
3
+ exports.createSshHostKeyRsa = exports.createSshHostKey = exports.isSshHostKeyValid = void 0;
4
4
  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
8
  const createSshHostKey = () => (0, sshChannelWindow_1.requireSsh2)().utils.generateKeyPairSync('ed25519', {}).private;
9
9
  exports.createSshHostKey = createSshHostKey;
10
+ // The second host key the SSH server of a tunnel offers. A client names the algorithm, and one that
11
+ // knows the Ed25519 key goes on asking for it, so this one changes nothing for it.
12
+ const createSshHostKeyRsa = () => (0, sshChannelWindow_1.requireSsh2)().utils.generateKeyPairSync('rsa', { bits: 4096 }).private;
13
+ exports.createSshHostKeyRsa = createSshHostKeyRsa;
@@ -160,7 +160,7 @@ class ApiBuddyClass {
160
160
  tags
161
161
  });
162
162
  }
163
- async addTunnel(agentId, host, token, prepared, sshHostKey) {
163
+ async addTunnel(agentId, host, token, prepared, sshHostKey, sshHostKeyRsa) {
164
164
  logger_1.default.info(texts_1.LOG_REGISTERING_TUNNEL);
165
165
  const config = await makeRequest(host, '/tunnel/add', {
166
166
  ...prepared,
@@ -171,6 +171,7 @@ class ApiBuddyClass {
171
171
  return new tunnel_1.default({
172
172
  ...config,
173
173
  sshHostKey,
174
+ sshHostKeyRsa,
174
175
  agent: { id: agentId, host, token },
175
176
  });
176
177
  }
@@ -117,14 +117,14 @@ class ServerSsh extends events_1.default {
117
117
  login;
118
118
  password;
119
119
  server;
120
- constructor(agent, login, password, hostKey) {
120
+ constructor(agent, login, password, hostKey, hostKeyRsa) {
121
121
  super();
122
122
  this.agent = agent;
123
123
  this.login = login;
124
124
  this.password = password;
125
125
  this.server = new ssh2.Server({
126
126
  ...sshChannelWindow_1.SSH_CHANNEL_OPTIONS,
127
- hostKeys: [hostKey],
127
+ hostKeys: hostKeyRsa ? [hostKey, hostKeyRsa] : [hostKey],
128
128
  highWaterMark: 65536,
129
129
  ident: 'SSH-2.0-Buddy',
130
130
  algorithms: {
@@ -81,6 +81,9 @@ class SshClient extends events_1.default {
81
81
  // for a worker that does not: it was the only one this list had, so every worker
82
82
  // deployed before the post-quantum exchange takes it.
83
83
  kex: (0, sshKex_1.withPqKex)(['ecdh-sha2-nistp256']),
84
+ // The worker's RSA 4096 host key where it has one, its Ed25519 key where it does not -
85
+ // a worker deployed before the RSA key. Either is checked the same way below.
86
+ serverHostKey: ['rsa-sha2-512', 'rsa-sha2-256', 'ssh-ed25519'],
84
87
  },
85
88
  keepaliveInterval: 10000,
86
89
  // Capability advertisement, read by the worker off info.header at connection time. An
@@ -11,7 +11,10 @@ const node_net_1 = __importDefault(require("node:net"));
11
11
  exports.WORKER_HOST_KEY_CA = [
12
12
  'MCowBQYDK2VwAyEA2fgQwY2Ey9PRsJKdcAL4cGXkWmrVZsMJTww3lsUVYWE=',
13
13
  ].map((der) => node_crypto_1.default.createPublicKey({ key: Buffer.from(der, 'base64'), format: 'der', type: 'spki' }));
14
- const SIGNATURE = / bdy-sig:([A-Za-z0-9+/=]+)\s*$/;
14
+ // One signature per host key the worker serves: ` bdy-sig:` for its Ed25519 key, ` bdy-sig-rsa:`
15
+ // for the RSA one. Each covers the exact key, so only the one made for the key the server showed
16
+ // verifies - whichever of them the key exchange settled on.
17
+ const SIGNATURES = / bdy-sig(?:-[a-z0-9]+)?:([A-Za-z0-9+/=]+)/g;
15
18
  // Workers nobody deploys through the manager - a developer's local stack, the e2e one - have no
16
19
  // signed key. Only ever reachable on an address of one's own network, so only those are let off.
17
20
  const isLocalWorkerAddress = (ip) => {
@@ -42,18 +45,15 @@ exports.isLocalWorkerAddress = isLocalWorkerAddress;
42
45
  const verifyWorkerHostKey = (ip, key, identRaw) => {
43
46
  if ((0, exports.isLocalWorkerAddress)(ip))
44
47
  return true;
45
- const m = String(identRaw || '').match(SIGNATURE);
46
- if (!m)
47
- return false;
48
+ const signatures = [...String(identRaw || '').matchAll(SIGNATURES)].map((m) => Buffer.from(m[1], 'base64'));
48
49
  const message = Buffer.from(`bdy-worker-host-key\n${ip}\n${key.toString('base64')}`);
49
- const signature = Buffer.from(m[1], 'base64');
50
- return exports.WORKER_HOST_KEY_CA.some((ca) => {
50
+ return signatures.some((signature) => exports.WORKER_HOST_KEY_CA.some((ca) => {
51
51
  try {
52
52
  return node_crypto_1.default.verify(null, message, ca, signature);
53
53
  }
54
54
  catch {
55
55
  return false;
56
56
  }
57
- });
57
+ }));
58
58
  };
59
59
  exports.verifyWorkerHostKey = verifyWorkerHostKey;
@@ -57,6 +57,7 @@ class Tunnel extends events_1.default {
57
57
  agent;
58
58
  id;
59
59
  sshHostKey;
60
+ sshHostKeyRsa;
60
61
  config;
61
62
  auth;
62
63
  totalConnections;
@@ -78,7 +79,7 @@ class Tunnel extends events_1.default {
78
79
  // drift the value. A drifted counter would latch the tunnel into answering
79
80
  // 503 forever with no way back short of restarting the agent.
80
81
  inFlight = new Set();
81
- constructor({ agent, id, sshHostKey, ...options }) {
82
+ constructor({ agent, id, sshHostKey, sshHostKeyRsa, ...options }) {
82
83
  super();
83
84
  const { createSshHostKey, isSshHostKeyValid } = require('../sshKeygen');
84
85
  if (!isSshHostKeyValid(sshHostKey))
@@ -86,6 +87,7 @@ class Tunnel extends events_1.default {
86
87
  this.agent = agent;
87
88
  this.id = id;
88
89
  this.sshHostKey = sshHostKey;
90
+ this.sshHostKeyRsa = sshHostKeyRsa;
89
91
  this.auth = new auth_1.default(this);
90
92
  this.config = new config_1.default(options);
91
93
  this.resetState();
@@ -637,7 +639,13 @@ class Tunnel extends events_1.default {
637
639
  else if (this.type === tunnel_1.TUNNEL_TYPE.SSH) {
638
640
  // ssh server
639
641
  const ServerSsh = require('./server/ssh').default;
640
- this.sshServer = new ServerSsh(this.agent, this.sshClientUser || '', this.sshClientPassword || '', this.sshHostKey);
642
+ // Made here and not in the constructor like the Ed25519 one: an RSA 4096 key takes long
643
+ // enough to generate that only a tunnel which serves SSH should pay for it. The agent
644
+ // hands over the one it keeps (agent/manager.ts), so this is for a tunnel without one.
645
+ const { createSshHostKeyRsa, isSshHostKeyValid } = require('../sshKeygen');
646
+ if (!isSshHostKeyValid(this.sshHostKeyRsa))
647
+ this.sshHostKeyRsa = createSshHostKeyRsa();
648
+ this.sshServer = new ServerSsh(this.agent, this.sshClientUser || '', this.sshClientPassword || '', this.sshHostKey, this.sshHostKeyRsa);
641
649
  }
642
650
  // ssh
643
651
  const SshClientImpl = require('./ssh/client').default;
@@ -5,7 +5,7 @@ SSH2 client and server modules written in pure JavaScript for [node.js](http://n
5
5
  This is `@buddy-works/ssh2`, a fork of [ssh2](https://github.com/mscdex/ssh2) that can be used in its place:
6
6
 
7
7
  ```json
8
- "ssh2": "npm:@buddy-works/ssh2@1.17.0-pq.1"
8
+ "ssh2": "npm:@buddy-works/ssh2@1.17.0-pq.2"
9
9
  ```
10
10
 
11
11
  The version is the one of ssh2 it is based on, with a suffix of its own. What it adds:
@@ -16,6 +16,7 @@ The version is the one of ssh2 it is based on, with a suffix of its own. What it
16
16
  * `destroy()` on server connections, and a client `destroy()` that also frees a half-closed socket.
17
17
  * `hostVerifier` is passed the server's identification.
18
18
  * `setNoDelay()` works before `connect()`.
19
+ * Servers work with OpenSSH 10 clients that use an RSA key: the answer to a key query names the algorithm of the query (`rsa-sha2-256`, `rsa-sha2-512`) instead of `ssh-rsa`, and `server-sig-algs` no longer runs `ecdsa-sha2-nistp521` and `rsa-sha2-512` together.
19
20
  * Fixes: Ed25519 keys generated with a public key starting with a zero byte, the exit status of the SFTP subsystem ([#1492](https://github.com/mscdex/ssh2/pull/1492)), an exception on a write after the connection is gone with compression on.
20
21
 
21
22
  Development/testing is done against OpenSSH (8.7 currently).
@@ -2112,7 +2112,7 @@ function modesToBytes(modes) {
2112
2112
 
2113
2113
  function sendExtInfo(proto) {
2114
2114
  let serverSigAlgs =
2115
- 'ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521'
2115
+ 'ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,'
2116
2116
  + 'rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss';
2117
2117
  if (eddsaSupported)
2118
2118
  serverSigAlgs = `ssh-ed25519,${serverSigAlgs}`;
@@ -274,6 +274,7 @@ module.exports = {
274
274
  );
275
275
  methodData = {
276
276
  keyAlgo: realKeyAlgo,
277
+ sigAlgo: keyAlgo,
277
278
  key,
278
279
  signature,
279
280
  blob,
@@ -282,7 +283,12 @@ module.exports = {
282
283
  }
283
284
  }
284
285
  } else {
285
- methodData = { keyAlgo: realKeyAlgo, key, hashAlgo };
286
+ methodData = {
287
+ keyAlgo: realKeyAlgo,
288
+ sigAlgo: keyAlgo,
289
+ key,
290
+ hashAlgo,
291
+ };
286
292
  methodDesc = 'publickey -- check';
287
293
  }
288
294
  }
@@ -152,6 +152,10 @@ class PKAuthContext extends AuthContext {
152
152
  super(protocol, username, service, method, cb);
153
153
 
154
154
  this.key = { algo: pkInfo.keyAlgo, data: pkInfo.key };
155
+ // The algorithm name as the client sent it: `key.algo` is the key type, so
156
+ // for an RSA key it says 'ssh-rsa' where the client asked for
157
+ // 'rsa-sha2-256' or 'rsa-sha2-512'
158
+ this._sigAlgo = pkInfo.sigAlgo || pkInfo.keyAlgo;
155
159
  this.hashAlgo = pkInfo.hashAlgo;
156
160
  this.signature = pkInfo.signature;
157
161
  this.blob = pkInfo.blob;
@@ -160,7 +164,10 @@ class PKAuthContext extends AuthContext {
160
164
  accept() {
161
165
  if (!this.signature) {
162
166
  this._initialResponse = true;
163
- this._protocol.authPKOK(this.key.algo, this.key.data);
167
+ // PK_OK has to name the algorithm of the request (RFC 4252, 7). OpenSSH
168
+ // 10 checks it and drops the connection on 'ssh-rsa', which it no longer
169
+ // accepts.
170
+ this._protocol.authPKOK(this._sigAlgo, this.key.data);
164
171
  } else if (hasValidSignature(this)) {
165
172
  AuthContext.prototype.accept.call(this);
166
173
  } else {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buddy-works/ssh2",
3
- "version": "1.17.0-pq.1",
3
+ "version": "1.17.0-pq.2",
4
4
  "author": "Brian White <mscdex@mscdex.net>",
5
5
  "description": "SSH2 client and server modules written in pure JavaScript for node.js (fork of ssh2 with post-quantum key exchange)",
6
6
  "main": "./lib/index.js",
@@ -0,0 +1,83 @@
1
+ 'use strict';
2
+
3
+ const assert = require('assert');
4
+
5
+ const {
6
+ fixture,
7
+ fixtureKey,
8
+ mustCall,
9
+ setup,
10
+ } = require('./common.js');
11
+
12
+ const { generateKeyPairSync, parseKey } = require('../lib/index.js').utils;
13
+
14
+ const serverCfg = { hostKeys: [ fixture('ssh_host_rsa_key') ] };
15
+ // There is no Ed25519 fixture
16
+ const ed25519Key = (() => {
17
+ const raw = generateKeyPairSync('ed25519').private;
18
+ return { raw, key: parseKey(raw) };
19
+ })();
20
+ const debug = false;
21
+
22
+ // What the server tells a client about public key algorithms: the list it
23
+ // accepts (server-sig-algs) and, in its answer to a key query, the algorithm
24
+ // of that query (RFC 4252, 7). OpenSSH 10 drops the connection when the answer
25
+ // names another one, as 'ssh-rsa' for a query with 'rsa-sha2-512'.
26
+ [
27
+ { desc: 'RSA', clientKey: fixtureKey('id_rsa'), queried: 'rsa-sha2-256' },
28
+ { desc: 'ECDSA', clientKey: fixtureKey('id_ecdsa') },
29
+ { desc: 'Ed25519', clientKey: ed25519Key },
30
+ ].forEach(({ desc, clientKey, queried }) => {
31
+ const { client, server } = setup(
32
+ `publickey, ${desc}: algorithm names sent by the server`,
33
+ {
34
+ client: { username: 'foo', privateKey: clientKey.raw },
35
+ server: serverCfg,
36
+ debug,
37
+ }
38
+ );
39
+
40
+ // The key type, which is what the application is given as `ctx.key.algo`
41
+ const keyType = clientKey.key.type;
42
+ const expected = queried || keyType;
43
+
44
+ server.on('connection', mustCall((conn) => {
45
+ conn.on('authentication', mustCall((ctx) => {
46
+ if (ctx.method !== 'publickey')
47
+ return ctx.reject();
48
+ assert.strictEqual(ctx.key.algo, keyType);
49
+ ctx.accept();
50
+ }, 3)).on('ready', mustCall(() => {
51
+ conn.end();
52
+ }));
53
+ }));
54
+
55
+ // The handlers exist once the socket is connected, before anything is read
56
+ client.on('connect', mustCall(() => {
57
+ const handlers = client._protocol._handlers;
58
+
59
+ const onExtInfo = handlers.EXT_INFO;
60
+ handlers.EXT_INFO = mustCall((p, exts) => {
61
+ const ext = exts.find((e) => e.name === 'server-sig-algs');
62
+ assert(ext, 'Missing server-sig-algs');
63
+ assert.deepStrictEqual(ext.algs, [
64
+ 'ssh-ed25519',
65
+ 'ecdsa-sha2-nistp256',
66
+ 'ecdsa-sha2-nistp384',
67
+ 'ecdsa-sha2-nistp521',
68
+ 'rsa-sha2-512',
69
+ 'rsa-sha2-256',
70
+ 'ssh-rsa',
71
+ 'ssh-dss',
72
+ ]);
73
+ onExtInfo(p, exts);
74
+ });
75
+
76
+ const onPKOK = handlers.USERAUTH_PK_OK;
77
+ handlers.USERAUTH_PK_OK = mustCall((p, keyAlgo, key) => {
78
+ assert.strictEqual(keyAlgo, expected);
79
+ assert.deepStrictEqual(key, clientKey.key.getPublicSSH());
80
+ onPKOK(p, keyAlgo, key);
81
+ });
82
+ }));
83
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.26.11",
4
+ "version": "1.26.13-dev",
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": "npm:@buddy-works/ssh2@1.17.0-pq.1",
92
+ "ssh2": "npm:@buddy-works/ssh2@1.17.0-pq.2",
93
93
  "tar-stream": "3.2.0",
94
94
  "terminal-kit": "3.1.2",
95
95
  "undici": "8.12.3",