-
-
Notifications
You must be signed in to change notification settings - Fork 4
SSH.KnownHosts
SSH.KnownHosts
Protected Class KnownHosts
This class represents a list of known SSH servers. When you connect to a server you can use this class to verify that the server fingerprint matches the one stored in the list. If the fingerprint doesn't match then you should show a big scary warning to the user and bail out. If the server isn't found in the list then you can add it.
Verifying the server's fingerprint is optional, but strongly recommended, and should be done before sending the user's credentials.
This example connects to the remote server and then compares its fingerprint to a list of known hosts loaded from the user's home folder.
Dim session As New SSH.Session()
If Not session.Connect("ssh.example.com", 22) Then MsgBox("Unable to connect!")
' locate the user's known_hosts file (or supply your own)
Dim f As FolderItem = SpecialFolder.UserHome.Child(".ssh")
If f.Exists Then f = f.Child("known_hosts")
If f.Exists Then
Dim known As New SSH.KnownHosts(session)
Call known.Load(f)
If Not session.CheckHost(known, False) Then
If session.LastError = SSH.ERR_HOSTKEY_NOTFOUND Then
Call MsgBox("Fingerprint not known!", 16, "Unknown server")
Return
ElseIf session.LastError = SSH.ERR_HOSTKEY_MISMATCH Then
Call MsgBox("Fingerprint has changed!", 16, "Security breach")
Return
ElseIf session.LastError <> 0 Then
Call MsgBox("Unable to verify fingerprint.", 16, "Unknown error")
Return
End If
End If
End If
' proceed with the session by sending the credentials
Wiki home | Project page | Bugs | Become a sponsor
Text and code examples are Copyright ©2018-24 Andrew Lambert, offered under the CC BY-SA 3.0 License.