ssh2
Advanced tools
Comparing version 0.2.14 to 0.2.15
103
lib/agent.js
@@ -5,2 +5,3 @@ var Socket = require('net').Socket, | ||
path = require('path'), | ||
fs = require('fs'), | ||
cp = require('child_process'); | ||
@@ -16,2 +17,4 @@ | ||
var RE_CYGWIN_SOCK = /^\!<socket >(\d+) s ([A-Z0-9]{8}\-[A-Z0-9]{8}\-[A-Z0-9]{8}\-[A-Z0-9]{8})/; | ||
module.exports = function(sockPath, key, keyType, data, cb) { | ||
@@ -175,11 +178,99 @@ var sock, error, sig, keylen = 0, datalen, flags, | ||
sock = new PageantSock(); | ||
else | ||
return cb(new Error('Invalid agent type for Windows')); | ||
else { | ||
fs.readFile(sockPath, function(err, data) { | ||
if (err) | ||
return cb(new Error('Invalid cygwin unix socket path')); | ||
var m; | ||
if (m = RE_CYGWIN_SOCK.exec(data.toString('ascii'))) { | ||
var port, | ||
secret, | ||
secretbuf, | ||
state, | ||
bc = 0, | ||
isRetrying = false, | ||
inbuf = [], | ||
credsbuf = new Buffer(12), | ||
i, j; | ||
// use 0 for pid, uid, and gid to ensure we get an error and also | ||
// a valid uid and gid from cygwin so that we don't have to figure it | ||
// out ourselves | ||
credsbuf.fill(0); | ||
// parse cygwin unix socket file contents | ||
port = parseInt(m[1], 10); | ||
secret = m[2].replace(/\-/g, ''); | ||
secretbuf = new Buffer(16); | ||
for (i = 0, j = 0; j < 32; ++i,j+=2) | ||
secretbuf[i] = parseInt(secret.substring(j, j + 2), 16); | ||
// convert to host order (always LE for Windows) | ||
for (i = 0; i < 16; i += 4) | ||
secretbuf.writeUInt32LE(secretbuf.readUInt32BE(i, true), i, true); | ||
function _onconnect() { | ||
bc = 0; | ||
state = 'secret'; | ||
sock.write(secretbuf); | ||
} | ||
function _ondata(data) { | ||
bc += data.length; | ||
if (state === 'secret') { | ||
// the secret we sent is echoed back to us by cygwin, not sure of | ||
// the reason for that, but we ignore it nonetheless ... | ||
if (bc === 16) { | ||
bc = 0; | ||
state = 'creds'; | ||
sock.write(credsbuf); | ||
} | ||
} else if (state === 'creds') { | ||
// if this is the first attempt, make sure to gather the valid | ||
// uid and gid for our next attempt | ||
if (!isRetrying) | ||
inbuf.push(data); | ||
if (bc === 12) { | ||
sock.removeListener('connect', _onconnect); | ||
sock.removeListener('data', _ondata); | ||
sock.removeListener('close', _onclose); | ||
if (isRetrying) { | ||
addSockListeners(); | ||
sock.emit('connect'); | ||
} else { | ||
isRetrying = true; | ||
credsbuf = Buffer.concat(inbuf); | ||
credsbuf.writeUInt32LE(process.pid, 0, true); | ||
sock.destroy(); | ||
tryConnect(); | ||
} | ||
} | ||
} | ||
} | ||
function _onclose() { | ||
cb(new Error('Problem negotiating cygwin unix socket security')); | ||
} | ||
function tryConnect() { | ||
sock = new Socket(); | ||
sock.once('connect', _onconnect); | ||
sock.on('data', _ondata); | ||
sock.once('close', _onclose); | ||
sock.connect(port); | ||
} | ||
tryConnect(); | ||
} else | ||
cb(new Error('Malformed cygwin unix socket file')); | ||
}); | ||
return; | ||
} | ||
} else | ||
sock = new Socket(); | ||
sock.once('connect', onconnect); | ||
sock.on('data', ondata); | ||
sock.once('error', onerror); | ||
sock.once('close', onclose); | ||
function addSockListeners() { | ||
sock.once('connect', onconnect); | ||
sock.on('data', ondata); | ||
sock.once('error', onerror); | ||
sock.once('close', onclose); | ||
} | ||
addSockListeners(); | ||
sock.connect(sockPath); | ||
@@ -186,0 +277,0 @@ }; |
{ "name": "ssh2", | ||
"version": "0.2.14", | ||
"version": "0.2.15", | ||
"author": "Brian White <mscdex@mscdex.net>", | ||
@@ -4,0 +4,0 @@ "description": "An SSH2 client module written in pure JavaScript for node.js", |
@@ -30,5 +30,2 @@ Description | ||
var c = new Connection(); | ||
c.on('connect', function() { | ||
console.log('Connection :: connect'); | ||
}); | ||
c.on('ready', function() { | ||
@@ -86,5 +83,2 @@ console.log('Connection :: ready'); | ||
var c = new Connection(); | ||
c.on('connect', function() { | ||
console.log('Connection :: connect'); | ||
}); | ||
c.on('ready', function() { | ||
@@ -161,5 +155,2 @@ console.log('Connection :: ready'); | ||
var c = new Connection(); | ||
c.on('connect', function() { | ||
console.log('Connection :: connect'); | ||
}); | ||
c.on('tcp connection', function(info, accept, reject) { | ||
@@ -240,5 +231,2 @@ console.log('TCP :: INCOMING CONNECTION: ' + require('util').inspect(info)); | ||
var c = new Connection(); | ||
c.on('connect', function() { | ||
console.log('Connection :: connect'); | ||
}); | ||
c.on('ready', function() { | ||
@@ -341,6 +329,2 @@ console.log('Connection :: ready'); | ||
c.on('connect', function() { | ||
console.log('Connection :: connect'); | ||
}); | ||
c.on('ready', function() { | ||
@@ -383,4 +367,2 @@ console.log('Connection :: ready'); | ||
* **connect**() - A connection to the server was successful. | ||
* **banner**(< _string_ >message, < _string_ >language) - A notice was sent by the server upon connection. | ||
@@ -432,3 +414,3 @@ | ||
* **agent** - < _string_ > - Path to ssh-agent's UNIX socket for ssh-agent-based user authentication. **Windows users: set to 'pageant' for authenticating with Pageant.** **Default:** (none) | ||
* **agent** - < _string_ > - Path to ssh-agent's UNIX socket for ssh-agent-based user authentication. **Windows users: set to 'pageant' for authenticating with Pageant or (actual) path to a cygwin "UNIX socket."** **Default:** (none) | ||
@@ -501,3 +483,3 @@ * **privateKey** - < _mixed_ > - Buffer or string that contains a private key for key-based user authentication (OpenSSH format). **Default:** (none) | ||
* **signal**(< _string_ >signalName) - _(void)_ - Sends a POSIX signal to the current process on the server. Valid signal names are: 'ABRT', 'ALRM', 'FPE', 'HUP', 'ILL', 'INT', 'KILL', 'PIPE', 'QUIT', 'SEGV', 'TERM', 'USR1', and 'USR2'. Also, from the RFC: "Some systems may not implement signals, in which case they SHOULD ignore this message." | ||
* **signal**(< _string_ >signalName) - _(void)_ - Sends a POSIX signal to the current process on the server. Valid signal names are: 'ABRT', 'ALRM', 'FPE', 'HUP', 'ILL', 'INT', 'KILL', 'PIPE', 'QUIT', 'SEGV', 'TERM', 'USR1', and 'USR2'. Also, from the RFC: "Some systems may not implement signals, in which case they SHOULD ignore this message." Note: If you are trying to send SIGINT and you find signal() doesn't work, try writing '\x03' to the exec/shell stream instead. | ||
@@ -504,0 +486,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
276092
5601
653
2