Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mongodb-js/ssh-tunnel

Package Overview
Dependencies
Maintainers
28
Versions
432
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mongodb-js/ssh-tunnel - npm Package Compare versions

Comparing version 1.2.3 to 1.3.0

dist/index.d.ts.map

13

dist/index.d.ts
/// <reference types="node" />
import { EventEmitter } from 'events';
import { ConnectConfig } from 'ssh2';
declare type ForwardOutConfig = {
srcAddr: string;
srcPort: number;
dstAddr: string;
dstPort: number;
};
import type { ConnectConfig } from 'ssh2';
declare type LocalProxyServerConfig = {
localAddr: string;
localPort: number;
socks5Username?: string;
socks5Password?: string;
};
export declare type SshTunnelConfig = ConnectConfig & ForwardOutConfig & LocalProxyServerConfig;
export declare type SshTunnelConfig = ConnectConfig & LocalProxyServerConfig;
export declare class SshTunnel extends EventEmitter {

@@ -31,1 +27,2 @@ private connections;

export default SshTunnel;
//# sourceMappingURL=index.d.ts.map
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -6,19 +9,20 @@ exports.SshTunnel = void 0;

const events_1 = require("events");
const net_1 = require("net");
const ssh2_1 = require("ssh2");
const debug_1 = __importDefault(require("debug"));
const server_1 = __importDefault(require("socksv5/lib/server"));
const None_1 = __importDefault(require("socksv5/lib/auth/None"));
const UserPassword_1 = __importDefault(require("socksv5/lib/auth/UserPassword"));
const debug = (0, debug_1.default)('mongodb:ssh-tunnel');
function getConnectConfig(config) {
const { srcAddr, srcPort, dstAddr, dstPort, localAddr, localPort, ...connectConfig } = config;
const { localAddr, localPort, socks5Password, socks5Username, ...connectConfig } = config;
return connectConfig;
}
function getSshTunnelConfig(config) {
const connectConfig = { port: 22, ...getConnectConfig(config) };
return Object.assign({}, {
srcPort: 0,
srcAddr: '127.0.0.1',
dstAddr: '127.0.0.1',
dstPort: connectConfig.port,
}, {
return {
localAddr: '127.0.0.1',
localPort: 0,
}, config);
socks5Username: undefined,
socks5Password: undefined,
...config,
};
}

@@ -32,27 +36,48 @@ class SshTunnel extends events_1.EventEmitter {

this.forwardOut = (0, util_1.promisify)(this.sshClient.forwardOut.bind(this.sshClient));
this.server = (0, net_1.createServer)(async (socket) => {
this.connections.add(socket);
socket.on('error', (err) => {
var _a;
err.origin = (_a = err.origin) !== null && _a !== void 0 ? _a : 'connection';
this.server.emit('error', err);
});
socket.once('close', () => {
this.connections.delete(socket);
});
this.server = server_1.default.createServer(async (info, accept, deny) => {
debug('receiving socks5 forwarding request', info);
let socket = null;
try {
const { srcAddr, srcPort, dstAddr, dstPort } = this.rawConfig;
const channel = await this.forwardOut(srcAddr, srcPort, dstAddr, dstPort);
const channel = await this.forwardOut(info.srcAddr, info.srcPort, info.dstAddr, info.dstPort);
debug('channel opened, accepting socks5 request', info);
socket = accept(true);
this.connections.add(socket);
socket.on('error', (err) => {
var _a;
debug('error on socksv5 socket', info, err);
err.origin = (_a = err.origin) !== null && _a !== void 0 ? _a : 'connection';
this.server.emit('error', err);
});
socket.once('close', () => {
debug('socksv5 socket closed, removing from set');
this.connections.delete(socket);
});
socket.pipe(channel).pipe(socket);
}
catch (err) {
err.origin = 'ssh-client';
socket.destroy(err);
debug('caught error, rejecting socks5 request', info, err);
deny();
if (socket) {
err.origin = 'ssh-client';
socket.destroy(err);
}
}
});
if (!this.rawConfig.socks5Username) {
debug('skipping auth setup for this server');
this.server.useAuth((0, None_1.default)());
}
else {
this.server.useAuth((0, UserPassword_1.default)((user, pass, cb) => {
const success = this.rawConfig.socks5Username === user &&
this.rawConfig.socks5Password === pass;
debug('validating auth parameters', success);
process.nextTick(cb, success);
}));
}
this.serverListen = (0, util_1.promisify)(this.server.listen.bind(this.server));
this.serverClose = (0, util_1.promisify)(this.server.close.bind(this.server));
['close', 'connection', 'error', 'listening'].forEach((eventName) => {
for (const eventName of ['close', 'error', 'listening']) {
this.server.on(eventName, this.emit.bind(this, eventName));
});
}
}

@@ -69,4 +94,6 @@ get config() {

const { localPort, localAddr } = this.rawConfig;
debug('starting to listen', { localAddr, localPort });
await this.serverListen(localPort, localAddr);
try {
debug('creating SSH connection');
await Promise.race([

@@ -82,4 +109,6 @@ (0, events_1.once)(this.sshClient, 'error').then(([err]) => {

]);
debug('created SSH connection');
}
catch (err) {
debug('failed to establish SSH connection', err);
await this.serverClose();

@@ -90,2 +119,3 @@ throw err;

async close() {
debug('closing SSH tunnel');
const [maybeError] = await Promise.all([

@@ -92,0 +122,0 @@ this.serverClose().catch((e) => e),

@@ -16,3 +16,3 @@ {

"homepage": "https://github.com/mongodb-js/compass",
"version": "1.2.3",
"version": "1.3.0",
"repository": {

@@ -44,3 +44,3 @@ "type": "git",

"test": "mocha",
"test-cov": "nyc -x \"**/*.spec.*\" npm run test",
"test-cov": "nyc -x \"**/*.spec.*\" --reporter=lcov --reporter=text --reporter=html npm run test",
"test-watch": "npm run test -- --watch",

@@ -51,7 +51,8 @@ "test-ci": "npm run test-cov",

"devDependencies": {
"@mongodb-js/eslint-config-compass": "^0.5.0",
"@mongodb-js/mocha-config-compass": "^0.7.0",
"@mongodb-js/eslint-config-compass": "^0.6.0",
"@mongodb-js/mocha-config-compass": "^0.8.0",
"@mongodb-js/prettier-config-compass": "^0.4.0",
"@mongodb-js/tsconfig-compass": "^0.4.0",
"@mongodb-js/tsconfig-compass": "^0.5.0",
"@types/chai": "^4.2.21",
"@types/debug": "^4.1.7",
"@types/mocha": "^9.0.0",

@@ -70,8 +71,11 @@ "@types/node-fetch": "^2.5.8",

"sinon": "^9.2.3",
"socks": "^2.6.1",
"typescript": "^4.3.5"
},
"dependencies": {
"debug": "4.3.0",
"socksv5": "0.0.6",
"ssh2": "^0.8.9"
},
"gitHead": "75710b287ad6e3ea08bc36b15e0be5ebb8f62050"
"gitHead": "6563679c816fa44691a53b7e27fa0cb5539e0854"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc