edtFTPnet/PRO - Secure FTP component for .NET | Free Trial | Pricing

KnownHostsManager Class

Holds details of the known hosts and their public keys.

Definition

Namespace: EnterpriseDT.Net.Ftp.Ssh
Assembly: edtFTPnetPRO (in edtFTPnetPRO.dll) Version: 12.7.0.0
C#
public class KnownHostsManager
Inheritance
Object    KnownHostsManager

Remarks

The known_hosts file contains a list of approved servers and their public keys. Setting ServerValidation to Automatic instructs the client to use this list to validate the servers that it connects to. Setting ServerValidation to AutomaticNoNameCheck is similar, however the server name is ignored in the validation process.

A single line in a known_hosts file looks like this:

edtmobile,10.0.0.3 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAt60CtjBMxiOO qgqfFtKZHY3g99uZpuh5E143FTO4dw+EHWNKemoWq59FMFMIZfSLyUpWmsjVT3PP1bc zOXP1OSn967kxLB/w7Xr84B1ZrTLwuR/ilq73HpgO7A8pdEJN7ybprzhs5CBEgaLQo2 pOxfqRYyc8TO2ADnZ1WwtjW48=

The first field is the hostname, i.e. the SSH server. The IP address is also listed - a number of comma separated hostnames and IP addresses can be listed. The second field is the applicable public key algorithm -"ssh-rsa" (for RSA key pairs) or "ssh-dss" (for DSA key pairs). The third field is the public key encoded using base 64.

The known_hosts file normally consists of multiple lines, one for each of the hosts that the client may wish to connect to. It is quite typical for a host to have entries in two lines, so that both RSA and DSA public keys can be listed.

The path of the known_hosts file should be assigned to the KnownHostsFile property to load the known hosts in that file into the manager. If another known_hosts file is subsequently assigned to this property, its contents will be added to the current list of known hosts. Use ClearKnownHosts to clear the current list.

Server public keys can also be maintained in their own key file and be used for server validation without adding them to the known_hosts file. The KnownHostsManager supports explicitly adding server public keys in this manner, via AddKnownHost(String, String).

Use WriteKnownHosts(String) to write the current contents of the known hosts lists to a file. If hosts are loaded via the KnownHostsFile and also by AddKnownHost(String, String), the combined list can be merged into one known_hosts file by using WriteKnownHosts(String).

Constructors

KnownHostsManagerInitializes a new instance of the KnownHostsManager class

Properties

KnownHostsFile Name of file containing the list of known hosts and their public keys that was most recently loaded.
NumHosts Number of known hosts names and IP addresses that have been loaded.

Methods

Add Add the hostname along with its public key to the hashtable
AddHostKey Add the key for this host
AddKnownHost(String, Byte) Add a hostname/public key pair to the known hosts data.
AddKnownHost(String, String) Add a hostname/public key pair to the known hosts data.
ClearKnownHosts Clear all loaded known hosts from the internal list.
EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetPublicKey Get the public key for this hostname/algorithm.
GetPublicKeys Get all the public keys loaded for the supplied key algorithm
GetTypeGets the Type of the current instance.
(Inherited from Object)
IsKeyLoaded Determines if this key is loaded for this host
LoadKnownHosts(Stream) Read the known hosts file to obtain the host public keys.
LoadKnownHosts(String) Read the given known hosts file to obtain the host public keys.
MemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
ToString Represent the instance as a string.
(Overrides ObjectToString)
WriteKnownHosts Write the known hosts to file, together with their public keys, in the standard known_hosts format.

See Also