bdy 1.23.6-dev → 1.23.7-dev
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/distTs/package.json +10 -2
- package/distTs/src/agent/linux.js +53 -3
- package/distTs/src/agent/manager.js +3 -6
- package/distTs/src/agent/osx.js +51 -3
- package/distTs/src/agent/system.js +400 -21
- package/distTs/src/agent/windows.js +4 -7
- package/distTs/src/command/agent/debug.js +2 -2
- package/distTs/src/command/agent/install.js +37 -10
- package/distTs/src/command/agent/restart.js +2 -2
- package/distTs/src/command/agent/run.js +3 -0
- package/distTs/src/command/agent/start.js +2 -2
- package/distTs/src/command/agent/status.js +19 -0
- package/distTs/src/command/agent/stop.js +2 -2
- package/distTs/src/command/agent/uninstall.js +5 -8
- package/distTs/src/command/agent/update.js +2 -2
- package/distTs/src/command/artifact/publish.js +3 -1
- package/distTs/src/command/version.js +13 -5
- package/distTs/src/logger.js +40 -4
- package/distTs/src/texts.js +35 -19
- package/distTs/src/utils.js +98 -3
- package/node_modules/asn1/Jenkinsfile +65 -0
- package/node_modules/asn1/LICENSE +19 -0
- package/node_modules/asn1/README.md +50 -0
- package/node_modules/asn1/lib/ber/errors.js +13 -0
- package/node_modules/asn1/lib/ber/index.js +27 -0
- package/node_modules/asn1/lib/ber/reader.js +262 -0
- package/node_modules/asn1/lib/ber/types.js +36 -0
- package/node_modules/asn1/lib/ber/writer.js +317 -0
- package/node_modules/asn1/lib/index.js +20 -0
- package/node_modules/asn1/package.json +31 -0
- package/node_modules/bcrypt-pbkdf/CONTRIBUTING.md +13 -0
- package/node_modules/bcrypt-pbkdf/LICENSE +66 -0
- package/node_modules/bcrypt-pbkdf/README.md +45 -0
- package/node_modules/bcrypt-pbkdf/index.js +556 -0
- package/node_modules/bcrypt-pbkdf/package.json +15 -0
- package/node_modules/safer-buffer/LICENSE +21 -0
- package/node_modules/safer-buffer/Porting-Buffer.md +268 -0
- package/node_modules/safer-buffer/Readme.md +156 -0
- package/node_modules/safer-buffer/dangerous.js +58 -0
- package/node_modules/safer-buffer/package.json +34 -0
- package/node_modules/safer-buffer/safer.js +77 -0
- package/node_modules/safer-buffer/tests.js +406 -0
- package/node_modules/ssh2/.eslintignore +4 -0
- package/node_modules/ssh2/.eslintrc.js +5 -0
- package/node_modules/ssh2/.github/workflows/ci.yml +110 -0
- package/node_modules/ssh2/.github/workflows/lint.yml +27 -0
- package/node_modules/ssh2/LICENSE +19 -0
- package/node_modules/ssh2/README.md +1529 -0
- package/node_modules/ssh2/SFTP.md +413 -0
- package/node_modules/ssh2/examples/server-chat.js +238 -0
- package/node_modules/ssh2/examples/sftp-server-download-only.js +134 -0
- package/node_modules/ssh2/install.js +27 -0
- package/node_modules/ssh2/lib/Channel.js +295 -0
- package/node_modules/ssh2/lib/agent.js +1123 -0
- package/node_modules/ssh2/lib/client.js +2176 -0
- package/node_modules/ssh2/lib/http-agents.js +84 -0
- package/node_modules/ssh2/lib/index.js +44 -0
- package/node_modules/ssh2/lib/keygen.js +582 -0
- package/node_modules/ssh2/lib/protocol/Protocol.js +2136 -0
- package/node_modules/ssh2/lib/protocol/SFTP.js +4052 -0
- package/node_modules/ssh2/lib/protocol/constants.js +356 -0
- package/node_modules/ssh2/lib/protocol/crypto/binding.gyp +23 -0
- package/node_modules/ssh2/lib/protocol/crypto/poly1305.js +43 -0
- package/node_modules/ssh2/lib/protocol/crypto/src/binding.cc +2300 -0
- package/node_modules/ssh2/lib/protocol/crypto.js +1602 -0
- package/node_modules/ssh2/lib/protocol/handlers.js +16 -0
- package/node_modules/ssh2/lib/protocol/handlers.misc.js +1285 -0
- package/node_modules/ssh2/lib/protocol/kex.js +1908 -0
- package/node_modules/ssh2/lib/protocol/keyParser.js +1484 -0
- package/node_modules/ssh2/lib/protocol/node-fs-compat.js +115 -0
- package/node_modules/ssh2/lib/protocol/utils.js +356 -0
- package/node_modules/ssh2/lib/protocol/zlib.js +255 -0
- package/node_modules/ssh2/lib/server.js +1380 -0
- package/node_modules/ssh2/lib/utils.js +336 -0
- package/node_modules/ssh2/package.json +49 -0
- package/node_modules/ssh2/test/common.js +316 -0
- package/node_modules/ssh2/test/fixtures/bad_rsa_private_key +26 -0
- package/node_modules/ssh2/test/fixtures/https_cert.pem +33 -0
- package/node_modules/ssh2/test/fixtures/https_key.pem +52 -0
- package/node_modules/ssh2/test/fixtures/id_dsa +12 -0
- package/node_modules/ssh2/test/fixtures/id_ecdsa +5 -0
- package/node_modules/ssh2/test/fixtures/id_rsa +15 -0
- package/node_modules/ssh2/test/fixtures/id_rsa.ppk +26 -0
- package/node_modules/ssh2/test/fixtures/id_rsa_enc +30 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa +21 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub +1 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc +22 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub +1 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm +23 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub +1 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa +9 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub +1 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc +10 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub +1 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub.result +8 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm +10 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub +1 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub.result +8 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519 +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub +1 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa +27 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub +1 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc +28 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub +1 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub.result +8 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm +29 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub +1 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub.result +8 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa +12 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub +1 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc +15 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub +1 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub.result +8 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa +5 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub +1 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc +8 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub +1 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub.result +8 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa +27 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub +1 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc +30 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub +1 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub.result +8 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256 +54 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub +1 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub.result +6 -0
- package/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.result +6 -0
- package/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc +17 -0
- package/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa +26 -0
- package/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc +18 -0
- package/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub +9 -0
- package/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub +10 -0
- package/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub +11 -0
- package/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub +11 -0
- package/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub +8 -0
- package/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub.result +7 -0
- package/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub +13 -0
- package/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub.result +7 -0
- package/node_modules/ssh2/test/fixtures/openssh_new_rsa +27 -0
- package/node_modules/ssh2/test/fixtures/ssh_host_dsa_key +12 -0
- package/node_modules/ssh2/test/fixtures/ssh_host_ecdsa_key +5 -0
- package/node_modules/ssh2/test/fixtures/ssh_host_rsa_key +15 -0
- package/node_modules/ssh2/test/test-exec.js +578 -0
- package/node_modules/ssh2/test/test-integration-openssh.js +486 -0
- package/node_modules/ssh2/test/test-keygen.js +60 -0
- package/node_modules/ssh2/test/test-misc-client-server.js +1460 -0
- package/node_modules/ssh2/test/test-openssh.js +261 -0
- package/node_modules/ssh2/test/test-protocol-crypto.js +631 -0
- package/node_modules/ssh2/test/test-protocol-keyparser.js +177 -0
- package/node_modules/ssh2/test/test-server-hostkeys.js +138 -0
- package/node_modules/ssh2/test/test-sftp.js +842 -0
- package/node_modules/ssh2/test/test-shell.js +109 -0
- package/node_modules/ssh2/test/test-userauth-agent-openssh.js +110 -0
- package/node_modules/ssh2/test/test-userauth-agent.js +171 -0
- package/node_modules/ssh2/test/test-userauth.js +611 -0
- package/node_modules/ssh2/test/test-worker-imports.js +25 -0
- package/node_modules/ssh2/test/test.js +20 -0
- package/node_modules/ssh2/util/build_pagent.bat +2 -0
- package/node_modules/ssh2/util/pagent.c +88 -0
- package/node_modules/ssh2/util/pagent.exe +0 -0
- package/node_modules/tweetnacl/.npmignore +4 -0
- package/node_modules/tweetnacl/AUTHORS.md +28 -0
- package/node_modules/tweetnacl/CHANGELOG.md +221 -0
- package/node_modules/tweetnacl/LICENSE +24 -0
- package/node_modules/tweetnacl/PULL_REQUEST_TEMPLATE.md +20 -0
- package/node_modules/tweetnacl/README.md +459 -0
- package/node_modules/tweetnacl/nacl-fast.js +2388 -0
- package/node_modules/tweetnacl/nacl-fast.min.js +2 -0
- package/node_modules/tweetnacl/nacl.d.ts +98 -0
- package/node_modules/tweetnacl/nacl.js +1175 -0
- package/node_modules/tweetnacl/nacl.min.js +1 -0
- package/node_modules/tweetnacl/package.json +58 -0
- package/package.json +10 -2
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { timingSafeEqual } = require('crypto');
|
|
4
|
+
const { constants, readFileSync } = require('fs');
|
|
5
|
+
|
|
6
|
+
const { Server, sftp: { OPEN_MODE, STATUS_CODE } } = require('ssh2');
|
|
7
|
+
|
|
8
|
+
const allowedUser = Buffer.from('foo');
|
|
9
|
+
const allowedPassword = Buffer.from('bar');
|
|
10
|
+
|
|
11
|
+
function checkValue(input, allowed) {
|
|
12
|
+
const autoReject = (input.length !== allowed.length);
|
|
13
|
+
if (autoReject) {
|
|
14
|
+
// Prevent leaking length information by always making a comparison with the
|
|
15
|
+
// same input when lengths don't match what we expect ...
|
|
16
|
+
allowed = input;
|
|
17
|
+
}
|
|
18
|
+
const isMatch = timingSafeEqual(input, allowed);
|
|
19
|
+
return (!autoReject && isMatch);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
new Server({
|
|
23
|
+
hostKeys: [readFileSync('host.key')]
|
|
24
|
+
}, (client) => {
|
|
25
|
+
console.log('Client connected!');
|
|
26
|
+
|
|
27
|
+
client.on('authentication', (ctx) => {
|
|
28
|
+
let allowed = true;
|
|
29
|
+
if (!checkValue(Buffer.from(ctx.username), allowedUser))
|
|
30
|
+
allowed = false;
|
|
31
|
+
|
|
32
|
+
switch (ctx.method) {
|
|
33
|
+
case 'password':
|
|
34
|
+
if (!checkValue(Buffer.from(ctx.password), allowedPassword))
|
|
35
|
+
return ctx.reject();
|
|
36
|
+
break;
|
|
37
|
+
default:
|
|
38
|
+
return ctx.reject();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (allowed)
|
|
42
|
+
ctx.accept();
|
|
43
|
+
else
|
|
44
|
+
ctx.reject();
|
|
45
|
+
}).on('ready', () => {
|
|
46
|
+
console.log('Client authenticated!');
|
|
47
|
+
|
|
48
|
+
client.on('session', (accept, reject) => {
|
|
49
|
+
const session = accept();
|
|
50
|
+
session.on('sftp', (accept, reject) => {
|
|
51
|
+
console.log('Client SFTP session');
|
|
52
|
+
|
|
53
|
+
const openFiles = new Map();
|
|
54
|
+
let handleCount = 0;
|
|
55
|
+
const sftp = accept();
|
|
56
|
+
sftp.on('OPEN', (reqid, filename, flags, attrs) => {
|
|
57
|
+
// Only allow opening /tmp/foo.txt for writing
|
|
58
|
+
if (filename !== '/tmp/foo.txt' || !(flags & OPEN_MODE.READ))
|
|
59
|
+
return sftp.status(reqid, STATUS_CODE.FAILURE);
|
|
60
|
+
|
|
61
|
+
// Create a fake handle to return to the client, this could easily
|
|
62
|
+
// be a real file descriptor number for example if actually opening
|
|
63
|
+
// the file on the disk
|
|
64
|
+
const handle = Buffer.alloc(4);
|
|
65
|
+
openFiles.set(handleCount, { read: false });
|
|
66
|
+
handle.writeUInt32BE(handleCount++, 0, true);
|
|
67
|
+
|
|
68
|
+
console.log('Opening file for read');
|
|
69
|
+
sftp.handle(reqid, handle);
|
|
70
|
+
}).on('READ', (reqid, handle, offset, length) => {
|
|
71
|
+
let fnum;
|
|
72
|
+
if (handle.length !== 4
|
|
73
|
+
|| !openFiles.has(fnum = handle.readUInt32BE(0, true))) {
|
|
74
|
+
return sftp.status(reqid, STATUS_CODE.FAILURE);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Fake the read
|
|
78
|
+
const state = openFiles.get(fnum);
|
|
79
|
+
if (state.read) {
|
|
80
|
+
sftp.status(reqid, STATUS_CODE.EOF);
|
|
81
|
+
} else {
|
|
82
|
+
state.read = true;
|
|
83
|
+
|
|
84
|
+
console.log(
|
|
85
|
+
'Read from file at offset %d, length %d', offset, length
|
|
86
|
+
);
|
|
87
|
+
sftp.data(reqid, 'bar');
|
|
88
|
+
}
|
|
89
|
+
}).on('CLOSE', (reqid, handle) => {
|
|
90
|
+
let fnum;
|
|
91
|
+
if (handle.length !== 4
|
|
92
|
+
|| !openFiles.has(fnum = handle.readUInt32BE(0))) {
|
|
93
|
+
return sftp.status(reqid, STATUS_CODE.FAILURE);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
openFiles.delete(fnum);
|
|
97
|
+
|
|
98
|
+
console.log('Closing file');
|
|
99
|
+
sftp.status(reqid, STATUS_CODE.OK);
|
|
100
|
+
}).on('REALPATH', function(reqid, path) {
|
|
101
|
+
const name = [{
|
|
102
|
+
filename: '/tmp/foo.txt',
|
|
103
|
+
longname: '-rwxrwxrwx 1 foo foo 3 Dec 8 2009 foo.txt',
|
|
104
|
+
attrs: {}
|
|
105
|
+
}];
|
|
106
|
+
sftp.name(reqid, name);
|
|
107
|
+
}).on('STAT', onSTAT)
|
|
108
|
+
.on('LSTAT', onSTAT);
|
|
109
|
+
|
|
110
|
+
function onSTAT(reqid, path) {
|
|
111
|
+
if (path !== '/tmp/foo.txt')
|
|
112
|
+
return sftp.status(reqid, STATUS_CODE.FAILURE);
|
|
113
|
+
|
|
114
|
+
let mode = constants.S_IFREG; // Regular file
|
|
115
|
+
mode |= constants.S_IRWXU; // Read, write, execute for user
|
|
116
|
+
mode |= constants.S_IRWXG; // Read, write, execute for group
|
|
117
|
+
mode |= constants.S_IRWXO; // Read, write, execute for other
|
|
118
|
+
sftp.attrs(reqid, {
|
|
119
|
+
mode: mode,
|
|
120
|
+
uid: 0,
|
|
121
|
+
gid: 0,
|
|
122
|
+
size: 3,
|
|
123
|
+
atime: Date.now(),
|
|
124
|
+
mtime: Date.now(),
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}).on('close', () => {
|
|
130
|
+
console.log('Client disconnected');
|
|
131
|
+
});
|
|
132
|
+
}).listen(0, '127.0.0.1', function() {
|
|
133
|
+
console.log(`Listening on port ${this.address().port}`);
|
|
134
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { spawnSync } = require('child_process');
|
|
4
|
+
|
|
5
|
+
const forceFailOnNonZero = (process.env.CI_CHECK_FAIL === 'ssh2');
|
|
6
|
+
|
|
7
|
+
// Attempt to build the bundled optional binding
|
|
8
|
+
const args = [
|
|
9
|
+
`--target=${process.version}`,
|
|
10
|
+
`--real_openssl_major=${/^\d+/.exec(process.versions.openssl)[0]}`,
|
|
11
|
+
'rebuild',
|
|
12
|
+
];
|
|
13
|
+
const result = spawnSync('node-gyp', args, {
|
|
14
|
+
cwd: 'lib/protocol/crypto',
|
|
15
|
+
encoding: 'utf8',
|
|
16
|
+
shell: true,
|
|
17
|
+
stdio: 'inherit',
|
|
18
|
+
windowsHide: true,
|
|
19
|
+
});
|
|
20
|
+
if (result.error || result.status !== 0) {
|
|
21
|
+
console.log('Failed to build optional crypto binding');
|
|
22
|
+
if (forceFailOnNonZero)
|
|
23
|
+
process.exit(1);
|
|
24
|
+
} else {
|
|
25
|
+
console.log('Succeeded in building optional crypto binding');
|
|
26
|
+
}
|
|
27
|
+
process.exit(0);
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
Duplex: DuplexStream,
|
|
5
|
+
Readable: ReadableStream,
|
|
6
|
+
Writable: WritableStream,
|
|
7
|
+
} = require('stream');
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
CHANNEL_EXTENDED_DATATYPE: { STDERR },
|
|
11
|
+
} = require('./protocol/constants.js');
|
|
12
|
+
const { bufferSlice } = require('./protocol/utils.js');
|
|
13
|
+
|
|
14
|
+
const PACKET_SIZE = 32 * 1024;
|
|
15
|
+
const MAX_WINDOW = 2 * 1024 * 1024;
|
|
16
|
+
const WINDOW_THRESHOLD = MAX_WINDOW / 2;
|
|
17
|
+
|
|
18
|
+
class ClientStderr extends ReadableStream {
|
|
19
|
+
constructor(channel, streamOpts) {
|
|
20
|
+
super(streamOpts);
|
|
21
|
+
|
|
22
|
+
this._channel = channel;
|
|
23
|
+
}
|
|
24
|
+
_read(n) {
|
|
25
|
+
if (this._channel._waitChanDrain) {
|
|
26
|
+
this._channel._waitChanDrain = false;
|
|
27
|
+
if (this._channel.incoming.window <= WINDOW_THRESHOLD)
|
|
28
|
+
windowAdjust(this._channel);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class ServerStderr extends WritableStream {
|
|
34
|
+
constructor(channel) {
|
|
35
|
+
super({ highWaterMark: MAX_WINDOW });
|
|
36
|
+
|
|
37
|
+
this._channel = channel;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
_write(data, encoding, cb) {
|
|
41
|
+
const channel = this._channel;
|
|
42
|
+
const protocol = channel._client._protocol;
|
|
43
|
+
const outgoing = channel.outgoing;
|
|
44
|
+
const packetSize = outgoing.packetSize;
|
|
45
|
+
const id = outgoing.id;
|
|
46
|
+
let window = outgoing.window;
|
|
47
|
+
const len = data.length;
|
|
48
|
+
let p = 0;
|
|
49
|
+
|
|
50
|
+
if (outgoing.state !== 'open')
|
|
51
|
+
return;
|
|
52
|
+
|
|
53
|
+
while (len - p > 0 && window > 0) {
|
|
54
|
+
let sliceLen = len - p;
|
|
55
|
+
if (sliceLen > window)
|
|
56
|
+
sliceLen = window;
|
|
57
|
+
if (sliceLen > packetSize)
|
|
58
|
+
sliceLen = packetSize;
|
|
59
|
+
|
|
60
|
+
if (p === 0 && sliceLen === len)
|
|
61
|
+
protocol.channelExtData(id, data, STDERR);
|
|
62
|
+
else
|
|
63
|
+
protocol.channelExtData(id, bufferSlice(data, p, p + sliceLen), STDERR);
|
|
64
|
+
|
|
65
|
+
p += sliceLen;
|
|
66
|
+
window -= sliceLen;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
outgoing.window = window;
|
|
70
|
+
|
|
71
|
+
if (len - p > 0) {
|
|
72
|
+
if (window === 0)
|
|
73
|
+
channel._waitWindow = true;
|
|
74
|
+
if (p > 0)
|
|
75
|
+
channel._chunkErr = bufferSlice(data, p, len);
|
|
76
|
+
else
|
|
77
|
+
channel._chunkErr = data;
|
|
78
|
+
channel._chunkcbErr = cb;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
cb();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
class Channel extends DuplexStream {
|
|
87
|
+
constructor(client, info, opts) {
|
|
88
|
+
const streamOpts = {
|
|
89
|
+
highWaterMark: MAX_WINDOW,
|
|
90
|
+
allowHalfOpen: (!opts || (opts && opts.allowHalfOpen !== false)),
|
|
91
|
+
emitClose: false,
|
|
92
|
+
};
|
|
93
|
+
super(streamOpts);
|
|
94
|
+
this.allowHalfOpen = streamOpts.allowHalfOpen;
|
|
95
|
+
|
|
96
|
+
const server = !!(opts && opts.server);
|
|
97
|
+
|
|
98
|
+
this.server = server;
|
|
99
|
+
this.type = info.type;
|
|
100
|
+
this.subtype = undefined;
|
|
101
|
+
|
|
102
|
+
/*
|
|
103
|
+
incoming and outgoing contain these properties:
|
|
104
|
+
{
|
|
105
|
+
id: undefined,
|
|
106
|
+
window: undefined,
|
|
107
|
+
packetSize: undefined,
|
|
108
|
+
state: 'closed'
|
|
109
|
+
}
|
|
110
|
+
*/
|
|
111
|
+
this.incoming = info.incoming;
|
|
112
|
+
this.outgoing = info.outgoing;
|
|
113
|
+
this._callbacks = [];
|
|
114
|
+
|
|
115
|
+
this._client = client;
|
|
116
|
+
this._hasX11 = false;
|
|
117
|
+
this._exit = {
|
|
118
|
+
code: undefined,
|
|
119
|
+
signal: undefined,
|
|
120
|
+
dump: undefined,
|
|
121
|
+
desc: undefined,
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
this.stdin = this.stdout = this;
|
|
125
|
+
|
|
126
|
+
if (server)
|
|
127
|
+
this.stderr = new ServerStderr(this);
|
|
128
|
+
else
|
|
129
|
+
this.stderr = new ClientStderr(this, streamOpts);
|
|
130
|
+
|
|
131
|
+
// Outgoing data
|
|
132
|
+
this._waitWindow = false; // SSH-level backpressure
|
|
133
|
+
|
|
134
|
+
// Incoming data
|
|
135
|
+
this._waitChanDrain = false; // Channel Readable side backpressure
|
|
136
|
+
|
|
137
|
+
this._chunk = undefined;
|
|
138
|
+
this._chunkcb = undefined;
|
|
139
|
+
this._chunkErr = undefined;
|
|
140
|
+
this._chunkcbErr = undefined;
|
|
141
|
+
|
|
142
|
+
this.on('finish', onFinish)
|
|
143
|
+
.on('prefinish', onFinish); // For node v0.11+
|
|
144
|
+
|
|
145
|
+
this.on('end', onEnd).on('close', onEnd);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
_read(n) {
|
|
149
|
+
if (this._waitChanDrain) {
|
|
150
|
+
this._waitChanDrain = false;
|
|
151
|
+
if (this.incoming.window <= WINDOW_THRESHOLD)
|
|
152
|
+
windowAdjust(this);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
_write(data, encoding, cb) {
|
|
157
|
+
const protocol = this._client._protocol;
|
|
158
|
+
const outgoing = this.outgoing;
|
|
159
|
+
const packetSize = outgoing.packetSize;
|
|
160
|
+
const id = outgoing.id;
|
|
161
|
+
let window = outgoing.window;
|
|
162
|
+
const len = data.length;
|
|
163
|
+
let p = 0;
|
|
164
|
+
|
|
165
|
+
if (outgoing.state !== 'open')
|
|
166
|
+
return;
|
|
167
|
+
|
|
168
|
+
while (len - p > 0 && window > 0) {
|
|
169
|
+
let sliceLen = len - p;
|
|
170
|
+
if (sliceLen > window)
|
|
171
|
+
sliceLen = window;
|
|
172
|
+
if (sliceLen > packetSize)
|
|
173
|
+
sliceLen = packetSize;
|
|
174
|
+
|
|
175
|
+
if (p === 0 && sliceLen === len)
|
|
176
|
+
protocol.channelData(id, data);
|
|
177
|
+
else
|
|
178
|
+
protocol.channelData(id, bufferSlice(data, p, p + sliceLen));
|
|
179
|
+
|
|
180
|
+
p += sliceLen;
|
|
181
|
+
window -= sliceLen;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
outgoing.window = window;
|
|
185
|
+
|
|
186
|
+
if (len - p > 0) {
|
|
187
|
+
if (window === 0)
|
|
188
|
+
this._waitWindow = true;
|
|
189
|
+
if (p > 0)
|
|
190
|
+
this._chunk = bufferSlice(data, p, len);
|
|
191
|
+
else
|
|
192
|
+
this._chunk = data;
|
|
193
|
+
this._chunkcb = cb;
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
cb();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
eof() {
|
|
201
|
+
if (this.outgoing.state === 'open') {
|
|
202
|
+
this.outgoing.state = 'eof';
|
|
203
|
+
this._client._protocol.channelEOF(this.outgoing.id);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
close() {
|
|
208
|
+
if (this.outgoing.state === 'open' || this.outgoing.state === 'eof') {
|
|
209
|
+
this.outgoing.state = 'closing';
|
|
210
|
+
this._client._protocol.channelClose(this.outgoing.id);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
destroy() {
|
|
215
|
+
this.end();
|
|
216
|
+
this.close();
|
|
217
|
+
return this;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Session type-specific methods =============================================
|
|
221
|
+
setWindow(rows, cols, height, width) {
|
|
222
|
+
if (this.server)
|
|
223
|
+
throw new Error('Client-only method called in server mode');
|
|
224
|
+
|
|
225
|
+
if (this.type === 'session'
|
|
226
|
+
&& (this.subtype === 'shell' || this.subtype === 'exec')
|
|
227
|
+
&& this.writable
|
|
228
|
+
&& this.outgoing.state === 'open') {
|
|
229
|
+
this._client._protocol.windowChange(this.outgoing.id,
|
|
230
|
+
rows,
|
|
231
|
+
cols,
|
|
232
|
+
height,
|
|
233
|
+
width);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
signal(signalName) {
|
|
238
|
+
if (this.server)
|
|
239
|
+
throw new Error('Client-only method called in server mode');
|
|
240
|
+
|
|
241
|
+
if (this.type === 'session'
|
|
242
|
+
&& this.writable
|
|
243
|
+
&& this.outgoing.state === 'open') {
|
|
244
|
+
this._client._protocol.signal(this.outgoing.id, signalName);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
exit(statusOrSignal, coreDumped, msg) {
|
|
249
|
+
if (!this.server)
|
|
250
|
+
throw new Error('Server-only method called in client mode');
|
|
251
|
+
|
|
252
|
+
if (this.type === 'session'
|
|
253
|
+
&& this.writable
|
|
254
|
+
&& this.outgoing.state === 'open') {
|
|
255
|
+
if (typeof statusOrSignal === 'number') {
|
|
256
|
+
this._client._protocol.exitStatus(this.outgoing.id, statusOrSignal);
|
|
257
|
+
} else {
|
|
258
|
+
this._client._protocol.exitSignal(this.outgoing.id,
|
|
259
|
+
statusOrSignal,
|
|
260
|
+
coreDumped,
|
|
261
|
+
msg);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function onFinish() {
|
|
269
|
+
this.eof();
|
|
270
|
+
if (this.server || !this.allowHalfOpen)
|
|
271
|
+
this.close();
|
|
272
|
+
this.writable = false;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function onEnd() {
|
|
276
|
+
this.readable = false;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function windowAdjust(self) {
|
|
280
|
+
if (self.outgoing.state === 'closed')
|
|
281
|
+
return;
|
|
282
|
+
const amt = MAX_WINDOW - self.incoming.window;
|
|
283
|
+
if (amt <= 0)
|
|
284
|
+
return;
|
|
285
|
+
self.incoming.window += amt;
|
|
286
|
+
self._client._protocol.channelWindowAdjust(self.outgoing.id, amt);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
module.exports = {
|
|
290
|
+
Channel,
|
|
291
|
+
MAX_WINDOW,
|
|
292
|
+
PACKET_SIZE,
|
|
293
|
+
windowAdjust,
|
|
294
|
+
WINDOW_THRESHOLD,
|
|
295
|
+
};
|