Class OpenSSHKnownHosts

java.lang.Object
net.schmizz.sshj.transport.verification.OpenSSHKnownHosts
All Implemented Interfaces:
HostKeyVerifier
Direct Known Subclasses:
ConsoleKnownHostsVerifier

public class OpenSSHKnownHosts extends Object implements HostKeyVerifier
A HostKeyVerifier implementation for a known_hosts file i.e. in the format used by OpenSSH.
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • readEntries

      private void readEntries(BufferedReader br) throws IOException
      Throws:
      IOException
    • adjustHostname

      private String adjustHostname(String hostname, int port)
    • getFile

      public File getFile()
    • verify

      public boolean verify(String hostname, int port, PublicKey key)
      Description copied from interface: HostKeyVerifier
      This callback is invoked when the server's host key needs to be verified. The return value indicates to the caller whether the SSH connection should proceed.

      Note: host key verification is the basis for security in SSH, therefore exercise due caution in implementing!

      Specified by:
      verify in interface HostKeyVerifier
      Parameters:
      hostname - remote hostname
      port - remote port
      key - host key of server
      Returns:
      true if key is acceptable, false otherwise
    • findExistingAlgorithms

      public List<String> findExistingAlgorithms(String hostname, int port)
      Description copied from interface: HostKeyVerifier
      It is necessary to connect with the type of algorithm that matches an existing know_host entry. This will allow a match when we later verify with the negotiated key HostKeyVerifier.verify
      Specified by:
      findExistingAlgorithms in interface HostKeyVerifier
      Parameters:
      hostname - remote hostname
      port - remote port
      Returns:
      existing key types or empty list if no keys known for hostname
    • hostKeyUnverifiableAction

      protected boolean hostKeyUnverifiableAction(String hostname, PublicKey key)
    • hostKeyChangedAction

      protected boolean hostKeyChangedAction(String hostname, PublicKey key)
    • entries

    • write

      public void write() throws IOException
      Throws:
      IOException
    • write

      public void write(OpenSSHKnownHosts.KnownHostEntry entry) throws IOException
      Append a single entry
      Throws:
      IOException
    • detectSSHDir

      public static File detectSSHDir()
    • toString

      public String toString()
      Overrides:
      toString in class Object