Skip to content

Verify SSH host keys against known_hosts - #396

Open
jameshoweee wants to merge 1 commit into
sandbox-quantum:mainfrom
jameshoweee:security/ssh-host-key-verification
Open

jameshoweee wants to merge 1 commit into
sandbox-quantum:mainfrom
jameshoweee:security/ssh-host-key-verification

Conversation

@jameshoweee

Copy link
Copy Markdown
Contributor

ssh2 accepts any host key when no hostVerifier is set, and the Console never sets one. So a remote connection completes against whatever answers on the address and hands it the user's password or private key, plus the forwarded agent socket when agent forwarding is on. There is no host-key check today at all.

This adds one. It reads the same known_hosts files OpenSSH would use for that host (resolved from ssh -G, so aliases and UserKnownHostsFile / GlobalKnownHostsFile are honoured), matches plain, hashed, glob and negated patterns, honours @revoked, pins the key on first use, and refuses when a pinned key changes. StrictHostKeyChecking is respected: yes refuses an unknown host, anything else accepts and records it. A changed key is refused under every setting. An unreadable known_hosts fails closed rather than turning into blind trust.

@cert-authority lines are reported as unknown rather than as a match. This does not validate host certificates, and ssh2 never advertises the *-cert-v01@openssh.com algorithms, so a server cannot present one on this path anyway.

Tests: 44 new cases over the parser, the matcher and the verifier, plus an end-to-end case proving the resolved ConnectConfig refuses a changed key, and one against a real known_hosts file on disk. 153/153 in the ssh suite, 3100/3101 across the node project (the one failure is session-spawner, which fails the same way on main).

ssh2 accepts any host key when no hostVerifier is set, so the Console
completed the handshake with whatever answered the address and handed it
the user's credentials and forwarded agent.

Read the known_hosts files `ssh -G` resolves for the host, pin the key on
first use, and refuse to connect when a pinned key changes. Honours
StrictHostKeyChecking, UserKnownHostsFile, GlobalKnownHostsFile and
HashKnownHosts.
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.

1 participant