Class OpenSSHKnownHosts
- java.lang.Object
-
- net.schmizz.sshj.transport.verification.OpenSSHKnownHosts
-
- All Implemented Interfaces:
HostKeyVerifier
- Direct Known Subclasses:
ConsoleKnownHostsVerifier
public class OpenSSHKnownHosts extends java.lang.Object implements HostKeyVerifier
AHostKeyVerifierimplementation for aknown_hostsfile i.e. in the format used by OpenSSH.- See Also:
- Hashed hostnames spec
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOpenSSHKnownHosts.BadHostEntrystatic classOpenSSHKnownHosts.CommentEntryclassOpenSSHKnownHosts.EntryFactoryEach line in these files contains the following fields: markers (optional), hostnames, bits, exponent, modulus, comment.static classOpenSSHKnownHosts.HostEntrystatic interfaceOpenSSHKnownHosts.KnownHostEntrystatic classOpenSSHKnownHosts.Marker
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<OpenSSHKnownHosts.KnownHostEntry>entriesprotected java.io.FilekhFileprotected org.slf4j.Loggerlog
-
Constructor Summary
Constructors Constructor Description OpenSSHKnownHosts(java.io.File khFile)OpenSSHKnownHosts(java.io.File khFile, LoggerFactory loggerFactory)OpenSSHKnownHosts(java.io.Reader reader)OpenSSHKnownHosts(java.io.Reader reader, LoggerFactory loggerFactory)
-
Method Summary
Modifier and Type Method Description static java.io.FiledetectSSHDir()java.util.List<OpenSSHKnownHosts.KnownHostEntry>entries()java.util.List<java.lang.String>findExistingAlgorithms(java.lang.String hostname, int port)It is necessary to connect with the type of algorithm that matches an existing know_host entry.java.io.FilegetFile()protected booleanhostKeyChangedAction(java.lang.String hostname, java.security.PublicKey key)protected booleanhostKeyUnverifiableAction(java.lang.String hostname, java.security.PublicKey key)java.lang.StringtoString()booleanverify(java.lang.String hostname, int port, java.security.PublicKey key)This callback is invoked when the server's host key needs to be verified.voidwrite()voidwrite(OpenSSHKnownHosts.KnownHostEntry entry)Append a single entry
-
-
-
Field Detail
-
log
protected final org.slf4j.Logger log
-
khFile
protected final java.io.File khFile
-
entries
protected final java.util.List<OpenSSHKnownHosts.KnownHostEntry> entries
-
-
Constructor Detail
-
OpenSSHKnownHosts
public OpenSSHKnownHosts(java.io.Reader reader) throws java.io.IOException- Throws:
java.io.IOException
-
OpenSSHKnownHosts
public OpenSSHKnownHosts(java.io.File khFile) throws java.io.IOException- Throws:
java.io.IOException
-
OpenSSHKnownHosts
public OpenSSHKnownHosts(java.io.File khFile, LoggerFactory loggerFactory) throws java.io.IOException- Throws:
java.io.IOException
-
OpenSSHKnownHosts
public OpenSSHKnownHosts(java.io.Reader reader, LoggerFactory loggerFactory) throws java.io.IOException- Throws:
java.io.IOException
-
-
Method Detail
-
getFile
public java.io.File getFile()
-
verify
public boolean verify(java.lang.String hostname, int port, java.security.PublicKey key)Description copied from interface:HostKeyVerifierThis 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:
verifyin interfaceHostKeyVerifier- Parameters:
hostname- remote hostnameport- remote portkey- host key of server- Returns:
trueif key is acceptable,falseotherwise
-
findExistingAlgorithms
public java.util.List<java.lang.String> findExistingAlgorithms(java.lang.String hostname, int port)Description copied from interface:HostKeyVerifierIt is necessary to connect with the type of algorithm that matches an existing know_host entry. This will allow a match when we later verify with the negotiated keyHostKeyVerifier.verify- Specified by:
findExistingAlgorithmsin interfaceHostKeyVerifier- Parameters:
hostname- remote hostnameport- remote port- Returns:
- existing key types or empty list if no keys known for hostname
-
hostKeyUnverifiableAction
protected boolean hostKeyUnverifiableAction(java.lang.String hostname, java.security.PublicKey key)
-
hostKeyChangedAction
protected boolean hostKeyChangedAction(java.lang.String hostname, java.security.PublicKey key)
-
entries
public java.util.List<OpenSSHKnownHosts.KnownHostEntry> entries()
-
write
public void write() throws java.io.IOException- Throws:
java.io.IOException
-
write
public void write(OpenSSHKnownHosts.KnownHostEntry entry) throws java.io.IOException
Append a single entry- Throws:
java.io.IOException
-
detectSSHDir
public static java.io.File detectSSHDir()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-