Top Description Fields Constructors Methods
org.eclipse.jgit.internal.transport.sshd

public Class KnownHostEntryReader

extends Object
Class Inheritance
Static Imports
java.nio.charset.StandardCharsets.UTF_8, java.text.MessageFormat.format, org.apache.sshd.client.config.hosts.HostPatternsHolder.NON_STANDARD_PORT_PATTERN_ENCLOSURE_END_DELIM, .HostPatternsHolder.NON_STANDARD_PORT_PATTERN_ENCLOSURE_START_DELIM

Apache MINA sshd 2.0.0 KnownHostEntry cannot read a host entry line like "host:port ssh-rsa <key>"; 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

Modifier and TypeField and Description
private static final Logger

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static String
clean(String line)

pack-priv static KnownHostEntry
private static Collection<HostPatternValue>
public static List<KnownHostEntry>

Returns:

a List of all valid entries read from the file
readFromFile
(Path
of the file to read
path
)

Reads a known_hosts file and returns all valid entries.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGback to summary
private static final Logger LOG

Constructor Detail

KnownHostEntryReaderback to summary
private KnownHostEntryReader()

Method Detail

cleanback to summary
private static String clean(String line)
parseHostEntryback to summary
pack-priv static KnownHostEntry parseHostEntry(String line)
parsePatternsback to summary
private static Collection<HostPatternValue> parsePatterns(String text)
readFromFileback to summary
public static List<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:Path

of the file to read

Returns:List<KnownHostEntry>

a List of all valid entries read from the file

Exceptions
IOException:
if the file cannot be read.