-
-
Notifications
You must be signed in to change notification settings - Fork 931
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
Accessing a hash algorithm by manipulating the HashName property is not supported on this platform. #859
Comments
Can you provide the call stack of the exception? |
That is exactly the error message I am seeing, it's throwing it when trying to connect to the sftp. at System.Security.Cryptography.HMAC.HashFinal() How can I. change the DefineConstants? |
I have changed it like here dd-morphi@9d3387e?branch=9d3387e1d6b406c215a160d2bc0f0bb338c39f6f for
I put
with reference to compiled library |
This seems to be the problem mentioned in dotnet/runtime#22929. |
@IgorMilavec backporting to SshNet.Security.Cryptography helps, but SSH.NET uses
The first works correctly always, the second fails with this strange error message on .net5.0. (it looks like |
Same here! Using on Azure Function v3 (netcoreapp3.1), but with a specific SFTP server. I'm connecting with 3 different SFTP servers, 2 work flawlessly and 1 is failing with this exact error.
Hoping for a permanent solution :) I really don't want to switch to another package. |
I can confirm that the solution provided by @dd-morphi works. Thanks for that :) |
Hitting the same issue running .net5 on windows. What is the recommended course of action here? I'm not super thrilled about having to package a custom version here similar to @dd-morphi, as I use this in an enterprise ETL tool. @drieseng - is there a timeline for a resolution? |
I tried @dd-morphi 's solution and its worked for us. I'd be willing to put a PR up if it would be merged in relatively soon. Haven't had a release for a little while as well. |
It was good to find this discussion here, since we could not get past connecting with our client's SFTP server. We started down the path of this workaround, but were deeply unsatisfied with maintaining our own copy of the assembly. I poked a little and found an easier workaround that uses the published package:
In our case, we only had to override the MD5 macs, but as many (or all) of the crypto algorithms can be fixed up via the connection info. Super nicely designed. HTH someone else until the bug is fixed in a release, and thanks to the maintainers of this sweet library. |
Thanks, @Aethon! Your workaround was very helpful! I looked at the default HmacAlgorithms set by ConnectionInfo.cs, and I extended your example code to override them all with concrete implementations instead of using the CryptoAbstraction defaults. var info = new ConnectionInfo(
"host.com",
22,
"user1",
new PasswordAuthenticationMethod("user1", "secret_password")
);
IDictionary<string, HashInfo> hmacAlgorithms = info.HmacAlgorithms;
hmacAlgorithms["hmac-md5"] = new HashInfo(128, key => new SshNet.Security.Cryptography.HMACMD5(key));
hmacAlgorithms["hmac-md5-96"] = new HashInfo(128, key => new SshNet.Security.Cryptography.HMACMD5(key, 96));
hmacAlgorithms["hmac-sha1"] = new HashInfo(160, key => new SshNet.Security.Cryptography.HMACSHA1(key));
hmacAlgorithms["hmac-sha1-96"] = new HashInfo(160, key => new SshNet.Security.Cryptography.HMACSHA1(key, 96));
hmacAlgorithms["hmac-sha2-256"] = new HashInfo(256, key => new SshNet.Security.Cryptography.HMACSHA256(key));
hmacAlgorithms["hmac-sha2-256-96"] = new HashInfo(256, key => new SshNet.Security.Cryptography.HMACSHA256(key, 96));
hmacAlgorithms["hmac-sha2-512"] = new HashInfo(512, key => new SshNet.Security.Cryptography.HMACSHA512(key));
hmacAlgorithms["hmac-sha2-512-96"] = new HashInfo(512, key => new SshNet.Security.Cryptography.HMACSHA512(key, 96));
hmacAlgorithms["hmac-ripemd160"] = new HashInfo(160, key => new SshNet.Security.Cryptography.HMACRIPEMD160(key));
hmacAlgorithms["hmac-ripemd160@openssh.com"] = new HashInfo(160, key => new SshNet.Security.Cryptography.HMACRIPEMD160(key)); |
This only repros on .NET Core targets using the .NET Standard 2.0 version of the library, which as of the latest package 2020.0.2, is all of them. It is (inadvertently) fixed in the The reason is that SSH.NET/src/Renci.SshNet/Security/Cryptography/HMACSHA1.cs Lines 52 to 56 in 004b57a
I can only really explain with pictures, but when targeting which on .NET Core is just: throwing (with a misleading exception message?):
Whereas when actually targeting .NET Core it is pointing to Right now the It actually also has a target for |
is the issue permanent solved? I still face the issue on 2020.0.2 |
Yes on the develop branch and the next (imminent) release |
Version 2023.0.0 has been published https://www.nuget.org/packages/SSH.NET/2023.0.0 |
Hi, using the latest version in our webapp, 2023.0.0, and getting an issue similar to this one. Below is the error and stack trace. Error: System.ArgumentException: Could not create HashAlgorithm from Stack Trace: at Renci.SshNet.Security.Cryptography.RsaDigitalSignature..ctor(RsaKey rsaKey, HashAlgorithmName hashAlgorithmName) |
@Eduard-Nuco what OS and .NET version are you using? edit: also, is this a published application, or could trimming be otherwise involved? |
@Rob-Hague I'm developing on Windows 11, the project is using .NET 7. It's in release configuration with deployment mode as self-contained and target runtime is win-x86. The app is hosted on our local server running Windows 10. I disabled trimming and am not getting the error anymore. I didn't consider this an issue previously, so thank you for the input. |
Thanks for the info. I have opened #1216 to fix the trimming issues |
Hi, I am using the library to send some files through an sftp, I am connecting to the site via the SftpClient class:
var client = new SftpClient(host, port, username, password);
client.Connect();
client.UploadFile(zipFile, outPath);
client.Disconnect();
This code is running in an azure function, it was working fine but it stopped working back in May and its now throwing this message:
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.)
Any ideas??
Thanks.
The text was updated successfully, but these errors were encountered: