ssh-client-wrapper 3.3.2 → 3.3.4
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 +1 -1
- package/lib/agent.js +14 -1
- package/lib/rsyncExec.js +1 -1
- package/lib/util.js +25 -2
- package/package.json +1 -1
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"),
|
|
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/rsyncExec.js
CHANGED
|
@@ -143,7 +143,7 @@ export async function recv(hostInfo, argSrc, dst, rsyncOpt, timeout, retryableEx
|
|
|
143
143
|
const args = ["-avv", "--copy-unsafe-links", ...rshOpt, ...rsyncOpt, ...src, dst];
|
|
144
144
|
|
|
145
145
|
//make destination directory
|
|
146
|
-
const dstDir =
|
|
146
|
+
const dstDir = src.length > 1 || hasMagic(argSrc[0]) ? dst : path.dirname(dst);
|
|
147
147
|
await fs.mkdir(dstDir, { recursive: true });
|
|
148
148
|
|
|
149
149
|
debug(`recv ${src.join(" ")} to ${dst}`);
|
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
|
-
|
|
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
|
/**
|