Repository navigation
fix(ssh): retry over system ssh when ssh2 shares no algorithm with the host - #33680
Conversation
…e host ssh2 supports fewer algorithms than OpenSSH. A host that offers only certificate host keys (or only kex/cipher choices ssh2 lacks) fails the handshake with "Handshake failed: no matching ...", even though the system ssh binary connects fine. Treat any such negotiation failure as a client capability gap: probe system ssh once, and if that also fails, report its error, since ssh2 can never reach the host. Fixes #33582 Co-authored-by: Kyou12138 <kyou12138@gmail.com>
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes.
|
…iation failure System OpenSSH never reads Orca's own host key store, so an on-path impostor could advertise algorithms ssh2 lacks to steer a pinned host onto system ssh and around its pin. Only fall back when Orca has no stored key for the endpoint. Co-authored-by: Kyou12138 <kyou12138@gmail.com>
e6f4649 to
7a1dabe
Compare
A superseded attempt that finished its trust read late could overwrite the current attempt's pin marker, letting a negotiation failure on a pinned host fall back to system ssh.
There was a problem hiding this comment.
Actionable comments posted: 2

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
c6a48f43-f867-4558-99fb-f33a2096274e
Files selected for processing: 6-
src/main/ssh/connection/ssh-connection-manager-sign-in-reuse.test.tssrc/main/ssh/connection/ssh-connection-system-transport.test.tssrc/main/ssh/connection/ssh-connection.tssrc/main/ssh/connection/ssh2-credential-fallback.tssrc/main/ssh/connection/ssh2-host-key-verification.tssrc/main/ssh/ssh-reconnect-error-classification.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
-
| if (verdict.pinnedByOrcaStore) { | ||
| this.orcaStorePinnedGeneration = connectGeneration |
There was a problem hiding this comment.
Do not let a stale attempt overwrite the current pin.
If two connect generations overlap, the older trust-source load can finish after the newer one. This assignment then replaces the newer generation’s pin. If the newer SSH2 attempt fails negotiation, isPinnedByOrcaHostKeyStore() returns false and permits system OpenSSH fallback for a pinned host. Require isCurrentAttempt() before recording the verdict.
| const verdict: Ssh2HostKeyVerdict = { rejection: null } | ||
| const verdict: Ssh2HostKeyVerdict = { | ||
| rejection: null, | ||
| pinnedByOrcaStore: storedKeyTypes.length > 0 |
There was a problem hiding this comment.
🔎 Supported by static analysis
-
Script executed:
#!/bin/bash ast-grep outline src/main/ssh/ssh-host-key-store.ts --match 'loadTrustedHostKeys|readStore' --view expanded rg -n -C 8 'loadTrustedHostKeys|readStore|withheld|unreadable' src/main/ssh/ssh-host-key-store.ts rg -n -C 8 '\breadHostKeyTrustSources\s*\(' src/main/ssh
Repository: stablyai/orca
Length of output: 9004
Script executed:
sed -n '1,180p' src/main/ssh/connection/ssh2-host-key-verification.ts sed -n '180,280p' src/main/ssh/connection/ssh2-host-key-verification.ts sed -n '700,840p' src/main/ssh/connection/ssh-connection.ts rg -n -C 12 'pinnedByOrcaStore|storedKeyTypes|system.*ssh|negotiat|fallback|HostKeyVerification' src/main/ssh/connection src/main/ssh
Repository: stablyai/orca
Length of output: 45667
Script executed:
python3 - <<'PY' from pathlib import Path for name, start, end in [ ('src/main/ssh/connection/ssh2-host-key-verification.ts', 1, 180), ('src/main/ssh/connection/ssh-connection.ts', 735, 840), ]: p = Path(name) lines = p.read_text().splitlines() print(f'--- {name}:{start}-{min(end, len(lines))} ---') for i in range(start, min(end, len(lines)) + 1): print(f'{i}:{lines[i-1]}') PY rg -n -C 10 -F -- 'pinnedByOrcaStore' src/main/ssh
Repository: stablyai/orca
Length of output: 18821
Script executed:
rg -n -C 14 -F -- 'orcaStorePinnedGeneration' src/main/ssh/connection src/main/ssh rg -n -C 12 -e 'system.*fallback' -e 'fallback.*system' -e 'doSystemSsh' -e 'isSystemSshFallback' src/main/ssh/connection src/main/ssh sed -n '200,230p' src/main/ssh/ssh-host-key-store.ts
Repository: stablyai/orca
Length of output: 42040
Script executed:
sed -n '70,145p' src/main/ssh/connection/ssh2-credential-fallback.ts rg -n -C 8 -F -- 'isPinnedByOrcaHostKeyStore' src/main/ssh/connection
Repository: stablyai/orca
Length of output: 7862
Preserve an unavailable store as an unknown pin state.
A store read failure or timeout becomes []. storedKeyTypesForEndpoint then finds no types, so isPinnedByOrcaHostKeyStore() returns false. The algorithm-negotiation branch therefore starts system OpenSSH even though Orca cannot determine whether the endpoint is pinned. Carry the unavailable state into the verdict and block this fallback when the store state is unknown.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

Major · Do not treat an unreadable Orca key store as unpinned. · ssh-connection.ts:515
src/main/ssh/connection/ssh-connection.ts:515
🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy liftDo not treat an unreadable Orca key store as unpinned.
If the store read times out or fails,
readHostKeyTrustSourcessupplies an empty key list. This predicate then permits the new system SSH fallback after a negotiation error, even if the endpoint has an Orca-stored pin. System SSH does not consult that pin. Track an unsuccessful store read separately, and permit this fallback only when the store read confirms that no pin exists. (raw.githubusercontent.com)

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
b5eaccb2-a997-42d2-b6cc-de6234f63c27
Files selected for processing: 2-
src/main/ssh/connection/ssh-connection-host-key-pin-race.test.tssrc/main/ssh/connection/ssh-connection.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
-
ELI5
Some SSH servers prove who they are with a signed certificate instead of a plain key. Orca's built-in SSH client can't read those, so it gave up, even though the
sshprogram already on your computer connects fine. Now Orca tries thatsshprogram once before giving up.What Changed
Before: a host that offers only certificate host keys (for example
ssh-ed25519-cert-v01@openssh.com) failed withHandshake failed: no matching host key format, and the host stayed disconnected. The only workaround was adding a dummyProxyCommand.After: Orca retries the connection over system OpenSSH and connects. If system OpenSSH fails too, Orca shows its error (for example "No ED25519 host key is known for ... and you have requested strict checking"), which tells the user what to fix, instead of the ssh2 message.
How: the ssh2 fallback ladder already retries over system ssh for local reachability errors. It now does the same for any ssh2 algorithm-negotiation failure (
Handshake failed: no matching ...), which covers host key formats, key exchange, ciphers, MACs and compression. ssh2 never reads algorithm choices from the user's ssh config, so a negotiation failure always means ssh2 can't support the server, not that the user's config rejected it.Why
ssh2 1.17 doesn't support host certificates, and it supports fewer key exchange and cipher algorithms than OpenSSH. Orca already falls back to system OpenSSH for other things ssh2 lacks (proxies, FIDO keys, GSSAPI). Covering every negotiation failure fixes the whole class, not only the certificate case. Trust stays the same: system OpenSSH checks the host against
known_hosts, including@cert-authoritylines, just as it does for proxied hosts today. A rejected host key never reaches this path. A host whose key Orca has already saved in its own key store stays on ssh2 and keeps the ssh2 error, because system OpenSSH doesn't read that store. Otherwise, someone in the middle could advertise algorithms ssh2 lacks and push a pinned host onto a path that skips its pin.Builds on #33602 by @Kyou12138, who found the cause and proposed the same fallback for the certificate case. This PR widens it to every negotiation failure and reports the system ssh error when the fallback fails too. Thanks to @Kyou12138 for the report, too.
Linked Issue
Fixes #33582
Visual Proof
N/A. No UI change; this only changes which transport Orca retries on after a failed handshake.
Testing
Reproduced against a real server: a Docker sshd with
HostKeyAlgorithms ssh-ed25519-cert-v01@openssh.comand a CA-signed host certificate. Plain ssh2 fails withHandshake failed: no matching host key format.SshConnectiononmainfails with the same error. With this change it connects over system ssh (@cert-authorityin an isolated known_hosts). With the CA removed from known_hosts, it now reports the system ssh strict-checking error.New tests in
ssh-connection-system-transport.test.ts(fail onmain): fallback for host key, kex and cipher negotiation failures, the system ssh error surfacing when the probe fails, and a host pinned in Orca's key store not falling back.ssh-connection-manager-sign-in-reuse.test.tsused a cipher negotiation failure as an example of "a failure that isn't about sign-in". That failure now falls back, so the test uses a different non-sign-in handshake failure.Ran every test file that imports the changed modules. Static checks and typecheck pass for the changed files.
Docker managed-orcad lane dispatched on this branch.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Codex review and an independent review on the final head.
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)