bdy 1.9.49-dev → 1.9.51-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.9.49-dev",
4
+ "version": "1.9.51-dev",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -10,6 +10,18 @@ const crypto_1 = require("crypto");
10
10
  const child_process_1 = require("child_process");
11
11
  const sftp_1 = __importDefault(require("./sftp"));
12
12
  const buddy_1 = __importDefault(require("../api/buddy"));
13
+ const pipeStreamToChannel = (stream, channel) => {
14
+ channel.once('exit', (code, signal) => {
15
+ logger_js_1.default.debug(`shell channel exit: ${code}, signal: ${signal}`);
16
+ if (stream.exit)
17
+ stream.exit(signal || code);
18
+ });
19
+ channel.on('close', () => {
20
+ stream.end();
21
+ });
22
+ channel.pipe(stream, { end: false }).pipe(channel);
23
+ channel.stderr.pipe(stream.stderr);
24
+ };
13
25
  class ServerSsh extends events_1.default {
14
26
  constructor(agent, login, password, hostKey) {
15
27
  super();
@@ -216,13 +228,7 @@ class ServerSsh extends events_1.default {
216
228
  reject();
217
229
  return;
218
230
  }
219
- channel = c;
220
- channel.once('exit', (code) => {
221
- if (stream && stream.exit)
222
- stream.exit(code);
223
- });
224
- stream.pipe(channel);
225
- channel.pipe(stream);
231
+ pipeStreamToChannel(stream, c);
226
232
  });
227
233
  });
228
234
  session.on('signal', (accept, reject, info) => {
@@ -254,13 +260,7 @@ class ServerSsh extends events_1.default {
254
260
  reject();
255
261
  return;
256
262
  }
257
- channel = c;
258
- channel.once('exit', (code) => {
259
- if (stream && stream.exit)
260
- stream.exit(code);
261
- });
262
- stream.pipe(channel);
263
- channel.pipe(stream);
263
+ pipeStreamToChannel(stream, c);
264
264
  });
265
265
  });
266
266
  session.on('x11', (accept, reject, info) => {
@@ -298,13 +298,7 @@ class ServerSsh extends events_1.default {
298
298
  reject();
299
299
  return;
300
300
  }
301
- channel = c;
302
- channel.once('exit', (code) => {
303
- if (stream && stream.exit)
304
- stream.exit(code);
305
- });
306
- stream.pipe(channel);
307
- channel.pipe(stream);
301
+ pipeStreamToChannel(stream, c);
308
302
  });
309
303
  });
310
304
  session.on('env', (accept, reject, info) => {
@@ -332,6 +326,23 @@ class ServerSsh extends events_1.default {
332
326
  client.setNoDelay();
333
327
  client.on('authentication', async (ctx) => {
334
328
  proxyClient = await this.authenticateClient(ctx);
329
+ if (proxyClient) {
330
+ proxyClient.on('tcp connection', (details, accept, reject) => {
331
+ logger_js_1.default.debug('new ssh client forward connection');
332
+ logger_js_1.default.debug(details);
333
+ const { destIP, destPort, srcIP, srcPort } = details;
334
+ client.forwardOut(destIP, destPort, srcIP, srcPort, (err, channel) => {
335
+ logger_js_1.default.debug('new ssh client forward out connection');
336
+ logger_js_1.default.debug({ destIP, destPort, srcIP, srcPort });
337
+ if (err) {
338
+ reject();
339
+ return;
340
+ }
341
+ const stream = accept();
342
+ channel.pipe(stream).pipe(channel);
343
+ });
344
+ });
345
+ }
335
346
  logger_js_1.default.debug('ssh authentication', !!proxyClient);
336
347
  });
337
348
  client.on('close', () => {
@@ -351,6 +362,38 @@ class ServerSsh extends events_1.default {
351
362
  client = null;
352
363
  }, 1000);
353
364
  });
365
+ client.on('request', (accept, reject, name, info) => {
366
+ logger_js_1.default.debug('ssh forward request');
367
+ logger_js_1.default.debug(name);
368
+ logger_js_1.default.debug(info);
369
+ if (!proxyClient) {
370
+ reject();
371
+ return;
372
+ }
373
+ if (name === 'tcpip-forward') {
374
+ let { bindAddr, bindPort } = info;
375
+ proxyClient.forwardIn(bindAddr, bindPort, (err, port) => {
376
+ if (err) {
377
+ reject();
378
+ return;
379
+ }
380
+ accept(port);
381
+ });
382
+ return;
383
+ }
384
+ if (name === 'cancel-tcpip-forward') {
385
+ const { bindAddr, bindPort } = info;
386
+ proxyClient.unforwardIn(bindAddr, bindPort, (err) => {
387
+ if (err) {
388
+ reject();
389
+ return;
390
+ }
391
+ accept();
392
+ });
393
+ return;
394
+ }
395
+ reject();
396
+ });
354
397
  client.on('error', (err) => {
355
398
  logger_js_1.default.debug('Error on ssh server client');
356
399
  logger_js_1.default.debug(err);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.9.49-dev",
4
+ "version": "1.9.51-dev",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {