@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,631 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const assert = require('assert');
|
|
4
|
-
const { randomBytes } = require('crypto');
|
|
5
|
-
|
|
6
|
-
const {
|
|
7
|
-
CIPHER_INFO,
|
|
8
|
-
MAC_INFO,
|
|
9
|
-
bindingAvailable,
|
|
10
|
-
NullCipher,
|
|
11
|
-
createCipher,
|
|
12
|
-
NullDecipher,
|
|
13
|
-
createDecipher,
|
|
14
|
-
init: cryptoInit,
|
|
15
|
-
} = require('../lib/protocol/crypto.js');
|
|
16
|
-
|
|
17
|
-
(async () => {
|
|
18
|
-
await cryptoInit;
|
|
19
|
-
|
|
20
|
-
console.log(`Crypto binding ${bindingAvailable ? '' : 'not '}available`);
|
|
21
|
-
{
|
|
22
|
-
const PAIRS = [
|
|
23
|
-
// cipher, decipher
|
|
24
|
-
['native', 'native'],
|
|
25
|
-
['binding', 'native'],
|
|
26
|
-
['native', 'binding'],
|
|
27
|
-
['binding', 'binding'],
|
|
28
|
-
].slice(0, bindingAvailable ? 4 : 1);
|
|
29
|
-
|
|
30
|
-
[
|
|
31
|
-
{ cipher: null },
|
|
32
|
-
{ cipher: 'chacha20-poly1305@openssh.com' },
|
|
33
|
-
{ cipher: 'aes128-gcm@openssh.com' },
|
|
34
|
-
{ cipher: 'aes128-cbc', mac: 'hmac-sha1-etm@openssh.com' },
|
|
35
|
-
{ cipher: 'aes128-ctr', mac: 'hmac-sha1' },
|
|
36
|
-
{ cipher: 'arcfour', mac: 'hmac-sha2-256-96' },
|
|
37
|
-
].forEach((testConfig) => {
|
|
38
|
-
for (const pair of PAIRS) {
|
|
39
|
-
function onCipherData(data) {
|
|
40
|
-
ciphered = Buffer.concat([ciphered, data]);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function onDecipherPayload(payload) {
|
|
44
|
-
deciphered.push(payload);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function reset() {
|
|
48
|
-
ciphered = Buffer.alloc(0);
|
|
49
|
-
deciphered = [];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function reinit() {
|
|
53
|
-
if (testConfig.cipher === null) {
|
|
54
|
-
cipher = new NullCipher(1, onCipherData);
|
|
55
|
-
decipher = new NullDecipher(1, onDecipherPayload);
|
|
56
|
-
} else {
|
|
57
|
-
cipher = createCipher(config);
|
|
58
|
-
decipher = createDecipher(config);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
let ciphered;
|
|
63
|
-
let deciphered;
|
|
64
|
-
let cipher;
|
|
65
|
-
let decipher;
|
|
66
|
-
let macSize;
|
|
67
|
-
let packet;
|
|
68
|
-
let payload;
|
|
69
|
-
let cipherInfo;
|
|
70
|
-
let config;
|
|
71
|
-
|
|
72
|
-
console.log('Testing cipher: %s, mac: %s (%s encrypt, %s decrypt) ...',
|
|
73
|
-
testConfig.cipher,
|
|
74
|
-
testConfig.mac
|
|
75
|
-
|| (testConfig.cipher === null ? '<none>' : '<implicit>'),
|
|
76
|
-
pair[0],
|
|
77
|
-
pair[1]);
|
|
78
|
-
|
|
79
|
-
if (testConfig.cipher === null) {
|
|
80
|
-
cipher = new NullCipher(1, onCipherData);
|
|
81
|
-
decipher = new NullDecipher(1, onDecipherPayload);
|
|
82
|
-
macSize = 0;
|
|
83
|
-
} else {
|
|
84
|
-
cipherInfo = CIPHER_INFO[testConfig.cipher];
|
|
85
|
-
let macInfo;
|
|
86
|
-
let macKey;
|
|
87
|
-
if (testConfig.mac) {
|
|
88
|
-
macInfo = MAC_INFO[testConfig.mac];
|
|
89
|
-
macKey = randomBytes(macInfo.len);
|
|
90
|
-
macSize = macInfo.actualLen;
|
|
91
|
-
} else if (cipherInfo.authLen) {
|
|
92
|
-
macSize = cipherInfo.authLen;
|
|
93
|
-
} else {
|
|
94
|
-
throw new Error('Missing MAC for cipher');
|
|
95
|
-
}
|
|
96
|
-
const key = randomBytes(cipherInfo.keyLen);
|
|
97
|
-
const iv = (cipherInfo.ivLen
|
|
98
|
-
? randomBytes(cipherInfo.ivLen)
|
|
99
|
-
: Buffer.alloc(0));
|
|
100
|
-
config = {
|
|
101
|
-
outbound: {
|
|
102
|
-
onWrite: onCipherData,
|
|
103
|
-
cipherInfo,
|
|
104
|
-
cipherKey: Buffer.from(key),
|
|
105
|
-
cipherIV: Buffer.from(iv),
|
|
106
|
-
seqno: 1,
|
|
107
|
-
macInfo,
|
|
108
|
-
macKey: (macKey && Buffer.from(macKey)),
|
|
109
|
-
forceNative: (pair[0] === 'native'),
|
|
110
|
-
},
|
|
111
|
-
inbound: {
|
|
112
|
-
onPayload: onDecipherPayload,
|
|
113
|
-
decipherInfo: cipherInfo,
|
|
114
|
-
decipherKey: Buffer.from(key),
|
|
115
|
-
decipherIV: Buffer.from(iv),
|
|
116
|
-
seqno: 1,
|
|
117
|
-
macInfo,
|
|
118
|
-
macKey: (macKey && Buffer.from(macKey)),
|
|
119
|
-
forceNative: (pair[1] === 'native'),
|
|
120
|
-
},
|
|
121
|
-
};
|
|
122
|
-
try {
|
|
123
|
-
cipher = createCipher(config);
|
|
124
|
-
} catch (ex) {
|
|
125
|
-
if (ex.code === 'ERR_OSSL_EVP_UNSUPPORTED'
|
|
126
|
-
|| /unsupported/i.test(ex.message)) {
|
|
127
|
-
console.log(
|
|
128
|
-
' ... skipping because cipher is unsupported by OpenSSL'
|
|
129
|
-
);
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
throw ex;
|
|
133
|
-
}
|
|
134
|
-
try {
|
|
135
|
-
decipher = createDecipher(config);
|
|
136
|
-
} catch (ex) {
|
|
137
|
-
if (ex.code === 'ERR_OSSL_EVP_UNSUPPORTED'
|
|
138
|
-
|| /unsupported/i.test(ex.message)) {
|
|
139
|
-
console.log(
|
|
140
|
-
' ... skipping because cipher is unsupported by OpenSSL'
|
|
141
|
-
);
|
|
142
|
-
continue;
|
|
143
|
-
}
|
|
144
|
-
throw ex;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (pair[0] === 'binding')
|
|
148
|
-
assert(/binding/i.test(cipher.constructor.name));
|
|
149
|
-
else
|
|
150
|
-
assert(/native/i.test(cipher.constructor.name));
|
|
151
|
-
if (pair[1] === 'binding')
|
|
152
|
-
assert(/binding/i.test(decipher.constructor.name));
|
|
153
|
-
else
|
|
154
|
-
assert(/native/i.test(decipher.constructor.name));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
let expectedSeqno;
|
|
158
|
-
// Test zero-length payload ============================================
|
|
159
|
-
payload = Buffer.alloc(0);
|
|
160
|
-
expectedSeqno = 2;
|
|
161
|
-
|
|
162
|
-
reset();
|
|
163
|
-
packet = cipher.allocPacket(payload.length);
|
|
164
|
-
payload.copy(packet, 5);
|
|
165
|
-
cipher.encrypt(packet);
|
|
166
|
-
assert.strictEqual(decipher.decrypt(ciphered, 0, ciphered.length),
|
|
167
|
-
undefined);
|
|
168
|
-
|
|
169
|
-
assert.strictEqual(cipher.outSeqno, expectedSeqno);
|
|
170
|
-
assert(ciphered.length >= 9 + macSize);
|
|
171
|
-
assert.strictEqual(decipher.inSeqno, cipher.outSeqno);
|
|
172
|
-
assert.strictEqual(deciphered.length, 1);
|
|
173
|
-
assert.deepStrictEqual(deciphered[0], payload);
|
|
174
|
-
|
|
175
|
-
// Test single byte payload ============================================
|
|
176
|
-
payload = Buffer.from([ 0xEF ]);
|
|
177
|
-
expectedSeqno = 3;
|
|
178
|
-
|
|
179
|
-
reset();
|
|
180
|
-
packet = cipher.allocPacket(payload.length);
|
|
181
|
-
payload.copy(packet, 5);
|
|
182
|
-
cipher.encrypt(packet);
|
|
183
|
-
assert.strictEqual(decipher.decrypt(ciphered, 0, ciphered.length),
|
|
184
|
-
undefined);
|
|
185
|
-
|
|
186
|
-
assert.strictEqual(cipher.outSeqno, 3);
|
|
187
|
-
assert(ciphered.length >= 9 + macSize);
|
|
188
|
-
assert.strictEqual(decipher.inSeqno, cipher.outSeqno);
|
|
189
|
-
assert.strictEqual(deciphered.length, 1);
|
|
190
|
-
assert.deepStrictEqual(deciphered[0], payload);
|
|
191
|
-
|
|
192
|
-
// Test large payload ==================================================
|
|
193
|
-
payload = randomBytes(32 * 1024);
|
|
194
|
-
expectedSeqno = 4;
|
|
195
|
-
|
|
196
|
-
reset();
|
|
197
|
-
packet = cipher.allocPacket(payload.length);
|
|
198
|
-
payload.copy(packet, 5);
|
|
199
|
-
cipher.encrypt(packet);
|
|
200
|
-
assert.strictEqual(decipher.decrypt(ciphered, 0, ciphered.length),
|
|
201
|
-
undefined);
|
|
202
|
-
|
|
203
|
-
assert.strictEqual(cipher.outSeqno, expectedSeqno);
|
|
204
|
-
assert(ciphered.length >= 9 + macSize);
|
|
205
|
-
assert.strictEqual(decipher.inSeqno, cipher.outSeqno);
|
|
206
|
-
assert.strictEqual(deciphered.length, 1);
|
|
207
|
-
assert.deepStrictEqual(deciphered[0], payload);
|
|
208
|
-
|
|
209
|
-
// Test sequnce number rollover ========================================
|
|
210
|
-
payload = randomBytes(4);
|
|
211
|
-
expectedSeqno = 0;
|
|
212
|
-
cipher.outSeqno = decipher.inSeqno = (2 ** 32) - 1;
|
|
213
|
-
|
|
214
|
-
reset();
|
|
215
|
-
packet = cipher.allocPacket(payload.length);
|
|
216
|
-
payload.copy(packet, 5);
|
|
217
|
-
cipher.encrypt(packet);
|
|
218
|
-
assert.strictEqual(decipher.decrypt(ciphered, 0, ciphered.length),
|
|
219
|
-
undefined);
|
|
220
|
-
|
|
221
|
-
assert.strictEqual(cipher.outSeqno, expectedSeqno);
|
|
222
|
-
assert(ciphered.length >= 9 + macSize);
|
|
223
|
-
assert.strictEqual(decipher.inSeqno, cipher.outSeqno);
|
|
224
|
-
assert.strictEqual(deciphered.length, 1);
|
|
225
|
-
assert.deepStrictEqual(deciphered[0], payload);
|
|
226
|
-
|
|
227
|
-
// Test chunked input -- split length bytes ============================
|
|
228
|
-
payload = randomBytes(32 * 768);
|
|
229
|
-
expectedSeqno = 1;
|
|
230
|
-
|
|
231
|
-
reset();
|
|
232
|
-
packet = cipher.allocPacket(payload.length);
|
|
233
|
-
payload.copy(packet, 5);
|
|
234
|
-
cipher.encrypt(packet);
|
|
235
|
-
assert.strictEqual(decipher.decrypt(ciphered, 0, 2), undefined);
|
|
236
|
-
assert.strictEqual(decipher.decrypt(ciphered, 2, ciphered.length),
|
|
237
|
-
undefined);
|
|
238
|
-
|
|
239
|
-
assert.strictEqual(cipher.outSeqno, expectedSeqno);
|
|
240
|
-
assert(ciphered.length >= 9 + macSize);
|
|
241
|
-
assert.strictEqual(decipher.inSeqno, cipher.outSeqno);
|
|
242
|
-
assert.strictEqual(deciphered.length, 1);
|
|
243
|
-
assert.deepStrictEqual(deciphered[0], payload);
|
|
244
|
-
|
|
245
|
-
// Test chunked input -- split length from payload =====================
|
|
246
|
-
payload = randomBytes(32 * 768);
|
|
247
|
-
expectedSeqno = 2;
|
|
248
|
-
|
|
249
|
-
reset();
|
|
250
|
-
packet = cipher.allocPacket(payload.length);
|
|
251
|
-
payload.copy(packet, 5);
|
|
252
|
-
cipher.encrypt(packet);
|
|
253
|
-
assert.strictEqual(decipher.decrypt(ciphered, 0, 4), undefined);
|
|
254
|
-
assert.strictEqual(decipher.decrypt(ciphered, 4, ciphered.length),
|
|
255
|
-
undefined);
|
|
256
|
-
|
|
257
|
-
assert.strictEqual(cipher.outSeqno, expectedSeqno);
|
|
258
|
-
assert(ciphered.length >= 9 + macSize);
|
|
259
|
-
assert.strictEqual(decipher.inSeqno, cipher.outSeqno);
|
|
260
|
-
assert.strictEqual(deciphered.length, 1);
|
|
261
|
-
assert.deepStrictEqual(deciphered[0], payload);
|
|
262
|
-
|
|
263
|
-
// Test chunked input -- split length and payload from MAC =============
|
|
264
|
-
payload = randomBytes(32 * 768);
|
|
265
|
-
expectedSeqno = 3;
|
|
266
|
-
|
|
267
|
-
reset();
|
|
268
|
-
packet = cipher.allocPacket(payload.length);
|
|
269
|
-
payload.copy(packet, 5);
|
|
270
|
-
cipher.encrypt(packet);
|
|
271
|
-
assert.strictEqual(
|
|
272
|
-
decipher.decrypt(ciphered, 0, ciphered.length - macSize),
|
|
273
|
-
undefined
|
|
274
|
-
);
|
|
275
|
-
assert.strictEqual(
|
|
276
|
-
decipher.decrypt(ciphered,
|
|
277
|
-
ciphered.length - macSize,
|
|
278
|
-
ciphered.length),
|
|
279
|
-
undefined
|
|
280
|
-
);
|
|
281
|
-
|
|
282
|
-
assert.strictEqual(cipher.outSeqno, expectedSeqno);
|
|
283
|
-
assert(ciphered.length >= 9 + macSize);
|
|
284
|
-
assert.strictEqual(decipher.inSeqno, cipher.outSeqno);
|
|
285
|
-
assert.strictEqual(deciphered.length, 1);
|
|
286
|
-
assert.deepStrictEqual(deciphered[0], payload);
|
|
287
|
-
|
|
288
|
-
// Test packet length checks ===========================================
|
|
289
|
-
[0, 2 ** 32 - 1].forEach((n) => {
|
|
290
|
-
reset();
|
|
291
|
-
packet = cipher.allocPacket(0);
|
|
292
|
-
packet.writeUInt32BE(n, 0); // Overwrite packet length field
|
|
293
|
-
cipher.encrypt(packet);
|
|
294
|
-
let threw = false;
|
|
295
|
-
try {
|
|
296
|
-
decipher.decrypt(ciphered, 0, ciphered.length);
|
|
297
|
-
} catch (ex) {
|
|
298
|
-
threw = true;
|
|
299
|
-
assert(ex instanceof Error);
|
|
300
|
-
assert(/packet length/i.test(ex.message));
|
|
301
|
-
}
|
|
302
|
-
if (!threw)
|
|
303
|
-
throw new Error('Expected error');
|
|
304
|
-
|
|
305
|
-
// Recreate deciphers since errors leave them in an unusable state.
|
|
306
|
-
// We recreate the ciphers as well so that internal states of both
|
|
307
|
-
// ends match again.
|
|
308
|
-
reinit();
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
// Test minimum padding length check ===================================
|
|
312
|
-
if (testConfig.cipher !== null) {
|
|
313
|
-
let payloadLen;
|
|
314
|
-
const blockLen = cipherInfo.blockLen;
|
|
315
|
-
if (/chacha|gcm/i.test(testConfig.cipher)
|
|
316
|
-
|| /etm/i.test(testConfig.mac)) {
|
|
317
|
-
payloadLen = blockLen - 2;
|
|
318
|
-
} else {
|
|
319
|
-
payloadLen = blockLen - 6;
|
|
320
|
-
}
|
|
321
|
-
const minLen = 4 + 1 + payloadLen + (blockLen + 1);
|
|
322
|
-
// We don't do strict equality checks here since the length of the
|
|
323
|
-
// returned Buffer can vary due to implementation details.
|
|
324
|
-
assert(cipher.allocPacket(payloadLen).length >= minLen);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// =====================================================================
|
|
328
|
-
cipher.free();
|
|
329
|
-
decipher.free();
|
|
330
|
-
if (testConfig.cipher === null)
|
|
331
|
-
break;
|
|
332
|
-
}
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
// Test createCipher()/createDecipher() exceptions
|
|
337
|
-
{
|
|
338
|
-
[
|
|
339
|
-
[
|
|
340
|
-
[true, null],
|
|
341
|
-
/invalid config/i
|
|
342
|
-
],
|
|
343
|
-
[
|
|
344
|
-
[{}],
|
|
345
|
-
[/invalid outbound/i, /invalid inbound/i]
|
|
346
|
-
],
|
|
347
|
-
[
|
|
348
|
-
[{ outbound: {}, inbound: {} }],
|
|
349
|
-
[/invalid outbound\.onWrite/i, /invalid inbound\.onPayload/i]
|
|
350
|
-
],
|
|
351
|
-
[
|
|
352
|
-
[
|
|
353
|
-
{ outbound: {
|
|
354
|
-
onWrite: () => {},
|
|
355
|
-
cipherInfo: true
|
|
356
|
-
},
|
|
357
|
-
inbound: {
|
|
358
|
-
onPayload: () => {},
|
|
359
|
-
decipherInfo: true
|
|
360
|
-
},
|
|
361
|
-
},
|
|
362
|
-
{ outbound: {
|
|
363
|
-
onWrite: () => {},
|
|
364
|
-
cipherInfo: null
|
|
365
|
-
},
|
|
366
|
-
inbound: {
|
|
367
|
-
onPayload: () => {},
|
|
368
|
-
decipherInfo: null
|
|
369
|
-
},
|
|
370
|
-
},
|
|
371
|
-
],
|
|
372
|
-
[/invalid outbound\.cipherInfo/i, /invalid inbound\.decipherInfo/i]
|
|
373
|
-
],
|
|
374
|
-
[
|
|
375
|
-
[
|
|
376
|
-
{ outbound: {
|
|
377
|
-
onWrite: () => {},
|
|
378
|
-
cipherInfo: {},
|
|
379
|
-
cipherKey: {},
|
|
380
|
-
},
|
|
381
|
-
inbound: {
|
|
382
|
-
onPayload: () => {},
|
|
383
|
-
decipherInfo: {},
|
|
384
|
-
decipherKey: {},
|
|
385
|
-
},
|
|
386
|
-
},
|
|
387
|
-
{ outbound: {
|
|
388
|
-
onWrite: () => {},
|
|
389
|
-
cipherInfo: { keyLen: 32 },
|
|
390
|
-
cipherKey: Buffer.alloc(8),
|
|
391
|
-
},
|
|
392
|
-
inbound: {
|
|
393
|
-
onPayload: () => {},
|
|
394
|
-
decipherInfo: { keyLen: 32 },
|
|
395
|
-
decipherKey: Buffer.alloc(8),
|
|
396
|
-
},
|
|
397
|
-
},
|
|
398
|
-
],
|
|
399
|
-
[/invalid outbound\.cipherKey/i, /invalid inbound\.decipherKey/i]
|
|
400
|
-
],
|
|
401
|
-
[
|
|
402
|
-
[
|
|
403
|
-
{ outbound: {
|
|
404
|
-
onWrite: () => {},
|
|
405
|
-
cipherInfo: { keyLen: 1, ivLen: 12 },
|
|
406
|
-
cipherKey: Buffer.alloc(1),
|
|
407
|
-
cipherIV: true
|
|
408
|
-
},
|
|
409
|
-
inbound: {
|
|
410
|
-
onPayload: () => {},
|
|
411
|
-
decipherInfo: { keyLen: 1, ivLen: 12 },
|
|
412
|
-
decipherKey: Buffer.alloc(1),
|
|
413
|
-
cipherIV: true
|
|
414
|
-
},
|
|
415
|
-
},
|
|
416
|
-
{ outbound: {
|
|
417
|
-
onWrite: () => {},
|
|
418
|
-
cipherInfo: { keyLen: 1, ivLen: 12 },
|
|
419
|
-
cipherKey: Buffer.alloc(1),
|
|
420
|
-
cipherIV: null
|
|
421
|
-
},
|
|
422
|
-
inbound: {
|
|
423
|
-
onPayload: () => {},
|
|
424
|
-
decipherInfo: { keyLen: 1, ivLen: 12 },
|
|
425
|
-
decipherKey: Buffer.alloc(1),
|
|
426
|
-
cipherIV: null
|
|
427
|
-
},
|
|
428
|
-
},
|
|
429
|
-
{ outbound: {
|
|
430
|
-
onWrite: () => {},
|
|
431
|
-
cipherInfo: { keyLen: 1, ivLen: 12 },
|
|
432
|
-
cipherKey: Buffer.alloc(1),
|
|
433
|
-
cipherIV: {}
|
|
434
|
-
},
|
|
435
|
-
inbound: {
|
|
436
|
-
onPayload: () => {},
|
|
437
|
-
decipherInfo: { keyLen: 1, ivLen: 12 },
|
|
438
|
-
decipherKey: Buffer.alloc(1),
|
|
439
|
-
cipherIV: {}
|
|
440
|
-
},
|
|
441
|
-
},
|
|
442
|
-
{ outbound: {
|
|
443
|
-
onWrite: () => {},
|
|
444
|
-
cipherInfo: { keyLen: 1, ivLen: 12 },
|
|
445
|
-
cipherKey: Buffer.alloc(1),
|
|
446
|
-
cipherIV: Buffer.alloc(1)
|
|
447
|
-
},
|
|
448
|
-
inbound: {
|
|
449
|
-
onPayload: () => {},
|
|
450
|
-
decipherInfo: { keyLen: 1, ivLen: 12 },
|
|
451
|
-
decipherKey: Buffer.alloc(1),
|
|
452
|
-
cipherIV: Buffer.alloc(1)
|
|
453
|
-
},
|
|
454
|
-
},
|
|
455
|
-
],
|
|
456
|
-
[/invalid outbound\.cipherIV/i, /invalid inbound\.decipherIV/i]
|
|
457
|
-
],
|
|
458
|
-
[
|
|
459
|
-
[
|
|
460
|
-
{ outbound: {
|
|
461
|
-
onWrite: () => {},
|
|
462
|
-
cipherInfo: { keyLen: 1, ivLen: 0 },
|
|
463
|
-
cipherKey: Buffer.alloc(1),
|
|
464
|
-
seqno: true
|
|
465
|
-
},
|
|
466
|
-
inbound: {
|
|
467
|
-
onPayload: () => {},
|
|
468
|
-
decipherInfo: { keyLen: 1, ivLen: 0 },
|
|
469
|
-
decipherKey: Buffer.alloc(1),
|
|
470
|
-
seqno: true
|
|
471
|
-
},
|
|
472
|
-
},
|
|
473
|
-
{ outbound: {
|
|
474
|
-
onWrite: () => {},
|
|
475
|
-
cipherInfo: { keyLen: 1, ivLen: 0 },
|
|
476
|
-
cipherKey: Buffer.alloc(1),
|
|
477
|
-
seqno: -1
|
|
478
|
-
},
|
|
479
|
-
inbound: {
|
|
480
|
-
onPayload: () => {},
|
|
481
|
-
decipherInfo: { keyLen: 1, ivLen: 0 },
|
|
482
|
-
decipherKey: Buffer.alloc(1),
|
|
483
|
-
seqno: -1
|
|
484
|
-
},
|
|
485
|
-
},
|
|
486
|
-
{ outbound: {
|
|
487
|
-
onWrite: () => {},
|
|
488
|
-
cipherInfo: { keyLen: 1, ivLen: 0 },
|
|
489
|
-
cipherKey: Buffer.alloc(1),
|
|
490
|
-
seqno: 2 ** 32
|
|
491
|
-
},
|
|
492
|
-
inbound: {
|
|
493
|
-
onPayload: () => {},
|
|
494
|
-
decipherInfo: { keyLen: 1, ivLen: 0 },
|
|
495
|
-
decipherKey: Buffer.alloc(1),
|
|
496
|
-
seqno: 2 ** 32
|
|
497
|
-
},
|
|
498
|
-
},
|
|
499
|
-
],
|
|
500
|
-
[/invalid outbound\.seqno/i, /invalid inbound\.seqno/i]
|
|
501
|
-
],
|
|
502
|
-
[
|
|
503
|
-
[
|
|
504
|
-
{ outbound: {
|
|
505
|
-
onWrite: () => {},
|
|
506
|
-
cipherInfo: { keyLen: 1, ivLen: 0, sslName: 'foo' },
|
|
507
|
-
cipherKey: Buffer.alloc(1),
|
|
508
|
-
seqno: 0
|
|
509
|
-
},
|
|
510
|
-
inbound: {
|
|
511
|
-
onPayload: () => {},
|
|
512
|
-
decipherInfo: { keyLen: 1, ivLen: 0, sslName: 'foo' },
|
|
513
|
-
decipherKey: Buffer.alloc(1),
|
|
514
|
-
seqno: 0
|
|
515
|
-
},
|
|
516
|
-
},
|
|
517
|
-
{ outbound: {
|
|
518
|
-
onWrite: () => {},
|
|
519
|
-
cipherInfo: { keyLen: 1, ivLen: 0, sslName: 'foo' },
|
|
520
|
-
cipherKey: Buffer.alloc(1),
|
|
521
|
-
seqno: 0,
|
|
522
|
-
macInfo: true
|
|
523
|
-
},
|
|
524
|
-
inbound: {
|
|
525
|
-
onPayload: () => {},
|
|
526
|
-
decipherInfo: { keyLen: 1, ivLen: 0, sslName: 'foo' },
|
|
527
|
-
decipherKey: Buffer.alloc(1),
|
|
528
|
-
seqno: 0,
|
|
529
|
-
macInfo: true
|
|
530
|
-
},
|
|
531
|
-
},
|
|
532
|
-
{ outbound: {
|
|
533
|
-
onWrite: () => {},
|
|
534
|
-
cipherInfo: { keyLen: 1, ivLen: 0, sslName: 'foo' },
|
|
535
|
-
cipherKey: Buffer.alloc(1),
|
|
536
|
-
seqno: 0,
|
|
537
|
-
macInfo: null
|
|
538
|
-
},
|
|
539
|
-
inbound: {
|
|
540
|
-
onPayload: () => {},
|
|
541
|
-
decipherInfo: { keyLen: 1, ivLen: 0, sslName: 'foo' },
|
|
542
|
-
decipherKey: Buffer.alloc(1),
|
|
543
|
-
seqno: 0,
|
|
544
|
-
macInfo: null
|
|
545
|
-
},
|
|
546
|
-
},
|
|
547
|
-
],
|
|
548
|
-
[/invalid outbound\.macInfo/i, /invalid inbound\.macInfo/i]
|
|
549
|
-
],
|
|
550
|
-
[
|
|
551
|
-
[
|
|
552
|
-
{ outbound: {
|
|
553
|
-
onWrite: () => {},
|
|
554
|
-
cipherInfo: { keyLen: 1, ivLen: 0, sslName: 'foo' },
|
|
555
|
-
cipherKey: Buffer.alloc(1),
|
|
556
|
-
seqno: 0,
|
|
557
|
-
macInfo: { keyLen: 16 }
|
|
558
|
-
},
|
|
559
|
-
inbound: {
|
|
560
|
-
onPayload: () => {},
|
|
561
|
-
decipherInfo: { keyLen: 1, ivLen: 0, sslName: 'foo' },
|
|
562
|
-
decipherKey: Buffer.alloc(1),
|
|
563
|
-
seqno: 0,
|
|
564
|
-
macInfo: { keyLen: 16 }
|
|
565
|
-
},
|
|
566
|
-
},
|
|
567
|
-
{ outbound: {
|
|
568
|
-
onWrite: () => {},
|
|
569
|
-
cipherInfo: { keyLen: 1, ivLen: 0, sslName: 'foo' },
|
|
570
|
-
cipherKey: Buffer.alloc(1),
|
|
571
|
-
seqno: 0,
|
|
572
|
-
macInfo: { keyLen: 16 },
|
|
573
|
-
macKey: true
|
|
574
|
-
},
|
|
575
|
-
inbound: {
|
|
576
|
-
onPayload: () => {},
|
|
577
|
-
decipherInfo: { keyLen: 1, ivLen: 0, sslName: 'foo' },
|
|
578
|
-
decipherKey: Buffer.alloc(1),
|
|
579
|
-
seqno: 0,
|
|
580
|
-
macInfo: { keyLen: 16 },
|
|
581
|
-
macKey: true
|
|
582
|
-
},
|
|
583
|
-
},
|
|
584
|
-
{ outbound: {
|
|
585
|
-
onWrite: () => {},
|
|
586
|
-
cipherInfo: { keyLen: 1, ivLen: 0, sslName: 'foo' },
|
|
587
|
-
cipherKey: Buffer.alloc(1),
|
|
588
|
-
seqno: 0,
|
|
589
|
-
macInfo: { keyLen: 16 },
|
|
590
|
-
macKey: null
|
|
591
|
-
},
|
|
592
|
-
inbound: {
|
|
593
|
-
onPayload: () => {},
|
|
594
|
-
decipherInfo: { keyLen: 1, ivLen: 0, sslName: 'foo' },
|
|
595
|
-
decipherKey: Buffer.alloc(1),
|
|
596
|
-
seqno: 0,
|
|
597
|
-
macInfo: { keyLen: 16 },
|
|
598
|
-
macKey: null
|
|
599
|
-
},
|
|
600
|
-
},
|
|
601
|
-
{ outbound: {
|
|
602
|
-
onWrite: () => {},
|
|
603
|
-
cipherInfo: { keyLen: 1, ivLen: 0, sslName: 'foo' },
|
|
604
|
-
cipherKey: Buffer.alloc(1),
|
|
605
|
-
seqno: 0,
|
|
606
|
-
macInfo: { keyLen: 16 },
|
|
607
|
-
macKey: Buffer.alloc(1)
|
|
608
|
-
},
|
|
609
|
-
inbound: {
|
|
610
|
-
onPayload: () => {},
|
|
611
|
-
decipherInfo: { keyLen: 1, ivLen: 0, sslName: 'foo' },
|
|
612
|
-
decipherKey: Buffer.alloc(1),
|
|
613
|
-
seqno: 0,
|
|
614
|
-
macInfo: { keyLen: 16 },
|
|
615
|
-
macKey: Buffer.alloc(1)
|
|
616
|
-
},
|
|
617
|
-
},
|
|
618
|
-
],
|
|
619
|
-
[/invalid outbound\.macKey/i, /invalid inbound\.macKey/i]
|
|
620
|
-
],
|
|
621
|
-
].forEach((testCase) => {
|
|
622
|
-
let errorChecks = testCase[1];
|
|
623
|
-
if (!Array.isArray(errorChecks))
|
|
624
|
-
errorChecks = [errorChecks[0], errorChecks[0]];
|
|
625
|
-
for (const input of testCase[0]) {
|
|
626
|
-
assert.throws(() => createCipher(input), errorChecks[0]);
|
|
627
|
-
assert.throws(() => createDecipher(input), errorChecks[1]);
|
|
628
|
-
}
|
|
629
|
-
});
|
|
630
|
-
}
|
|
631
|
-
})();
|