jssh
Class KnownHostsFile

java.lang.Object
  |
  +--java.io.File
        |
        +--jssh.KnownHostsFile
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable

public class KnownHostsFile
extends java.io.File

This class provides methods for checking whether a server's public key is in a known_hosts file, and for adding a key to the file.

See Also:
Serialized Form

Field Summary
static int HOST_KEY_DIFFERS
           
static int HOST_KEY_NEW
           
static int HOST_KEY_OK
           
 
Fields inherited from class java.io.File
pathSeparator, pathSeparatorChar, separator, separatorChar
 
Constructor Summary
KnownHostsFile(java.lang.String pathname_)
          Constructor
 
Method Summary
 void add_host_key(java.lang.String server_name_, java.math.BigInteger modulus_, java.math.BigInteger exponent_)
          Add the server's host key to this known_hosts file.
 int check_host_key(java.lang.String server_name_, java.math.BigInteger received_modulus_, java.math.BigInteger received_exponent_)
          Check that the server's host key is in the known_hosts file.
 
Methods inherited from class java.io.File
canRead, canWrite, compareTo, compareTo, createNewFile, createTempFile, createTempFile, delete, deleteOnExit, equals, exists, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getCanonicalPath, getName, getParent, getParentFile, getPath, hashCode, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list, list, listFiles, listFiles, listFiles, listRoots, mkdir, mkdirs, renameTo, setLastModified, setReadOnly, toString, toURI, toURL
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

HOST_KEY_OK

public static final int HOST_KEY_OK
See Also:
Constant Field Values

HOST_KEY_DIFFERS

public static final int HOST_KEY_DIFFERS
See Also:
Constant Field Values

HOST_KEY_NEW

public static final int HOST_KEY_NEW
See Also:
Constant Field Values
Constructor Detail

KnownHostsFile

public KnownHostsFile(java.lang.String pathname_)
Constructor

Parameters:
pathname_ - the filename of the known_hosts file.
Method Detail

check_host_key

public int check_host_key(java.lang.String server_name_,
                          java.math.BigInteger received_modulus_,
                          java.math.BigInteger received_exponent_)
                   throws java.io.IOException
Check that the server's host key is in the known_hosts file.

Returns:
the return status:

  • HOST_KEY_OK if the host key was found in the known_hosts file and matched the received key.
  • HOST_KEY_DIFFERS if the host key was found in the known_hosts file but differed from the received key.
  • HOST_KEY_NEW if the host key was not found in the known_hosts file (or the known_hosts file did not exist).
java.io.IOException

add_host_key

public void add_host_key(java.lang.String server_name_,
                         java.math.BigInteger modulus_,
                         java.math.BigInteger exponent_)
                  throws java.io.IOException
Add the server's host key to this known_hosts file.

Parameters:
server_name_ - the hostname of the SSH server.
java.io.IOException