Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Host key verification with multiple entries for the same server in known_hosts #405

Closed
ragebiswas opened this issue Mar 1, 2018 · 4 comments

Comments

@ragebiswas
Copy link

ragebiswas commented Mar 1, 2018

Hi,
Please correct me if I'm wrong, but it looks like SSHJ does not handle the case of the OpenSSH known_hosts file having multiple entries for the same server. This can end up in practice due to new keys (or even due to servers behind a load balancer perhaps).

The following code in OpenSSHKnownHosts:verify seems to be doing the verification:

  try {
        if (e.appliesTo(type, adjustedHostname))
           return e.verify(key) || hostKeyChangedAction(e, adjustedHostname, key);
        } catch (IOException ioe) {
           log.error("Error with {}: {}", e, ioe);
           return false;
  }

However, openssh itself seems to handle this by trying all keys that match the server, and validates if any of them match.

Am I missing something here? If the above diagnosis is correct, I'd be happy to submit a PR :)

@hierynomus
Copy link
Owner

Seems like you're right, I missed that corner case!
Happy to accept a PR! Don't forget to add tests ;)

@hierynomus
Copy link
Owner

What I'm wondering though, how does OpenSSH handle multiple keys of the same keyformat for the same host? Does it try all of the host entries?

@ragebiswas
Copy link
Author

Yes, that's what it looked like from my experiments. I will submit a PR by next week (with test cases :-) )

@ragebiswas
Copy link
Author

Hey @hierynomus - #406 is the PR. Please take a look whenever you get a chance :)

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

No branches or pull requests

2 participants