ssh-client-wrapper 3.3.1 → 3.3.3

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/README.md CHANGED
@@ -222,7 +222,7 @@ If no agent can be used, or `ssh-add` fails, the wrapper silently falls back to
222
222
 
223
223
  **Keyless / browser agents:** with no `keyFile`, set `identityAgent` to the socket of an already-populated agent (for example [`bssh-agent`](https://github.com/so5/browser-ssh-agent), which keeps the private key in a browser tab) and the wrapper will authenticate through it.
224
224
 
225
- **Windows:** an already-running agent (the OpenSSH Authentication Agent service, or a supplied `identityAgent`) is used, but the wrapper never spawns one; without a reachable agent it falls back to the legacy path.
225
+ **Windows:** an already-running agent (the OpenSSH Authentication Agent service, or a supplied `identityAgent`) is used, but the wrapper never spawns one; without a reachable agent it falls back to the legacy path. The agent of Windows refuses keys with a lifetime, so `agentKeyTTL` is not applied there (the key stays in the agent until it is removed or the agent stops). Git for Windows' ssh/ssh-add can not use the Windows agent service; the wrapper then falls back to the legacy path.
226
226
 
227
227
  ## Running the tests
228
228
 
package/lib/agent.js CHANGED
@@ -234,6 +234,18 @@ async function resolvePassphrase(ph) {
234
234
  return null;
235
235
  }
236
236
 
237
+ /**
238
+ * arguments of ssh-add to add a key
239
+ * the ssh-agent of Windows refuses a key with a lifetime ("agent refused operation"), so -t is not passed there
240
+ * @param {string} keyFile - private key path
241
+ * @param {number} ttl - ssh-add -t lifetime in seconds
242
+ * @param {string} platform - platform name (for tests)
243
+ * @returns {string[]} - arguments
244
+ */
245
+ function addKeyArgs(keyFile, ttl, platform = process.platform) {
246
+ return platform === "win32" ? [keyFile] : ["-t", String(ttl), keyFile];
247
+ }
248
+
237
249
  /**
238
250
  * add a key to an agent via `ssh-add`, answering the passphrase prompt from a pty
239
251
  * @param {string} sock - agent socket path (or AGENT_DEFAULT)
@@ -244,7 +256,7 @@ async function resolvePassphrase(ph) {
244
256
  */
245
257
  function addKey(sock, keyFile, phCallback, ttl) {
246
258
  return new Promise((resolve, reject)=>{
247
- const pty = _internal.spawn(resolveExecutable("ssh-add"), ["-t", String(ttl), keyFile], {
259
+ const pty = _internal.spawn(resolveExecutable("ssh-add"), addKeyArgs(keyFile, ttl), {
248
260
  windowsHide: true,
249
261
  env: sockEnv(sock)
250
262
  });
@@ -512,6 +524,7 @@ async function ensureAgentForHost(hostInfo) {
512
524
  }
513
525
 
514
526
  export {
527
+ addKeyArgs,
515
528
  shouldUseAgent,
516
529
  canSpawnSharedAgent,
517
530
  ensureAgentForHost,
package/lib/sshExec.js CHANGED
@@ -101,6 +101,8 @@ export async function canConnect(hostInfo, timeout) {
101
101
  debug("canConnect called");
102
102
  sanityCheck(hostInfo);
103
103
 
104
+ //login must be tried again even if the host has been verified before (the credentials may have changed)
105
+ delete hostInfo._connectionVerified;
104
106
  await connect(hostInfo, timeout);
105
107
  await disconnect(hostInfo);
106
108
  //if connection fail, Error is throwed.
@@ -180,6 +182,7 @@ async function verifyConnection(hostInfo, timeout) {
180
182
  } else if (/Operation|Connection timed out/.test(output)) {
181
183
  err.message = "Operation timed out";
182
184
  } else {
185
+ e.output = output;
183
186
  throw e;
184
187
  }
185
188
  throw err;
package/lib/util.js CHANGED
@@ -107,13 +107,36 @@ const numberOptions = [
107
107
 
108
108
  const validate = ajv.compile(hostInfoSchema);
109
109
 
110
+ //CSI sequence, OSC sequence (terminated by BEL or ST) and the other two-character escape sequences
111
+ //eslint-disable-next-line no-control-regex
112
+ const reTerminalSequences = /\u001b\[[0-?]*[ -/]*[@-~]|\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)|\u001b[@-Z\\^_]/g;
113
+
114
+ /**
115
+ * remove terminal control sequences from output of a pty
116
+ * ConPTY on Windows redraws the screen, so they surround the real output
117
+ * @param {string} str - output of a pty
118
+ * @returns {string} - str without control sequences
119
+ */
120
+ export const stripTerminalSequences = (str)=>{
121
+ return str.replace(reTerminalSequences, "");
122
+ };
123
+
110
124
  /**
111
125
  * bridge function to functions which need string
126
+ * control sequences are removed on win32, and func is not called if nothing is left
112
127
  * @param {Function} func - function
113
128
  * @param {data} data - binary data which can be converted to string
129
+ * @param {string} platform - platform name (for tests)
114
130
  */
115
- export const buff2String = (func, data)=>{
116
- func(data.toString().replace(/\r\n/g, EOL));
131
+ export const buff2String = (func, data, platform = process.platform)=>{
132
+ let str = data.toString();
133
+ if (platform === "win32") {
134
+ str = stripTerminalSequences(str);
135
+ if (str === "") {
136
+ return;
137
+ }
138
+ }
139
+ func(str.replace(/\r\n/g, EOL));
117
140
  };
118
141
 
119
142
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssh-client-wrapper",
3
- "version": "3.3.1",
3
+ "version": "3.3.3",
4
4
  "description": "wrapper library for open ssh client and rsync",
5
5
  "keywords": [
6
6
  "ssh",