connect w/private key never returns

Jul 20, 2012 at 4:50 PM

I'm a first time user of private key access. Here's what I did:

Generated keys with a passphrase in PuTTYGen.

Saved the public & private keys. Exported "OpenSSH key".

Sent the public key to the SFTP server folks (our friends at CMS).

In Filezilla made the connection, added the private key. Waited a day. Connected - it worked!

Now the problem - tried running the following code. (Naturally the constants aren't shown.)

Sub Main()

        Dim key As New PrivateKeyFile(File.OpenRead("openSSH.key"), conPassPhrase)
        Using client As New SftpClient(conSite, conPort, conUsername, key)

            Try
                client.Connect()
                Console.WriteLine("connected")


            Catch ex As Exception

                Console.WriteLine("exception: " & ex.Message)
            End Try
        End Using

        Console.ReadKey()

    End Sub

Execution gets down to the line where the connection occurs. And never gets any further. As in neither console.writeline ever happens. Just hangs.

I'd expect if a problem to see an exception. Never happens.

2 things done in Filzilla: 1) protocol changed to "SFTP" & 2) login type changed to "normal"

Any ideas?

Coordinator
Jul 21, 2012 at 12:08 AM

Hi,

 

Could be few things.

One, is the server that you using handles private key or connection in general a little bit differently, may be waits for some different packet that I am not expecting or something like that.

 

May be the problem with private key or the way I handle it.

Few suggestions, can you try to connect to the same server using username password combination, and try to connect using private key using different server.

Also, try to use source code version and see where it hangs, it might give a clue to whats going on.

 

Thanks,

Oleg

Jul 22, 2012 at 2:58 PM

thanks for the quick response.

i'll try some of the things you mentioned.

one thing (& not all that important),do you make the source available in framework3.5?

Coordinator
Jul 23, 2012 at 5:58 PM

Hi,

 

If you download the source version, you can find a project there for 3.5 vresion but it relays on refernceing 4.0 project, so you can have them together.

 

If you need only 3.5 then I guess what you can do is manually copy files that references by 3.5 and copy them from 4.0 project to 3.5.

 

Hope it helps.

 

Thanks,

Oleg

Jul 31, 2012 at 3:47 PM

Sorry, gone for a week of training.

It appears the problem of never returning from the DLL is that authenticaion is partially failing. This in connectInfo, about line 370. Each and every returned result is PartialSuccess. So the loop continues, looks like forever.

Any ideas?


Coordinator
Aug 10, 2012 at 2:16 PM

Hi,

Thanks for investigating this issue.

The only idea which comes to my mind is that this server requires multiple authentication methods,

for example private key and username/password combination or may be some other.

 

Can you connect to this server using putty?

 

Thanks,

Oleg

Aug 13, 2012 at 4:48 PM

You're right, I think.

Used putty (first time) & server says it's using keyboard-interactive authentication. Then it asks for a password, which I enter & it doesn't accept.

Server then says "further authentication required", then "SSH server: password", (blah blah blah), then "Password:".

So changed the code to add 3 authentication methods (in this order, if that's important): PasswordAuthentication, KeyboardInteractiveAuthentication, & PrivateKeyAuthentication.

Run but still just hangs.

Here's latest code:

       _keyboardInteractive = New KeyboardInteractiveAuthenticationMethod(conUsername)
        Dim pam As New PasswordAuthenticationMethod(conUsername, conPassword)
        Dim keyFile As New PrivateKeyFile(conFile, conPassPhrase)
        Dim ci As New ConnectionInfo(conHost,
                                     conPort,
                                     conUsername,
                                     pam,
                                     _keyboardInteractive,
                                     New PrivateKeyAuthenticationMethod(conUsername, keyFile))

        AddHandler _keyboardInteractive.AuthenticationPrompt, AddressOf _keyboardInteractive_AuthenticationPrompt

        Using client As New SftpClient(ci)
            Try
                client.Connect()
                Console.WriteLine("connected")
            Catch ex As Exception
                Console.WriteLine("exception: " & ex.ToString)
            End Try
        End Using
        Console.ReadKey()

    End Sub

    Private Sub _keyboardInteractive_AuthenticationPrompt(sender As Object, e As Renci.SshNet.Common.AuthenticationPromptEventArgs)

        For Each prompt As AuthenticationPrompt In e.Prompts
            Debug.Print(prompt.Request)
            If prompt.Request.IndexOf("Password:") > -1 Then
                prompt.Response = conPassword
                Exit For
            End If
        Next
    End Sub
Note prompt event occurs & password is passed. Lots of times, not just once.
Any ideas?