pi-remote-call 0.3.2 → 0.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/CHANGELOG.md +18 -0
- package/README.md +7 -6
- package/package.json +1 -1
- package/src/host-key.ts +29 -1
- package/src/host-manager.ts +2 -1
- package/src/remote-helper.ts +7 -0
- package/src/ssh-config.ts +9 -0
- package/src/transport.ts +54 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.3 - 2026-11-29
|
|
4
|
+
|
|
5
|
+
### Security
|
|
6
|
+
|
|
7
|
+
- Apply the effective OpenSSH `HostKeyAlgorithms` allowlist to every SSH hop. Configuration with no supported host-key algorithm fails closed instead of silently widening policy.
|
|
8
|
+
- Refuse non-`none` `RevokedHostKeys`/KRL configuration before DNS, known-hosts lookup, authentication, or proxy setup; full KRL evaluation remains unsupported. Existing `@revoked` known-hosts entries are still enforced.
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Preserve network, timeout, proxy, and authentication error categories instead of reporting every failed connection as `E_AUTH`.
|
|
13
|
+
- Absorb repeated SSH errors while a failed handshake is being cleaned up, and retain the active ProxyJump/ProxyCommand context in diagnostics.
|
|
14
|
+
- Treat numeric exit status 1 from `ssh-keygen -F` as no known-hosts match on all supported platforms.
|
|
15
|
+
- Report a sanitized `helperCacheError` stage and reason when cache initialization falls back to the inline helper.
|
|
16
|
+
|
|
17
|
+
### Tests
|
|
18
|
+
|
|
19
|
+
- Add real OpenSSH coverage for session loss without exit status, cancellation and remote process-group cleanup, corrupted helper caches, inline-cache fallback diagnostics, and injected `fsync` failure without target modification.
|
|
20
|
+
|
|
3
21
|
## 0.3.2 - 2026-11-28
|
|
4
22
|
|
|
5
23
|
### Added
|
package/README.md
CHANGED
|
@@ -25,13 +25,13 @@ Remote machine:
|
|
|
25
25
|
### npm
|
|
26
26
|
|
|
27
27
|
```sh
|
|
28
|
-
pi install npm:pi-remote-call@0.3.
|
|
28
|
+
pi install npm:pi-remote-call@0.3.3
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
### GitHub
|
|
32
32
|
|
|
33
33
|
```sh
|
|
34
|
-
pi install git:github.com/therainisme/pi-remote-call@v0.3.
|
|
34
|
+
pi install git:github.com/therainisme/pi-remote-call@v0.3.3
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
### Local directory
|
|
@@ -49,7 +49,7 @@ Create `~/.pi/agent/pi-remote-call.json`:
|
|
|
49
49
|
}
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
Only aliases in `hosts[]` can be used. User, hostname, port, identity files, agent, `HostKeyAlias`, and known-hosts paths come from the existing OpenSSH configuration via `ssh -G <alias>`; secrets and connection fields are not duplicated into this file.
|
|
52
|
+
Only aliases in `hosts[]` can be used. User, hostname, port, identity files, agent, `HostKeyAlias`, `HostKeyAlgorithms`, and known-hosts paths come from the existing OpenSSH configuration via `ssh -G <alias>`; secrets and connection fields are not duplicated into this file.
|
|
53
53
|
|
|
54
54
|
Set `PI_REMOTE_CALL_CONFIG` to use a different local config path.
|
|
55
55
|
|
|
@@ -64,7 +64,7 @@ Each new connection probes for Python 3 and reports `fileMode` in host status an
|
|
|
64
64
|
|
|
65
65
|
Python is never installed by this extension. The helper runs without a daemon, remote Pi, Node.js, or MCP server. Its source is cached at `~/.pi/agent/cache/pi-remote-call/helper-v1-<sha256>.py`; the directory is mode `0700` and the helper is `0600`. Each connection verifies the regular file, size, and SHA-256 before its first cached operation, and concurrent callers share that initialization. Cache installation uses a temporary file, `fsync`, and atomic rename. Old versions are not deleted automatically.
|
|
66
66
|
|
|
67
|
-
If the cache cannot be prepared, the helper source is sent inline instead. Fallback is selected before an operation starts: a Python operation that fails is never replayed through SFTP. Host status reports `helperCache` as `installed`, `hit`, or `inline` after initialization.
|
|
67
|
+
If the cache cannot be prepared, the helper source is sent inline instead. Fallback is selected before an operation starts: a Python operation that fails is never replayed through SFTP. Host status reports `helperCache` as `installed`, `hit`, or `inline` after initialization. Inline fallback also exposes a sanitized `helperCacheError` with the failed stage and reason.
|
|
68
68
|
|
|
69
69
|
## Tools
|
|
70
70
|
|
|
@@ -150,6 +150,7 @@ Connections also close during Pi session shutdown. A later call reconnects on de
|
|
|
150
150
|
## Failure behavior
|
|
151
151
|
|
|
152
152
|
- Unknown or changed host keys fail. The extension never disables host-key checks or automatically trusts a new key.
|
|
153
|
+
- Effective `HostKeyAlgorithms` are enforced on every hop. If no configured algorithm is supported by the transport, the connection fails closed. Non-`none` `RevokedHostKeys`/KRL configuration is also refused before connection setup because full KRL evaluation is not implemented; `@revoked` known-hosts entries remain supported.
|
|
153
154
|
- Passwords, private-key passphrases, interactive 2FA, and keyboard-interactive authentication are not requested. Fix `ssh <alias>` so it works noninteractively first.
|
|
154
155
|
- A failed command or write is not automatically replayed after reconnecting.
|
|
155
156
|
- Bash commands use a random stderr completion marker to recover the real exit code if SSH omits `exit-status`. If both are absent, the outcome remains unknown. A Python helper success is accepted without either status only when its complete JSON envelope contains `result`; writes are never replayed.
|
|
@@ -164,7 +165,7 @@ Connections also close during Pi session shutdown. A later call reconnects on de
|
|
|
164
165
|
- Remote paths use POSIX `/`. Local Windows is supported. However, when Pi runs on Windows, `remote_read` cannot address a remote POSIX file name containing a literal backslash (`\`), because Pi's native read parser treats it as a path separator. Normal `/` paths and the other remote tools are unaffected.
|
|
165
166
|
- No interactive terminal, port forwarding, remote Pi worker, or separate search tool. Use `remote_bash` with existing remote tools such as `rg` for search.
|
|
166
167
|
- SFTP compatibility mode retains 0.1.1 behavior, including whole-file network reads and whole-file edit download/upload. Use Python mode for large remote text files.
|
|
167
|
-
- Python edit loads file content into remote memory
|
|
168
|
+
- Python edit loads file content into remote memory. Read retains only the requested lines but scans to EOF for exact `totalFileLines`, matching Pi's native read behavior. Atomic rename reduces partial-file writes but cannot eliminate the small check/rename race or make a disconnected operation's outcome certain.
|
|
168
169
|
- Python mode refuses hard-linked files, special mode bits, and metadata it cannot preserve. SFTP mode has the original 0.1.1 metadata and race limitations.
|
|
169
170
|
|
|
170
171
|
## Development
|
|
@@ -176,7 +177,7 @@ npm run check
|
|
|
176
177
|
|
|
177
178
|
`npm run check` typechecks, builds, and runs unit/integration tests. It does not open SSH connections unless `PI_REMOTE_CALL_E2E=1` is explicitly set on Linux.
|
|
178
179
|
|
|
179
|
-
Helper integration tests run when `python3` is available. Set `PI_REMOTE_CALL_PYTHON` to select a specific local interpreter; CI provisions Python explicitly. Ordinary local tests do not open SSH connections. Ubuntu CI additionally installs OpenSSH server and sets `PI_REMOTE_CALL_E2E=1` to run direct, ProxyJump, ProxyCommand, file-operation,
|
|
180
|
+
Helper integration tests run when `python3` is available. Set `PI_REMOTE_CALL_PYTHON` to select a specific local interpreter; CI provisions Python explicitly. Ordinary local tests do not open SSH connections. Ubuntu CI additionally installs OpenSSH server and sets `PI_REMOTE_CALL_E2E=1` to run direct, ProxyJump, ProxyCommand, file-operation, host-key diagnostics, session loss, cancellation, cache corruption/fallback, and injected `fsync` failure against temporary local `sshd` instances with generated keys and random ports.
|
|
180
181
|
|
|
181
182
|
Package layout:
|
|
182
183
|
|
package/package.json
CHANGED
package/src/host-key.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
+
import type { ServerHostKeyAlgorithm } from "ssh2";
|
|
3
4
|
import type { EffectiveSshConfig } from "./ssh-config.ts";
|
|
4
5
|
import { RemoteCallError } from "./errors.ts";
|
|
5
6
|
|
|
@@ -9,6 +10,32 @@ export interface KnownHostEntry {
|
|
|
9
10
|
certAuthority?: boolean;
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
const SSH2_HOST_KEY_ALGORITHMS = new Set<string>([
|
|
14
|
+
"ssh-ed25519",
|
|
15
|
+
"ecdsa-sha2-nistp256",
|
|
16
|
+
"ecdsa-sha2-nistp384",
|
|
17
|
+
"ecdsa-sha2-nistp521",
|
|
18
|
+
"rsa-sha2-512",
|
|
19
|
+
"rsa-sha2-256",
|
|
20
|
+
"ssh-rsa",
|
|
21
|
+
"ssh-dss",
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
export function selectServerHostKeyAlgorithms(config: EffectiveSshConfig): ServerHostKeyAlgorithm[] | undefined {
|
|
25
|
+
if (!config.hostKeyAlgorithms?.length) return undefined;
|
|
26
|
+
const selected = [...new Set(config.hostKeyAlgorithms.filter((algorithm): algorithm is ServerHostKeyAlgorithm =>
|
|
27
|
+
SSH2_HOST_KEY_ALGORITHMS.has(algorithm)
|
|
28
|
+
))];
|
|
29
|
+
if (selected.length === 0) {
|
|
30
|
+
throw new RemoteCallError(
|
|
31
|
+
"E_UNSUPPORTED_SSH_OPTION",
|
|
32
|
+
`None of the HostKeyAlgorithms configured for ${config.alias} are supported by the ssh2 transport`,
|
|
33
|
+
"Certificate and security-key host algorithms require separate transport support",
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return selected;
|
|
37
|
+
}
|
|
38
|
+
|
|
12
39
|
export function parseKnownHosts(output: string): KnownHostEntry[] {
|
|
13
40
|
const entries: KnownHostEntry[] = [];
|
|
14
41
|
for (const rawLine of output.split(/\r?\n/)) {
|
|
@@ -32,7 +59,8 @@ async function lookupKnownHosts(target: string, file: string): Promise<KnownHost
|
|
|
32
59
|
if (!existsSync(file)) return [];
|
|
33
60
|
return new Promise((resolve, reject) => {
|
|
34
61
|
execFile("ssh-keygen", ["-F", target, "-f", file], { timeout: 10_000, windowsHide: true }, (error, stdout) => {
|
|
35
|
-
|
|
62
|
+
const exitCode = error ? (error as unknown as { code?: unknown }).code : undefined;
|
|
63
|
+
if (error && exitCode !== 1 && exitCode !== "1") {
|
|
36
64
|
// A missing known_hosts file is equivalent to no matching entries.
|
|
37
65
|
if ((error as NodeJS.ErrnoException).code === "ENOENT") return resolve([]);
|
|
38
66
|
return reject(error);
|
package/src/host-manager.ts
CHANGED
|
@@ -13,7 +13,7 @@ export class HostManager {
|
|
|
13
13
|
|
|
14
14
|
constructor(readonly config: RemoteCallConfig) {}
|
|
15
15
|
|
|
16
|
-
list(): Array<{ host: string; connected: boolean; home?: string; hostname?: string; user?: string; platform?: string; fileMode?: "python" | "sftp"; pythonVersion?: string; helperCache?: "hit" | "installed" | "inline" }> {
|
|
16
|
+
list(): Array<{ host: string; connected: boolean; home?: string; hostname?: string; user?: string; platform?: string; fileMode?: "python" | "sftp"; pythonVersion?: string; helperCache?: "hit" | "installed" | "inline"; helperCacheError?: string }> {
|
|
17
17
|
return this.config.hosts.map((host) => {
|
|
18
18
|
const connection = this.entries.get(host)?.connection;
|
|
19
19
|
return {
|
|
@@ -28,6 +28,7 @@ export class HostManager {
|
|
|
28
28
|
fileMode: connection.facts.fileMode,
|
|
29
29
|
pythonVersion: connection.facts.python?.version,
|
|
30
30
|
...(connection.facts.helperCache ? { helperCache: connection.facts.helperCache } : {}),
|
|
31
|
+
...(connection.facts.helperCacheError ? { helperCacheError: connection.facts.helperCacheError } : {}),
|
|
31
32
|
}
|
|
32
33
|
: {}),
|
|
33
34
|
};
|
package/src/remote-helper.ts
CHANGED
|
@@ -10,3 +10,10 @@ export const PYTHON_HELPER_BYTES = Buffer.byteLength(PYTHON_HELPER_SOURCE, "utf8
|
|
|
10
10
|
export function pythonHelperCachePath(home: string): string {
|
|
11
11
|
return posix.join(home, ".pi", "agent", "cache", "pi-remote-call", `helper-v${PYTHON_HELPER_PROTOCOL}-${PYTHON_HELPER_SHA256}.py`);
|
|
12
12
|
}
|
|
13
|
+
|
|
14
|
+
export function helperCacheErrorMessage(stage: string, error: unknown, home: string): string {
|
|
15
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
16
|
+
const withoutHome = home ? message.split(home).join("~") : message;
|
|
17
|
+
const sanitized = withoutHome.replace(/[\u0000-\u001f\u007f]+/g, " ").trim();
|
|
18
|
+
return `${stage}: ${sanitized || "unknown error"}`.slice(0, 400);
|
|
19
|
+
}
|
package/src/ssh-config.ts
CHANGED
|
@@ -18,6 +18,8 @@ export interface EffectiveSshConfig {
|
|
|
18
18
|
proxyJump?: string;
|
|
19
19
|
proxyCommand?: string;
|
|
20
20
|
hostKeyAlias?: string;
|
|
21
|
+
hostKeyAlgorithms?: string[];
|
|
22
|
+
revokedHostKeys?: string;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
function unquote(value: string): string {
|
|
@@ -110,6 +112,11 @@ export function parseSshG(alias: string, output: string): EffectiveSshConfig {
|
|
|
110
112
|
].map((path) => normalizeLocalSshPath(path));
|
|
111
113
|
if (knownHostsFiles.length === 0) knownHostsFiles.push(join(homedir(), ".ssh", "known_hosts"));
|
|
112
114
|
const proxyJump = one("proxyjump");
|
|
115
|
+
const hostKeyAlgorithms = one("hostkeyalgorithms")?.split(",").map((value) => value.trim()).filter(Boolean);
|
|
116
|
+
const revokedHostKeysValue = one("revokedhostkeys");
|
|
117
|
+
const revokedHostKeys = revokedHostKeysValue && revokedHostKeysValue.toLowerCase() !== "none"
|
|
118
|
+
? normalizeLocalSshPath(revokedHostKeysValue)
|
|
119
|
+
: undefined;
|
|
113
120
|
return {
|
|
114
121
|
alias,
|
|
115
122
|
host,
|
|
@@ -122,6 +129,8 @@ export function parseSshG(alias: string, output: string): EffectiveSshConfig {
|
|
|
122
129
|
proxyJump: proxyJump && proxyJump !== "none" ? proxyJump : undefined,
|
|
123
130
|
proxyCommand: one("proxycommand") && one("proxycommand") !== "none" ? one("proxycommand") : undefined,
|
|
124
131
|
hostKeyAlias: one("hostkeyalias"),
|
|
132
|
+
...(hostKeyAlgorithms?.length ? { hostKeyAlgorithms } : {}),
|
|
133
|
+
...(revokedHostKeys ? { revokedHostKeys } : {}),
|
|
125
134
|
};
|
|
126
135
|
}
|
|
127
136
|
|
package/src/transport.ts
CHANGED
|
@@ -2,13 +2,13 @@ import { randomBytes } from "node:crypto";
|
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
import { posix } from "node:path";
|
|
4
4
|
import type { Duplex } from "node:stream";
|
|
5
|
-
import { Client, type ClientChannel, type ConnectConfig, type SFTPWrapper } from "ssh2";
|
|
5
|
+
import { Client, type ClientChannel, type ConnectConfig, type ServerHostKeyAlgorithm, type SFTPWrapper } from "ssh2";
|
|
6
6
|
import type { BashOperations, EditOperations, ReadOperations, WriteOperations } from "@earendil-works/pi-coding-agent";
|
|
7
7
|
import { asRemoteCallError, RemoteCallError } from "./errors.ts";
|
|
8
8
|
import { ExitMarkerFilter } from "./exit-marker.ts";
|
|
9
|
-
import { loadKnownHostEntries, verifyKnownHostKey, type KnownHostEntry } from "./host-key.ts";
|
|
9
|
+
import { loadKnownHostEntries, selectServerHostKeyAlgorithms, verifyKnownHostKey, type KnownHostEntry } from "./host-key.ts";
|
|
10
10
|
import type { PythonFileRequest } from "./python-files.ts";
|
|
11
|
-
import { PYTHON_HELPER_BYTES, PYTHON_HELPER_SHA256, PYTHON_HELPER_SOURCE, pythonHelperCachePath } from "./remote-helper.ts";
|
|
11
|
+
import { PYTHON_HELPER_BYTES, PYTHON_HELPER_SHA256, PYTHON_HELPER_SOURCE, helperCacheErrorMessage, pythonHelperCachePath } from "./remote-helper.ts";
|
|
12
12
|
import { parsePythonHelperResponse } from "./python-protocol.ts";
|
|
13
13
|
import { openProxyCommand, parseProxyJumpDestination } from "./proxy.ts";
|
|
14
14
|
import { remoteCommandScript, shellQuote } from "./remote-path.ts";
|
|
@@ -35,6 +35,7 @@ export interface RemoteHostFacts {
|
|
|
35
35
|
fileMode: "python" | "sftp";
|
|
36
36
|
python?: { path: string; version: string };
|
|
37
37
|
helperCache?: "hit" | "installed" | "inline";
|
|
38
|
+
helperCacheError?: string;
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
type AuthAttempt =
|
|
@@ -106,10 +107,12 @@ async function connectWithAttempt(
|
|
|
106
107
|
knownHosts: KnownHostEntry[],
|
|
107
108
|
attempt: AuthAttempt,
|
|
108
109
|
sock?: Duplex,
|
|
110
|
+
hostKeyAlgorithms?: ServerHostKeyAlgorithm[],
|
|
109
111
|
): Promise<Client> {
|
|
110
112
|
return new Promise((resolve, reject) => {
|
|
111
113
|
const client = new Client();
|
|
112
114
|
let hostKeyError: RemoteCallError | undefined;
|
|
115
|
+
let settled = false;
|
|
113
116
|
const options: ConnectConfig = {
|
|
114
117
|
host: config.host,
|
|
115
118
|
port: config.port,
|
|
@@ -130,15 +133,19 @@ async function connectWithAttempt(
|
|
|
130
133
|
},
|
|
131
134
|
};
|
|
132
135
|
if (sock) options.sock = sock;
|
|
136
|
+
if (hostKeyAlgorithms) options.algorithms = { serverHostKey: hostKeyAlgorithms };
|
|
133
137
|
if (attempt.kind === "agent") options.agent = attempt.agent;
|
|
134
138
|
else options.privateKey = attempt.privateKey;
|
|
135
139
|
const onError = (error: Error) => {
|
|
136
140
|
client.end();
|
|
141
|
+
if (settled) return;
|
|
142
|
+
settled = true;
|
|
137
143
|
if (hostKeyError) return reject(hostKeyError);
|
|
138
144
|
reject(error);
|
|
139
145
|
};
|
|
140
|
-
client.
|
|
146
|
+
client.on("error", onError);
|
|
141
147
|
client.once("ready", () => {
|
|
148
|
+
settled = true;
|
|
142
149
|
client.removeListener("error", onError);
|
|
143
150
|
client.on("error", () => undefined);
|
|
144
151
|
resolve(client);
|
|
@@ -162,6 +169,14 @@ async function authAttempts(config: EffectiveSshConfig): Promise<AuthAttempt[]>
|
|
|
162
169
|
return attempts;
|
|
163
170
|
}
|
|
164
171
|
|
|
172
|
+
export function isAuthenticationFailure(error: unknown): boolean {
|
|
173
|
+
if (error instanceof RemoteCallError) return error.code === "E_AUTH";
|
|
174
|
+
const candidate = error as { level?: unknown } | undefined;
|
|
175
|
+
if (candidate?.level === "client-authentication") return true;
|
|
176
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
177
|
+
return /Cannot parse privateKey|encrypted private key|private key.*passphrase|All configured authentication methods failed/i.test(message);
|
|
178
|
+
}
|
|
179
|
+
|
|
165
180
|
export type SshConfigResolver = (specification: string) => Promise<EffectiveSshConfig>;
|
|
166
181
|
|
|
167
182
|
interface ClientTransport {
|
|
@@ -193,12 +208,22 @@ async function connectClient(
|
|
|
193
208
|
if (!via && config.proxyJump && config.proxyCommand) {
|
|
194
209
|
throw new RemoteCallError("E_SSH_CONFIG", `${config.alias} has both ProxyJump and ProxyCommand; use one proxy method`);
|
|
195
210
|
}
|
|
211
|
+
if (config.revokedHostKeys) {
|
|
212
|
+
throw new RemoteCallError(
|
|
213
|
+
"E_UNSUPPORTED_SSH_OPTION",
|
|
214
|
+
`${config.alias} uses RevokedHostKeys/KRL, which this transport cannot enforce`,
|
|
215
|
+
"The connection was refused before authentication. KRL support is required for this alias",
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
const hostKeyAlgorithms = selectServerHostKeyAlgorithms(config);
|
|
219
|
+
let transportDescription = via ? `ProxyJump forwarding for ${config.alias}` : `SSH transport for ${config.alias}`;
|
|
196
220
|
const parents: Client[] = [];
|
|
197
221
|
try {
|
|
198
222
|
// A socket supplied by an explicit ProxyJump list defines this hop's route.
|
|
199
223
|
// Do not apply the hop's own proxy configuration a second time.
|
|
200
224
|
let socketFactory = via;
|
|
201
225
|
if (!socketFactory && config.proxyJump) {
|
|
226
|
+
transportDescription = `ProxyJump transport for ${config.alias}`;
|
|
202
227
|
const specifications = config.proxyJump.split(",").map((value) => value.trim()).filter(Boolean);
|
|
203
228
|
if (specifications.length === 0) throw new RemoteCallError("E_SSH_CONFIG", `ProxyJump is empty for ${config.alias}`);
|
|
204
229
|
let previous: Client | undefined;
|
|
@@ -214,6 +239,7 @@ async function connectClient(
|
|
|
214
239
|
const jump = previous;
|
|
215
240
|
socketFactory = () => forwardOut(jump, config.host, config.port);
|
|
216
241
|
} else if (!socketFactory && config.proxyCommand) {
|
|
242
|
+
transportDescription = `ProxyCommand transport for ${config.alias}`;
|
|
217
243
|
socketFactory = async () => openProxyCommand(config);
|
|
218
244
|
}
|
|
219
245
|
const knownHosts = await loadKnownHostEntries(config);
|
|
@@ -232,19 +258,22 @@ async function connectClient(
|
|
|
232
258
|
for (const attempt of attempts) {
|
|
233
259
|
try {
|
|
234
260
|
const sock = socketFactory ? await socketFactory() : undefined;
|
|
235
|
-
const client = await connectWithAttempt(config, knownHosts, attempt, sock);
|
|
261
|
+
const client = await connectWithAttempt(config, knownHosts, attempt, sock, hostKeyAlgorithms);
|
|
236
262
|
return { client, parents };
|
|
237
263
|
} catch (error) {
|
|
238
264
|
lastError = error;
|
|
239
265
|
if (error instanceof RemoteCallError && (error.code.startsWith("E_HOST_KEY") || error.code === "E_UNSUPPORTED_SSH_OPTION")) throw error;
|
|
240
266
|
}
|
|
241
267
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
268
|
+
if (isAuthenticationFailure(lastError)) {
|
|
269
|
+
throw new RemoteCallError(
|
|
270
|
+
"E_AUTH",
|
|
271
|
+
`Non-interactive SSH authentication failed for ${config.alias}`,
|
|
272
|
+
`Make ssh ${config.alias} work without a password or passphrase, then retry. Last error: ${lastError instanceof Error ? lastError.message : String(lastError)}`,
|
|
273
|
+
{ cause: lastError },
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
throw asRemoteCallError(lastError, "E_CONNECT", `Cannot establish ${transportDescription}`);
|
|
248
277
|
} catch (error) {
|
|
249
278
|
closeClients(parents);
|
|
250
279
|
throw error;
|
|
@@ -416,21 +445,31 @@ export class SshConnection {
|
|
|
416
445
|
this.helperReady = (async () => {
|
|
417
446
|
const cachePath = pythonHelperCachePath(this.facts.home);
|
|
418
447
|
const cacheDirectory = posix.dirname(cachePath);
|
|
448
|
+
let stage = "inspect cache";
|
|
419
449
|
try {
|
|
420
450
|
const cached = await sftpLstat(this.sftp, cachePath).catch(() => undefined);
|
|
421
|
-
if (cached?.isFile() && cached.size === PYTHON_HELPER_BYTES && (cached.mode & 0o077) === 0
|
|
422
|
-
|
|
423
|
-
|
|
451
|
+
if (cached?.isFile() && cached.size === PYTHON_HELPER_BYTES && (cached.mode & 0o077) === 0) {
|
|
452
|
+
stage = "verify cached helper";
|
|
453
|
+
if (await this.verifyPythonHelper(cachePath)) {
|
|
454
|
+
this.facts.helperCache = "hit";
|
|
455
|
+
delete this.facts.helperCacheError;
|
|
456
|
+
return cachePath;
|
|
457
|
+
}
|
|
424
458
|
}
|
|
459
|
+
stage = "create cache directory";
|
|
425
460
|
await sftpMkdirP(this.sftp, cacheDirectory);
|
|
426
461
|
await sftpSetStat(this.sftp, cacheDirectory, { mode: 0o700 });
|
|
462
|
+
stage = "install helper";
|
|
427
463
|
await sftpWriteFileAtomic(this.sftp, cachePath, PYTHON_HELPER_SOURCE, true);
|
|
428
464
|
await sftpSetStat(this.sftp, cachePath, { mode: 0o600 });
|
|
465
|
+
stage = "verify installed helper";
|
|
429
466
|
if (!await this.verifyPythonHelper(cachePath)) throw new Error("Cached helper hash verification failed");
|
|
430
467
|
this.facts.helperCache = "installed";
|
|
468
|
+
delete this.facts.helperCacheError;
|
|
431
469
|
return cachePath;
|
|
432
|
-
} catch {
|
|
470
|
+
} catch (error) {
|
|
433
471
|
this.facts.helperCache = "inline";
|
|
472
|
+
this.facts.helperCacheError = helperCacheErrorMessage(stage, error, this.facts.home);
|
|
434
473
|
return undefined;
|
|
435
474
|
}
|
|
436
475
|
})();
|