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

ssh2

Package Overview
Dependencies
Maintainers
1
Versions
105
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ssh2 - npm Package Compare versions

Comparing version 0.1.9 to 0.1.10

14

lib/Channel.js

@@ -126,2 +126,3 @@ var inherits = require('util').inherits,

if (this.outgoing.state === 'open') {
this._conn._debug&&this._conn._debug('DEBUG: Channel: Sent EOF');
// Note: CHANNEL_EOF does not consume window space

@@ -143,2 +144,3 @@ /*

if (this.outgoing.state === 'open' || this.outgoing.state === 'eof') {
this._conn._debug&&this._conn._debug('DEBUG: Channel: Sent CLOSE');
// Note: CHANNEL_CLOSE does not consume window space

@@ -170,2 +172,3 @@ /*

*/
this._conn._debug&&this._conn._debug('DEBUG: Channel: Sent CHANNEL_REQUEST (window-change)');
var buf = new Buffer(1 + 4 + 4 + 13 + 1 + 4 + 4 + 4 + 4);

@@ -200,2 +203,3 @@ buf[0] = MESSAGE.CHANNEL_REQUEST;

*/
this._conn._debug&&this._conn._debug('DEBUG: Channel: Sent CHANNEL_REQUEST (pty-req)');
if (!term || !term.length)

@@ -242,2 +246,3 @@ term = 'vt100';

*/
this._conn._debug&&this._conn._debug('DEBUG: Channel: Sent CHANNEL_REQUEST (shell)');
var self = this;

@@ -271,2 +276,3 @@ var buf = new Buffer(1 + 4 + 4 + 5 + 1);

*/
this._conn._debug&&this._conn._debug('DEBUG: Channel: Sent CHANNEL_REQUEST (exec)');
var self = this;

@@ -306,2 +312,3 @@ var cmdlen = (Buffer.isBuffer(cmd) ? cmd.length : Buffer.byteLength(cmd)),

*/
this._conn._debug&&this._conn._debug('DEBUG: Channel: Sent CHANNEL_REQUEST (signal)');
signal = signal.toUpperCase();

@@ -329,2 +336,3 @@ if (signal.length >= 3

if (env && (keys = Object.keys(env)).length > 0) {
this._conn._debug&&this._conn._debug('DEBUG: Channel: Sent CHANNEL_REQUEST (env)');
// Note: CHANNEL_REQUEST does not consume window space

@@ -374,2 +382,3 @@ /*

*/
this._conn._debug&&this._conn._debug('DEBUG: Channel: Sent CHANNEL_REQUEST (subsystem)');
var sublen = Buffer.byteLength(name),

@@ -407,2 +416,3 @@ self = this,

if (extendedType === undefined) {
this._conn._debug&&this._conn._debug('DEBUG: Channel: Sent CHANNEL_DATA');
/*

@@ -419,2 +429,3 @@ byte SSH_MSG_CHANNEL_DATA

} else {
this._conn._debug&&this._conn._debug('DEBUG: Channel: Sent CHANNEL_EXTENDED_DATA');
/*

@@ -464,2 +475,3 @@ byte SSH_MSG_CHANNEL_EXTENDED_DATA

*/
this._conn._debug&&this._conn._debug('DEBUG: Channel: Sent CHANNEL_WINDOW_ADJUST');
amt = amt || MAX_WINDOW;

@@ -539,3 +551,3 @@ var buf = new Buffer(1 + 4 + 4);

ChannelStream.prototype._drainInBuffer = function() {
var i = 0, val, vallen, len = this._inbuffer.length, ret;
var i = 0, val, vallen, len = this._inbuffer.length;

@@ -542,0 +554,0 @@ for (; i < len; ++i) {

60

lib/Connection.js

@@ -51,3 +51,3 @@ var net = require('net'),

this._agent = undefined;
this._debug = false;
this._debug = undefined;

@@ -61,2 +61,3 @@ this._sock = undefined;

this._seqno = 0;
this._bufseqno = new Buffer(4);
this._encryptSize = 8;

@@ -75,3 +76,2 @@ this._encrypt = false;

this._parser.on('header', function(header) {
self._debug&&self._debug('header', header);
if (header.versions.protocol !== '1.99'

@@ -85,10 +85,6 @@ && header.versions.protocol !== '2.0') {

this._parser.on('packet', function(type, typeid, data) {
self._debug&&self._debug('packet', type, typeid, data);
});
//this._parser.on('DEBUG', function(msg, lang) {
// self._debug&&self._debug('Server debug: ' + msg);
//});
this._parser.on('DEBUG', function(msg, lang) {
self._debug&&self._debug('debug', msg, lang);
});
this._parser.on('KEXINIT', function(init) {

@@ -173,2 +169,3 @@ if (this._state === 'authenticated')

self._debug&&self._debug('DEBUG: Connection: Sent KEXINIT');
self._kexinit = bufKexInit;

@@ -213,3 +210,2 @@ self._send(bufKexInit, function() {

var kex_algorithm = ALGORITHMS.KEX[i],
pubkey, pubkeyLen,
bufDHInit;

@@ -298,2 +294,3 @@

self._debug&&self._debug('DEBUG: Connection: Sent KEXDH_INIT');
self._send(bufDHInit);

@@ -401,2 +398,3 @@ });

self._kexreply = info;
self._debug&&self._debug('DEBUG: Connection: Sent NEWKEYS');
self._send(new Buffer([MESSAGE.NEWKEYS]));

@@ -653,2 +651,3 @@ });

svcBuf.write('ssh-userauth', 5, 12, 'ascii');
self._debug&&self._debug('DEBUG: Connection: Sent SERVICE_REQUEST');
self._send(svcBuf);

@@ -765,2 +764,3 @@ } else if (self._state === 'reexchg') {

}
self._debug&&self._debug('DEBUG: Connection: Sent USERAUTH_INFO_RESPONSE');
self._send(buf);

@@ -848,2 +848,3 @@ } else {

self._debug&&self._debug('DEBUG: Connection: Sent CHANNEL_OPEN_CONFIRMATION');
self._send(buf);

@@ -874,2 +875,3 @@

self._debug&&self._debug('DEBUG: Connection: Sent CHANNEL_OPEN_FAILURE');
self._send(buf);

@@ -919,3 +921,4 @@ };

this._pingInterval = opts.pingInterval;
this._debug = (typeof opts.debug === 'function' ? opts.debug : false);
this._debug = (typeof opts.debug === 'function' ? opts.debug : undefined);
this._parser.debug = this._debug;

@@ -1312,2 +1315,3 @@ this._sock = new net.Socket();

this._debug&&this._debug('DEBUG: Connection: Sent GLOBAL_REQUEST (tcpip-forward)');
return this._send(buf);

@@ -1344,2 +1348,3 @@ };

this._debug&&this._debug('DEBUG: Connection: Sent GLOBAL_REQUEST (cancel-tcpip-forward)');
return this._send(buf);

@@ -1408,3 +1413,6 @@ };

Connection.prototype.end = function() {
this._disconnect(DISCONNECT_REASON.CONNECTION_LOST);
if (this._sock.writable && this._state === 'authenticated')
this._disconnect(DISCONNECT_REASON.CONNECTION_LOST);
else
this._sock.destroy();
};

@@ -1479,2 +1487,3 @@

this._debug&&this._debug('DEBUG: Connection: Sent CHANNEL_OPEN');
return this._send(buf);

@@ -1501,2 +1510,3 @@ };

// simply send an SSH_MSG_IGNORE message for pinging purposes
this._debug&&this._debug('DEBUG: Connection: Sent ping');
this._send(PING_PACKET);

@@ -1576,2 +1586,3 @@ };

this._parser._authMethod = 'password';
this._debug&&this._debug('DEBUG: Connection: Sent USERAUTH_REQUEST (password)');
return this._send(buf);

@@ -1611,2 +1622,3 @@ };

this._parser._authMethod = 'keyboard-interactive';
this._debug&&this._debug('DEBUG: Connection: Sent USERAUTH_REQUEST (keyboard-interactive)');
return this._send(buf);

@@ -1673,4 +1685,6 @@ };

if (!sign)
if (!sign) {
this._debug&&this._debug('DEBUG: Connection: Sent USERAUTH_REQUEST (publickey -- check)');
return this._send(sig);
}

@@ -1682,3 +1696,2 @@ var signature, sigLen, privAlgoLen = 7, privAlgo;

if (err) {
var error = new Error(err);
err.level = 'agent';

@@ -1713,4 +1726,3 @@ self.emit('error', err);

var newsig = new Buffer(40);
var rlen = signature[3], rstart = 4,
slen = signature[4 + 1 + rlen], sstart = 4 + 1 + rlen + 1;
var rlen = signature[3], rstart = 4, sstart = 4 + 1 + rlen + 1;
while (signature[rstart] === 0)

@@ -1771,2 +1783,3 @@ ++rstart;

self._debug&&self._debug('DEBUG: Connection: Sent USERAUTH_REQUEST (publickey)');
return self._send(buf);

@@ -1784,3 +1797,2 @@ }

if (err) {
var error = new Error(err);
err.level = 'agent';

@@ -1827,2 +1839,3 @@ self.emit('error', err);

self._debug&&self._debug('DEBUG: Connection: Sent DISCONNECT');
return this._send(buf, function() {

@@ -1865,5 +1878,4 @@ self._sock.end();

hmac = crypto.createHmac(SSH_TO_OPENSSL[self._hmac], self._hmacKey);
var bufSeqNo = new Buffer(4);
bufSeqNo.writeUInt32BE(self._seqno, 0, true);
hmac.update(bufSeqNo);
this._bufseqno.writeUInt32BE(self._seqno, 0, true);
hmac.update(this._bufseqno);
hmac.update(buf);

@@ -1879,8 +1891,4 @@ hmac = hmac.digest('binary');

if (self._encrypt !== false) {
var encbuf = new Buffer(self._encrypt.update(buf, 'binary', 'binary'),
'binary');
var newbuf = new Buffer(encbuf.length + hmac.length);
encbuf.copy(newbuf);
hmac.copy(newbuf, encbuf.length);
ret = self._sock.write(newbuf);
self._sock.write(self._encrypt.update(buf, 'binary', 'binary'), 'binary');
self._sock.write(hmac);
} else

@@ -1887,0 +1895,0 @@ ret = self._sock.write(buf);

@@ -211,12 +211,11 @@ var i = 0, keys, len;

if (process.versions.openssl >= '1.0.1') {
// ciphers in CTR mode disabled for now
/*if (process.versions.openssl >= '1.0.1') {
CIPHER = [
// from <http://tools.ietf.org/html/rfc4344#section-4>:
'aes128-ctr', // RECOMMENDED
'aes192-ctr', // RECOMMENDED
'aes256-ctr' // RECOMMENDED
'aes128-ctr' // RECOMMENDED
].concat(CIPHER);
}
}*/
var ALGORITHMS = exports.ALGORITHMS = {
exports.ALGORITHMS = {
KEX: KEX,

@@ -259,5 +258,5 @@ KEX_LIST: KEX_LIST,

/*'3des-ctr': 'des-ede3',
'blowfish-ctr': 'bf-ecb',*/
'blowfish-ctr': 'bf-ecb',
'aes256-ctr': 'aes-256-ctr',
'aes192-ctr': 'aes-192-ctr',
'aes192-ctr': 'aes-192-ctr',*/
'aes128-ctr': 'aes-128-ctr',

@@ -264,0 +263,0 @@ /*'cast128-ctr': 'cast5-ecb',

@@ -29,9 +29,4 @@ // TODO: * Filter control codes from strings

var EXP_BYTES_CRLF = bytes('\n'),
EXP_BYTES_SSHHEADER = bytes('SSH-'),
EXP_BYTES_SSHHEADERGREETING = EXP_BYTES_CRLF.concat(EXP_BYTES_SSHHEADER);
EXP_BYTES_SSHHEADER = bytes('SSH-');
var EXP_ACTION_NONE = 0, // skip expected bytes
EXP_ACTION_BUFFER = 1, // buffer expected bytes
EXP_ACTION_EMIT = 2; // emit expected bytes as some event
var EXP_TYPE_MATCH = 0, // waits for byte array match

@@ -41,2 +36,4 @@ EXP_TYPE_BYTES = 1; // waits until n bytes have been seen

function Parser() {
this.debug = undefined;
this._hmacBuf = new Buffer(9);
this.reset();

@@ -68,3 +65,2 @@ }

this._expectType = undefined;
this._expectEmit = undefined;
start = i;

@@ -89,5 +85,3 @@ }

}
if (this._expectEmit !== undefined)
this.emit(this._expectEmit, buf);
else if (this._expectBuf !== undefined) {
if (this._expectBuf !== undefined) {
this._expectBuf.push(buf);

@@ -105,5 +99,3 @@ this._expectBufLen += buf.length;

if (this._expectPtr === 0 && i === end) {
if (this._expectEmit !== undefined)
this.emit(this._expectEmit, (start === 0 ? b : b.slice(start)));
else if (this._expectBuf !== undefined) {
if (this._expectBuf !== undefined) {
buf = (start === 0 ? b : b.slice(start));

@@ -119,6 +111,3 @@ this._expectBuf.push(buf);

leftovers = 0;
if (this._expectEmit !== undefined && leftovers) {
this.emit(this._expectEmit,
b.slice(start, start + leftovers));
} else if (this._expectBuf !== undefined) {
if (this._expectBuf !== undefined) {
var expbuflen = this._expectBuf.length;

@@ -151,3 +140,2 @@ if (expbuflen === 0) {

this._expectType = undefined;
this._expectEmit = undefined;
start = i;

@@ -159,14 +147,17 @@ }

case STATE_INIT:
this.debug&&this.debug('DEBUG: Parser: STATE_INIT');
// retrieve all bytes that may come before the header
this.expect(EXP_BYTES_SSHHEADER, EXP_ACTION_BUFFER);
this.expect(EXP_BYTES_SSHHEADER);
this._state = STATE_GREETING;
break;
case STATE_GREETING:
this.debug&&this.debug('DEBUG: Parser: STATE_GREETING');
if (buffer && buffer.length)
this._greeting = buffer;
// retrieve the identification bytes after the "SSH-" header
this.expect(EXP_BYTES_CRLF, EXP_ACTION_BUFFER);
this.expect(EXP_BYTES_CRLF);
this._state = STATE_HEADER;
break;
case STATE_HEADER:
this.debug&&this.debug('DEBUG: Parser: STATE_HEADER');
buffer = buffer.toString('ascii').trim();

@@ -197,8 +188,10 @@ var idxDash = buffer.indexOf('-'),

case STATE_PACKETBEFORE:
this.debug&&this.debug('DEBUG: Parser: STATE_PACKETBEFORE (expecting ' + this._decryptSize + ')');
// wait for the right number of bytes so we can determine the incoming
// packet length
this.expect(this._decryptSize, EXP_ACTION_BUFFER);
this.expect(this._decryptSize);
this._state = STATE_PACKET;
break;
case STATE_PACKET:
this.debug&&this.debug('DEBUG: Parser: STATE_PACKET');
if (this._decrypt)

@@ -209,6 +202,7 @@ buffer = this.decrypt(buffer);

var remainLen = this._pktLen + 4 - this._decryptSize;
this.debug&&this.debug('DEBUG: Parser: remainLen === ' + remainLen);
if (remainLen > 0) {
this._pktExtra = buffer.slice(5);
// grab the rest of the packet
this.expect(remainLen, EXP_ACTION_BUFFER);
this.expect(remainLen);
this._state = STATE_PACKETDATA;

@@ -225,2 +219,3 @@ } else if (remainLen < 0)

case STATE_PACKETDATA:
this.debug&&this.debug('DEBUG: Parser: STATE_PACKETDATA');
if (this._decrypt && !skipDecrypt)

@@ -243,3 +238,4 @@ buffer = this.decrypt(buffer);

// wait for hmac hash
this.expect(this._hmacSize, EXP_ACTION_BUFFER);
this.debug&&this.debug('DEBUG: Parser: hmacSize === ' + this._hmacSize);
this.expect(this._hmacSize);
this._state = STATE_PACKETDATAVERIFY;

@@ -253,2 +249,3 @@ this._packet = buf;

case STATE_PACKETDATAVERIFY:
this.debug&&this.debug('DEBUG: Parser: STATE_PACKETDATAVERIFY');
// verify packet data integrity

@@ -264,6 +261,18 @@ if (this.hmacVerify(buffer)) {

case STATE_PACKETDATAAFTER:
if (this.debug) {
if (this._payload[0] === 60) {
if (this._authMethod === 'password')
this.debug('DEBUG: Parser: STATE_PACKETDATAAFTER, packet: USERAUTH_PASSWD_CHANGEREQ');
else if (this._authMethod === 'keyboard-interactive')
this.debug('DEBUG: Parser: STATE_PACKETDATAAFTER, packet: USERAUTH_INFO_REQUEST');
else if (this._authMethod === 'pubkey')
this.debug('DEBUG: Parser: STATE_PACKETDATAAFTER, packet: USERAUTH_PK_OK');
} else {
this.debug('DEBUG: Parser: STATE_PACKETDATAAFTER, packet: '
+ MESSAGE[this._payload[0]]);
}
}
var payload = this._payload;
if (++this._seqno > MAX_SEQNO)
this._seqno = 0;
this.emit('packet', MESSAGE[payload[0]], payload[0], payload.slice(1));

@@ -669,10 +678,11 @@ // payload[0] === packet type

Parser.prototype.hmacVerify = function(hmac) {
// seqno + pktLen + padLen + (payload + padding) length
var buf = new Buffer(4 + 4 + 1 + this._packet.length);
buf.writeUInt32BE(this._seqno, 0, true);
buf.writeUInt32BE(this._pktLen, 4, true);
buf[8] = this._padLen;
this._packet.copy(buf, 9);
var calcHmac = crypto.createHmac(SSH_TO_OPENSSL[this._hmac], this._hmacKey);
calcHmac.update(buf);
this._hmacBuf.writeUInt32BE(this._seqno, 0, true);
this._hmacBuf.writeUInt32BE(this._pktLen, 4, true);
this._hmacBuf[8] = this._padLen;
calcHmac.update(this._hmacBuf);
calcHmac.update(this._packet);
return (calcHmac.digest('binary') === hmac.toString('binary'));

@@ -686,3 +696,3 @@ };

Parser.prototype.expect = function(what, action, emitEventName) {
Parser.prototype.expect = function(what) {
this._expect = what;

@@ -692,11 +702,7 @@ this._expectType = (Array.isArray(what) ? EXP_TYPE_MATCH : EXP_TYPE_BYTES);

this._expectPtr = 0;
if (action === EXP_ACTION_BUFFER) {
if (Array.isArray(what))
this._expectBuf = [];
else
this._expectBuf = new Buffer(what);
} else
this._expectBuf = undefined;
if (Array.isArray(what))
this._expectBuf = [];
else
this._expectBuf = new Buffer(what);
this._expectBufLen = 0;
this._expectEmit = (action === EXP_ACTION_EMIT ? emitEventName : undefined);
};

@@ -712,3 +718,2 @@

this._expectBufLen = 0;
this._expectEmit = undefined;

@@ -731,10 +736,5 @@ this._greeting = undefined;

Parser.prototype._emitError = function(msg) {
this.emit('error', new Error(msg));
this.reset();
};
function bytes(str) {
var ret = new Array(str.length);
for (var i=0,len=ret.length; i<len; ++i)
for (var i = 0, len = ret.length; i < len; ++i)
ret[i] = str.charCodeAt(i);

@@ -741,0 +741,0 @@ return ret;

{ "name": "ssh2",
"version": "0.1.9",
"version": "0.1.10",
"author": "Brian White <mscdex@mscdex.net>",

@@ -4,0 +4,0 @@ "description": "An SSH2 client module written in pure JavaScript for node.js",

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