net.schmizz.sshj.transport.verification
Class OpenSSHKnownHosts

java.lang.Object
  extended by 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:
Hashed hostnames spec

Nested Class Summary
static class OpenSSHKnownHosts.AbstractEntry
           
static class OpenSSHKnownHosts.CommentEntry
           
static class OpenSSHKnownHosts.EntryFactory
          Each line in these files contains the following fields: markers (optional), hostnames, bits, exponent, modulus, comment.
static class OpenSSHKnownHosts.HashedEntry
           
static interface OpenSSHKnownHosts.HostEntry
           
static class OpenSSHKnownHosts.Marker
           
static class OpenSSHKnownHosts.SimpleEntry
           
 
Field Summary
protected  List<OpenSSHKnownHosts.HostEntry> entries
           
protected  File khFile
           
protected  org.slf4j.Logger log
           
 
Constructor Summary
OpenSSHKnownHosts(File khFile)
           
 
Method Summary
static File detectSSHDir()
           
 List<OpenSSHKnownHosts.HostEntry> entries()
           
 File getFile()
           
protected  boolean hostKeyChangedAction(OpenSSHKnownHosts.HostEntry entry, String hostname, PublicKey key)
           
protected  boolean hostKeyUnverifiableAction(String hostname, PublicKey key)
           
 boolean verify(String hostname, int port, PublicKey key)
          This callback is invoked when the server's host key needs to be verified.
 void write()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final org.slf4j.Logger log

khFile

protected final File khFile

entries

protected final List<OpenSSHKnownHosts.HostEntry> entries
Constructor Detail

OpenSSHKnownHosts

public OpenSSHKnownHosts(File khFile)
                  throws IOException
Throws:
IOException
Method Detail

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

hostKeyUnverifiableAction

protected boolean hostKeyUnverifiableAction(String hostname,
                                            PublicKey key)

hostKeyChangedAction

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

entries

public List<OpenSSHKnownHosts.HostEntry> entries()

write

public void write()
           throws IOException
Throws:
IOException

detectSSHDir

public static File detectSSHDir()


Copyright © 2009-2012. All Rights Reserved.