@andy.ian/dsh-homing 2.0.3 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/bin/restart-daemon.mjs +3 -0
  2. package/bin/restart.mjs +3 -0
  3. package/index.js +714 -21
  4. package/lib/devices.mjs +0 -1
  5. package/lib/files-page.mjs +0 -18
  6. package/lib/files.mjs +39 -27
  7. package/package.json +7 -9
  8. package/restart/client.mjs +184 -0
  9. package/restart/config.mjs +187 -0
  10. package/restart/daemon/README.md +102 -0
  11. package/restart/daemon/cli.mjs +366 -0
  12. package/restart/daemon/lib/detach.mjs +126 -0
  13. package/restart/daemon/lib/process-tree.mjs +69 -0
  14. package/restart/daemon/lib/restart-flow.mjs +111 -0
  15. package/restart/daemon/lib/update-state.mjs +72 -0
  16. package/restart/daemon/main.mjs +691 -0
  17. package/restart/engine.mjs +93 -0
  18. package/restart/face.mjs +62 -0
  19. package/restart/runner.mjs +184 -0
  20. package/restart/service.mjs +91 -0
  21. package/bin/supervisor.mjs +0 -488
  22. package/bin/watchdog.mjs +0 -144
  23. package/lib/vendor/node_modules/ssh2/examples/server-chat.js +0 -238
  24. package/lib/vendor/node_modules/ssh2/examples/sftp-server-download-only.js +0 -134
  25. package/lib/vendor/node_modules/ssh2/test/common.js +0 -316
  26. package/lib/vendor/node_modules/ssh2/test/fixtures/bad_rsa_private_key +0 -26
  27. package/lib/vendor/node_modules/ssh2/test/fixtures/https_cert.pem +0 -33
  28. package/lib/vendor/node_modules/ssh2/test/fixtures/https_key.pem +0 -52
  29. package/lib/vendor/node_modules/ssh2/test/fixtures/id_dsa +0 -12
  30. package/lib/vendor/node_modules/ssh2/test/fixtures/id_ecdsa +0 -5
  31. package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa +0 -15
  32. package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa.ppk +0 -26
  33. package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa_enc +0 -30
  34. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa +0 -21
  35. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub +0 -1
  36. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub.result +0 -7
  37. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.result +0 -7
  38. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc +0 -22
  39. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub +0 -1
  40. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub.result +0 -7
  41. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.result +0 -7
  42. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm +0 -23
  43. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub +0 -1
  44. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub.result +0 -7
  45. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.result +0 -7
  46. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa +0 -9
  47. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub +0 -1
  48. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub.result +0 -7
  49. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.result +0 -7
  50. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc +0 -10
  51. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub +0 -1
  52. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub.result +0 -8
  53. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.result +0 -7
  54. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm +0 -10
  55. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub +0 -1
  56. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub.result +0 -8
  57. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.result +0 -7
  58. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519 +0 -7
  59. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub +0 -1
  60. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub.result +0 -7
  61. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.result +0 -7
  62. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa +0 -27
  63. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub +0 -1
  64. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub.result +0 -7
  65. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.result +0 -7
  66. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc +0 -28
  67. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub +0 -1
  68. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub.result +0 -8
  69. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.result +0 -7
  70. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm +0 -29
  71. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub +0 -1
  72. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub.result +0 -8
  73. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.result +0 -7
  74. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa +0 -12
  75. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub +0 -1
  76. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub.result +0 -7
  77. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.result +0 -7
  78. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc +0 -15
  79. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub +0 -1
  80. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub.result +0 -8
  81. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.result +0 -7
  82. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa +0 -5
  83. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub +0 -1
  84. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub.result +0 -7
  85. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.result +0 -7
  86. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc +0 -8
  87. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub +0 -1
  88. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub.result +0 -8
  89. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.result +0 -7
  90. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa +0 -27
  91. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub +0 -1
  92. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub.result +0 -7
  93. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.result +0 -7
  94. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc +0 -30
  95. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub +0 -1
  96. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub.result +0 -8
  97. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.result +0 -7
  98. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256 +0 -54
  99. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub +0 -1
  100. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub.result +0 -6
  101. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.result +0 -6
  102. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc +0 -17
  103. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc.result +0 -7
  104. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa +0 -26
  105. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa.result +0 -7
  106. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc +0 -18
  107. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc.result +0 -7
  108. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub +0 -9
  109. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub.result +0 -7
  110. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub +0 -10
  111. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub.result +0 -7
  112. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub +0 -11
  113. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub.result +0 -7
  114. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub +0 -11
  115. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub.result +0 -7
  116. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub +0 -8
  117. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub.result +0 -7
  118. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub +0 -13
  119. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub.result +0 -7
  120. package/lib/vendor/node_modules/ssh2/test/fixtures/openssh_new_rsa +0 -27
  121. package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_dsa_key +0 -12
  122. package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_ecdsa_key +0 -5
  123. package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_rsa_key +0 -15
  124. package/lib/vendor/node_modules/ssh2/test/test-exec.js +0 -578
  125. package/lib/vendor/node_modules/ssh2/test/test-integration-openssh.js +0 -486
  126. package/lib/vendor/node_modules/ssh2/test/test-keygen.js +0 -60
  127. package/lib/vendor/node_modules/ssh2/test/test-misc-client-server.js +0 -1460
  128. package/lib/vendor/node_modules/ssh2/test/test-openssh.js +0 -261
  129. package/lib/vendor/node_modules/ssh2/test/test-protocol-crypto.js +0 -631
  130. package/lib/vendor/node_modules/ssh2/test/test-protocol-keyparser.js +0 -177
  131. package/lib/vendor/node_modules/ssh2/test/test-server-hostkeys.js +0 -138
  132. package/lib/vendor/node_modules/ssh2/test/test-sftp.js +0 -842
  133. package/lib/vendor/node_modules/ssh2/test/test-shell.js +0 -109
  134. package/lib/vendor/node_modules/ssh2/test/test-userauth-agent-openssh.js +0 -110
  135. package/lib/vendor/node_modules/ssh2/test/test-userauth-agent.js +0 -171
  136. package/lib/vendor/node_modules/ssh2/test/test-userauth.js +0 -611
  137. package/lib/vendor/node_modules/ssh2/test/test-worker-imports.js +0 -25
  138. package/lib/vendor/node_modules/ssh2/test/test.js +0 -20
@@ -1,109 +0,0 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
- const { inspect } = require('util');
5
-
6
- const {
7
- mustCall,
8
- mustCallAtLeast,
9
- setupSimple,
10
- } = require('./common.js');
11
-
12
- const DEBUG = false;
13
-
14
- const setup = setupSimple.bind(undefined, DEBUG);
15
-
16
- {
17
- const { client, server } = setup('Simple shell()');
18
-
19
- const OUTPUT = 'shell output!\n';
20
-
21
- server.on('connection', mustCall((conn) => {
22
- conn.on('ready', mustCall(() => {
23
- conn.on('session', mustCall((accept, reject) => {
24
- const session = accept();
25
- session.on('pty', mustCall((accept, reject, info) => {
26
- accept();
27
- session.on('shell', mustCall((accept, reject) => {
28
- let input = '';
29
- const stream = accept();
30
- stream.write(OUTPUT);
31
- stream.on('data', mustCallAtLeast((data) => {
32
- input += data;
33
- if (input === 'exit\n') {
34
- stream.end();
35
- conn.end();
36
- }
37
- }));
38
- }));
39
- }));
40
- }));
41
- }));
42
- }));
43
-
44
- client.on('ready', mustCall(() => {
45
- let output = '';
46
- client.on('close', mustCall(() => {
47
- assert(output === OUTPUT, `Wrong shell output: ${inspect(output)}`);
48
- })).shell(mustCall((err, stream) => {
49
- assert(!err, `Unexpected shell error: ${err}`);
50
- stream.write('exit\n');
51
- stream.on('data', mustCallAtLeast((d) => {
52
- output += d;
53
- })).on('close', mustCall(() => {}));
54
- }));
55
- }));
56
- }
57
-
58
- {
59
- const { client, server } = setup('Shell with environment set');
60
-
61
- const OUTPUT = 'shell output!\n';
62
- const clientEnv = { SSH2NODETEST: 'foo' };
63
-
64
- server.on('connection', mustCall((conn) => {
65
- conn.on('ready', mustCall(() => {
66
- conn.on('session', mustCall((accept, reject) => {
67
- let pty = false;
68
- let env = false;
69
- accept().on('pty', mustCall((accept, reject, info) => {
70
- accept();
71
- pty = true;
72
- })).on('env', mustCall((accept, reject, info) => {
73
- accept && accept();
74
- env = true;
75
- assert(info.key === Object.keys(clientEnv)[0],
76
- `Wrong env key: ${inspect(info.key)}`);
77
- assert(info.val === Object.values(clientEnv)[0],
78
- `Wrong env value: ${inspect(info.val)}`);
79
- })).on('shell', mustCall((accept, reject) => {
80
- assert(pty, 'Expected pty before shell');
81
- assert(env, 'Expected env before shell');
82
- let input = '';
83
- const stream = accept();
84
- stream.write(OUTPUT);
85
- stream.on('data', mustCallAtLeast((data) => {
86
- input += data;
87
- if (input === 'exit\n') {
88
- stream.end();
89
- conn.end();
90
- }
91
- }));
92
- }));
93
- }));
94
- }));
95
- }));
96
-
97
- client.on('ready', mustCall(() => {
98
- let output = '';
99
- client.on('close', mustCall(() => {
100
- assert(output === OUTPUT, `Wrong shell output: ${inspect(output)}`);
101
- })).shell({ env: clientEnv }, mustCall((err, stream) => {
102
- assert(!err, `Unexpected shell error: ${err}`);
103
- stream.write('exit\n');
104
- stream.on('data', mustCallAtLeast((d) => {
105
- output += d;
106
- })).on('close', mustCall(() => {}));
107
- }));
108
- }));
109
- }
@@ -1,110 +0,0 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
- const { spawnSync } = require('child_process');
5
-
6
- const debug = false;
7
- const SPAWN_OPTS = { windowsHide: true };
8
-
9
- // TODO: figure out why this test is failing on Windows
10
- if (process.platform === 'win32') {
11
- console.log('Skipping ssh-agent test on Windows');
12
- process.exit(0);
13
- }
14
-
15
- if (process.argv[2] === 'child') {
16
- const {
17
- fixtureKey,
18
- mustCall,
19
- setup,
20
- } = require('./common.js');
21
-
22
- const serverCfg = { hostKeys: [ fixtureKey('ssh_host_rsa_key').raw ] };
23
-
24
- const clientKey = fixtureKey('openssh_new_rsa');
25
-
26
- // Add key to the agent first
27
- {
28
- const {
29
- error, status
30
- } = spawnSync('ssh-add', [ clientKey.fullPath ], SPAWN_OPTS);
31
- if (error || status !== 0) {
32
- console.error('Failed to add key to agent');
33
- process.exit(1);
34
- }
35
- }
36
-
37
- const username = 'Agent User';
38
- const { server } = setup(
39
- 'Agent authentication',
40
- {
41
- client: { username, agent: process.env.SSH_AUTH_SOCK },
42
- server: serverCfg,
43
-
44
- debug,
45
- }
46
- );
47
-
48
- server.on('connection', mustCall((conn) => {
49
- let authAttempt = 0;
50
- conn.on('authentication', mustCall((ctx) => {
51
- assert(ctx.username === username,
52
- `Wrong username: ${ctx.username}`);
53
- switch (++authAttempt) {
54
- case 1:
55
- assert(ctx.method === 'none', `Wrong auth method: ${ctx.method}`);
56
- return ctx.reject();
57
- case 3:
58
- assert(ctx.signature, 'Missing publickey signature');
59
- // FALLTHROUGH
60
- case 2:
61
- assert(ctx.method === 'publickey',
62
- `Wrong auth method: ${ctx.method}`);
63
- assert(ctx.key.algo === clientKey.key.type,
64
- `Wrong key algo: ${ctx.key.algo}`);
65
- assert.deepStrictEqual(clientKey.key.getPublicSSH(),
66
- ctx.key.data,
67
- 'Public key mismatch');
68
- break;
69
- }
70
- if (ctx.signature) {
71
- const result =
72
- clientKey.key.verify(ctx.blob, ctx.signature, ctx.hashAlgo);
73
- assert(result === true, 'Could not verify publickey signature');
74
- }
75
- ctx.accept();
76
- }, 3)).on('ready', mustCall(() => {
77
- conn.end();
78
- }));
79
- }));
80
- } else {
81
- {
82
- const {
83
- error, status
84
- } = spawnSync('which', ['ssh-agent'], SPAWN_OPTS);
85
-
86
- if (error || status !== 0) {
87
- console.log('No ssh-agent available, skipping agent test ...');
88
- process.exit(0);
89
- }
90
- }
91
-
92
- {
93
- const {
94
- error, status
95
- } = spawnSync('which', ['ssh-add'], SPAWN_OPTS);
96
-
97
- if (error || status !== 0) {
98
- console.log('No ssh-add available, skipping agent test ...');
99
- process.exit(0);
100
- }
101
- }
102
-
103
- const {
104
- error, status
105
- } = spawnSync('ssh-agent',
106
- [ process.execPath, __filename, 'child' ],
107
- { ...SPAWN_OPTS, stdio: 'inherit' });
108
- if (error || status !== 0)
109
- throw new Error('Agent test failed');
110
- }
@@ -1,171 +0,0 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
-
5
- const debug = false;
6
-
7
- const {
8
- fixtureKey,
9
- mustCall,
10
- setup,
11
- } = require('./common.js');
12
- const {
13
- AgentProtocol,
14
- BaseAgent,
15
- utils: { parseKey },
16
- } = require('../lib/index.js');
17
-
18
- const serverCfg = { hostKeys: [ fixtureKey('ssh_host_rsa_key').raw ] };
19
-
20
- const clientKey = fixtureKey('openssh_new_rsa');
21
-
22
- {
23
- let getIdentitiesCount = 0;
24
- let signCount = 0;
25
- class MyAgent extends BaseAgent {
26
- getIdentities(cb) {
27
- assert.strictEqual(++getIdentitiesCount, 1);
28
- // Ensure that no private portion of the key is used by re-parsing the
29
- // public version of the key
30
- cb(null, [ parseKey(clientKey.key.getPublicSSH()) ]);
31
- }
32
- sign(pubKey, data, options, cb) {
33
- assert.strictEqual(++signCount, 1);
34
- assert.strictEqual(pubKey.getPublicPEM(), clientKey.key.getPublicPEM());
35
- const sig = clientKey.key.sign(data, options.hash);
36
- cb(null, sig);
37
- }
38
- }
39
-
40
- const username = 'Agent User';
41
- const { server } = setup(
42
- 'Custom agent authentication',
43
- {
44
- client: { username, agent: new MyAgent() },
45
- server: serverCfg,
46
-
47
- debug,
48
- }
49
- );
50
-
51
- server.on('connection', mustCall((conn) => {
52
- let authAttempt = 0;
53
- conn.on('authentication', mustCall((ctx) => {
54
- assert(ctx.username === username,
55
- `Wrong username: ${ctx.username}`);
56
- switch (++authAttempt) {
57
- case 1:
58
- assert(ctx.method === 'none', `Wrong auth method: ${ctx.method}`);
59
- return ctx.reject();
60
- case 3:
61
- assert(ctx.signature, 'Missing publickey signature');
62
- // FALLTHROUGH
63
- case 2:
64
- assert(ctx.method === 'publickey',
65
- `Wrong auth method: ${ctx.method}`);
66
- assert(ctx.key.algo === clientKey.key.type,
67
- `Wrong key algo: ${ctx.key.algo}`);
68
- assert.deepStrictEqual(clientKey.key.getPublicSSH(),
69
- ctx.key.data,
70
- 'Public key mismatch');
71
- break;
72
- }
73
- if (ctx.signature) {
74
- const result =
75
- clientKey.key.verify(ctx.blob, ctx.signature, ctx.hashAlgo);
76
- assert(result === true, 'Could not verify publickey signature');
77
- }
78
- ctx.accept();
79
- }, 3)).on('ready', mustCall(() => {
80
- assert.strictEqual(getIdentitiesCount, 1);
81
- assert.strictEqual(signCount, 1);
82
- conn.end();
83
- }));
84
- }));
85
- }
86
- {
87
- const client = new AgentProtocol(true);
88
- const server = new AgentProtocol(false);
89
-
90
- server.on('identities', mustCall((req) => {
91
- setImmediate(() => server.failureReply(req));
92
- }));
93
- client.getIdentities(mustCall((err, keys) => {
94
- assert(err, 'Missing expected error');
95
- }));
96
-
97
- client.pipe(server).pipe(client);
98
- }
99
- {
100
- const client = new AgentProtocol(true);
101
- const server = new AgentProtocol(false);
102
-
103
- server.on('identities', mustCall((req) => {
104
- const keys = [ clientKey.key ];
105
- server.getIdentitiesReply(req, keys);
106
- }));
107
- client.getIdentities(mustCall((err, keys) => {
108
- assert(!err, 'Unexpected error');
109
- assert.strictEqual(keys.length, 1);
110
- assert.strictEqual(keys[0].isPrivateKey(), false);
111
- assert.strictEqual(keys[0].getPublicPEM(), clientKey.key.getPublicPEM());
112
- }));
113
-
114
- client.pipe(server).pipe(client);
115
- }
116
- {
117
- const client = new AgentProtocol(true);
118
- const server = new AgentProtocol(false);
119
- const buf = Buffer.from('data to sign');
120
-
121
- server.on('sign', mustCall((req, pubKey, data, options) => {
122
- assert.strictEqual(pubKey.getPublicPEM(), clientKey.key.getPublicPEM());
123
- assert.deepStrictEqual(data, buf);
124
- assert.strictEqual(options.hash, undefined);
125
- server.failureReply(req);
126
- }));
127
- client.sign(clientKey.key.getPublicSSH(),
128
- buf,
129
- mustCall((err, signature) => {
130
- assert(err, 'Missing expected error');
131
- }));
132
-
133
- client.pipe(server).pipe(client);
134
- }
135
- {
136
- const client = new AgentProtocol(true);
137
- const server = new AgentProtocol(false);
138
- const buf = Buffer.from('data to sign');
139
-
140
- server.on('sign', mustCall((req, pubKey, data, options) => {
141
- assert.strictEqual(pubKey.getPublicPEM(), clientKey.key.getPublicPEM());
142
- assert.deepStrictEqual(data, buf);
143
- assert.strictEqual(options.hash, undefined);
144
- server.signReply(req, clientKey.key.sign(data));
145
- }));
146
- client.sign(clientKey.key.getPublicSSH(),
147
- buf,
148
- mustCall((err, signature) => {
149
- assert(!err, 'Unexpected error');
150
- const pubKey = parseKey(clientKey.key.getPublicSSH());
151
- assert.strictEqual(pubKey.verify(buf, signature), true);
152
- }));
153
-
154
- client.pipe(server).pipe(client);
155
- }
156
- {
157
- // Test that outstanding requests are handled upon unexpected closure of the
158
- // protocol stream
159
-
160
- const client = new AgentProtocol(true);
161
- const server = new AgentProtocol(false);
162
-
163
- server.on('identities', mustCall((req) => {
164
- server.destroy();
165
- }));
166
- client.getIdentities(mustCall((err) => {
167
- assert(err, 'Missing expected error');
168
- }));
169
-
170
- client.pipe(server).pipe(client);
171
- }