SSh with dotconnect. Exporting the ssh host key

SSh with dotconnect. Exporting the ssh host key

Postby KW » Tue 06 Jul 2010 23:34

Can someone help me understasnd the difference between the host key and the fingerprint?

For example in the code:

Code: Select all

MySqlConnection conn = new MySqlConnection("User Id=root;Password=root;Host=localhost;Port=3306;Database=test;");
    conn.ConnectionTimeout = 300;
    conn.Protocol = MySqlProtocol.Ssh;

    conn.SshOptions.AuthenticationType = SshAuthenticationType.Password;
    conn.SshOptions.Host = "testHost";
    conn.SshOptions.Port = 22;
    conn.SshOptions.User = "testUser";
    conn.SshOptions.Password = "test";
    // sets host key  verification options
    conn.SshOptions.StrictHostKeyChecking = true;
    conn.SshOptions.HostKey = @"D:\Test\HostKey.pub"; // file with incorrect key
    conn.SshHostKeyConfirmation += new SshHostKeyConfirmationHandler(conn_SshHostKeyConfirmation);


How do you go about correctly exporting the HostKey from your server? Do you just copy the ssh_host__rsa_key.pub from the server? Or do you just need to generate the fingerprint? And if so what is the correct way to get the fingerprint from your server to your client?
KW
 
Posts: 121
Joined: Tue 19 Feb 2008 19:12

Postby Shalex » Thu 08 Jul 2010 15:58

Yes, you are right: ssh_host__rsa_key.pub - is a file that contains a public part of host key. You can copy this file from your server and pass it in connection string. When establishing connection to the SSH server, dotConnect for PostgreSQL obtains the public host key from the SSH server and compares it as a byte array with the public host key provided in the connection string. If verification during establishing connection failed, the SshHostKeyConfirmation event occurs, and you can handle this event by providing fingerprints to your user with a confirmation request for establising connection.
For more information and sample, please refer to
http://www.devart.com/dotconnect/mysql/docs/Devart.Data.MySql~Devart.Data.MySql.SshOptions~StrictHostKeyChecking.html.
Shalex
Devart Team
 
Posts: 7616
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for MySQL