-
Notifications
You must be signed in to change notification settings - Fork 5k
NotSupportedException at at System.Security.Cryptography.HMAC.HashFinal() #59289
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
Comments
Tagging subscribers to this area: @bartonjs, @vcsjones, @krwq, @GrabYourPitchforks Issue DetailsDescriptionRelated to: sshnet/SSH.NET#776 I am using SSH.NET to connect to a SFTP Client with private key. Exception: Other users have reported same issue with password authetication. I don't know any workarounds. ConfigurationDOTNETCORE 3.1 Other informationFull stack trace: " at System.Security.Cryptography.HMAC.HashFinal() in //src/System.Security.Cryptography.Primitives/src/System/Security/Cryptography/HMAC.cs:line 68\r\n at Renci.SshNet.Security.Cryptography.HMACSHA1.HashFinal()\r\n at System.Security.Cryptography.HashAlgorithm.CaptureHashCodeAndReinitialize() in //src/System.Security.Cryptography.Primitives/src/System/Security/Cryptography/HashAlgorithm.cs:line 115\r\n at Renci.SshNet.Session.SendMessage(Message message)\r\n at Renci.SshNet.Session.Connect()\r\n at Renci.SshNet.BaseClient.CreateAndConnectSession()\r\n at Renci.SshNet.BaseClient.Connect()\r\n at ... (my code) Exception type:
|
The SSH.NET project has a custom type which subclasses If this library is compiled against .NET Framework, where the Seems like our introduction of a method override in an unsealed type has introduced a behavioral breaking change between .NET Framework and .NET Core / .NET 5. @ericstj @bartonjs As people who understand binary compat better than me, does this theory seem sound? |
Thanks @GrabYourPitchforks for the comment. If that is the case, a workaround would be to clone SSH.NET and recompile it against .NET Core? |
Note: our business partner reports that this works with .NET Core 2.1. |
I think the problem would just fix itself if https://github.com/sshnet/SSH.NET/blob/a5bd08d655bb6a3c762306472cec354556dca3a3/src/Renci.SshNet/Renci.SshNet.csproj#L10 added a target for .NET (netcoreapp3.1, net5.0, whatever), and it stems from the netstandard2.0 definition of HMACSHA1: public partial class HMACSHA1 : System.Security.Cryptography.HMAC
{
public HMACSHA1() { }
public HMACSHA1(byte[] key) { }
public HMACSHA1(byte[] key, bool useManagedSha1) { }
} which matches the .NET Framework implementation of the type: https://referencesource.microsoft.com/#mscorlib/system/security/cryptography/hmacsha1.cs,ac2ad0c1e5c1be3e. This is one of those frustrating things where doing more work in the compiler (determining the specific derived type that base.Foo will target) produces wrong answers (the runtime handles missing overrides or methods "moving down", just costs an extra few CPU cycles at JIT time). |
@bartonjs I just wanted to follow up on this: I forked the (SSH.NET) repository and made the explicit build for .NET Core 3.1 and .NET 5.0 and the issue was resolved / worked around. |
Uh oh!
There was an error while loading. Please reload this page.
Description
Related to: sshnet/SSH.NET#776
I am using SSH.NET to connect to a SFTP Client with private key.
I can succesfully connect to the website using an interactive client (FileZilla)
When using the SSH.NET library, the exception I get is internal to .NET:
Exception:
Accessing a hash algorithm by manipulating the HashName property is not supported on this platform. Instead, you must instantiate one of the supplied subtypes (such as HMACSHA1.)
Other users have reported same issue with password authentication.
They also claim that the problem does not occur if they use the same SSH.NET library from .NET Framework.
I don't know any workarounds.
Is this a known issue? Fixed maybe in .NET5?
Configuration
DOTNETCORE 3.1
Windows 10 x64
Using SSH.NET
Other information
Full stack trace:
" at System.Security.Cryptography.HMAC.HashFinal() in //src/System.Security.Cryptography.Primitives/src/System/Security/Cryptography/HMAC.cs:line 68\r\n at Renci.SshNet.Security.Cryptography.HMACSHA1.HashFinal()\r\n at System.Security.Cryptography.HashAlgorithm.CaptureHashCodeAndReinitialize() in //src/System.Security.Cryptography.Primitives/src/System/Security/Cryptography/HashAlgorithm.cs:line 115\r\n at Renci.SshNet.Session.SendMessage(Message message)\r\n at Renci.SshNet.Session.Connect()\r\n at Renci.SshNet.BaseClient.CreateAndConnectSession()\r\n at Renci.SshNet.BaseClient.Connect()\r\n at ... (my code)
Exception type:
{Name = "PlatformNotSupportedException" FullName = "System.PlatformNotSupportedException"} Assembly: {System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e} AssemblyQualifiedName: "System.PlatformNotSupportedException, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e" Attributes: Public | Serializable | BeforeFieldInit BaseType: {Name = "NotSupportedException" FullName = "System.NotSupportedException"} Cache: {System.RuntimeType.RuntimeTypeCache} CacheIfExists: {System.RuntimeType.RuntimeTypeCache} ContainsGenericParameters: false CustomAttributes: Count = 4 DeclaredConstructors: {System.Reflection.ConstructorInfo[4]} DeclaredEvents: {System.Reflection.EventInfo[0]} DeclaredFields: {System.Reflection.FieldInfo[0]} DeclaredMembers: {System.Reflection.MemberInfo[4]} DeclaredMethods: {System.Reflection.MethodInfo[0]} DeclaredNestedTypes: {System.Reflection.TypeInfo.<get_DeclaredNestedTypes>d__22} DeclaredProperties: {System.Reflection.PropertyInfo[0]} DeclaringMethod: '((System.RuntimeType)exception.GetType()).DeclaringMethod' threw an exception of type 'System.InvalidOperationException' }
The text was updated successfully, but these errors were encountered: