Class KnownHostEntryReader

java.lang.Object
org.eclipse.jgit.internal.transport.sshd.KnownHostEntryReader

public class KnownHostEntryReader extends Object
Apache MINA sshd 2.0.0 KnownHostEntry cannot read a host entry line like "host:port ssh-rsa "; it complains about an illegal character in the host name (correct would be "[host]:port"). The default known_hosts reader also aborts reading on the first error.

This reader is a bit more robust and tries to handle this case if there is only one colon (otherwise it might be an IPv6 address (without port)), and it skips and logs invalid entries, but still returns all other valid entries from the file.

  • Field Details

    • LOG

      private static final org.slf4j.Logger LOG
  • Constructor Details

    • KnownHostEntryReader

      private KnownHostEntryReader()
  • Method Details

    • readFromFile

      public static List<org.apache.sshd.client.config.hosts.KnownHostEntry> readFromFile(Path path) throws IOException
      Reads a known_hosts file and returns all valid entries. Invalid entries are skipped (and a message is logged).
      Parameters:
      path - of the file to read
      Returns:
      a List of all valid entries read from the file
      Throws:
      IOException - if the file cannot be read.
    • clean

      private static String clean(String line)
    • parseHostEntry

      private static org.apache.sshd.client.config.hosts.KnownHostEntry parseHostEntry(String line)
    • parsePatterns

      private static Collection<org.apache.sshd.client.config.hosts.HostPatternValue> parsePatterns(String text)