Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,9 @@ You can find more examples in the `examples` directory of this repository.

* **forwardOut**(< _string_ >boundAddr, < _integer_ >boundPort, < _string_ >remoteAddr, < _integer_ >remotePort, < _function_ >callback) - _(void)_ - Alert the client of an incoming TCP connection on `boundAddr` on port `boundPort` from `remoteAddr` on port `remotePort`. `callback` has 2 parameters: < _Error_ >err, < _Channel_ >stream.

* **openssh_authAgent**(< _function_ >callback) - _boolean_ - Alert the client of an incoming `ssh-agent` socket connection. `callback` has 2 parameters: < _Error_ >err, < _Channel_ >stream. Returns `false` if you should wait for the `continue` event before sending any more traffic.


* **openssh_forwardOutStreamLocal**(< _string_ >socketPath, < _function_ >callback) - _(void)_ - Alert the client of an incoming UNIX domain socket connection on `socketPath`. `callback` has 2 parameters: < _Error_ >err, < _Channel_ >stream.

* **rekey**([< _function_ >callback]) - _(void)_ - Initiates a rekey with the client. If `callback` is supplied, it is added as a one-time handler for the `rekey` event.
Expand Down
9 changes: 9 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,12 @@ class Client extends EventEmitter {
return this;
}


openssh_authAgent(cb) {
openChannel(this, 'auth-agent@openssh.com', cb);
return this;
}

openssh_forwardOutStreamLocal(socketPath, cb) {
const opts = { socketPath };
openChannel(this, 'forwarded-streamlocal@openssh.com', opts, cb);
Expand Down Expand Up @@ -1362,6 +1368,9 @@ function openChannel(self, type, opts, cb) {
case 'x11':
self._protocol.x11(localChan, initWindow, maxPacket, opts);
break;
case 'auth-agent@openssh.com':
self._protocol.openssh_authAgent(localChan, initWindow, maxPacket);
break;
case 'forwarded-streamlocal@openssh.com':
self._protocol.openssh_forwardedStreamLocal(
localChan, initWindow, maxPacket, opts
Expand Down
42 changes: 40 additions & 2 deletions test/test-openssh.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

const assert = require('assert');
const { inspect } = require('util');
const { spawn } = require('child_process');
const net = require('net');
const fs = require('fs');

const {
fixture,
Expand All @@ -16,12 +19,37 @@ const clientCfg = { username: 'foo', password: 'bar' };
const serverCfg = { hostKeys: [ fixture('ssh_host_rsa_key') ] };

{

const agentSockPath =
process.platform === 'win32'
? `\\\\.\\pipe\\nodejs-ssh2-test-${process.pid}`
: `${os.tmpdir()}${
path.sep
}nodejs-ssh2-test-${process.pid}.sock`;

if (fs.existsSync(agentSockPath)) {
fs.unlinkSync(agentSockPath);
}

const agent = net.createServer((agentSocket) => {
assert(!agentSocket.readable, 'Agent socket not readable');
}).listen(agentSockPath, () => {
const cleanup = () => {
server.close(() => {
if (fs.existsSync(agentSockPath)) {
fs.unlinkSync(agentSockPath);
}
});
};
process.on('exit', cleanup);
});

const { client, server } = setup_(
'Exec with OpenSSH agent forwarding',
{
client: {
...clientCfg,
agent: '/path/to/agent',
agent: agentSockPath,
},
server: serverCfg,

Expand All @@ -45,8 +73,18 @@ const serverCfg = { hostKeys: [ fixture('ssh_host_rsa_key') ] };
const stream = accept();
stream.exit(100);
stream.end();
conn.end();

conn.openssh_authAgent(function(err, stream) {
assert(!err, `Unexpected openssh_authAgent error: ${err}`);
assert(stream.type === 'auth-agent@openssh.com',
`Unexpected openssh_authAgent channel type : ${stream.type}`);

conn.end();
agent.kill();
});

}));

}));
}));
}));
Expand Down