'Declaration Public Event SshHostKeyConfirmation As SshHostKeyConfirmationHandler
public event SshHostKeyConfirmationHandler SshHostKeyConfirmation
Event Data
The event handler receives an argument of type SshHostKeyConfirmationEventArgs containing data related to this event. The following SshHostKeyConfirmationEventArgs properties provide information specific to this event.
Property | Description |
---|---|
Confirmation | Gets or sets the value, indicating whether to continue connecting after this event. |
Host | Gets the name of the host, we are connecting with. |
KeyType | Gets the server public key type. |
Md5Fingerprint | Gets the string representation of the server public key fingerprint, generated with MD5 hash algorithm |
Port | Gets the port, we are connecting with. |
Sha1Fingerprint | Gets the string representation of the server public key fingerprint, generated with SHA1 hash algorithm |
Warning | Gets the warning message string. |
Remarks
You may use this event to handle the situation when you don't have the host key, and have only its fingerprint. Devart.Common.SshHostKeyConfirmationEventArgs.Md5Fingerprint and Devart.Common.SshHostKeyConfirmationEventArgs.Sha1Fingerprint properties contain the string representation of the fingerprint, generated by the corresponding algorythm, as the hexadecimal digits. If you agree to continue connecting, you should set the Devart.Common.SshHostKeyConfirmationEventArgs.Confirmation property to Devart.Common.SshHostKeyConfirmation.Confirm.
Example
static void Main(string[] args) { PgSqlConnection conn = new PgSqlConnection("host=server;database=test;user id=postgres;"); conn.ConnectionTimeout = 300; conn.SshOptions.AuthenticationType = SshAuthenticationType.Password; conn.SshOptions.Host = "testHost"; conn.SshOptions.Port = 22; conn.SshOptions.User = "testUser"; conn.SshOptions.Password = "test"; // set 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); try { conn.Open(); Console.WriteLine("\nConnected successfully"); } catch (Exception ex) { Console.WriteLine("\nConnection failed: {0}", ex.Message); } Console.ReadKey(); } static void conn_SshHostKeyConfirmation(object sender, SshHostKeyConfirmationEventArgs e) { Console.WriteLine("--------- Warning message --------"); Console.WriteLine(e.Warning); Console.WriteLine("---------Host Key information--------"); Console.WriteLine("Host - {0}", e.Host); Console.WriteLine("Port - {0}", e.Port); Console.WriteLine("Key Type - {0}", e.KeyType); Console.WriteLine("Md5Fingerprint - {0}", e.Md5Fingerprint); Console.WriteLine("Sha1Fingerprint - {0}", e.Sha1Fingerprint); Console.WriteLine("-------------------------------------"); Console.Write("Continue?: "); if (Console.ReadKey().Key == ConsoleKey.Y) e.Confirmation = SshHostKeyConfirmation.Confirm; else e.Confirmation = SshHostKeyConfirmation.NotConfirm; }
Module Module1 Sub Main() Dim conn As PgSqlConnection = New PgSqlConnection("host=server;database=test;user id=postgres;") conn.ConnectionTimeout = 300 ' set ssh options conn.SshOptions.AuthenticationType = SshAuthenticationType.Password conn.SshOptions.Host = "testHost" conn.SshOptions.Port = 22 conn.SshOptions.User = "testUser" conn.SshOptions.Password = "test" ' set host key verification options conn.SshOptions.StrictHostKeyChecking = True conn.SshOptions.HostKey = "D:\Test\HostKey.pub"; ' file with incorrect key AddHandler conn.SshHostKeyConfirmation, AddressOf conn_SshHostKeyConfirmation Try conn.Open() Console.WriteLine(vbCrLf + "Connected successfully") Catch ex As Exception Console.WriteLine(vbCrLf + "Connection failed: {0}", ex.Message) End Try Console.ReadKey() End Sub Sub conn_SshHostKeyConfirmation(ByVal sender As Object, ByVal e As SshHostKeyConfirmationEventArgs) Console.WriteLine("--------- Warning message --------") Console.WriteLine(e.Warning) Console.WriteLine("---------Host Key information--------") Console.WriteLine("Host - {0}", e.Host) Console.WriteLine("Port - {0}", e.Port) Console.WriteLine("Key Type - {0}", e.KeyType) Console.WriteLine("Md5Fingerprint - {0}", e.Md5Fingerprint) Console.WriteLine("Sha1Fingerprint - {0}", e.Sha1Fingerprint) Console.WriteLine("-------------------------------------") Console.Write("Continue?: ") If (Console.ReadKey().Key = ConsoleKey.Y) Then e.Confirmation = SshHostKeyConfirmation.Confirm Else e.Confirmation = SshHostKeyConfirmation.NotConfirm End If End Sub End Module
Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
See Also