| java.lang.Object | |
| ↳ | com.trilead.ssh2.KnownHosts |
The KnownHosts class is a handy tool to verify received server hostkeys
based on the information in known_hosts files (the ones used by OpenSSH).
It offers basically an in-memory database for known_hosts entries, as well as some
helper functions. Entries from a
It is a thread safe implementation, therefore, you need only to instantiate one
known_hosts file can be loaded at construction time.
It is also possible to add more keys later (e.g., one can parse different
known_hosts files).
KnownHosts for your whole application.
| Constants | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| int | HOSTKEY_HAS_CHANGED | ||||||||||
| int | HOSTKEY_IS_NEW | ||||||||||
| int | HOSTKEY_IS_OK | ||||||||||
| Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| publicKeys | |||||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Adds a single public key entry to the database.
| |||||||||||
Adds a single public key entry to the a known_hosts file.
| |||||||||||
Parses the given known_hosts file and adds entries to the database.
| |||||||||||
Parses the given known_hosts data and adds entries to the database.
| |||||||||||
Convert a ssh2 key-blob into a human readable bubblebabble fingerprint.
| |||||||||||
Generate the hashed representation of the given hostname.
| |||||||||||
Convert a ssh2 key-blob into a human readable hex fingerprint.
| |||||||||||
Try to find the preferred order of hostkey algorithms for the given hostname.
| |||||||||||
Checks the internal hostkey database for the given hostkey.
| |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
Adds a single public key entry to the database. Note: this will NOT add the public key
to any physical file (e.g., "~/.ssh/known_hosts") - use addHostkeyToFile() for that purpose.
This method is designed to be used in a ServerHostKeyVerifier.
| hostnames | A list of hostname patterns - at least one most be specified. Check out the OpenSSH sshd man page for a description of the pattern matching algorithm. |
|---|---|
| serverHostKeyAlgorithm | As passed to the ServerHostKeyVerifier. |
| serverHostKey | As passed to the ServerHostKeyVerifier. |
| IOException |
|---|
Adds a single public key entry to the a known_hosts file.
This method is designed to be used in a ServerHostKeyVerifier.
| knownHosts | The file where the publickey entry will be appended. |
|---|---|
| hostnames | A list of hostname patterns - at least one most be specified. Check out the OpenSSH sshd man page for a description of the pattern matching algorithm. |
| serverHostKeyAlgorithm | As passed to the ServerHostKeyVerifier. |
| serverHostKey | As passed to the ServerHostKeyVerifier. |
| IOException |
|---|
Parses the given known_hosts file and adds entries to the database.
| knownHosts |
|---|
| IOException |
|---|
Parses the given known_hosts data and adds entries to the database.
| knownHostsData |
|---|
| IOException |
|---|
Convert a ssh2 key-blob into a human readable bubblebabble fingerprint. The used bubblebabble algorithm (taken from OpenSSH) generates fingerprints that are easier to remember for humans.
Example fingerprint: xofoc-bubuz-cazin-zufyl-pivuk-biduk-tacib-pybur-gonar-hotat-lyxux.
| keytype | Either "ssh-rsa" or "ssh-dss" |
|---|---|
| publickey | Key data |
Generate the hashed representation of the given hostname. Useful for adding entries with hashed hostnames to a known_hosts file. (see -H option of OpenSSH key-gen).
| hostname |
|---|
Convert a ssh2 key-blob into a human readable hex fingerprint. Generated fingerprints are identical to those generated by OpenSSH.
Example fingerprint: d0:cb:76:19:99:5a:03:fc:73:10:70:93:f2:44:63:47.
| keytype | Either "ssh-rsa" or "ssh-dss" |
|---|---|
| publickey | Key blob |
Try to find the preferred order of hostkey algorithms for the given hostname.
Based on the type of hostkey that is present in the internal database
(i.e., either ssh-rsa or ssh-dss)
an ordered list of hostkey algorithms is returned which can be passed
to Connection.setServerHostKeyAlgorithms.
| hostname |
|---|
null if no key for the given hostname is present or
there are keys of multiple types present for the given hostname. Otherwise,
an array with hostkey algorithms is returned (i.e., an array of length 2).
Checks the internal hostkey database for the given hostkey. If no matching key can be found, then the hostname is resolved to an IP address and the search is repeated using that IP address.
| hostname | The server's hostname, will be matched with all hostname patterns |
|---|---|
| serverHostKeyAlgorithm | Type of hostkey, either ssh-rsa or ssh-dss |
| serverHostKey | The key blob |
HOSTKEY_IS_OK: the given hostkey matches an entry for the given hostnameHOSTKEY_IS_NEW: no entries found for this hostname and this type of hostkeyHOSTKEY_HAS_CHANGED: hostname is known, but with another key of the same type
(man-in-the-middle attack?)| IOException | if the supplied key blob cannot be parsed or does not match the given hostkey type. |
|---|