@andy.ian/dsh-homing 2.0.2 → 2.1.0
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.
- package/bin/restart-daemon.mjs +3 -0
- package/bin/restart.mjs +3 -0
- package/index.js +785 -29
- package/lib/devices.mjs +0 -1
- package/lib/files-page.mjs +10 -18
- package/lib/files.mjs +39 -27
- package/package.json +8 -9
- package/restart/client.mjs +184 -0
- package/restart/config.mjs +187 -0
- package/restart/engine.mjs +93 -0
- package/restart/face.mjs +62 -0
- package/restart/runner.mjs +184 -0
- package/restart/service.mjs +91 -0
- package/restart-daemon/README.md +66 -0
- package/restart-daemon/cli.mjs +321 -0
- package/restart-daemon/lib/detach.mjs +126 -0
- package/restart-daemon/lib/process-tree.mjs +69 -0
- package/restart-daemon/lib/restart-flow.mjs +111 -0
- package/restart-daemon/lib/update-state.mjs +72 -0
- package/restart-daemon/main.mjs +691 -0
- package/bin/supervisor.mjs +0 -488
- package/bin/watchdog.mjs +0 -144
- package/lib/vendor/node_modules/ssh2/examples/server-chat.js +0 -238
- package/lib/vendor/node_modules/ssh2/examples/sftp-server-download-only.js +0 -134
- package/lib/vendor/node_modules/ssh2/test/common.js +0 -316
- package/lib/vendor/node_modules/ssh2/test/fixtures/bad_rsa_private_key +0 -26
- package/lib/vendor/node_modules/ssh2/test/fixtures/https_cert.pem +0 -33
- package/lib/vendor/node_modules/ssh2/test/fixtures/https_key.pem +0 -52
- package/lib/vendor/node_modules/ssh2/test/fixtures/id_dsa +0 -12
- package/lib/vendor/node_modules/ssh2/test/fixtures/id_ecdsa +0 -5
- package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa +0 -15
- package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa.ppk +0 -26
- package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa_enc +0 -30
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa +0 -21
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub +0 -1
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc +0 -22
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub +0 -1
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm +0 -23
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub +0 -1
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa +0 -9
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub +0 -1
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc +0 -10
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub +0 -1
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub.result +0 -8
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm +0 -10
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub +0 -1
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub.result +0 -8
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519 +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub +0 -1
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa +0 -27
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub +0 -1
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc +0 -28
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub +0 -1
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub.result +0 -8
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm +0 -29
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub +0 -1
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub.result +0 -8
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa +0 -12
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub +0 -1
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc +0 -15
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub +0 -1
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub.result +0 -8
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa +0 -5
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub +0 -1
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc +0 -8
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub +0 -1
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub.result +0 -8
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa +0 -27
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub +0 -1
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc +0 -30
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub +0 -1
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub.result +0 -8
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256 +0 -54
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub +0 -1
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub.result +0 -6
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.result +0 -6
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc +0 -17
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa +0 -26
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc +0 -18
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub +0 -9
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub +0 -10
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub +0 -11
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub +0 -11
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub +0 -8
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub +0 -13
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub.result +0 -7
- package/lib/vendor/node_modules/ssh2/test/fixtures/openssh_new_rsa +0 -27
- package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_dsa_key +0 -12
- package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_ecdsa_key +0 -5
- package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_rsa_key +0 -15
- package/lib/vendor/node_modules/ssh2/test/test-exec.js +0 -578
- package/lib/vendor/node_modules/ssh2/test/test-integration-openssh.js +0 -486
- package/lib/vendor/node_modules/ssh2/test/test-keygen.js +0 -60
- package/lib/vendor/node_modules/ssh2/test/test-misc-client-server.js +0 -1460
- package/lib/vendor/node_modules/ssh2/test/test-openssh.js +0 -261
- package/lib/vendor/node_modules/ssh2/test/test-protocol-crypto.js +0 -631
- package/lib/vendor/node_modules/ssh2/test/test-protocol-keyparser.js +0 -177
- package/lib/vendor/node_modules/ssh2/test/test-server-hostkeys.js +0 -138
- package/lib/vendor/node_modules/ssh2/test/test-sftp.js +0 -842
- package/lib/vendor/node_modules/ssh2/test/test-shell.js +0 -109
- package/lib/vendor/node_modules/ssh2/test/test-userauth-agent-openssh.js +0 -110
- package/lib/vendor/node_modules/ssh2/test/test-userauth-agent.js +0 -171
- package/lib/vendor/node_modules/ssh2/test/test-userauth.js +0 -611
- package/lib/vendor/node_modules/ssh2/test/test-worker-imports.js +0 -25
- package/lib/vendor/node_modules/ssh2/test/test.js +0 -20
|
@@ -1,486 +0,0 @@
|
|
|
1
|
-
// TODO: add more rekey tests that at least include switching from no
|
|
2
|
-
// compression to compression and vice versa
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
const assert = require('assert');
|
|
6
|
-
const { spawn, spawnSync } = require('child_process');
|
|
7
|
-
const { chmodSync, readdirSync } = require('fs');
|
|
8
|
-
const { join } = require('path');
|
|
9
|
-
const readline = require('readline');
|
|
10
|
-
|
|
11
|
-
const Server = require('../lib/server.js');
|
|
12
|
-
|
|
13
|
-
const {
|
|
14
|
-
fixture,
|
|
15
|
-
fixtureKey,
|
|
16
|
-
FIXTURES_DIR,
|
|
17
|
-
mustCall,
|
|
18
|
-
mustCallAtLeast,
|
|
19
|
-
} = require('./common.js');
|
|
20
|
-
|
|
21
|
-
const SPAWN_OPTS = { windowsHide: true };
|
|
22
|
-
const CLIENT_TIMEOUT = 5000;
|
|
23
|
-
|
|
24
|
-
const debug = false;
|
|
25
|
-
const opensshPath = 'ssh';
|
|
26
|
-
let opensshVer;
|
|
27
|
-
|
|
28
|
-
// TODO: figure out why this test is failing on Windows
|
|
29
|
-
if (process.platform === 'win32') {
|
|
30
|
-
console.log('Skipping OpenSSH integration tests on Windows');
|
|
31
|
-
process.exit(0);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Fix file modes to avoid OpenSSH client complaints about keys' permissions
|
|
35
|
-
for (const file of readdirSync(FIXTURES_DIR, { withFileTypes: true })) {
|
|
36
|
-
if (file.isFile())
|
|
37
|
-
chmodSync(join(FIXTURES_DIR, file.name), 0o600);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
{
|
|
41
|
-
// Get OpenSSH client version first
|
|
42
|
-
const {
|
|
43
|
-
error, stderr, stdout
|
|
44
|
-
} = spawnSync(opensshPath, ['-V'], SPAWN_OPTS);
|
|
45
|
-
|
|
46
|
-
if (error) {
|
|
47
|
-
console.error('OpenSSH client is required for these tests');
|
|
48
|
-
process.exitCode = 5;
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const re = /^OpenSSH_([\d.]+)/;
|
|
53
|
-
let m = re.exec(stdout.toString());
|
|
54
|
-
if (!m || !m[1]) {
|
|
55
|
-
m = re.exec(stderr.toString());
|
|
56
|
-
if (!m || !m[1]) {
|
|
57
|
-
console.error('OpenSSH client is required for these tests');
|
|
58
|
-
process.exitCode = 5;
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
opensshVer = m[1];
|
|
64
|
-
console.log(`Testing with OpenSSH version: ${opensshVer}`);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// Key-based authentication
|
|
69
|
-
[
|
|
70
|
-
{ desc: 'RSA user key (old OpenSSH)',
|
|
71
|
-
clientKey: fixtureKey('id_rsa') },
|
|
72
|
-
{ desc: 'RSA user key (new OpenSSH)',
|
|
73
|
-
clientKey: fixtureKey('openssh_new_rsa') },
|
|
74
|
-
{ desc: 'DSA user key',
|
|
75
|
-
clientKey: fixtureKey('id_dsa') },
|
|
76
|
-
{ desc: 'ECDSA user key',
|
|
77
|
-
clientKey: fixtureKey('id_ecdsa') },
|
|
78
|
-
].forEach((test) => {
|
|
79
|
-
const { desc, clientKey } = test;
|
|
80
|
-
const username = 'KeyUser';
|
|
81
|
-
const { server } = setup(
|
|
82
|
-
desc,
|
|
83
|
-
{
|
|
84
|
-
client: {
|
|
85
|
-
username,
|
|
86
|
-
privateKeyPath: clientKey.fullPath,
|
|
87
|
-
},
|
|
88
|
-
server: { hostKeys: [ fixture('ssh_host_rsa_key') ] },
|
|
89
|
-
debug,
|
|
90
|
-
}
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
server.on('connection', mustCall((conn) => {
|
|
94
|
-
let authAttempt = 0;
|
|
95
|
-
conn.on('authentication', mustCallAtLeast((ctx) => {
|
|
96
|
-
assert(ctx.username === username,
|
|
97
|
-
`Wrong username: ${ctx.username}`);
|
|
98
|
-
switch (++authAttempt) {
|
|
99
|
-
case 1:
|
|
100
|
-
assert(ctx.method === 'none',
|
|
101
|
-
`Wrong auth method: ${ctx.method}`);
|
|
102
|
-
return ctx.reject();
|
|
103
|
-
case 2:
|
|
104
|
-
case 3:
|
|
105
|
-
if (authAttempt === 3)
|
|
106
|
-
assert(ctx.signature, 'Missing publickey signature');
|
|
107
|
-
assert(ctx.method === 'publickey',
|
|
108
|
-
`Wrong auth method: ${ctx.method}`);
|
|
109
|
-
assert(ctx.key.algo === clientKey.key.type,
|
|
110
|
-
`Wrong key algo: ${ctx.key.algo}`);
|
|
111
|
-
assert.deepStrictEqual(clientKey.key.getPublicSSH(),
|
|
112
|
-
ctx.key.data,
|
|
113
|
-
'Public key mismatch');
|
|
114
|
-
break;
|
|
115
|
-
default:
|
|
116
|
-
assert(false, 'Unexpected number of auth attempts');
|
|
117
|
-
}
|
|
118
|
-
if (ctx.signature) {
|
|
119
|
-
const result =
|
|
120
|
-
clientKey.key.verify(ctx.blob, ctx.signature, ctx.hashAlgo);
|
|
121
|
-
assert(result === true, 'Could not verify publickey signature');
|
|
122
|
-
// We should not expect any further auth attempts after we verify a
|
|
123
|
-
// signature
|
|
124
|
-
authAttempt = Infinity;
|
|
125
|
-
}
|
|
126
|
-
ctx.accept();
|
|
127
|
-
}, 2)).on('ready', mustCall(() => {
|
|
128
|
-
conn.on('session', mustCall((accept, reject) => {
|
|
129
|
-
accept().on('exec', mustCall((accept, reject) => {
|
|
130
|
-
const stream = accept();
|
|
131
|
-
stream.exit(0);
|
|
132
|
-
stream.end();
|
|
133
|
-
}));
|
|
134
|
-
}));
|
|
135
|
-
}));
|
|
136
|
-
}));
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
// Different host key types
|
|
141
|
-
[
|
|
142
|
-
{ desc: 'RSA host key (old OpenSSH)',
|
|
143
|
-
hostKey: fixture('id_rsa') },
|
|
144
|
-
{ desc: 'RSA host key (new OpenSSH)',
|
|
145
|
-
hostKey: fixture('openssh_new_rsa') },
|
|
146
|
-
{ desc: 'DSA host key',
|
|
147
|
-
hostKey: fixture('ssh_host_dsa_key') },
|
|
148
|
-
{ desc: 'ECDSA host key',
|
|
149
|
-
hostKey: fixture('ssh_host_ecdsa_key') },
|
|
150
|
-
{ desc: 'PPK',
|
|
151
|
-
hostKey: fixture('id_rsa.ppk') },
|
|
152
|
-
].forEach((test) => {
|
|
153
|
-
const { desc, hostKey } = test;
|
|
154
|
-
const clientKey = fixtureKey('openssh_new_rsa');
|
|
155
|
-
const username = 'KeyUser';
|
|
156
|
-
const { server } = setup(
|
|
157
|
-
desc,
|
|
158
|
-
{
|
|
159
|
-
client: {
|
|
160
|
-
username,
|
|
161
|
-
privateKeyPath: clientKey.fullPath,
|
|
162
|
-
},
|
|
163
|
-
server: { hostKeys: [ hostKey ] },
|
|
164
|
-
debug,
|
|
165
|
-
}
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
server.on('connection', mustCall((conn) => {
|
|
169
|
-
let authAttempt = 0;
|
|
170
|
-
conn.on('authentication', mustCallAtLeast((ctx) => {
|
|
171
|
-
assert(ctx.username === username,
|
|
172
|
-
`Wrong username: ${ctx.username}`);
|
|
173
|
-
switch (++authAttempt) {
|
|
174
|
-
case 1:
|
|
175
|
-
assert(ctx.method === 'none',
|
|
176
|
-
`Wrong auth method: ${ctx.method}`);
|
|
177
|
-
return ctx.reject();
|
|
178
|
-
case 2:
|
|
179
|
-
case 3:
|
|
180
|
-
if (authAttempt === 3)
|
|
181
|
-
assert(ctx.signature, 'Missing publickey signature');
|
|
182
|
-
assert(ctx.method === 'publickey',
|
|
183
|
-
`Wrong auth method: ${ctx.method}`);
|
|
184
|
-
assert(ctx.key.algo === clientKey.key.type,
|
|
185
|
-
`Wrong key algo: ${ctx.key.algo}`);
|
|
186
|
-
assert.deepStrictEqual(clientKey.key.getPublicSSH(),
|
|
187
|
-
ctx.key.data,
|
|
188
|
-
'Public key mismatch');
|
|
189
|
-
break;
|
|
190
|
-
default:
|
|
191
|
-
assert(false, 'Unexpected number of auth attempts');
|
|
192
|
-
}
|
|
193
|
-
if (ctx.signature) {
|
|
194
|
-
const result =
|
|
195
|
-
clientKey.key.verify(ctx.blob, ctx.signature, ctx.hashAlgo);
|
|
196
|
-
assert(result === true, 'Could not verify publickey signature');
|
|
197
|
-
// We should not expect any further auth attempts after we verify a
|
|
198
|
-
// signature
|
|
199
|
-
authAttempt = Infinity;
|
|
200
|
-
}
|
|
201
|
-
ctx.accept();
|
|
202
|
-
}, 2)).on('ready', mustCall(() => {
|
|
203
|
-
conn.on('session', mustCall((accept, reject) => {
|
|
204
|
-
accept().on('exec', mustCall((accept, reject) => {
|
|
205
|
-
const stream = accept();
|
|
206
|
-
stream.exit(0);
|
|
207
|
-
stream.end();
|
|
208
|
-
}));
|
|
209
|
-
}));
|
|
210
|
-
}));
|
|
211
|
-
}));
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
// Various edge cases
|
|
216
|
-
{
|
|
217
|
-
const clientKey = fixtureKey('openssh_new_rsa');
|
|
218
|
-
const username = 'KeyUser';
|
|
219
|
-
const { server } = setup(
|
|
220
|
-
'Server closes stdin too early',
|
|
221
|
-
{
|
|
222
|
-
client: {
|
|
223
|
-
username,
|
|
224
|
-
privateKeyPath: clientKey.fullPath,
|
|
225
|
-
},
|
|
226
|
-
server: { hostKeys: [ fixture('ssh_host_rsa_key') ] },
|
|
227
|
-
debug,
|
|
228
|
-
}
|
|
229
|
-
);
|
|
230
|
-
|
|
231
|
-
server.on('_child', mustCall((childProc) => {
|
|
232
|
-
childProc.stderr.once('data', mustCall((data) => {
|
|
233
|
-
childProc.stdin.end();
|
|
234
|
-
}));
|
|
235
|
-
childProc.stdin.write('ping');
|
|
236
|
-
})).on('connection', mustCall((conn) => {
|
|
237
|
-
let authAttempt = 0;
|
|
238
|
-
conn.on('authentication', mustCallAtLeast((ctx) => {
|
|
239
|
-
assert(ctx.username === username,
|
|
240
|
-
`Wrong username: ${ctx.username}`);
|
|
241
|
-
switch (++authAttempt) {
|
|
242
|
-
case 1:
|
|
243
|
-
assert(ctx.method === 'none',
|
|
244
|
-
`Wrong auth method: ${ctx.method}`);
|
|
245
|
-
return ctx.reject();
|
|
246
|
-
case 2:
|
|
247
|
-
case 3:
|
|
248
|
-
if (authAttempt === 3)
|
|
249
|
-
assert(ctx.signature, 'Missing publickey signature');
|
|
250
|
-
assert(ctx.method === 'publickey',
|
|
251
|
-
`Wrong auth method: ${ctx.method}`);
|
|
252
|
-
assert(ctx.key.algo === clientKey.key.type,
|
|
253
|
-
`Wrong key algo: ${ctx.key.algo}`);
|
|
254
|
-
assert.deepStrictEqual(clientKey.key.getPublicSSH(),
|
|
255
|
-
ctx.key.data,
|
|
256
|
-
'Public key mismatch');
|
|
257
|
-
break;
|
|
258
|
-
default:
|
|
259
|
-
assert(false, 'Unexpected number of auth attempts');
|
|
260
|
-
}
|
|
261
|
-
if (ctx.signature) {
|
|
262
|
-
const result =
|
|
263
|
-
clientKey.key.verify(ctx.blob, ctx.signature, ctx.hashAlgo);
|
|
264
|
-
assert(result === true, 'Could not verify publickey signature');
|
|
265
|
-
// We should not expect any further auth attempts after we verify a
|
|
266
|
-
// signature
|
|
267
|
-
authAttempt = Infinity;
|
|
268
|
-
}
|
|
269
|
-
ctx.accept();
|
|
270
|
-
}, 2)).on('ready', mustCall(() => {
|
|
271
|
-
conn.on('session', mustCall((accept, reject) => {
|
|
272
|
-
accept().on('exec', mustCall((accept, reject) => {
|
|
273
|
-
const stream = accept();
|
|
274
|
-
stream.stdin.on('data', mustCallAtLeast((data) => {
|
|
275
|
-
stream.stdout.write('pong on stdout');
|
|
276
|
-
stream.stderr.write('pong on stderr');
|
|
277
|
-
})).on('end', mustCall(() => {
|
|
278
|
-
stream.stdout.write('pong on stdout');
|
|
279
|
-
stream.stderr.write('pong on stderr');
|
|
280
|
-
stream.exit(0);
|
|
281
|
-
stream.close();
|
|
282
|
-
}));
|
|
283
|
-
}));
|
|
284
|
-
}));
|
|
285
|
-
}));
|
|
286
|
-
}));
|
|
287
|
-
}
|
|
288
|
-
{
|
|
289
|
-
const clientKey = fixtureKey('openssh_new_rsa');
|
|
290
|
-
const username = 'KeyUser';
|
|
291
|
-
const { server } = setup(
|
|
292
|
-
'Rekey',
|
|
293
|
-
{
|
|
294
|
-
client: {
|
|
295
|
-
username,
|
|
296
|
-
privateKeyPath: clientKey.fullPath,
|
|
297
|
-
},
|
|
298
|
-
server: { hostKeys: [ fixture('ssh_host_rsa_key') ] },
|
|
299
|
-
debug,
|
|
300
|
-
}
|
|
301
|
-
);
|
|
302
|
-
|
|
303
|
-
server.on('connection', mustCall((conn) => {
|
|
304
|
-
let authAttempt = 0;
|
|
305
|
-
conn.on('authentication', mustCallAtLeast((ctx) => {
|
|
306
|
-
assert(ctx.username === username,
|
|
307
|
-
`Wrong username: ${ctx.username}`);
|
|
308
|
-
switch (++authAttempt) {
|
|
309
|
-
case 1:
|
|
310
|
-
assert(ctx.method === 'none',
|
|
311
|
-
`Wrong auth method: ${ctx.method}`);
|
|
312
|
-
return ctx.reject();
|
|
313
|
-
case 2:
|
|
314
|
-
case 3:
|
|
315
|
-
if (authAttempt === 3)
|
|
316
|
-
assert(ctx.signature, 'Missing publickey signature');
|
|
317
|
-
assert(ctx.method === 'publickey',
|
|
318
|
-
`Wrong auth method: ${ctx.method}`);
|
|
319
|
-
assert(ctx.key.algo === clientKey.key.type,
|
|
320
|
-
`Wrong key algo: ${ctx.key.algo}`);
|
|
321
|
-
assert.deepStrictEqual(clientKey.key.getPublicSSH(),
|
|
322
|
-
ctx.key.data,
|
|
323
|
-
'Public key mismatch');
|
|
324
|
-
break;
|
|
325
|
-
default:
|
|
326
|
-
assert(false, 'Unexpected number of auth attempts');
|
|
327
|
-
}
|
|
328
|
-
if (ctx.signature) {
|
|
329
|
-
const result =
|
|
330
|
-
clientKey.key.verify(ctx.blob, ctx.signature, ctx.hashAlgo);
|
|
331
|
-
assert(result === true, 'Could not verify publickey signature');
|
|
332
|
-
// We should not expect any further auth attempts after we verify a
|
|
333
|
-
// signature
|
|
334
|
-
authAttempt = Infinity;
|
|
335
|
-
}
|
|
336
|
-
ctx.accept();
|
|
337
|
-
}, 2)).on('ready', mustCall(() => {
|
|
338
|
-
conn.on('session', mustCall((accept, reject) => {
|
|
339
|
-
const session = accept();
|
|
340
|
-
conn.rekey();
|
|
341
|
-
session.on('exec', mustCall((accept, reject) => {
|
|
342
|
-
const stream = accept();
|
|
343
|
-
stream.exit(0);
|
|
344
|
-
stream.end();
|
|
345
|
-
}));
|
|
346
|
-
}));
|
|
347
|
-
}));
|
|
348
|
-
}));
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
function setup(title, configs) {
|
|
353
|
-
const {
|
|
354
|
-
client: clientCfg,
|
|
355
|
-
server: serverCfg,
|
|
356
|
-
allReady: allReady_,
|
|
357
|
-
timeout: timeout_,
|
|
358
|
-
debug,
|
|
359
|
-
noForceServerReady,
|
|
360
|
-
} = configs;
|
|
361
|
-
let clientClose = false;
|
|
362
|
-
let serverClose = false;
|
|
363
|
-
let serverReady = false;
|
|
364
|
-
let client;
|
|
365
|
-
const msg = (text) => {
|
|
366
|
-
return `${title}: ${text}`;
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
const timeout = (typeof timeout_ === 'number'
|
|
370
|
-
? timeout_
|
|
371
|
-
: CLIENT_TIMEOUT);
|
|
372
|
-
|
|
373
|
-
const allReady = (typeof allReady_ === 'function' ? allReady_ : undefined);
|
|
374
|
-
|
|
375
|
-
if (debug) {
|
|
376
|
-
serverCfg.debug = (...args) => {
|
|
377
|
-
console.log(`[${title}][SERVER]`, ...args);
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
const serverReadyFn = (noForceServerReady ? onReady : mustCall(onReady));
|
|
382
|
-
const server = new Server(serverCfg);
|
|
383
|
-
|
|
384
|
-
server.on('error', onError)
|
|
385
|
-
.on('connection', mustCall((conn) => {
|
|
386
|
-
conn.on('error', onError)
|
|
387
|
-
.on('ready', serverReadyFn);
|
|
388
|
-
server.close();
|
|
389
|
-
}))
|
|
390
|
-
.on('close', mustCall(onClose));
|
|
391
|
-
|
|
392
|
-
function onError(err) {
|
|
393
|
-
const which = (arguments.length >= 3 ? 'client' : 'server');
|
|
394
|
-
assert(false, msg(`Unexpected ${which} error: ${err}`));
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
function onReady() {
|
|
398
|
-
assert(!serverReady, msg('Received multiple ready events for server'));
|
|
399
|
-
serverReady = true;
|
|
400
|
-
allReady && allReady();
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
function onClose() {
|
|
404
|
-
if (arguments.length >= 3) {
|
|
405
|
-
assert(!clientClose, msg('Received multiple close events for client'));
|
|
406
|
-
clientClose = true;
|
|
407
|
-
} else {
|
|
408
|
-
assert(!serverClose, msg('Received multiple close events for server'));
|
|
409
|
-
serverClose = true;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
process.nextTick(mustCall(() => {
|
|
414
|
-
server.listen(0, 'localhost', mustCall(() => {
|
|
415
|
-
const args = [
|
|
416
|
-
'-o', 'UserKnownHostsFile=/dev/null',
|
|
417
|
-
'-o', 'StrictHostKeyChecking=no',
|
|
418
|
-
'-o', 'CheckHostIP=no',
|
|
419
|
-
'-o', 'ConnectTimeout=3',
|
|
420
|
-
'-o', 'GlobalKnownHostsFile=/dev/null',
|
|
421
|
-
'-o', 'GSSAPIAuthentication=no',
|
|
422
|
-
'-o', 'IdentitiesOnly=yes',
|
|
423
|
-
'-o', 'BatchMode=yes',
|
|
424
|
-
'-o', 'VerifyHostKeyDNS=no',
|
|
425
|
-
|
|
426
|
-
'-vvvvvv',
|
|
427
|
-
'-T',
|
|
428
|
-
'-o', 'KbdInteractiveAuthentication=no',
|
|
429
|
-
'-o', 'HostbasedAuthentication=no',
|
|
430
|
-
'-o', 'PasswordAuthentication=no',
|
|
431
|
-
'-o', 'PubkeyAuthentication=yes',
|
|
432
|
-
'-o', 'PreferredAuthentications=publickey'
|
|
433
|
-
];
|
|
434
|
-
|
|
435
|
-
if (clientCfg.privateKeyPath)
|
|
436
|
-
args.push('-o', `IdentityFile=${clientCfg.privateKeyPath}`);
|
|
437
|
-
|
|
438
|
-
if (!/^[0-6]\./.test(opensshVer)) {
|
|
439
|
-
// OpenSSH 7.0+ disables DSS/DSA host (and user) key support by
|
|
440
|
-
// default, so we explicitly enable it here
|
|
441
|
-
args.push('-o', 'HostKeyAlgorithms=+ssh-dss');
|
|
442
|
-
args.push('-o', 'PubkeyAcceptedKeyTypes=+ssh-dss');
|
|
443
|
-
args.push('-o', 'PubkeyAcceptedAlgorithms=+ssh-dss');
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
args.push('-p', server.address().port.toString(),
|
|
447
|
-
'-l', clientCfg.username,
|
|
448
|
-
'localhost',
|
|
449
|
-
'uptime');
|
|
450
|
-
|
|
451
|
-
client = spawn(opensshPath, args, SPAWN_OPTS);
|
|
452
|
-
server.emit('_child', client);
|
|
453
|
-
|
|
454
|
-
if (debug) {
|
|
455
|
-
readline.createInterface({
|
|
456
|
-
input: client.stdout
|
|
457
|
-
}).on('line', (line) => {
|
|
458
|
-
console.log(`[${title}][CLIENT][STDOUT]`, line);
|
|
459
|
-
});
|
|
460
|
-
readline.createInterface({
|
|
461
|
-
input: client.stderr
|
|
462
|
-
}).on('line', (line) => {
|
|
463
|
-
console.error(`[${title}][CLIENT][STDERR]`, line);
|
|
464
|
-
});
|
|
465
|
-
} else {
|
|
466
|
-
client.stdout.resume();
|
|
467
|
-
client.stderr.resume();
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
client.on('error', (err) => {
|
|
471
|
-
onError(err, null, null);
|
|
472
|
-
}).on('exit', (code) => {
|
|
473
|
-
clearTimeout(client.timer);
|
|
474
|
-
if (code !== 0)
|
|
475
|
-
return onError(new Error(`Non-zero exit code ${code}`), null, null);
|
|
476
|
-
onClose(null, null, null);
|
|
477
|
-
});
|
|
478
|
-
|
|
479
|
-
client.timer = setTimeout(() => {
|
|
480
|
-
assert(false, msg('Client timeout'));
|
|
481
|
-
}, timeout);
|
|
482
|
-
}));
|
|
483
|
-
}));
|
|
484
|
-
|
|
485
|
-
return { server };
|
|
486
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const assert = require('assert');
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
utils: {
|
|
7
|
-
generateKeyPair,
|
|
8
|
-
generateKeyPairSync,
|
|
9
|
-
parseKey,
|
|
10
|
-
},
|
|
11
|
-
} = require('..');
|
|
12
|
-
|
|
13
|
-
const { mustCall } = require('./common.js');
|
|
14
|
-
|
|
15
|
-
const nodeMajor = +/(?<=^v)\d+/.exec(process.version)[0];
|
|
16
|
-
|
|
17
|
-
function tryParse(...args) {
|
|
18
|
-
const ret = parseKey(...args);
|
|
19
|
-
if (ret instanceof Error)
|
|
20
|
-
throw ret;
|
|
21
|
-
return ret;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const inputs = [
|
|
25
|
-
{ args: ['rsa', { bits: 2048 }], sshType: 'ssh-rsa' },
|
|
26
|
-
{ args: ['ecdsa', { bits: 256 }], sshType: 'ecdsa-sha2-nistp256' },
|
|
27
|
-
{ args: ['ecdsa', { bits: 521 }], sshType: 'ecdsa-sha2-nistp521' },
|
|
28
|
-
{ args: ['ed25519'], sshType: 'ssh-ed25519' },
|
|
29
|
-
{ args: ['rsa', { bits: 2048, passphrase: 'foo', cipher: 'aes256-cbc' }],
|
|
30
|
-
sshType: 'ssh-rsa' },
|
|
31
|
-
{ args: ['rsa', { bits: 2048, comment: 'foobarbaz' }], sshType: 'ssh-rsa' },
|
|
32
|
-
];
|
|
33
|
-
(function next() {
|
|
34
|
-
if (inputs.length === 0)
|
|
35
|
-
return;
|
|
36
|
-
const { args, sshType } = inputs.shift();
|
|
37
|
-
if (args[0] === 'ed25519' && nodeMajor < 12) {
|
|
38
|
-
console.log('Skipping ed25519 on node < 12');
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const passphrase = (args[1] && args[1].passphrase);
|
|
42
|
-
const comment = ((args[1] && args[1].comment) || '');
|
|
43
|
-
const check = (keys) => {
|
|
44
|
-
let parsed = tryParse(keys.private, passphrase);
|
|
45
|
-
assert.strictEqual(parsed.type, sshType);
|
|
46
|
-
assert.strictEqual(parsed.comment, comment);
|
|
47
|
-
|
|
48
|
-
parsed = tryParse(keys.public);
|
|
49
|
-
assert.strictEqual(parsed.type, sshType);
|
|
50
|
-
assert.strictEqual(parsed.comment, comment);
|
|
51
|
-
};
|
|
52
|
-
console.log(`Testing generateKeyPairSync(${JSON.stringify(args)}) ...`);
|
|
53
|
-
check(generateKeyPairSync(...args));
|
|
54
|
-
console.log(`Testing generateKeyPair(${JSON.stringify(args)}) ...`);
|
|
55
|
-
generateKeyPair(...args, mustCall((err, keys) => {
|
|
56
|
-
assert.ifError(err);
|
|
57
|
-
check(keys);
|
|
58
|
-
next();
|
|
59
|
-
}));
|
|
60
|
-
})();
|