public class

OpenSSHKnownHosts

extends Object
implements HostKeyVerifier
java.lang.Object
   ↳ net.schmizz.sshj.transport.verification.OpenSSHKnownHosts
Known Direct Subclasses

Class Overview

A HostKeyVerifier implementation for a known_hosts file i.e. in the format used by OpenSSH.

Summary

Nested Classes
class OpenSSHKnownHosts.AbstractEntry  
class OpenSSHKnownHosts.CommentEntry  
class OpenSSHKnownHosts.EntryFactory Each line in these files contains the following fields: markers (optional), hostnames, bits, exponent, modulus, comment. 
class OpenSSHKnownHosts.HashedEntry  
interface OpenSSHKnownHosts.HostEntry  
enum OpenSSHKnownHosts.Marker  
class OpenSSHKnownHosts.SimpleEntry  
Fields
private static final Logger LOG
private static final String LS
protected final List<OpenSSHKnownHosts.HostEntry> entries
protected final File khFile
protected final Logger log
Public Constructors
OpenSSHKnownHosts(File khFile)
Public Methods
static File detectSSHDir()
List<OpenSSHKnownHosts.HostEntry> entries()
File getFile()
boolean verify(String hostname, int port, PublicKey key)
This callback is invoked when the server's host key needs to be verified.
void write()
Protected Methods
boolean hostKeyChangedAction(OpenSSHKnownHosts.HostEntry entry, String hostname, PublicKey key)
boolean hostKeyUnverifiableAction(String hostname, PublicKey key)
[Expand]
Inherited Methods
From class java.lang.Object
From interface net.schmizz.sshj.transport.verification.HostKeyVerifier

Fields

private static final Logger LOG

private static final String LS

protected final List<OpenSSHKnownHosts.HostEntry> entries

protected final File khFile

protected final Logger log

Public Constructors

public OpenSSHKnownHosts (File khFile)

Parameters
khFile
Throws
IOException

Public Methods

public static File detectSSHDir ()

public List<OpenSSHKnownHosts.HostEntry> entries ()

public File getFile ()

public boolean verify (String hostname, int port, PublicKey key)

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!

Parameters
hostname Remote hostname
port Remote port
key Host key of server
Returns
  • true if key is acceptable, false otherwise

public void write ()

Throws
IOException

Protected Methods

protected boolean hostKeyChangedAction (OpenSSHKnownHosts.HostEntry entry, String hostname, PublicKey key)

Parameters
entry
hostname
key

protected boolean hostKeyUnverifiableAction (String hostname, PublicKey key)

Parameters
hostname
key