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

AES-GCM support under Netstandard2.1, Netstandard2.0 and Net Core 3.0 #877

Closed
wants to merge 1 commit into from

Conversation

jy824212
Copy link

This is to support AES-GCM algo and currently only support netstandard 2.0, netstandard 2.1 and netcoreapp3.0

@jy824212 jy824212 changed the title AES-GCM support under Netstandard2.1 and Net Core 3.0 AES-GCM support under Netstandard2.1, Netstandard2.0 and Net Core 3.0 Sep 21, 2021
@jy824212
Copy link
Author

Dear @drieseng ,

I wonder if you can look into this error as I didn't encounter any of these errors during my compilation.

Regards,
Jy

@zybexXL
Copy link
Contributor

zybexXL commented Sep 21, 2021

AppVeyor is failing on many PRs, I think this is the cause - #855 (comment)

The error is "SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted."

The testsuite is now running thousands of testcases, and many of them open a connection. After the connection is closed, the port stays in TIME_WAIT for a long time (default on windows is 240 seconds). Dynamic connections use a port from 1024 to 5000, so there are "only" 4000 ports available during that 240s window... I think AppVeyor/SSHNet is hitting this limit.

The fix is to add some flag to make the tests create sockets using SO_REUSEADDR, or to change the AppVeyor VM config to reduce the 240s timeout (setting in the Registry on Windows, somewhere else on Linux).

I don't recommend using SO_REUSEADDR by default as that may cause some pending packets to be dropped when the connection is closed.

@jy824212
Copy link
Author

@zybexXL thanks for the reply and much appreciated. Do you know who is able to re configure this on the AppVeyor VM or is there something I can do from my local appveyor.yml

@jy824212
Copy link
Author

Hi @drieseng,

Will you be able to take a look at this ?

Regards,
Jy

@@ -39,7 +39,7 @@ public override bool Verify(byte[] input, byte[] signature)
// for 521 sig_size is 132
var sig_size = _key.KeyLength == 521 ? 132 : _key.KeyLength / 4;
var ssh_data = new SshDataSignature(signature, sig_size);
#if NETSTANDARD2_0
#if NETSTANDARD2_0 || NETSTANDARD2_1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use #if NETSTANDARD2_0_OR_GREATER || NETCOREAPP3_1_OR_GREATER in all instances, so this will be compiled when we target higher frameworks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

certainly I can make such adjustment

string var_pt = GetHexStringFrom(plainText.ToArray());
string var_aad = GetHexStringFrom(associatedData.ToArray());

Console.WriteLine("[DEBUG] In GcmEncrypt()");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered other possibilities for outputting debug information? ILogger is not viable yet, but I would prefer System.Diagnostics.Debug.WriteLine over Console.WriteLine.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I will follow your suggestion as at the time I wrote the code I wasn't too familiar with the C# DEBUG utility. Thank you for the feedback.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am getting this error
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'CngKey' could not be found (are you missing a using directive or an
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'CngAlgorithm' could not be found (are you missing a using directive or an assembly reference?)

Is because these are out of date in netstandard2.0 and netstandard2.1 ?

@fmargueirat
Copy link

@jy824212 I was wondering if you were able to have this code running on later versions of Renci.SSH.NET. I try to add your code to the latest one, but I'm facing some issues.

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

Successfully merging this pull request may close these issues.

4 participants