Skip to content

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

Closed
@ragebiswas

Description

@ragebiswas

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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions