Skip to content

Commit 40fa58f

Browse files
author
François Leurent
committed
With openssh_authAgent & tests
1 parent 27795a3 commit 40fa58f

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,9 @@ You can find more examples in the `examples` directory of this repository.
11801180

11811181
* **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.
11821182

1183+
* **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.
1184+
1185+
11831186
* **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.
11841187

11851188
* **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.

lib/server.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,12 @@ class Client extends EventEmitter {
12841284
return this;
12851285
}
12861286

1287+
1288+
openssh_authAgent(cb) {
1289+
openChannel(this, 'auth-agent@openssh.com', cb);
1290+
return this;
1291+
}
1292+
12871293
openssh_forwardOutStreamLocal(socketPath, cb) {
12881294
const opts = { socketPath };
12891295
openChannel(this, 'forwarded-streamlocal@openssh.com', opts, cb);
@@ -1341,6 +1347,9 @@ function openChannel(self, type, opts, cb) {
13411347
case 'x11':
13421348
self._protocol.x11(localChan, initWindow, maxPacket, opts);
13431349
break;
1350+
case 'auth-agent@openssh.com':
1351+
self._protocol.openssh_authAgent(localChan, initWindow, maxPacket);
1352+
break;
13441353
case 'forwarded-streamlocal@openssh.com':
13451354
self._protocol.openssh_forwardedStreamLocal(
13461355
localChan, initWindow, maxPacket, opts

test/test-openssh.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const assert = require('assert');
44
const { inspect } = require('util');
5+
const { spawn } = require('child_process');
56

67
const {
78
fixture,
@@ -12,16 +13,27 @@ const {
1213

1314
const debug = false;
1415

16+
const test_forward = (process.platform !== 'win32');
17+
18+
if (!test_forward)
19+
console.log('Skipping agent forwarding test on Windows');
20+
21+
1522
const clientCfg = { username: 'foo', password: 'bar' };
1623
const serverCfg = { hostKeys: [ fixture('ssh_host_rsa_key') ] };
1724

1825
{
26+
const agent_sock = '/tmp/nodejs-ssh2-test-' + process.pid;
27+
let agent;
28+
if (test_forward)
29+
agent = spawn('ssh-agent', ['-d', '-a', agent_sock]);
30+
1931
const { client, server } = setup_(
2032
'Exec with OpenSSH agent forwarding',
2133
{
2234
client: {
2335
...clientCfg,
24-
agent: '/path/to/agent',
36+
agent: agent_sock,
2537
},
2638
server: serverCfg,
2739

@@ -45,8 +57,23 @@ const serverCfg = { hostKeys: [ fixture('ssh_host_rsa_key') ] };
4557
const stream = accept();
4658
stream.exit(100);
4759
stream.end();
48-
conn.end();
60+
61+
if (test_forward) {
62+
conn.openssh_authAgent(function(err, stream) {
63+
assert(!err, `Unexpected openssh_authAgent error: ${err}`);
64+
assert(stream.type === 'auth-agent@openssh.com',
65+
`Unexpected openssh_authAgent channel type : ${stream.type}`);
66+
67+
conn.end();
68+
agent.kill();
69+
});
70+
71+
} else {
72+
conn.end();
73+
}
74+
4975
}));
76+
5077
}));
5178
}));
5279
}));

0 commit comments

Comments
 (0)