Public Key Authentication with C++ Builder 6 - WeOnlyDo Discussion board

Public Key Authentication with C++ Builder 6 (wodSSH / wodSSH.NET)

by David Lucas, Tuesday, July 19, 2005, 12:44 (7067 days ago)

Posting this to the forum in case the answer helps others in the future.

I'm struggling to authenticate with an OpenSSH server (Windows XP) using public key authentication. I can authenticate with the server using Putty, but I receive the error key not found when using wodSSH (I can also authenticate using password authentication - either through Putty or wodSSH). I think the problem may lie in the retrieval of the Private Key - since when its returned as a WideString the first few characters are NULL. If you retrieve it as a SAFEARRAY then an authentication attempt actually takes place, but still fails.


Here is my code:

if(!ClientKey) ClientKey = new TKeys(NULL);

WideString Filename = c:\program files\openssh\etc\TestKey ;
if(FileExists(Filename))
{
ClientKey->Load(Filename);
}
else
{
ClientKey->Generate(Wodsshkeylib_tlb::RSAkey);
ClientKey->Save(Wodsshkeylib_tlb::RSAkey, Filename);
}


if(!Client) Client = new TwodSSHCom(NULL);

Client->set_Protocol(Wodsshcomlib_tlb::SSHAuto);
Client->set_Hostname(WideString( localhost ));

Client->set_Authentication(Wodsshcomlib_tlb::authPubkey);

// Using the get_PrivateKey method simply causes it to hang,
// whereas this will actually 'attempt' to authenticate.
SAFEARRAY *PrivateKey = ClientKey->get_PrivateKeyData
(Wodsshkeylib_tlb::RSAkey);
Client->set_PrivateKey(TVariant(PrivateKey));

Client->set_Port(22);
Client->set_Blocking(true);

Client->set_Login(WideString( lucasd ));
Client->set_Password(WideString( july2005 ));

Client->OnConnected = ClientConnected;
Client->OnReceived = ClientReceived;
Client->OnLoginChallenge = ClientLoginChallenge;

Client->Connect1();

Hoping you can shed some light on what I'm doing wrong,

Regards,


David Lucas
Data Track Technology


Complete thread: