Failed to user Key authentication for SFTP - WeOnlyDo Discussion board

Failed to user Key authentication for SFTP (wodSFTP / wodSFTP.NET / wodSFTPdll)

by tom, Wednesday, March 27, 2019, 07:27 (2066 days ago)

Hi All,

I got a problem by Delphi using wodSFTPComLib & wodSSHKeyLib to send file to OpenSSH SFTP Server.
Use username and password to send file is work fine, but failed to send file by using key.

I have tested public/private key by Winscp and Xshell it's both work fine, that means I can confirm that the keys correct.

--------------------------------------------------

var k: Tkeys;
begin
k := TKeys.Create(self);
k.Load('c:\private_key');
PrivateKey := k.ToXmlString(RSAkey, true);
CoreSC.Authentication := authPubkey;
CoreSC.Connect1; // if I use Connect it will nothing be happened, I do not know why.
end

--> with error: Invalid username or password reported by server
Private key does not have password.

--------------------------------------------------

var k: Tkeys;
begin
k := TKeys.Create(self);
k.Load('c:\private_key');
PrivateKey := k.PrivateKey[RSAkey];
CoreSC.Authentication := authPubkey;
CoreSC.Connect1; // if I use Connect it will nothing be happened, I do not know why.
end

--> with error: Private key type could not be determined


how could it be solved, someone can help :)
Thanks!

TOM

Failed to user Key authentication for SFTP

by Jasmine, Wednesday, March 27, 2019, 07:29 (2066 days ago) @ tom

Hi Tom.

Who created the key? wodSFTP can try to read "alien" keys, but doesn't have to succeed. If they are in some 3rd party format, then it will fail to read it.

Jasmine.

Failed to user Key authentication for SFTP

by tom, Wednesday, March 27, 2019, 08:40 (2066 days ago) @ Jasmine
edited by tom, Wednesday, March 27, 2019, 08:47

Hi Tom.

Who created the key? wodSFTP can try to read "alien" keys, but doesn't have to succeed. If they are in some 3rd party format, then it will fail to read it.

Jasmine.


Hi Jasmine,

Thanks!

The keys genereated by Tkeys object.

-----------------------------------------
var
k: TKeys;
begin
k := TKeys.Create(self);
k.Generate(RSAKey);
k.Save(RSAKey, 'private_key');

p := TStringList.Create;
p.Add(k.PublicKeyOpenSSH[RSAKey]);
p.SaveToFile('public_key');
end;

----------------------------------------------
The context of private key

-----BEGIN RSA PRIVATE KEY-----
MIICWwIBAAKBgQDBJdplJHxBVhismG5nK1oyfHiSm1FYZHa0qoMXti2PQEgnOwUK
--more--
4z9txiZTt9s3d6OT5XIae4+iz9ap5l1fTIPnsr4gwQ==
-----END RSA PRIVATE KEY-----

-----------------------------------------------
The context of public key for openSSH

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAwSXaZSR8Q
--more--
S08HEd0QlxDYMgvX5USzv8oz6NQc0=

-----------------------------------------------
The running value of k.PrivateKey[RSAKey] by Watch

#0#0#0#7'ssh-rsa'#0#0#0'?'#0'?趀$|AV'#$18'瑯ng+Z2|x挍QXdv椽??廆H'';
--more--
6O?恳"QRuZ鬬'#$14'^`?m?S粉7w錼'#$1A'{彚现╂]_L冪簿 ?'

--------------------------------------------------
The running value of k.ToXmlString(RSAKey, true); by Watch

'<RSAKeyValue><Modulus>wSXaZSR8QVYYrJh
--more--
4YtMIZLg0Irqo6b4ZR+c=</D></RSAKeyValue>'

------------------------------------------------

TOM

Failed to user Key authentication for SFTP

by Jasmine, Wednesday, March 27, 2019, 10:09 (2066 days ago) @ tom

Hi Tom,

I just checked, key is loaded ok.

But I think this line

PrivateKey := k.ToXmlString(RSAkey, true);

causes issue. Can you do something like

Sftp1.PrivateKey = k

or k.DefaultInterface() or something like that, I don't remember exact line for Delphi. PrivateKey will not accept XML, but will accept reference to wodKeys or raw data in some cases.

Jasmine.

Failed to user Key authentication for SFTP

by tom, Wednesday, March 27, 2019, 11:08 (2066 days ago) @ Jasmine

Hi Tom,

I just checked, key is loaded ok.

But I think this line

PrivateKey := k.ToXmlString(RSAkey, true);

causes issue. Can you do something like

Sftp1.PrivateKey = k

or k.DefaultInterface() or something like that, I don't remember exact line for Delphi. PrivateKey will not accept XML, but will accept reference to wodKeys or raw data in some cases.

Jasmine.

Hi Jasmine,

Issue has been solved by used sftp.PrivateKey := k.DefaultInterface;

Thanks very much!
Have a nice day!

TOM