@andy.ian/dsh-homing 0.0.0-stage → 2.0.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.
Files changed (226) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +71 -2
  3. package/bin/auth.mjs +159 -0
  4. package/bin/backup.mjs +118 -0
  5. package/bin/bootstrap-server.mjs +436 -0
  6. package/bin/entry-link.mjs +69 -0
  7. package/bin/nginx-dsh.template.conf +91 -0
  8. package/bin/nginx-gate.conf +9 -0
  9. package/bin/nginx-ws-map.conf +5 -0
  10. package/bin/renew-cert.mjs +127 -0
  11. package/bin/watchdog.mjs +158 -0
  12. package/cordis.patch.yml +30 -0
  13. package/icon.svg +9 -0
  14. package/index.js +3339 -0
  15. package/lib/csrf.mjs +60 -0
  16. package/lib/devices.mjs +221 -0
  17. package/lib/files-page.mjs +391 -0
  18. package/lib/files.mjs +464 -0
  19. package/lib/git.mjs +154 -0
  20. package/lib/limits.mjs +135 -0
  21. package/lib/pty.mjs +354 -0
  22. package/lib/session.mjs +216 -0
  23. package/lib/shell-page.mjs +430 -0
  24. package/lib/shell.mjs +274 -0
  25. package/lib/term-app.js +318 -0
  26. package/lib/term-page.mjs +117 -0
  27. package/lib/vendor/fonts/JetBrainsMono-Regular.ttf +0 -0
  28. package/lib/vendor/fonts/jetbrains-mono-400.woff2 +0 -0
  29. package/lib/vendor/fonts/jetbrains-mono-700.woff2 +0 -0
  30. package/lib/vendor/node_modules/@xterm/addon-fit/LICENSE +19 -0
  31. package/lib/vendor/node_modules/@xterm/addon-fit/README.md +24 -0
  32. package/lib/vendor/node_modules/@xterm/addon-fit/lib/addon-fit.js +2 -0
  33. package/lib/vendor/node_modules/@xterm/addon-fit/lib/addon-fit.js.map +1 -0
  34. package/lib/vendor/node_modules/@xterm/addon-fit/package.json +26 -0
  35. package/lib/vendor/node_modules/@xterm/addon-fit/src/FitAddon.ts +90 -0
  36. package/lib/vendor/node_modules/@xterm/addon-fit/typings/addon-fit.d.ts +55 -0
  37. package/lib/vendor/node_modules/asn1/Jenkinsfile +65 -0
  38. package/lib/vendor/node_modules/asn1/LICENSE +19 -0
  39. package/lib/vendor/node_modules/asn1/README.md +50 -0
  40. package/lib/vendor/node_modules/asn1/lib/ber/errors.js +13 -0
  41. package/lib/vendor/node_modules/asn1/lib/ber/index.js +27 -0
  42. package/lib/vendor/node_modules/asn1/lib/ber/reader.js +262 -0
  43. package/lib/vendor/node_modules/asn1/lib/ber/types.js +36 -0
  44. package/lib/vendor/node_modules/asn1/lib/ber/writer.js +317 -0
  45. package/lib/vendor/node_modules/asn1/lib/index.js +20 -0
  46. package/lib/vendor/node_modules/asn1/package.json +31 -0
  47. package/lib/vendor/node_modules/bcrypt-pbkdf/CONTRIBUTING.md +13 -0
  48. package/lib/vendor/node_modules/bcrypt-pbkdf/LICENSE +66 -0
  49. package/lib/vendor/node_modules/bcrypt-pbkdf/README.md +45 -0
  50. package/lib/vendor/node_modules/bcrypt-pbkdf/index.js +556 -0
  51. package/lib/vendor/node_modules/bcrypt-pbkdf/package.json +15 -0
  52. package/lib/vendor/node_modules/safer-buffer/LICENSE +21 -0
  53. package/lib/vendor/node_modules/safer-buffer/Porting-Buffer.md +268 -0
  54. package/lib/vendor/node_modules/safer-buffer/Readme.md +156 -0
  55. package/lib/vendor/node_modules/safer-buffer/dangerous.js +58 -0
  56. package/lib/vendor/node_modules/safer-buffer/package.json +34 -0
  57. package/lib/vendor/node_modules/safer-buffer/safer.js +77 -0
  58. package/lib/vendor/node_modules/safer-buffer/tests.js +406 -0
  59. package/lib/vendor/node_modules/ssh2/.eslintignore +4 -0
  60. package/lib/vendor/node_modules/ssh2/.eslintrc.js +5 -0
  61. package/lib/vendor/node_modules/ssh2/.github/workflows/ci.yml +110 -0
  62. package/lib/vendor/node_modules/ssh2/.github/workflows/lint.yml +27 -0
  63. package/lib/vendor/node_modules/ssh2/LICENSE +19 -0
  64. package/lib/vendor/node_modules/ssh2/README.md +1529 -0
  65. package/lib/vendor/node_modules/ssh2/SFTP.md +413 -0
  66. package/lib/vendor/node_modules/ssh2/examples/server-chat.js +238 -0
  67. package/lib/vendor/node_modules/ssh2/examples/sftp-server-download-only.js +134 -0
  68. package/lib/vendor/node_modules/ssh2/install.js +27 -0
  69. package/lib/vendor/node_modules/ssh2/lib/Channel.js +295 -0
  70. package/lib/vendor/node_modules/ssh2/lib/agent.js +1123 -0
  71. package/lib/vendor/node_modules/ssh2/lib/client.js +2176 -0
  72. package/lib/vendor/node_modules/ssh2/lib/http-agents.js +84 -0
  73. package/lib/vendor/node_modules/ssh2/lib/index.js +44 -0
  74. package/lib/vendor/node_modules/ssh2/lib/keygen.js +582 -0
  75. package/lib/vendor/node_modules/ssh2/lib/protocol/Protocol.js +2136 -0
  76. package/lib/vendor/node_modules/ssh2/lib/protocol/SFTP.js +4052 -0
  77. package/lib/vendor/node_modules/ssh2/lib/protocol/constants.js +356 -0
  78. package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/binding.gyp +23 -0
  79. package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/poly1305.js +43 -0
  80. package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/src/binding.cc +2300 -0
  81. package/lib/vendor/node_modules/ssh2/lib/protocol/crypto.js +1602 -0
  82. package/lib/vendor/node_modules/ssh2/lib/protocol/handlers.js +16 -0
  83. package/lib/vendor/node_modules/ssh2/lib/protocol/handlers.misc.js +1285 -0
  84. package/lib/vendor/node_modules/ssh2/lib/protocol/kex.js +1908 -0
  85. package/lib/vendor/node_modules/ssh2/lib/protocol/keyParser.js +1484 -0
  86. package/lib/vendor/node_modules/ssh2/lib/protocol/node-fs-compat.js +115 -0
  87. package/lib/vendor/node_modules/ssh2/lib/protocol/utils.js +356 -0
  88. package/lib/vendor/node_modules/ssh2/lib/protocol/zlib.js +255 -0
  89. package/lib/vendor/node_modules/ssh2/lib/server.js +1380 -0
  90. package/lib/vendor/node_modules/ssh2/lib/utils.js +336 -0
  91. package/lib/vendor/node_modules/ssh2/package.json +49 -0
  92. package/lib/vendor/node_modules/ssh2/test/common.js +316 -0
  93. package/lib/vendor/node_modules/ssh2/test/fixtures/bad_rsa_private_key +26 -0
  94. package/lib/vendor/node_modules/ssh2/test/fixtures/https_cert.pem +33 -0
  95. package/lib/vendor/node_modules/ssh2/test/fixtures/https_key.pem +52 -0
  96. package/lib/vendor/node_modules/ssh2/test/fixtures/id_dsa +12 -0
  97. package/lib/vendor/node_modules/ssh2/test/fixtures/id_ecdsa +5 -0
  98. package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa +15 -0
  99. package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa.ppk +26 -0
  100. package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa_enc +30 -0
  101. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa +21 -0
  102. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub +1 -0
  103. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub.result +7 -0
  104. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.result +7 -0
  105. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc +22 -0
  106. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub +1 -0
  107. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub.result +7 -0
  108. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.result +7 -0
  109. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm +23 -0
  110. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub +1 -0
  111. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub.result +7 -0
  112. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.result +7 -0
  113. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa +9 -0
  114. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub +1 -0
  115. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub.result +7 -0
  116. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.result +7 -0
  117. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc +10 -0
  118. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub +1 -0
  119. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub.result +8 -0
  120. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.result +7 -0
  121. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm +10 -0
  122. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub +1 -0
  123. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub.result +8 -0
  124. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.result +7 -0
  125. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519 +7 -0
  126. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub +1 -0
  127. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub.result +7 -0
  128. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.result +7 -0
  129. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa +27 -0
  130. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub +1 -0
  131. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub.result +7 -0
  132. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.result +7 -0
  133. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc +28 -0
  134. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub +1 -0
  135. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub.result +8 -0
  136. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.result +7 -0
  137. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm +29 -0
  138. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub +1 -0
  139. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub.result +8 -0
  140. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.result +7 -0
  141. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa +12 -0
  142. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub +1 -0
  143. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub.result +7 -0
  144. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.result +7 -0
  145. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc +15 -0
  146. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub +1 -0
  147. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub.result +8 -0
  148. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.result +7 -0
  149. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa +5 -0
  150. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub +1 -0
  151. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub.result +7 -0
  152. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.result +7 -0
  153. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc +8 -0
  154. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub +1 -0
  155. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub.result +8 -0
  156. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.result +7 -0
  157. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa +27 -0
  158. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub +1 -0
  159. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub.result +7 -0
  160. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.result +7 -0
  161. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc +30 -0
  162. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub +1 -0
  163. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub.result +8 -0
  164. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.result +7 -0
  165. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256 +54 -0
  166. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub +1 -0
  167. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub.result +6 -0
  168. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.result +6 -0
  169. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc +17 -0
  170. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc.result +7 -0
  171. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa +26 -0
  172. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa.result +7 -0
  173. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc +18 -0
  174. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc.result +7 -0
  175. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub +9 -0
  176. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub.result +7 -0
  177. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub +10 -0
  178. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub.result +7 -0
  179. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub +11 -0
  180. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub.result +7 -0
  181. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub +11 -0
  182. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub.result +7 -0
  183. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub +8 -0
  184. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub.result +7 -0
  185. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub +13 -0
  186. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub.result +7 -0
  187. package/lib/vendor/node_modules/ssh2/test/fixtures/openssh_new_rsa +27 -0
  188. package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_dsa_key +12 -0
  189. package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_ecdsa_key +5 -0
  190. package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_rsa_key +15 -0
  191. package/lib/vendor/node_modules/ssh2/test/test-exec.js +578 -0
  192. package/lib/vendor/node_modules/ssh2/test/test-integration-openssh.js +486 -0
  193. package/lib/vendor/node_modules/ssh2/test/test-keygen.js +60 -0
  194. package/lib/vendor/node_modules/ssh2/test/test-misc-client-server.js +1460 -0
  195. package/lib/vendor/node_modules/ssh2/test/test-openssh.js +261 -0
  196. package/lib/vendor/node_modules/ssh2/test/test-protocol-crypto.js +631 -0
  197. package/lib/vendor/node_modules/ssh2/test/test-protocol-keyparser.js +177 -0
  198. package/lib/vendor/node_modules/ssh2/test/test-server-hostkeys.js +138 -0
  199. package/lib/vendor/node_modules/ssh2/test/test-sftp.js +842 -0
  200. package/lib/vendor/node_modules/ssh2/test/test-shell.js +109 -0
  201. package/lib/vendor/node_modules/ssh2/test/test-userauth-agent-openssh.js +110 -0
  202. package/lib/vendor/node_modules/ssh2/test/test-userauth-agent.js +171 -0
  203. package/lib/vendor/node_modules/ssh2/test/test-userauth.js +611 -0
  204. package/lib/vendor/node_modules/ssh2/test/test-worker-imports.js +25 -0
  205. package/lib/vendor/node_modules/ssh2/test/test.js +20 -0
  206. package/lib/vendor/node_modules/ssh2/util/build_pagent.bat +2 -0
  207. package/lib/vendor/node_modules/ssh2/util/pagent.c +88 -0
  208. package/lib/vendor/node_modules/ssh2/util/pagent.exe +0 -0
  209. package/lib/vendor/node_modules/tweetnacl/AUTHORS.md +27 -0
  210. package/lib/vendor/node_modules/tweetnacl/CHANGELOG.md +283 -0
  211. package/lib/vendor/node_modules/tweetnacl/LICENSE +24 -0
  212. package/lib/vendor/node_modules/tweetnacl/PULL_REQUEST_TEMPLATE.md +20 -0
  213. package/lib/vendor/node_modules/tweetnacl/README.md +494 -0
  214. package/lib/vendor/node_modules/tweetnacl/nacl-fast.js +2391 -0
  215. package/lib/vendor/node_modules/tweetnacl/nacl-fast.min.js +1 -0
  216. package/lib/vendor/node_modules/tweetnacl/nacl.d.ts +98 -0
  217. package/lib/vendor/node_modules/tweetnacl/nacl.js +1178 -0
  218. package/lib/vendor/node_modules/tweetnacl/nacl.min.js +1 -0
  219. package/lib/vendor/node_modules/tweetnacl/package.json +56 -0
  220. package/lib/vendor/xterm.css +218 -0
  221. package/lib/vendor/xterm.js +2 -0
  222. package/locale/en.json +6 -0
  223. package/locale/zh.json +6 -0
  224. package/ops/watchdog/dsh-watchdog.ps1 +105 -0
  225. package/ops/watchdog/restart-now.ps1 +247 -0
  226. package/package.json +69 -4
@@ -0,0 +1,611 @@
1
+ 'use strict';
2
+
3
+ const assert = require('assert');
4
+ const { inspect } = require('util');
5
+
6
+ const {
7
+ fixtureKey,
8
+ mustCall,
9
+ mustNotCall,
10
+ setup,
11
+ } = require('./common.js');
12
+
13
+ const serverCfg = { hostKeys: [ fixtureKey('ssh_host_rsa_key').raw ] };
14
+
15
+ const debug = false;
16
+
17
+ // Keys ========================================================================
18
+ [
19
+ { desc: 'RSA (old OpenSSH)',
20
+ clientKey: fixtureKey('id_rsa') },
21
+ { desc: 'RSA (new OpenSSH)',
22
+ clientKey: fixtureKey('openssh_new_rsa') },
23
+ { desc: 'RSA (encrypted)',
24
+ clientKey: fixtureKey('id_rsa_enc', 'foobarbaz'),
25
+ passphrase: 'foobarbaz' },
26
+ { desc: 'DSA',
27
+ clientKey: fixtureKey('id_dsa') },
28
+ { desc: 'ECDSA',
29
+ clientKey: fixtureKey('id_ecdsa') },
30
+ { desc: 'PPK',
31
+ clientKey: fixtureKey('id_rsa.ppk') },
32
+ ].forEach((test) => {
33
+ const { desc, clientKey, passphrase } = test;
34
+ const username = 'Key User';
35
+ const { server } = setup(
36
+ desc,
37
+ {
38
+ client: { username, privateKey: clientKey.raw, passphrase },
39
+ server: serverCfg,
40
+
41
+ debug,
42
+ }
43
+ );
44
+
45
+ server.on('connection', mustCall((conn) => {
46
+ let authAttempt = 0;
47
+ conn.on('authentication', mustCall((ctx) => {
48
+ assert(ctx.username === username,
49
+ `Wrong username: ${ctx.username}`);
50
+ switch (++authAttempt) {
51
+ case 1:
52
+ assert(ctx.method === 'none', `Wrong auth method: ${ctx.method}`);
53
+ return ctx.reject();
54
+ case 3:
55
+ assert(ctx.signature, 'Missing publickey signature');
56
+ // FALLTHROUGH
57
+ case 2:
58
+ assert(ctx.method === 'publickey',
59
+ `Wrong auth method: ${ctx.method}`);
60
+ assert(ctx.key.algo === clientKey.key.type,
61
+ `Wrong key algo: ${ctx.key.algo}`);
62
+ assert.deepStrictEqual(clientKey.key.getPublicSSH(),
63
+ ctx.key.data,
64
+ 'Public key mismatch');
65
+ break;
66
+ }
67
+ if (ctx.signature) {
68
+ const result =
69
+ clientKey.key.verify(ctx.blob, ctx.signature, ctx.hashAlgo);
70
+ assert(result === true, 'Could not verify publickey signature');
71
+ }
72
+ ctx.accept();
73
+ }, 3)).on('ready', mustCall(() => {
74
+ conn.end();
75
+ }));
76
+ }));
77
+ });
78
+
79
+
80
+ // Password ====================================================================
81
+ {
82
+ const username = 'Password User';
83
+ const password = 'hi mom';
84
+ const { server } = setup(
85
+ 'Password',
86
+ {
87
+ client: { username, password },
88
+ server: serverCfg,
89
+
90
+ debug,
91
+ }
92
+ );
93
+
94
+ server.on('connection', mustCall((conn) => {
95
+ let authAttempt = 0;
96
+ conn.on('authentication', mustCall((ctx) => {
97
+ assert(ctx.username === username,
98
+ `Wrong username: ${ctx.username}`);
99
+ if (++authAttempt === 1) {
100
+ assert(ctx.method === 'none', `Wrong auth method: ${ctx.method}`);
101
+ return ctx.reject();
102
+ }
103
+ assert(ctx.method === 'password',
104
+ `Wrong auth method: ${ctx.method}`);
105
+ assert(ctx.password === password,
106
+ `Wrong password: ${ctx.password}`);
107
+ ctx.accept();
108
+ }, 2)).on('ready', mustCall(() => {
109
+ conn.end();
110
+ }));
111
+ }));
112
+ }
113
+ {
114
+ const username = '';
115
+ const password = 'hi mom';
116
+ const { server } = setup(
117
+ 'Password (empty username)',
118
+ {
119
+ client: { username, password },
120
+ server: serverCfg,
121
+
122
+ debug,
123
+ }
124
+ );
125
+
126
+ server.on('connection', mustCall((conn) => {
127
+ let authAttempt = 0;
128
+ conn.on('authentication', mustCall((ctx) => {
129
+ assert(ctx.username === username,
130
+ `Wrong username: ${ctx.username}`);
131
+ if (++authAttempt === 1) {
132
+ assert(ctx.method === 'none', `Wrong auth method: ${ctx.method}`);
133
+ return ctx.reject();
134
+ }
135
+ assert(ctx.method === 'password',
136
+ `Wrong auth method: ${ctx.method}`);
137
+ assert(ctx.password === password,
138
+ `Wrong password: ${ctx.password}`);
139
+ ctx.accept();
140
+ }, 2)).on('ready', mustCall(() => {
141
+ conn.end();
142
+ }));
143
+ }));
144
+ }
145
+ {
146
+ const username = 'foo';
147
+ const oldPassword = 'bar';
148
+ const newPassword = 'baz';
149
+ const changePrompt = 'Prithee changeth thy password';
150
+ const { client, server } = setup(
151
+ 'Password (change requested)',
152
+ {
153
+ client: { username, password: oldPassword },
154
+ server: serverCfg,
155
+
156
+ debug,
157
+ }
158
+ );
159
+
160
+ server.on('connection', mustCall((conn) => {
161
+ let authAttempt = 0;
162
+ conn.on('authentication', mustCall((ctx) => {
163
+ assert(ctx.username === username,
164
+ `Wrong username: ${ctx.username}`);
165
+ if (++authAttempt === 1) {
166
+ assert(ctx.method === 'none', `Wrong auth method: ${ctx.method}`);
167
+ return ctx.reject();
168
+ }
169
+ assert(ctx.method === 'password',
170
+ `Wrong auth method: ${ctx.method}`);
171
+ assert(ctx.password === oldPassword,
172
+ `Wrong old password: ${ctx.password}`);
173
+ ctx.requestChange(changePrompt, mustCall((newPassword_) => {
174
+ assert(newPassword_ === newPassword,
175
+ `Wrong new password: ${newPassword_}`);
176
+ ctx.accept();
177
+ }));
178
+ }, 2)).on('ready', mustCall(() => {
179
+ conn.end();
180
+ }));
181
+ }));
182
+
183
+ client.on('change password', mustCall((prompt, done) => {
184
+ assert(prompt === changePrompt, `Wrong password change prompt: ${prompt}`);
185
+ process.nextTick(done, newPassword);
186
+ }));
187
+ }
188
+
189
+
190
+ // Hostbased ===================================================================
191
+ {
192
+ const localUsername = 'Local User Foo';
193
+ const localHostname = 'Local Host Bar';
194
+ const username = 'Hostbased User';
195
+ const clientKey = fixtureKey('id_rsa');
196
+ const { server } = setup(
197
+ 'Hostbased',
198
+ {
199
+ client: {
200
+ username,
201
+ privateKey: clientKey.raw,
202
+ localUsername,
203
+ localHostname,
204
+ },
205
+ server: serverCfg,
206
+
207
+ debug,
208
+ }
209
+ );
210
+
211
+ server.on('connection', mustCall((conn) => {
212
+ let authAttempt = 0;
213
+ conn.on('authentication', mustCall((ctx) => {
214
+ assert(ctx.username === username,
215
+ `Wrong username: ${ctx.username}`);
216
+ switch (++authAttempt) {
217
+ case 1:
218
+ assert(ctx.method === 'none', `Wrong auth method: ${ctx.method}`);
219
+ return ctx.reject();
220
+ case 2:
221
+ assert(ctx.method === 'publickey',
222
+ `Wrong auth method: ${ctx.method}`);
223
+ return ctx.reject();
224
+ case 3: {
225
+ assert(ctx.method === 'hostbased',
226
+ `Wrong auth method: ${ctx.method}`);
227
+ assert(ctx.key.algo === clientKey.key.type,
228
+ `Wrong key algo: ${ctx.key.algo}`);
229
+ assert.deepStrictEqual(clientKey.key.getPublicSSH(),
230
+ ctx.key.data,
231
+ 'Public key mismatch');
232
+ assert(ctx.signature, 'Expected signature');
233
+ assert(ctx.localHostname === localHostname, 'Wrong local hostname');
234
+ assert(ctx.localUsername === localUsername, 'Wrong local username');
235
+ const result =
236
+ clientKey.key.verify(ctx.blob, ctx.signature, ctx.hashAlgo);
237
+ assert(result === true, 'Could not verify hostbased signature');
238
+
239
+ break;
240
+ }
241
+ }
242
+ ctx.accept();
243
+ }, 3)).on('ready', mustCall(() => {
244
+ conn.end();
245
+ }));
246
+ }));
247
+ }
248
+
249
+
250
+ // keyboard-interactive ========================================================
251
+ {
252
+ const username = 'Keyboard-Interactive User';
253
+ const request = {
254
+ name: 'SSH2 Authentication',
255
+ instructions: 'These are instructions',
256
+ prompts: [
257
+ { prompt: 'Password: ', echo: false },
258
+ { prompt: 'Is the cake a lie? ', echo: true },
259
+ ],
260
+ };
261
+ const responses = [
262
+ 'foobarbaz',
263
+ 'yes',
264
+ ];
265
+ const { client, server } = setup(
266
+ 'Password (empty username)',
267
+ {
268
+ client: {
269
+ username,
270
+ tryKeyboard: true,
271
+ },
272
+ server: serverCfg,
273
+
274
+ debug,
275
+ }
276
+ );
277
+
278
+ server.on('connection', mustCall((conn) => {
279
+ let authAttempt = 0;
280
+ conn.on('authentication', mustCall((ctx) => {
281
+ assert(ctx.username === username,
282
+ `Wrong username: ${ctx.username}`);
283
+ if (++authAttempt === 1) {
284
+ assert(ctx.method === 'none', `Wrong auth method: ${ctx.method}`);
285
+ return ctx.reject();
286
+ }
287
+ assert(ctx.method === 'keyboard-interactive',
288
+ `Wrong auth method: ${ctx.method}`);
289
+ ctx.prompt(request.prompts,
290
+ request.name,
291
+ request.instructions,
292
+ mustCall((responses_) => {
293
+ assert.deepStrictEqual(responses_, responses);
294
+ ctx.accept();
295
+ }));
296
+ }, 2)).on('ready', mustCall(() => {
297
+ conn.end();
298
+ }));
299
+ }));
300
+
301
+ client.on('keyboard-interactive',
302
+ mustCall((name, instructions, lang, prompts, finish) => {
303
+ assert(name === request.name, `Wrong prompt name: ${name}`);
304
+ assert(instructions === request.instructions,
305
+ `Wrong prompt instructions: ${instructions}`);
306
+ assert.deepStrictEqual(
307
+ prompts,
308
+ request.prompts,
309
+ `Wrong prompts: ${inspect(prompts)}`
310
+ );
311
+ process.nextTick(finish, responses);
312
+ }));
313
+ }
314
+
315
+ // authHandler() tests =========================================================
316
+ {
317
+ const username = 'foo';
318
+ const password = '1234';
319
+ const clientKey = fixtureKey('id_rsa');
320
+ const { server } = setup(
321
+ 'authHandler() (sync)',
322
+ {
323
+ client: {
324
+ username,
325
+ password,
326
+ privateKey: clientKey.raw,
327
+
328
+ authHandler: mustCall((methodsLeft, partial, cb) => {
329
+ assert(methodsLeft === null, 'expected null methodsLeft');
330
+ assert(partial === null, 'expected null partial');
331
+ return 'none';
332
+ }),
333
+ },
334
+ server: serverCfg,
335
+
336
+ debug,
337
+ }
338
+ );
339
+
340
+ server.on('connection', mustCall((conn) => {
341
+ conn.on('authentication', mustCall((ctx) => {
342
+ assert(ctx.username === username, `Wrong username: ${ctx.username}`);
343
+ assert(ctx.method === 'none', `Wrong auth method: ${ctx.method}`);
344
+ ctx.accept();
345
+ })).on('ready', mustCall(() => {
346
+ conn.end();
347
+ }));
348
+ }));
349
+ }
350
+ {
351
+ const username = 'foo';
352
+ const password = '1234';
353
+ const clientKey = fixtureKey('id_rsa');
354
+ const { server } = setup(
355
+ 'authHandler() (async)',
356
+ {
357
+ client: {
358
+ username,
359
+ password,
360
+ privateKey: clientKey.raw,
361
+
362
+ authHandler: mustCall((methodsLeft, partial, cb) => {
363
+ assert(methodsLeft === null, 'expected null methodsLeft');
364
+ assert(partial === null, 'expected null partial');
365
+ process.nextTick(mustCall(cb), 'none');
366
+ }),
367
+ },
368
+ server: serverCfg,
369
+
370
+ debug,
371
+ }
372
+ );
373
+
374
+ server.on('connection', mustCall((conn) => {
375
+ conn.on('authentication', mustCall((ctx) => {
376
+ assert(ctx.username === username, `Wrong username: ${ctx.username}`);
377
+ assert(ctx.method === 'none', `Wrong auth method: ${ctx.method}`);
378
+ ctx.accept();
379
+ })).on('ready', mustCall(() => {
380
+ conn.end();
381
+ }));
382
+ }));
383
+ }
384
+ {
385
+ const username = 'foo';
386
+ const password = '1234';
387
+ const clientKey = fixtureKey('id_rsa');
388
+ const { client, server } = setup(
389
+ 'authHandler() (no methods left -- sync)',
390
+ {
391
+ client: {
392
+ username,
393
+ password,
394
+ privateKey: clientKey.raw,
395
+
396
+ authHandler: mustCall((methodsLeft, partial, cb) => {
397
+ assert(methodsLeft === null, 'expected null methodsLeft');
398
+ assert(partial === null, 'expected null partial');
399
+ return false;
400
+ }),
401
+ },
402
+ server: serverCfg,
403
+
404
+ debug,
405
+ noForceClientReady: true,
406
+ noForceServerReady: true,
407
+ }
408
+ );
409
+
410
+ // Remove default client error handler added by `setup()` since we are
411
+ // expecting an error in this case
412
+ client.removeAllListeners('error');
413
+
414
+ client.on('error', mustCall((err) => {
415
+ assert.strictEqual(err.level, 'client-authentication');
416
+ assert(/configured authentication methods failed/i.test(err.message),
417
+ 'Wrong error message');
418
+ }));
419
+
420
+ server.on('connection', mustCall((conn) => {
421
+ conn.on('authentication', mustNotCall())
422
+ .on('ready', mustNotCall());
423
+ }));
424
+ }
425
+ {
426
+ const username = 'foo';
427
+ const password = '1234';
428
+ const clientKey = fixtureKey('id_rsa');
429
+ const { client, server } = setup(
430
+ 'authHandler() (no methods left -- async)',
431
+ {
432
+ client: {
433
+ username,
434
+ password,
435
+ privateKey: clientKey.raw,
436
+
437
+ authHandler: mustCall((methodsLeft, partial, cb) => {
438
+ assert(methodsLeft === null, 'expected null methodsLeft');
439
+ assert(partial === null, 'expected null partial');
440
+ process.nextTick(mustCall(cb), false);
441
+ }),
442
+ },
443
+ server: serverCfg,
444
+
445
+ debug,
446
+ noForceClientReady: true,
447
+ noForceServerReady: true,
448
+ }
449
+ );
450
+
451
+ // Remove default client error handler added by `setup()` since we are
452
+ // expecting an error in this case
453
+ client.removeAllListeners('error');
454
+
455
+ client.on('error', mustCall((err) => {
456
+ assert.strictEqual(err.level, 'client-authentication');
457
+ assert(/configured authentication methods failed/i.test(err.message),
458
+ 'Wrong error message');
459
+ }));
460
+
461
+ server.on('connection', mustCall((conn) => {
462
+ conn.on('authentication', mustNotCall())
463
+ .on('ready', mustNotCall());
464
+ }));
465
+ }
466
+ {
467
+ const username = 'foo';
468
+ const password = '1234';
469
+ const clientKey = fixtureKey('id_rsa');
470
+ const events = [];
471
+ const expectedEvents = [
472
+ 'client', 'server', 'client', 'server'
473
+ ];
474
+ let clientCalls = 0;
475
+ const { client, server } = setup(
476
+ 'authHandler() (multi-step)',
477
+ {
478
+ client: {
479
+ username,
480
+ password,
481
+ privateKey: clientKey.raw,
482
+
483
+ authHandler: mustCall((methodsLeft, partial, cb) => {
484
+ events.push('client');
485
+ switch (++clientCalls) {
486
+ case 1:
487
+ assert(methodsLeft === null, 'expected null methodsLeft');
488
+ assert(partial === null, 'expected null partial');
489
+ return 'publickey';
490
+ case 2:
491
+ assert.deepStrictEqual(
492
+ methodsLeft,
493
+ ['password'],
494
+ `expected 'password' method left, saw: ${methodsLeft}`
495
+ );
496
+ assert(partial === true, 'expected partial success');
497
+ return 'password';
498
+ }
499
+ }, 2),
500
+ },
501
+ server: serverCfg,
502
+
503
+ debug,
504
+ }
505
+ );
506
+
507
+ server.on('connection', mustCall((conn) => {
508
+ let attempts = 0;
509
+ conn.on('authentication', mustCall((ctx) => {
510
+ assert(++attempts === clientCalls, 'server<->client state mismatch');
511
+ assert(ctx.username === username,
512
+ `Unexpected username: ${ctx.username}`);
513
+ events.push('server');
514
+ switch (attempts) {
515
+ case 1:
516
+ assert(ctx.method === 'publickey',
517
+ `Wrong auth method: ${ctx.method}`);
518
+ assert(ctx.key.algo === clientKey.key.type,
519
+ `Unexpected key algo: ${ctx.key.algo}`);
520
+ assert.deepEqual(clientKey.key.getPublicSSH(),
521
+ ctx.key.data,
522
+ 'Public key mismatch');
523
+ ctx.reject(['password'], true);
524
+ break;
525
+ case 2:
526
+ assert(ctx.method === 'password',
527
+ `Wrong auth method: ${ctx.method}`);
528
+ assert(ctx.password === password,
529
+ `Unexpected password: ${ctx.password}`);
530
+ ctx.accept();
531
+ break;
532
+ }
533
+ }, 2)).on('ready', mustCall(() => {
534
+ conn.end();
535
+ }));
536
+ }));
537
+
538
+ client.on('close', mustCall(() => {
539
+ assert.deepStrictEqual(events, expectedEvents);
540
+ }));
541
+ }
542
+ {
543
+ const username = 'foo';
544
+ const password = '1234';
545
+ const { server } = setup(
546
+ 'authHandler() (custom auth configuration)',
547
+ {
548
+ client: {
549
+ username: 'bar',
550
+ password: '5678',
551
+
552
+ authHandler: mustCall((methodsLeft, partial, cb) => {
553
+ assert(methodsLeft === null, 'expected null methodsLeft');
554
+ assert(partial === null, 'expected null partial');
555
+ return {
556
+ type: 'password',
557
+ username,
558
+ password,
559
+ };
560
+ }),
561
+ },
562
+ server: serverCfg,
563
+
564
+ debug,
565
+ }
566
+ );
567
+
568
+ server.on('connection', mustCall((conn) => {
569
+ conn.on('authentication', mustCall((ctx) => {
570
+ assert(ctx.username === username, `Wrong username: ${ctx.username}`);
571
+ assert(ctx.method === 'password', `Wrong auth method: ${ctx.method}`);
572
+ assert(ctx.password === password, `Unexpected password: ${ctx.password}`);
573
+ ctx.accept();
574
+ })).on('ready', mustCall(() => {
575
+ conn.end();
576
+ }));
577
+ }));
578
+ }
579
+ {
580
+ const username = 'foo';
581
+ const password = '1234';
582
+ const { server } = setup(
583
+ 'authHandler() (simple construction with custom auth configuration)',
584
+ {
585
+ client: {
586
+ username: 'bar',
587
+ password: '5678',
588
+
589
+ authHandler: [{
590
+ type: 'password',
591
+ username,
592
+ password,
593
+ }],
594
+ },
595
+ server: serverCfg,
596
+
597
+ debug,
598
+ }
599
+ );
600
+
601
+ server.on('connection', mustCall((conn) => {
602
+ conn.on('authentication', mustCall((ctx) => {
603
+ assert(ctx.username === username, `Wrong username: ${ctx.username}`);
604
+ assert(ctx.method === 'password', `Wrong auth method: ${ctx.method}`);
605
+ assert(ctx.password === password, `Unexpected password: ${ctx.password}`);
606
+ ctx.accept();
607
+ })).on('ready', mustCall(() => {
608
+ conn.end();
609
+ }));
610
+ }));
611
+ }
@@ -0,0 +1,25 @@
1
+ // Test for thread-safety issues caused by subsequent imports of the module
2
+ // in worker threads: https://github.com/mscdex/ssh2/issues/1393.
3
+ // Each subsequent worker increases probability of abnormal termination.
4
+ // The probability of a false pass due to zero response becomes negligible
5
+ // for 4 consecutive workers.
6
+ 'use strict';
7
+
8
+ let Worker, isMainThread;
9
+ try {
10
+ ({ Worker, isMainThread } = require('worker_threads'));
11
+ } catch (e) {
12
+ if (e.code !== 'MODULE_NOT_FOUND') throw e;
13
+ process.exit(0);
14
+ }
15
+ require('../lib/index.js');
16
+
17
+ if (isMainThread) {
18
+ async function runWorker() {
19
+ return new Promise((r) => new Worker(__filename).on('exit', r));
20
+ }
21
+ runWorker()
22
+ .then(runWorker)
23
+ .then(runWorker)
24
+ .then(runWorker);
25
+ }
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ const { spawnSync } = require('child_process');
4
+ const { readdirSync } = require('fs');
5
+ const { join } = require('path');
6
+
7
+ const files = readdirSync(__dirname).sort();
8
+ for (const filename of files) {
9
+ if (filename.startsWith('test-')) {
10
+ const path = join(__dirname, filename);
11
+ console.log(`> Running ${filename} ...`);
12
+ const result = spawnSync(`${process.argv0} ${path}`, {
13
+ shell: true,
14
+ stdio: 'inherit',
15
+ windowsHide: true
16
+ });
17
+ if (result.status !== 0)
18
+ process.exitCode = 1;
19
+ }
20
+ }
@@ -0,0 +1,2 @@
1
+ @cl /Ox pagent.c User32.lib
2
+ @del /Q *.obj