ssh-client-wrapper 2.6.2 → 2.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ services:
3
3
  testbed:
4
4
  image: naoso5/test-sshd
5
5
  ports:
6
- - "4000:22"
6
+ - "4100:22"
7
7
  container_name: testbed
8
8
  tester:
9
9
  build:
package/lib/fork.js CHANGED
@@ -4,7 +4,7 @@ const debugVerbose = require("debug")("sshClientWrapper:verbose:fork");
4
4
  const debugSendPty = require("debug")("sshClientWrapperInsecure:fork_sendpty");
5
5
  const { spawn } = require("node-pty");
6
6
 
7
- const { rePwPrompt, rePhPrompt, reNewHostPrompt, buff2String, sendPty, watchDogTimer } = require("./util.js");
7
+ const { rePwPrompt, rePhPrompt, reNewHostPrompt, reRemoteHostIdentificationHasChanged, buff2String, sendPty, watchDogTimer } = require("./util.js");
8
8
 
9
9
  const nodePtyOpt = {
10
10
  shell: process.platform === "win32" ? process.env.ComSpec : process.env.SHELL,
@@ -13,7 +13,19 @@ const nodePtyOpt = {
13
13
 
14
14
  function sshLoginCallback (output, ptyProcess, pw, ph, logger = debugSendPty) {
15
15
  return new Promise((resolve, reject) => {
16
+ if (reRemoteHostIdentificationHasChanged.test(output)) {
17
+ debug("REMOTE HOST IDENTIFICATION HAS CHANGED");
18
+ const rt = /known_hosts:(\d+)/.exec(output);
19
+ const rt2 = /Host key for (.+) has changed and you have requested strict checking./.exec(output);
20
+ const err = new Error("REMOTE HOST IDENTIFICATION HAS CHANGED");
21
+ err.code = "HostKeyError";
22
+ err.output = output;
23
+ err.lineNumber = rt[1] || null;
24
+ err.host = rt2[1] || null;
25
+ reject(err);
26
+ }
16
27
  if (reNewHostPrompt.test(output)) {
28
+ debug("get warning about new host and send yes automatically");
17
29
  sendPty(ptyProcess, "yes\n", logger, 17);
18
30
  resolve();
19
31
  }
package/lib/index.js CHANGED
@@ -23,7 +23,7 @@ const { isArrayOfString, sanityCheck } = require("./util.js");
23
23
  * @param {string | Function} hostInfo.password - password or function which return password
24
24
  * @param {string | Function} hostInfo.passphrase - passphrase or function which return passphrase of private key
25
25
  * @param {string} hostInfo.keyFile - private key filename
26
- * @param {boolean} hostInfo.noStrictHostkeyChecking - bypass host key checking if true
26
+ * @param {boolean} hostInfo.noStrictHostKeyChecking - bypass host key checking if true
27
27
  * @param {Integer} hostInfo.ControlPersist=180 - how long keep master connection after last client connection has been closed (sec).
28
28
  * @param {Integer} hostInfo.ConnectTimeout=60 - timeout used when connectiong to ths SSH server
29
29
  * @param {Integer} hostInfo.maxRetry=3 - max number of retry
package/lib/util.js CHANGED
@@ -11,7 +11,7 @@ const acceptableRsyncRetrunCodes = [10, 11, 12, 13, 14];
11
11
  const rePwPrompt = /password:/;
12
12
  const rePhPrompt = /Enter passphrase for key/;
13
13
  const reNewHostPrompt = /Are you sure you want to continue connecting/;
14
-
14
+ const reRemoteHostIdentificationHasChanged = /WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! /;
15
15
  const Ajv = require("ajv");
16
16
 
17
17
  const ajv = new Ajv({
@@ -34,7 +34,7 @@ const hostInfoSchema = {
34
34
  user: { type: "string", pattern: "\\S+", transform: ["trim"] },
35
35
  port: { type: "number", minimum: 0, maximum: 65535 },
36
36
  keyFile: { type: "string", pattern: "\\S+", transform: ["trim"] },
37
- noStrictHostkeyChecking: { type: "boolean" },
37
+ noStrictHostKeyChecking: { type: "boolean" },
38
38
  ControlPersist: { type: "number", minimum: 0, default: 180 },
39
39
  ConnectTimeout: { type: "number", minimum: 0 },
40
40
  ControlPersistDir: { type: "string", pattern: "\\S+", transform: ["trim"] },
@@ -190,7 +190,7 @@ const getSshOption = (hostInfo, withoutDestination) => {
190
190
  }
191
191
  }
192
192
 
193
- if (hostInfo.noStrictHostkeyChecking) {
193
+ if (hostInfo.noStrictHostKeyChecking) {
194
194
  args.push("-oStrictHostKeyChecking=no");
195
195
  }
196
196
  const controlPersist = Number.isInteger(hostInfo.ControlPersist) && hostInfo.ControlPersist >= 0 ? hostInfo.ControlPersist : "180";
@@ -264,6 +264,7 @@ module.exports = {
264
264
  rePwPrompt,
265
265
  rePhPrompt,
266
266
  reNewHostPrompt,
267
+ reRemoteHostIdentificationHasChanged,
267
268
  buff2String,
268
269
  getSshOption,
269
270
  sanityCheck,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssh-client-wrapper",
3
- "version": "2.6.2",
3
+ "version": "2.9.1",
4
4
  "description": "wrapper library for open ssh client and rsync",
5
5
  "keywords": [
6
6
  "ssh",
@@ -34,10 +34,10 @@
34
34
  "*.js": "eslint --fix"
35
35
  },
36
36
  "dependencies": {
37
- "ajv": "^8.12.0",
37
+ "ajv": "^8.13.0",
38
38
  "ajv-keywords": "^5.1.0",
39
39
  "debug": "^4.3.4",
40
- "glob": "^10.3.10",
40
+ "glob": "^10.3.12",
41
41
  "node-pty": "^0.10.1",
42
42
  "promise-retry": "^2.0.1"
43
43
  },
package/run_test_all.sh CHANGED
@@ -11,8 +11,8 @@ docker-compose up testbed -d
11
11
  export TEST_HOST=localhost
12
12
  export TEST_USER=testuser
13
13
  export TEST_PW=passw0rd
14
- export TEST_PORT=4000
15
- ssh-keygen -R '[localhost]:4000'
14
+ export TEST_PORT=4100
15
+ ssh-keygen -R '[localhost]:4100'
16
16
 
17
17
  npm run test
18
18
  echo local test success
@@ -78,21 +78,21 @@ describe("test for sanityCheck", () => {
78
78
  it("should just change type if string value specified for boolean member", () => {
79
79
  expect(sanityCheck({
80
80
  host,
81
- noStrictHostkeyChecking: "true"
81
+ noStrictHostKeyChecking: "true"
82
82
  })).to.deep.equal({
83
83
  host,
84
84
  ...defaultValues,
85
- noStrictHostkeyChecking: true
85
+ noStrictHostKeyChecking: true
86
86
  });
87
87
  });
88
88
  it("should just change type if number value specified for boolean member", () => {
89
89
  expect(sanityCheck({
90
90
  host,
91
- noStrictHostkeyChecking: 0
91
+ noStrictHostKeyChecking: 0
92
92
  })).to.deep.equal({
93
93
  host,
94
94
  ...defaultValues,
95
- noStrictHostkeyChecking: false
95
+ noStrictHostKeyChecking: false
96
96
  });
97
97
  });
98
98
  it("shold keep addtional properties", () => {