EldoS | Feel safer!

Software components for data protection, secure storage and transfer

How do you Implement Host Based Authentication

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
#4413
Posted: 11/27/2007 16:47:19
by Jonathan Macpherson (Basic support level)
Joined: 11/27/2007
Posts: 1

Hi
I’m having a problem Implementing Host Based Authentication.

I’ve been given a User Identity Key and a Host Identity Key from my client to Log on their SFTP server (openSSH). I’m not sure how to specify the different types of Keys or whether I need to?

Here is my code:

'open with a specified Host Based SSH Key
Public Function Open_WithHostBasedKey(ByVal sHost As String, ByVal nPort As Int16, ByVal sHostKeyFilename As String, ByVal sUserKeyFilename As String) As String

If nPort = 0 Then
nPort = 22
End If

If sHost = "" Then
m_sLastError = "Error: No host specified"
Return m_sLastError
End If

Try

objSFTP.Address = sHost
objSFTP.Port = nPort

objSFTP.AuthenticationTypes = SBSSHConstants.Unit.SSH_AUTH_TYPE_HOSTBASED

'first clear any key we might have had
objSFTP.KeyStorage.Clear()

Dim nLoadKey As Integer

'------------------------------------------------------------------------------
'Host Key
Dim HostKey As New SBSSHKeyStorage.TElSSHKey
nLoadKey = HostKey.LoadPublicKey(sHostKeyFilename)
HostKey.KeyFormat = TSBSSHKeyFormat.kfOpenSSH


If nLoadKey <> 0 Then
m_sLastError = "Error loading private key: " & nLoadKey.ToString()
Return m_sLastError
End If

'------------------------------------------------------------------------------
'User Key
Dim UserKey As New SBSSHKeyStorage.TElSSHKey
nLoadKey = UserKey.LoadPublicKey(sUserKeyFilename)
UserKey.KeyFormat = TSBSSHKeyFormat.kfOpenSSH

If nLoadKey <> 0 Then
m_sLastError = "Error loading private key: " & nLoadKey.ToString()
Return m_sLastError
End If
'------------------------------------------------------------------------------

objSFTP.KeyStorage.Add(UserKey)
objSFTP.KeyStorage.Add(HostKey)

'open the connection
objSFTP.Open()

'mark the connection as being open
m_bIsOpen = True

m_sCurrentDir = objSFTP.RequestAbsolutePath(".")

Catch ex As Exception
m_sLastError = "Error opening SFTP session. " & ex.Message & " Server reason" & objSFTP.ServerCloseReason
Return m_sLastError
End Try

m_sLastError = ""
Return m_sLastError
End Function
#4414
Posted: 11/28/2007 01:13:09
by Ken Ivanov (EldoS Corp.)

You are loading public key instead of a private one. Key-based authentication (either host based or generic public key authentication) is performed using private (not public) key. Please use TElSSHMemoryKeyStorage.LoadPrivateKey() method.

Reply

Statistics

Topic viewed 1787 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!