0

I am using devart SecureBridge to create a connection over SFTP and I am having trouble setting the authentication type on the SSHClient.

When i try without it gives me an exception: 'The negotioation of host key algorithm is failed'. I guess it's trying to use private/public key, but I want it to use password authentication.

Here is my code, I hope someone can guide me in the right direction.

  oSSHClient    := TScSSHClient.Create(nil);
  oSFTPClient   := nil;
  oFileStorage  := nil;
  oFileStorage := TScFileStorage.Create(nil);
  oSSHClient.KeyStorage := oFileStorage;
  iColon := pos(':', edHost.text);
  oSSHClient.HostName := edHost.Text;
  if iColon > 0 then
  begin
    oSSHClient.Port := StrToIntDef(copy(edHost.Text, iColon+1, length(edHost.Text)), 22);
  end;
  oSSHClient.User := edUser.Text;
  oSSHClient.Password := edPassword.Text;

  oSSHClient.Authentication := oSSHClient.Authentication.atPassword; // How am i supposed to set this

  oSSHClient.Connect;

EDIT: WORKING CODE FOR OTHERS TO SEE:

  oSSHClient    := TScSSHClient.Create(nil);
  oFileStorage  := nil;
  try
    oFileStorage := TScFileStorage.Create(nil);
    oSSHClient.KeyStorage := oFileStorage;
    iColon := pos(':', edHost.text);
    oSSHClient.HostName := edHost.Text;
    if iColon > 0 then
    begin
      oSSHClient.Port := StrToIntDef(copy(edHost.Text, iColon+1, length(edHost.Text)), 22);
    end;
    oSSHClient.User := edUser.Text;
    oSSHClient.Password := edPassword.Text;
    oSSHClient.HostKeyAlgorithms.AsString:='ssh-rsa,ssh-dss';
    oSSHClient.OnServerKeyValidate := ScSSHClientServerKeyValidate;
    oSSHClient.Authentication := atPassword;
    try
      try
        oSSHClient.Connect;
        TestErrorTekst := GetLang('CaptConnectToServerOK');
      except
        TestErrorTekst := GetLang('CaptConnectToServerFailed'); 
      end;
    finally
      oSSHClient.Disconnect;
    end;
  finally
    edTest.Text := TestErrorTekst;
    oSSHClient.Free;
    oFileStorage.Free;
  end;
Matt Baech
  • 404
  • 11
  • 23
  • Since no-one else has jumped in I will give an opinion as a definite non-expert. It is my understanding that authentication is to do with secure sockets layer (SSL) and nothing to do with passwords. It is an encryption technique and ensures that data gets passed securely between client and server. Passwords are an extra layer of security under that to ensure that as well as the data being secure, the person using that data is entitled to access the FTP site. – Dsm Aug 23 '16 at 14:57

1 Answers1

1

I suppose you should not set Authentication.

You can try 2 things. Set correct algorithm

oSSHClient.HostKeyAlgorithms.AsString:='ssh-rsa,ssh-dss';

Or disable validaton of the key. Set Accept in ScSSHClientServerKeyValidate procedure to True.

procedure TForm1.ScSSHClientServerKeyValidate(Sender: TObject;
  NewServerKey: TScKey; var Accept: Boolean);
begin
  Accept:=True;
end;
smooty86
  • 1,112
  • 7
  • 13
  • I have tried to set the scSSHCLientServerKeyValidate to no avail. I don't really understand the string you wrote in the first example. would you mind explaining it ? – Matt Baech Aug 24 '16 at 07:03
  • That sets which algorithm for key will be used. – smooty86 Aug 24 '16 at 07:23
  • Okay, it works now, seems like I had to do both, I am accepting your answer and editing my question with the full code for others to see. Thank you – Matt Baech Aug 24 '16 at 13:28
  • Please note that disabling validation of the key is potential security risk. You should probably add some additional validation or prompt box. You can find out more in their forum, eg. http://forums.devart.com/viewtopic.php?t=21779 – smooty86 Aug 24 '16 at 13:50