public class SSHFTPValidator
extends java.lang.Object
SSHFTPClient
.
By default, SSHFTPClient
uses an instance of this class for all
its validation functions. It provides the following functions:
SCPClient.setValidator(SSHFTPValidator)
.Constructor and Description |
---|
SSHFTPValidator()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addKnownHost(java.lang.String hostName,
java.io.InputStream publicKeyStream)
Adds the given host (and associated key data supplied in the inputstream) to the
list of known hosts.
|
void |
addKnownHost(java.lang.String hostName,
SSHFTPPublicKey publicKey)
Adds the given host to the list of known hosts.
|
void |
addKnownHost(java.lang.String hostName,
java.lang.String publicKeyFile)
Adds the given host (and associated key-file) to the list of known hosts.
|
SSHFTPPublicKey |
getHostPublicKey()
Provides access to the current remote host's public key.
|
SSHFTPPublicKey[] |
getKnownHostKeys(java.lang.String hostname)
Get all the public keys in the known hosts file that match the
supplied hostname.
|
java.lang.String[] |
getKnownHostnames()
Get the known host name entries.
|
java.util.Hashtable |
getKnownHosts()
Deprecated.
use
getKnownHostnames() and getKnownHostKeys(String) instead |
boolean |
isHostValidationEnabled()
Returns
true if host validation is enabled. |
boolean |
isPortsInKnownHosts()
Are non-standard port numbers used in known_hosts files? If
so then hosts are stored as [hostname]:port if the port number
is not 22.
|
void |
loadKnownHosts(java.io.InputStream hostsStream)
Loads a list of hosts and their associated public keys from the
given
InputStream . |
void |
loadKnownHosts(java.lang.String hostsFileName)
Loads a list of hosts and their associated public keys from the
given file.
|
void |
removeAllKnownHosts()
Clears all known hosts.
|
void |
removeKnownHost(java.lang.String hostName)
Remove the given host from the list of known hosts.
|
void |
saveKnownHosts()
Overwrite the currently loaded known_hosts file with the cached known host
data, which may be different.
|
void |
saveKnownHosts(java.lang.String knownHosts)
Write the cached known host data to the supplied filename.
|
void |
setHostValidationEnabled(boolean hostValidationEnabled)
Sets the flag controlling whether or not hosts will be validated.
|
void |
setPortsInKnownHosts(boolean portsInKnownHosts)
Change whether or not non-standard port numbers are used in known_hosts files.
|
protected boolean |
validate(java.lang.String hostSpecifier,
SSHFTPPublicKey publicKey,
boolean hostKnown) |
protected boolean |
validate(java.lang.String hostSpecifier,
java.lang.String fingerPrint,
boolean hostKnown)
Deprecated.
|
public boolean isPortsInKnownHosts()
Default is true.
public void setPortsInKnownHosts(boolean portsInKnownHosts)
portsInKnownHosts
- true to enable, false to disablepublic void loadKnownHosts(java.lang.String hostsFileName) throws java.io.FileNotFoundException, java.io.IOException
jackspc,192.168.1.1 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIE...If there are more than one host using a given key the host-name may be replaced by a comma-separated list of host-names. IP addresses may be used. Wildcards may not be used.
Note that this method does not clear any previous settings.
hostsFileName
- Name of the file containing the hosts.java.io.FileNotFoundException
- Thrown if the file could not be found.java.io.IOException
- Thrown if the file could not be read.public void loadKnownHosts(java.io.InputStream hostsStream) throws java.io.IOException
InputStream
. The format of the content
of the stream is similar to
that used in OpenSSH. Each line contains the name of a host followed by
its IP address (separated by a comma), the type of
key it has, and its key (in base-64 printable form). For example:
jackspc,192.168.1.1 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIE...If there are more than one host using a given key the host-name may be replaced by a comma-separated list of host-names. IP addresses may be used. Wildcards may not be used.
Note that this method does not clear any previous settings.
hostsStream
- Stream containing the hosts.java.io.FileNotFoundException
- Thrown if the file could not be found.java.io.IOException
- Thrown if the file could not be read.public void saveKnownHosts() throws java.io.IOException
java.io.IOException
public void saveKnownHosts(java.lang.String knownHosts) throws java.io.IOException
knownHosts
- the path to the file to write tojava.io.IOException
public void addKnownHost(java.lang.String hostName, java.lang.String publicKeyFile) throws java.io.IOException, com.enterprisedt.net.j2ssh.transport.publickey.InvalidSshKeyException
hostName
- Name of the hostpublicKeyFile
- Name of the file containing the host's public key.java.io.IOException
- Thrown if there was a problem reading the key-file.com.enterprisedt.net.j2ssh.transport.publickey.InvalidSshKeyException
- Thrown if the key was not valid.public void addKnownHost(java.lang.String hostName, SSHFTPPublicKey publicKey) throws com.enterprisedt.net.j2ssh.transport.InvalidHostFileException, com.enterprisedt.net.j2ssh.transport.publickey.InvalidSshKeyException
hostName
- Name of the hostpublicKey
- Public keyjava.io.IOException
- Thrown if there was a problem reading the key-file.com.enterprisedt.net.j2ssh.transport.publickey.InvalidSshKeyException
- Thrown if the key was not valid.com.enterprisedt.net.j2ssh.transport.InvalidHostFileException
public void addKnownHost(java.lang.String hostName, java.io.InputStream publicKeyStream) throws java.io.IOException, com.enterprisedt.net.j2ssh.transport.publickey.InvalidSshKeyException
hostName
- Name of the hostpublicKeyStream
- stream containing the host's public key.java.io.IOException
- Thrown if there was a problem reading the stream.com.enterprisedt.net.j2ssh.transport.publickey.InvalidSshKeyException
- Thrown if the key was not valid.public void removeKnownHost(java.lang.String hostName)
hostName
- Name of the host.public void removeAllKnownHosts()
protected boolean validate(java.lang.String hostSpecifier, java.lang.String fingerPrint, boolean hostKnown)
validate(String, SSHFTPPublicKey, boolean)
.false
.hostSpecifier
- Host-name and IP address separated by a comma.fingerPrint
- Human-readable form of the host's fingerprint.hostKnown
- true
if there was an entry for the host
but not with the required algorithm (note that several algorithms may be
defined for each host).true
if the host is valid.protected boolean validate(java.lang.String hostSpecifier, SSHFTPPublicKey publicKey, boolean hostKnown)
public boolean isHostValidationEnabled()
true
if host validation is enabled.true
if host validation is enabled.public void setHostValidationEnabled(boolean hostValidationEnabled)
hostValidationEnabled
- New valid of the flag.public java.util.Hashtable getKnownHosts()
getKnownHostnames()
and getKnownHostKeys(String)
insteadNote that hashed host-names are not returned in the hashtable.
public java.lang.String[] getKnownHostnames()
public SSHFTPPublicKey[] getKnownHostKeys(java.lang.String hostname)
hostname
- hostname we want the keys forpublic SSHFTPPublicKey getHostPublicKey()
null
before the first connection attempt is made.
This method is particularly useful if the server's public key is not
available by other means. In such cases a connection attempt should be made
without adding any known hosts. This attempt will fail, but getHostPublicKey()
may be used afterwards to obtain the public key. The
SSHFTPPublicKey.write(OutputStream,int)
method may be used to write it
to a file for use in subsequent connections.
Note that null may be returned after a connection attempt is made if the attempt failed before public keys were exchanged between the client and the server.
Copyright © 2001-2014 Enterprise Distributed Technologies Ltd. All Rights Reserved.