Class KnownHostEntryReader


  • public class KnownHostEntryReader
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      private static org.slf4j.Logger LOG  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.String clean​(java.lang.String line)  
      private static org.apache.sshd.client.config.hosts.KnownHostEntry parseHostEntry​(java.lang.String line)  
      private static java.util.Collection<org.apache.sshd.client.config.hosts.HostPatternValue> parsePatterns​(java.lang.String text)  
      static java.util.List<org.apache.sshd.client.config.hosts.KnownHostEntry> readFromFile​(java.nio.file.Path path)
      Reads a known_hosts file and returns all valid entries.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

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

      • KnownHostEntryReader

        private KnownHostEntryReader()
    • Method Detail

      • readFromFile

        public static java.util.List<org.apache.sshd.client.config.hosts.KnownHostEntry> readFromFile​(java.nio.file.Path path)
                                                                                               throws java.io.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:
        java.io.IOException - if the file cannot be read.
      • clean

        private static java.lang.String clean​(java.lang.String line)
      • parseHostEntry

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

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