EldoS | Feel safer!

Software components for data protection, secure storage and transfer

SimpleSSHClient Sample -- internally trap auth. error dialog

Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.
#259
Posted: 05/17/2006 14:23:58
by Donald Benkendorf (Standard support level)
Joined: 05/17/2006
Posts: 20

Indeed, your suggestion took care of one of the exceptions thrown in the IDE. However, even outside of the IDE, using a "release build", I'm still getting: modal display of dialog box with title bar "Sshdemo", message text = "SSH connection failed due to error (114)", and a single "OK"-button, i.e. to discharge the dialog...
I need to handle connections, via SSH, to hundreds of Unix/Linux servers, etc., programmatically and unattended. A modal dialogbox coming up when a particular user i.d./password combination is incorrect for a server, is not going to be acceptable. Can you recommend where to stick a try..catch construct to catch this exception, i.e. before it throws the dialogbox ?
#262
Posted: 05/17/2006 14:44:21
by Eugene Mayevski (EldoS Corp.)

There's one place where the dialog box is shown -- in SSHDemo.cpp there's a try/catch block which displays exception text. Of course you can move this try/catch to Button1Click() in MainForm.cpp, around a call to Open() method.


Sincerely yours
Eugene Mayevski
#263
Posted: 05/17/2006 14:58:41
by Donald Benkendorf (Standard support level)
Joined: 05/17/2006
Posts: 20

This seemed to do the trick :

void __fastcall TForm1::ClientSocket1Connect(TObject *Sender,
TCustomWinSocket *Socket)
{
Memo2->Lines->Add("Client socket connected");
try {
Client->Open();
} catch (...) {
};
if (Client->Active)
{
Memo2->Lines->Add("Connection started");
Memo2->Lines->Add(AnsiString("Server: ") + Client->ServerSoftwareName);
switch (Client->Version)
{
case sbSSH1 :
Memo2->Lines->Add("Version: SSHv1");
break;
case sbSSH2 :
Memo2->Lines->Add("Version: SSHv2");
break;
}
}
}
#264
Posted: 05/17/2006 15:00:58
by Donald Benkendorf (Standard support level)
Joined: 05/17/2006
Posts: 20

Putting the try...catch into Button1Click didn't seem to do it, i.e. uncommenting it in this code :
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TElSSHKey* Key;

if (!Connected){
Sbsshcommon::TSSHVersions versions;
versions.Clear();
if (CheckBox1->Checked)
versions << sbSSH1;
if (CheckBox2->Checked)
versions << sbSSH2;
Client->Versions = versions;
Client->Username = Edit3->Text;
Client->Password = Edit4->Text;

KeyStorage->Clear();
Key = new TElSSHKey();
if ((Edit6->Text.Length() != 0) && (Key->LoadPrivateKey(Edit6->Text, "") == 0))
{
KeyStorage->Add(Key);
Client->AuthenticationTypes = Client->AuthenticationTypes | SSH_AUTH_TYPE_PUBLICKEY;
}
else
Client->AuthenticationTypes = Client->AuthenticationTypes & (~SSH_AUTH_TYPE_PUBLICKEY);

Client->AuthenticationTypes = Client->AuthenticationTypes | (SSH_AUTH_TYPE_PASSWORD);
Client->AuthenticationTypes = Client->AuthenticationTypes | (SSH_AUTH_TYPE_KEYBOARD);

delete Key;

ClientSocket1->Host = Edit1->Text;
ClientSocket1->Port = atoi((const char *) Edit2->Text.c_str());
//try {
ClientSocket1->Open();
Button1->Caption = "Disconnect";
Connected = true;
//} catch (...) {
//};
} else {
if (Client->Active)
Client->Close();
Button1->Caption = "Connect";
Connected = false;
};
}

Reply

Statistics

Topic viewed 14595 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!