Skip to content

fix(ssh): retry over system ssh when ssh2 shares no algorithm with the host - #33680

Merged
nwparker merged 4 commits into
mainfrom
fix/33582-ssh2-negotiation-fallback
Oct 26, 2026
Merged

nwparker merged 4 commits into
mainfrom
fix/33582-ssh2-negotiation-fallback

Conversation

@nwparker

@nwparker nwparker commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​128 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​124
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​42 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​39

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 ssh program already on your computer connects fine. Now Orca tries that ssh program once before giving up.

What Changed

Before: a host that offers only certificate host keys (for example ssh-ed25519-cert-v01@openssh.com) failed with Handshake failed: no matching host key format, and the host stayed disconnected. The only workaround was adding a dummy ProxyCommand.

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-authority lines, 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.com and a CA-signed host certificate. Plain ssh2 fails with Handshake failed: no matching host key format. SshConnection on main fails with the same error. With this change it connects over system ssh (@cert-authority in 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 on main): 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.ts used 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: host key denials are checked before this path and stay final. The fallback runs only after ssh2 has already failed, and system OpenSSH applies its own known_hosts policy.
  • Cross-platform: error classification only. The system ssh probe already exists on macOS, Linux and Windows.
  • SSH/remote: only hosts that ssh2 can't negotiate with are affected. No wire or protocol change, so mixed client and host versions are unaffected. WSL, folder workspaces and mobile: not affected.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…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>
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

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: d5206511-b674-460d-bf97-7c76f2f5e9e1
Commits

Reviewing files that changed from the base of the PR and between 3390513 and b1760a7.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
Walkthrough

SSH2 algorithm-negotiation errors now trigger a system OpenSSH probe when the host is not pinned in Orca’s host-key store. Pinned hosts retain the SSH2 negotiation error without a system SSH probe. Tests cover host-key format, key-exchange algorithm, and cipher negotiation errors, probe failure, pinned hosts, a connection race, and credential reuse after signature-verification errors.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Moderate · up to 33905

When Orca's host-key store cannot be read, a pinned host may fall back to system SSH after an algorithm-negotiation failure and skip Orca's pin. This needs a fix before merge, but it only occurs when the store read fails or times out.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title names the main change: ssh2 algorithm-negotiation failures now retry over system ssh. It is short, specific, and matches the changeset and the linked issue's objective. It uses the conventio…
Description check Passed The description follows the template closely. It has an ELI5, a What Changed section with before and after behavior and mechanism, a Why section with alternatives and trust reasoning, a Linked Issue (…
Linked Issues check Passed Issue #33582 requires SSH targets with certificate-only host keys to connect when system OpenSSH supports them. The supplied PR evidence shows that ssh2 algorithm-negotiation failures now trigger a sy…
Out of Scope Changes check Passed The reported changes stay within the SSH fallback scope of #33582. The broader negotiation-error classification addresses the same ssh2 capability gap. Host-key pin generation tracking preserves the r…
Docstring Coverage Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 7 files.
Full details: Title check

Explanation

The title names the main change: ssh2 algorithm-negotiation failures now retry over system ssh. It is short, specific, and matches the changeset and the linked issue's objective. It uses the conventional fix(ssh) prefix and has no vague terms.

Full details: Description check

Explanation

The description follows the template closely. It has an ELI5, a What Changed section with before and after behavior and mechanism, a Why section with alternatives and trust reasoning, a Linked Issue (Fixes #33582), Visual Proof marked N/A with a reason, Testing steps with a real-server reproduction and new tests, Notes covering security, cross-platform, and SSH/remote impact, and a completed checklist. The AI Disclosure and Review sections are present but thin. The Review section names Codex review and an independent review, and the AI Disclosure section is empty.

Full details: Linked Issues check

Explanation

Issue #33582 requires SSH targets with certificate-only host keys to connect when system OpenSSH supports them. The supplied PR evidence shows that ssh2 algorithm-negotiation failures now trigger a system OpenSSH retry, including host-key negotiation failures. It also shows system SSH errors surface when the retry fails. Tests cover host-key negotiation fallback, related negotiation failures, fallback failure, and the pinned-host exception. The evidence also states that host-key denials remain final.

Full details: Out of Scope Changes check

Explanation

The reported changes stay within the SSH fallback scope of #33582. The broader negotiation-error classification addresses the same ssh2 capability gap. Host-key pin generation tracking preserves the required trust boundary for this fallback. The tests and sign-in test updates support the changed behavior. No unrelated change is established by the supplied evidence.

Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…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>
@nwparker
nwparker force-pushed the fix/33582-ssh2-negotiation-fallback branch from e6f4649 to 7a1dabe Compare October 25, 2026 23:40
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Commits

Reviewing files that changed from the base of the PR and between ddd55a4 and 7a1dabe.

Files selected for processing: 6
  • src/main/ssh/connection/ssh-connection-manager-sign-in-reuse.test.ts
  • src/main/ssh/connection/ssh-connection-system-transport.test.ts
  • src/main/ssh/connection/ssh-connection.ts
  • src/main/ssh/connection/ssh2-credential-fallback.ts
  • src/main/ssh/connection/ssh2-host-key-verification.ts
  • src/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.

Comment on lines +748 to +749
if (verdict.pinnedByOrcaStore) {
this.orcaStorePinnedGeneration = connectGeneration

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major · Security & Privacy · Quick win

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major · Security & Privacy · Heavy lift

🔎 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

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 lift

Do not treat an unreadable Orca key store as unpinned.

If the store read times out or fails, readHostKeyTrustSources supplies 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
Commits

Reviewing files that changed from the base of the PR and between 7a1dabe and 3390513.

Files selected for processing: 2
  • src/main/ssh/connection/ssh-connection-host-key-pin-race.test.ts
  • src/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.

@nwparker
nwparker merged commit 1b58be9 into main Oct 26, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SSH targets with certificate-only host keys fail instead of falling back to system ssh

1 participant