Class KnownHostsKeyVerification
- All Implemented Interfaces:
HostKeyUpdater,HostKeyVerification
- Direct Known Subclasses:
KnownHostsFile
An abstract HostKeyVerification class implementation providing validation against the known_hosts format.
- Author:
- Lee David Painter
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassclassclassclassclassclassclassclass -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEntry(SshPublicKey key, String comment, boolean always, String... names) voidaddEntry(SshPublicKey key, String comment, String... names) voidallowHost(String host, SshPublicKey key, boolean always) voidclear()booleanbooleanisKnownHost(String host, SshPublicKey key) voidload(InputStream in) protected voidonHostKeyAdded(Set<String> names, SshPublicKey key) protected voidonHostKeyMismatch(String host, List<SshPublicKey> allowedHostKey, SshPublicKey actualHostKey) Called by theverifyHostmethod when the host key supplied by the host does not match the current key recording in the known hosts file.protected voidonHostKeyRemoved(Set<String> names, SshPublicKey key) protected voidonHostKeyUpdated(Set<String> names, SshPublicKey key) protected voidonInvalidHostEntry(String entry) protected voidonRevokedKey(String host, SshPublicKey key) Called by theverifyHostmethod when the host key supplied is listed as a revoked key.protected voidonUnknownHost(String host, SshPublicKey key) Called by theverifyHostmethod when the host key supplied is not recorded in the known_hosts file.voidvoidremoveEntries(String host) Removes an allowed host.voidremoveEntries(String... hosts) voidresolveNames(String host) voidsetComment(KnownHostsKeyVerification.KeyEntry entry, String comment) voidsetHashHosts(boolean hashHosts) voidsetUseCanonicalHostnames(boolean value) voidsetUseReverseDNS(boolean value) toString()Outputs the allowed hosts in the known_hosts file format.voidupdateHostKey(String host, SshPublicKey key) booleanbooleanbooleanbooleanverifyHost(String host, SshPublicKey pk) Verifies a host key against the list of known_hosts.protected booleanverifyHost(String host, SshPublicKey pk, boolean validateUnknown)
-
Constructor Details
-
KnownHostsKeyVerification
- Throws:
SshExceptionIOException
-
KnownHostsKeyVerification
- Throws:
SshExceptionIOException
-
KnownHostsKeyVerification
public KnownHostsKeyVerification()
-
-
Method Details
-
clear
public void clear() -
load
- Throws:
SshExceptionIOException
-
onHostKeyAdded
-
setComment
-
setHashHosts
public void setHashHosts(boolean hashHosts) -
onInvalidHostEntry
- Throws:
SshException
-
onHostKeyMismatch
protected void onHostKeyMismatch(String host, List<SshPublicKey> allowedHostKey, SshPublicKey actualHostKey) throws SshException Called by the
verifyHostmethod when the host key supplied by the host does not match the current key recording in the known hosts file.- Parameters:
host- the name of the hostallowedHostKey- the current key recorded in the known_hosts file.actualHostKey- the actual key supplied by the user- Throws:
SshException- if an error occurs- Since:
- 0.2.0
-
onUnknownHost
Called by the
verifyHostmethod when the host key supplied is not recorded in the known_hosts file.- Parameters:
host- the name of the hostkey- the public key supplied by the host- Throws:
SshException- if an error occurs- Since:
- 0.2.0
-
onRevokedKey
Called by theverifyHostmethod when the host key supplied is listed as a revoked key. This is informational, any changes made to the current entries will still result in a failed host verification.- Parameters:
host-key-- Throws:
SshException
-
removeEntries
Removes an allowed host.
- Parameters:
host- the host to remove- Throws:
SshException- Since:
- 0.2.0
-
removeEntries
- Throws:
SshException
-
removeEntries
-
removeEntry
-
onHostKeyRemoved
-
isHostFileWriteable
public boolean isHostFileWriteable() -
allowHost
- Throws:
SshException
-
addEntry
- Throws:
SshException
-
addEntry
public void addEntry(SshPublicKey key, String comment, boolean always, String... names) throws SshException - Throws:
SshException
-
verifyHost
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
onUnknownHostoronHostKeyMismatchmethods are called so that the caller may identify and allow the host.- Specified by:
verifyHostin interfaceHostKeyVerification- Parameters:
host- the name of the hostpk- the host key supplied- Returns:
- true if the host is accepted, otherwise false
- Throws:
SshException- if an error occurs- Since:
- 0.2.0
-
verifyHost
protected boolean verifyHost(String host, SshPublicKey pk, boolean validateUnknown) throws SshException - Throws:
SshException
-
resolveNames
-
useCanonicalHostname
public boolean useCanonicalHostname() -
useReverseDNS
public boolean useReverseDNS() -
useHashHosts
public boolean useHashHosts() -
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..... -
setUseCanonicalHostnames
public void setUseCanonicalHostnames(boolean value) -
setUseReverseDNS
public void setUseReverseDNS(boolean value) -
getKeyEntries
-
isKnownHost
- Specified by:
isKnownHostin interfaceHostKeyUpdater- Throws:
SshException
-
updateHostKey
- Specified by:
updateHostKeyin interfaceHostKeyUpdater- Throws:
SshException
-
onHostKeyUpdated
-