mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-13 21:40:21 +00:00
Adds ssh2-streams and cleans up ssh2
This commit is contained in:
Vendored
+1196
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,104 @@
|
||||
import * as stream from "stream";
|
||||
import * as ssh2 from "ssh2-streams";
|
||||
|
||||
declare const SERVER_KEY: string;
|
||||
declare const HOST_KEYS: { 'ssh-rsa': ssh2.HostKey };
|
||||
declare const clientBufStream: stream.Transform & { buffer: string; };
|
||||
declare const serverBufStream: stream.Transform & { buffer: string; };
|
||||
declare const parsedKey: ssh2.ParsedKey;
|
||||
declare const prompts: ssh2.Prompt[];
|
||||
declare const buffer: Buffer;
|
||||
|
||||
const algos = ['ssh-dss', 'ssh-rsa', 'ecdsa-sha2-nistp521'];
|
||||
const client = new ssh2.SSH2Stream({ algorithms: { serverHostKey: algos } });
|
||||
const server = new ssh2.SSH2Stream({ server: true, hostKeys: HOST_KEYS });
|
||||
|
||||
client
|
||||
.pipe(server)
|
||||
.pipe(client);
|
||||
|
||||
client
|
||||
.on("error", (err: Error) => {})
|
||||
.on("ready", () => {})
|
||||
.on("header", (header: ssh2.Header) => {})
|
||||
.on("fingerprint", (hostKey: Buffer, callback: (success: boolean) => void) => {})
|
||||
.on("USERAUTH_BANNER", (message: string) => {})
|
||||
.on("USERAUTH_SUCCESS", () => {})
|
||||
.on("USERAUTH_FAILURE", (authsLeft: string[], partial: boolean) => {})
|
||||
.on("USERAUTH_PK_OK", () => {})
|
||||
.on("USERAUTH_INFO_REQUEST", (name: string, instructions: string, lang: string, prompts: ssh2.Prompt[]) => {})
|
||||
.on("CHANNEL_OPEN", (info: ssh2.ChannelOpenInfo) => {})
|
||||
.on("SERVICE_ACCEPT", (serviceName: string) => {})
|
||||
.on("REQUEST_SUCCESS", (resData?: Buffer) => {})
|
||||
.on("REQUEST_FAILURE", () => {})
|
||||
.on("GLOBAL_REQUEST", (reqName: string, wantReply: boolean, reqData: ssh2.TcpipForwardGlobalRequest | ssh2.openssh_StreamLocalForwardGlobalRequest) => {});
|
||||
|
||||
client.ping();
|
||||
client.authPassword("username", "password");
|
||||
client.authPK("username", parsedKey);
|
||||
client.authHostBased("username", parsedKey, "localHostname", "localUsername");
|
||||
client.authKeyboard("username");
|
||||
client.authNone("username");
|
||||
client.authInfoRes();
|
||||
client.authInfoRes(["answer"]);
|
||||
client.service("ssh-userauth");
|
||||
client.requestFailure();
|
||||
client.disconnect();
|
||||
client.tcpipForward("bindAddr", 8080);
|
||||
client.cancelTcpipForward("bindAddr", 8080);
|
||||
client.openssh_noMoreSessions();
|
||||
client.openssh_streamLocalForward("socketPath");
|
||||
client.openssh_cancelStreamLocalForward("socketPath");
|
||||
client.session(0, 0, 0);
|
||||
client.directTcpip(0, 0, 0, { srcIP: "srcIP", srcPort: 0, destIP: "destIP", destPort: 0 });
|
||||
client.openssh_directStreamLocal(0, 0, 0, { socketPath: "socketPath" });
|
||||
client.x11Forward(0, { single: true, cookie: "cookie", protocol: "protocol", screen: 0 });
|
||||
client.pty(0, 0, 0, 0, 0, "term", null);
|
||||
client.openssh_agentForward(0);
|
||||
client.shell(0);
|
||||
client.exec(0, "command");
|
||||
client.env(0, "key", "value");
|
||||
client.subsystem(0, "name");
|
||||
client.channelOpenConfirm(0, 0, 0, 0);
|
||||
client.channelOpenFail(0, 0, "desc", "lang");
|
||||
|
||||
server
|
||||
.on("SERVICE_REQUEST", (serviceName: string) => {})
|
||||
.on("USERAUTH_REQUEST", (username: string, serviceName: string, authmethod: string, authMethodData: string | ssh2.PublicKeyAuthMethodData | ssh2.HostbasedAuthMethodData) => {})
|
||||
.on("USERAUTH_INFO_RESPONSE", (responses: string[]) => {})
|
||||
|
||||
server.disconnect(0);
|
||||
server.authSuccess();
|
||||
server.authFailure(["authMethods"], false);
|
||||
server.requestSuccess();
|
||||
server.requestFailure();
|
||||
server.rekey();
|
||||
server.channelSuccess(0);
|
||||
server.channelFailure(0);
|
||||
server.channelEOF(0);
|
||||
server.channelClose(0);
|
||||
server.channelWindowAdjust(0, 0);
|
||||
server.channelData(0, "data");
|
||||
server.channelExtData(0, "data", 0);
|
||||
server.authInfoReq("name", "instructions", prompts);
|
||||
server.authPKOK("keyAlgorithm", buffer);
|
||||
server.forwardedTcpip(0, 0, 0, { bindAddr: "bindAddr", bindPort: 8080, remoteAddr: "remoteAddr", remotePort: 8080 });
|
||||
server.x11(0, 0, 0, { originAddr: "originAddr", originPort: 0 });
|
||||
server.openssh_forwardedStreamLocal(0, 0, 0, { socketPath: "socketPath" });
|
||||
|
||||
const maybeParsedKey = ssh2.utils.parseKey("keyData");
|
||||
ssh2.utils.decryptKey(parsedKey, "passphrase");
|
||||
const publicKey = ssh2.utils.genPublicKey(parsedKey);
|
||||
|
||||
|
||||
declare const attrs: ssh2.Attributes;
|
||||
const sftp = new ssh2.SFTPStream();
|
||||
sftp.attrs(0, attrs);
|
||||
sftp.chmod("path", 0, () => {});
|
||||
sftp.chown("path", 0, 0, () => {});
|
||||
sftp.close(buffer, () => {});
|
||||
sftp.createReadStream("path");
|
||||
sftp.createWriteStream("path");
|
||||
sftp.data(0, buffer);
|
||||
sftp.fastGet("remotePath", "localPath", () => {});
|
||||
sftp.fastPut("localPath", "remotePath", () => {});
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"ssh2-streams-tests.ts"
|
||||
]
|
||||
}
|
||||
Vendored
+1490
-358
File diff suppressed because it is too large
Load Diff
+19
-20
@@ -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!');
|
||||
|
||||
|
||||
+1
-2
@@ -9,8 +9,7 @@
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
"noEmit": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
|
||||
Reference in New Issue
Block a user