pult / libssh2_delphi

delphi pascal libssh2 ssh2 sftp libssh2.dll
81 stars 30 forks source link

Authentication method "None" not supported #6

Closed rosch100 closed 4 years ago

rosch100 commented 5 years ago

uMySftpClient exits with "Could not get user auth list.", when the ssh server supports authentication method NONE. According to libssh2_userauth_list, a server accepting NONE as authentication returns nil. Therefore, we need to check libssh2_userauth_authenticated(FSession) after the call to libssh2_userauth_list.

Suggested change in line 1125:

    UserAuthList := libssh2_userauth_list(FSession, PAnsiChar(AnsiString(FUserName)), Length(AnsiString(FUserName)));
    if (libssh2_userauth_authenticated(FSession) = 0) then
    begin
      if UserAuthList = nil then
      begin
        Disconnect;
        RaiseSSHError('Could not get user auth list.');
      end;

    auth:

      AuthOK := False;
      AuthMode := ParseAuthList(UserAuthList);
      if amTryAll in AuthMode then
        AuthOK := UserAuthTryAll
      else
      begin
        if amPassword in AuthMode then
          AuthOK := UserAuthPassword;
        if not AuthOK and (amKeyboardInteractive in AuthMode) then
          AuthOK := UserAuthKeyboardInteractive;
        if not AuthOK and (amPublicKey in AuthMode) then
          AuthOK := UserAuthPKey;
        if not AuthOK and (amPublicKeyViaAgent in AuthMode) then
          AuthOK := UserAuthPKeyViaAgent;
      end;

      if not (AuthOK and (libssh2_userauth_authenticated(FSession) > 0)) then
      begin
        B := True;
        if Assigned(FOnAuthFail) then
          FOnAuthFail(Self, B);
        if not B then
        begin
          Disconnect;
          Exit;
        end
        else
          goto auth;
      end;
    end;
pult commented 4 years ago

Thanks! Fixed! https://github.com/pult/libssh2_delphi/commit/5d4cc614f96296fcbc8c8614b795b9e03895fe40