Skip to content

repository: negotiate the host key algorithms of known_hosts - #249

Open
KakatkarAkshay wants to merge 1 commit into
nlewo:mainfrom
KakatkarAkshay:fix/ssh-host-key-algorithms
Open

KakatkarAkshay wants to merge 1 commit into
nlewo:mainfrom
KakatkarAkshay:fix/ssh-host-key-algorithms

Conversation

@KakatkarAkshay

Copy link
Copy Markdown

Fixes #248.

go-git v5.18.0 (#241) no longer derives HostKeyAlgorithms from a caller-provided HostKeyCallback. comin set only the callback, so x/crypto/ssh negotiated its default host key order. A server like GitHub then presented a key type known_hosts doesn't pin, and every fetch failed with knownhosts: key mismatch.

comin now loads known_hosts with ssh.NewKnownHostsDb and sets both HostKeyCallback and HostKeyAlgorithms from it, for the remote's host and port. It's the same thing go-git does for its own default callback. The deploy key setup moved into sshAuth so it can be tested on its own.

The new test pins only an ed25519 host key, for a scp-like remote on the default port and an ssh:// remote on port 2222, and checks that the client config only offers ssh-ed25519. Without the fix, HostKeyAlgorithms is nil in both cases.

I've been running into this on two nix-darwin hosts and one NixOS host that pin only GitHub's ed25519 key.

go-git v5.18.0 no longer derives HostKeyAlgorithms from a custom HostKeyCallback, so the server could present a host key type that known_hosts doesn't pin and the fetch failed with "knownhosts: key mismatch". The callback and the algorithms now both come from the known_hosts database.

Fixes nlewo#248.

@nlewo nlewo left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks!

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.

SSH fetch fails with "knownhosts: key mismatch" since go-git v5.18.0

2 participants