Adds ssh2-streams and cleans up ssh2

This commit is contained in:
Ron Buckton
2016-09-27 14:59:17 -07:00
parent 20295577ac
commit 7cf2c1698f
6 changed files with 2828 additions and 380 deletions

1848
ssh2/index.d.ts vendored

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,7 @@
import * as fs from "fs";
import * as crypto from "crypto";
import * as ssh2 from 'ssh2';
import * as ssh2_streams from 'ssh2-streams';
declare var inspect: any;
@@ -14,7 +16,7 @@ var Client = require('ssh2').Client;
var conn = new Client();
conn.on('ready', () => {
console.log('Client :: ready');
conn.exec('uptime', (err: Error, stream: ssh2.Channel) => {
conn.exec('uptime', (err: Error, stream: ssh2.ClientChannel) => {
if (err) throw err;
stream
.on('close', (code: any, signal: any) => {
@@ -40,7 +42,7 @@ var Client = require('ssh2').Client;
var conn = new Client();
conn.on('ready', () => {
console.log('Client :: ready');
conn.shell( (err: Error, stream: ssh2.Channel) => {
conn.shell( (err: Error, stream: ssh2.ClientChannel) => {
if (err) throw err;
stream.on('close', () => {
console.log('Stream :: close');
@@ -66,7 +68,7 @@ var Client = require('ssh2').Client;
var conn = new Client();
conn.on('ready', () => {
console.log('Client :: ready');
conn.forwardOut('192.168.100.102', 8000, '127.0.0.1', 80, (err: Error, stream: ssh2.Channel) => {
conn.forwardOut('192.168.100.102', 8000, '127.0.0.1', 80, (err: Error, stream: ssh2.ClientChannel) => {
if (err) throw err;
stream.on('close', () => {
console.log('TCP :: CLOSED');
@@ -131,9 +133,9 @@ var Client = require('ssh2').Client;
var conn = new Client();
conn.on('ready', () => {
console.log('Client :: ready');
conn.sftp( (err: Error, sftp: ssh2.Sftp.Wrapper) => {
conn.sftp( (err: Error, sftp: ssh2.SFTPWrapper) => {
if (err) throw err;
sftp.readdir('foo', (err: Error, list: ssh2.Sftp.ReadDirItem[]) => {
sftp.readdir('foo', (err: Error, list: ssh2_streams.FileEntry[]) => {
if (err) throw err;
console.dir(list);
conn.end();
@@ -155,7 +157,7 @@ var conn1 = new Client(),
conn1.on('ready', () => {
console.log('FIRST :: connection ready');
conn1.exec('nc 192.168.1.2 22', (err: Error, stream: ssh2.Channel) => {
conn1.exec('nc 192.168.1.2 22', (err: Error, stream: ssh2.ClientChannel) => {
if (err) {
console.log('FIRST :: exec error: ' + err);
return conn1.end();
@@ -174,7 +176,7 @@ conn1.on('ready', () => {
conn2.on('ready', () => {
console.log('SECOND :: connection ready');
conn2.exec('uptime', (err: Error, stream: ssh2.Channel) => {
conn2.exec('uptime', (err: Error, stream: ssh2.ClientChannel) => {
if (err) {
console.log('SECOND :: exec error: ' + err);
return conn1.end();
@@ -205,7 +207,7 @@ conn.on('x11', (info: any, accept: any, reject: any) => {
});
conn.on('ready', () => {
conn.exec('xeyes', { x11: true }, (err: Error, stream: ssh2.Channel) => {
conn.exec('xeyes', { x11: true }, (err: Error, stream: ssh2.ClientChannel) => {
if (err) throw err;
var code = 0;
stream.on('end', () => {
@@ -244,7 +246,7 @@ socks.createServer( (info: any, accept: any, deny: any) => {
info.srcPort,
info.dstAddr,
info.dstPort,
(err: Error, stream: ssh2.Channel) => {
(err: Error, stream: ssh2.ClientChannel) => {
if (err) {
conn.end();
return deny();
@@ -279,7 +281,7 @@ var conn = new Client();
conn.on('ready', () => {
console.log('Client :: ready');
conn.subsys('netconf', (err: Error, stream: ssh2.Channel) => {
conn.subsys('netconf', (err: Error, stream: ssh2.ClientChannel) => {
if (err) throw err;
stream.on('data', (data: any) => {
console.log(data);
@@ -307,20 +309,18 @@ const sshconfig: ssh2.ConnectConfig = {
// Only allow password and public key authentication and command execution:
var fs = require('fs'),
crypto = require('crypto');
var buffersEqual = require('buffer-equal-constant-time'),
//ssh2 = require('ssh2'),
utils = ssh2.utils;
var pubKey = utils.genPublicKey(utils.parseKey(fs.readFileSync('user.pub')));
var pubKey = utils.genPublicKey(<ssh2_streams.ParsedKey>utils.parseKey(fs.readFileSync('user.pub')));
new ssh2.Server({
privateKey: fs.readFileSync('host.key')
}, (client: any) => {
hostKeys: [fs.readFileSync('host.key')]
}, (client: ssh2.Connection) => {
console.log('Client connected!');
client.on('authentication', (ctx: any) => {
client.on('authentication', ctx => {
if (ctx.method === 'password'
&& ctx.username === 'foo'
&& ctx.password === 'bar')
@@ -331,7 +331,7 @@ new ssh2.Server({
if (ctx.signature) {
var verifier = crypto.createVerify(ctx.sigAlgo);
verifier.update(ctx.blob);
if (verifier.verify(pubKey.publicOrig, ctx.signature, 'binary'))
if (verifier.verify(pubKey.publicOrig.toString("utf8"), ctx.signature))
ctx.accept();
else
ctx.reject();
@@ -365,13 +365,12 @@ new ssh2.Server({
// SFTP only server:
var fs = require('fs');
//var ssh2 = require('ssh2');
var OPEN_MODE = ssh2.SFTP_OPEN_MODE,
STATUS_CODE = ssh2.SFTP_STATUS_CODE;
new ssh2.Server({
privateKey: fs.readFileSync('host.key')
hostKeys: [fs.readFileSync('host.key')]
}, (client: any) => {
console.log('Client connected!');

View File

@@ -9,8 +9,7 @@
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
"noEmit": true
},
"files": [
"index.d.ts",