public abstract class AbstractMultipleKnownHostsKeyVerification extends Object implements HostKeyVerification
An abstract HostKeyVerification class implementation providing validation against the known_hosts format.
Constructor and Description |
---|
AbstractMultipleKnownHostsKeyVerification()
Deprecated.
Construct a known_hosts database based on the default path of
~/.ssh/known_hosts.
|
AbstractMultipleKnownHostsKeyVerification(String knownhosts)
Deprecated.
Constructs a known_hosts database based on the path provided.
|
Modifier and Type | Method and Description |
---|---|
Hashtable<String,List<SshPublicKey>> |
allowedHosts()
Deprecated.
Returns a Map of the allowed hosts.
|
void |
allowHost(String host,
SshPublicKey pk,
boolean always)
Deprecated.
Allows a host key, optionally recording the key to the known_hosts file.
|
File |
getKnownHostsFile()
Deprecated.
|
boolean |
isHostFileWriteable()
Deprecated.
Determines whether the host file is writable.
|
abstract void |
onHostKeyMismatch(String host,
List<SshPublicKey> allowedHostKey,
SshPublicKey actualHostKey)
Deprecated.
Called by the
verifyHost method when the host key supplied
by the host does not match the current key recording in the known hosts
file. |
protected void |
onInvalidHostEntry(String entry)
Deprecated.
|
abstract void |
onUnknownHost(String host,
SshPublicKey key)
Deprecated.
Called by the
verifyHost method when the host key supplied
is not recorded in the known_hosts file. |
void |
removeAllowedHost(String host)
Deprecated.
Removes an allowed host.
|
void |
saveHostFile()
Deprecated.
Save's the host key file to be saved.
|
void |
setHashHosts(boolean hashHosts)
Deprecated.
|
String |
toString()
Deprecated.
Outputs the allowed hosts in the known_hosts file format.
|
boolean |
verifyHost(String host,
SshPublicKey pk)
Deprecated.
Verifies a host key against the list of known_hosts.
|
public AbstractMultipleKnownHostsKeyVerification() throws SshException
SshException
public AbstractMultipleKnownHostsKeyVerification(String knownhosts) throws SshException
Constructs a known_hosts database based on the path provided.
knownhosts
- the path of the known_hosts fileInvalidHostFileException
- if the known_hosts file is invalidSshException
public File getKnownHostsFile()
public void setHashHosts(boolean hashHosts)
protected void onInvalidHostEntry(String entry) throws SshException
SshException
public boolean isHostFileWriteable()
Determines whether the host file is writable.
public abstract void onHostKeyMismatch(String host, List<SshPublicKey> allowedHostKey, SshPublicKey actualHostKey) throws SshException
Called by the verifyHost
method when the host key supplied
by the host does not match the current key recording in the known hosts
file.
host
- the name of the hostallowedHostKey
- the current key recorded in the known_hosts file.actualHostKey
- the actual key supplied by the userSshException
- if an error occurspublic abstract void onUnknownHost(String host, SshPublicKey key) throws SshException
Called by the verifyHost
method when the host key supplied
is not recorded in the known_hosts file.
host
- the name of the hostkey
- the public key supplied by the hostSshException
- if an error occurspublic void allowHost(String host, SshPublicKey pk, boolean always) throws SshException
Allows a host key, optionally recording the key to the known_hosts file.
host
- the name of the hostpk
- the public key to allowalways
- true if the key should be written to the known_hosts fileInvalidHostFileException
- if the host file cannot be writtenSshException
public Hashtable<String,List<SshPublicKey>> allowedHosts()
Returns a Map of the allowed hosts.
The keys of the returned Map are comma separated strings of "hostname,ipaddress". The value objects are Maps containing a string key of the public key alogorithm name and the public key as the value.
public void removeAllowedHost(String host)
Removes an allowed host.
host
- the host to removepublic boolean verifyHost(String host, SshPublicKey pk) throws SshException
Verifies a host key against the list of known_hosts.
If the host unknown or the key does not match the currently allowed host
key the abstract onUnknownHost
or
onHostKeyMismatch
methods are called so that the caller may
identify and allow the host.
verifyHost
in interface HostKeyVerification
host
- the name of the hostpk
- the host key suppliedSshException
- if an error occurspublic void saveHostFile() throws IOException
Save's the host key file to be saved.
InvalidHostFileException
- if the host file is invalidIOException
public String toString()
Outputs the allowed hosts in the known_hosts file format.
The format consists of any number of lines each representing one key for a single host.
titan,192.168.1.12 ssh-dss AAAAB3NzaC1kc3MAAACBAP1/U4Ed.....
titan,192.168.1.12 ssh-rsa AAAAB3NzaC1kc3MAAACBAP1/U4Ed.....
einstein,192.168.1.40 ssh-dss AAAAB3NzaC1kc3MAAACBAP1/U4Ed.....
Copyright © 2024. All rights reserved.