Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't create a class instance of PrivateKeyFile #728

Closed
orionplus opened this issue Sep 11, 2020 · 9 comments
Closed

Can't create a class instance of PrivateKeyFile #728

orionplus opened this issue Sep 11, 2020 · 9 comments

Comments

@orionplus
Copy link

orionplus commented Sep 11, 2020

I'm using version 2020.0.0-beta1.
Created the key pair with the command: ssh-keygen -t ecdsa -b 521
During the object creation
PrivateKeyFile keyFile = new PrivateKeyFile("c:..\id_ecdsa_private.key","passphrase")

I'm getting the error:
openssh key type: ecdsa-sha2-nistp521 is not supported
at Renci.SshNet.PrivateKeyFile.ParseOpenSshV1Key(Byte[] keyFileData, String passPhrase)
at Renci.SshNet.PrivateKeyFile.Open(Stream privateKey, String passPhrase)
at Renci.SshNet.PrivateKeyFile..ctor(String fileName, String passPhrase)
at Renci.SshNet.PrivateKeyFile..ctor(String fileName)
at Onboarding.Services.SFTPService.d__7.MoveNext() in C:\Projects...\SFTPService.cs:line 65

The documentation says SSH.NET supports the following host key algorithms:
...
ecdsa-sha2-nistp521
...
Can anyone tell me please what is wrong?
Thanks!

@darinkes
Copy link
Collaborator

PrivateKey != HostKey.
You have to wait for this MR to be merged: #614

@orionplus
Copy link
Author

Thanks for the prompt reply. What is the proper solution would be until that merge's done?

@darinkes
Copy link
Collaborator

darinkes commented Sep 11, 2020

You can create a key with the methods listed here: https://github.com/sshnet/SSH.NET#public-key-authentication.

ECDSA Keys are currently just supported in OpenSSL-Format. ssh-keygen generates them in OpenSSH-Format by default.
So a key generated with $ ssh-keygen -t ecdsa -b 521 -m pem should work.

Or you use ED25519 via: $ ssh-keygen -t ed25519

@orionplus
Copy link
Author

@darinkes Thanks!

@hhyyrylainen
Copy link

With ecdsa keys I got the following error:

System.NotImplementedException: The method or operation is not implemented.
  at System.Security.Cryptography.ECDsa.Create (System.Security.Cryptography.ECParameters parameters) [0x00000] in <d9f4d70345484e55bbf6c1ef353f07c4>:0 
  at Renci.SshNet.Security.EcdsaKey.Import (System.String curve_oid, System.Byte[] publickey, System.Byte[] privatekey) [0x0007e] in <c7169cd606324a41b931acc40c516428>:0 
  at Renci.SshNet.Security.EcdsaKey..ctor (System.Byte[] data) [0x000f0] in <c7169cd606324a41b931acc40c516428>:0 
  at Renci.SshNet.PrivateKeyFile.Open (System.IO.Stream privateKey, System.String passPhrase) [0x00322] in <c7169cd606324a41b931acc40c516428>:0 
  at Renci.SshNet.PrivateKeyFile..ctor (System.String fileName, System.String passPhrase) [0x00023] in <c7169cd606324a41b931acc40c516428>:0 
  at Renci.SshNet.PrivateKeyFile..ctor (System.String fileName) [0x00000] in <c7169cd606324a41b931acc40c516428>:0 
  at Submission#30+<<Initialize>>d__0.MoveNext () [0x00008] in <e93e87d6d7854cc0919a6dcae8d7157b>:0 

That was in PEM format, and (without specifying -m pem to key generation), I got this error:

Renci.SshNet.Common.SshException: openssh key type: ecdsa-sha2-nistp521 is not supported
  + Renci.SshNet.PrivateKeyFile.ParseOpenSshV1Key(byte[], string)
  + Renci.SshNet.PrivateKeyFile.Open(System.IO.Stream, string)
  + Renci.SshNet.PrivateKeyFile..ctor(string, string)
  + Renci.SshNet.PrivateKeyFile..ctor(string)

Only ed25519 key seems to load correctly.

@darinkes
Copy link
Collaborator

darinkes commented Aug 16, 2021

The method or operation is not implemented.

That sounds like Mono, not .NET Correct?

https://github.com/mono/mono/blob/main/mcs/class/referencesource/System.Core/System/Security/Cryptography/ECDsa.cs#L31

ed25519 is done in SSH.NET, ECDsa requires .NET or netstandard functionality.

See the Readme, Mono is not supported. Also cause most of the Crypto we need just throws NotImplementedExceptions.

@hhyyrylainen
Copy link

hhyyrylainen commented Aug 16, 2021

I'm using .NET SDK (5.0.205) on Linux.

Edit: I used C# Interactive from Rider, where I'm not 100% sure it uses that version as I also have SDK version 3.1.117 installed.

@darinkes
Copy link
Collaborator

Weird. Cant see why official .NET should raise this exception.
In .NET Ecdsa.Create(ECParameters) is implemented since ages, see:

https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.ecdsa.create?view=net-5.0#System_Security_Cryptography_ECDsa_Create_System_Security_Cryptography_ECParameters_

Just seen this error with Mono so far. Using SSH.NET myself on various linux systems, all work fine ECDsa and .NET.

@scott-xu
Copy link
Collaborator

scott-xu commented Sep 1, 2024

openssh key type: ecdsa-sha2-nistp521 is not supported

The issue should be fixed by #614

System.NotImplementedException: The method or operation is not implemented.

The issue should be fixed by #1461

I'm using .NET SDK (5.0.205) on Linux.

Edit: I used C# Interactive from Rider, where I'm not 100% sure it uses that version as I also have SDK version 3.1.117 installed.

On Mac OS X and Linux, JetBrains Rider defaults to Mono’s csharp. 1

Footnotes

  1. https://www.jetbrains.com/help/rider/CSHARP_Interactive.html

@scott-xu scott-xu closed this as completed Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants