-
-
Notifications
You must be signed in to change notification settings - Fork 947
Password Authentication - System.ArgumentException: data #1217
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
@okarpov We need a description of the context of what you want do do. |
This is connecting to VPS via SSH using username and password. no code to reproduce because of this error is not constant. |
@okarpov You have to provide more detail or help as to reproduce the problem, if not I going to close this issue. What do you mean by "multi-task", async code or threads. You can prepare a small console application that simulates what you do with this tasks. |
Seemingly related to #805 |
We can merge #818 but this will not fix the problem. This is simply adding a better error message. |
yes, seems so so this is simplified version of my code which works with +1000 Sftp and Ssh connections.
|
Maybe it is a race between SSH.NET/src/Renci.SshNet/Session.cs Line 1042 in 8e23633
and SSH.NET/src/Renci.SshNet/Session.cs Line 1436 in 8e23633
|
_clientCipher is the instance field so i do not think so. |
also, the stack trace mentiones Renci.SshNet.Security.Cryptography.BlockCipher.Encrypt |
Correct, and my thinking is that the SSH.NET/src/Renci.SshNet/Session.cs Line 1042 in 8e23633
But I have not thought about it too hard. |
@okarpov could you please try with the following patch? (save as diff.patch and run diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs
index 257cf8c2..cef26c65 100644
--- a/src/Renci.SshNet/Session.cs
+++ b/src/Renci.SshNet/Session.cs
@@ -1039,7 +1039,11 @@ namespace Renci.SshNet
DiagnosticAbstraction.Log(string.Format("[{0}] Sending message '{1}' to server: '{2}'.", ToHex(SessionId), message.GetType().Name, message));
- var paddingMultiplier = _clientCipher is null ? (byte) 8 : Math.Max((byte) 8, _serverCipher.MinimumSize);
+ // Use locals to avoid races
+ var clientCipher = _clientCipher;
+ var clientMac = _clientMac;
+
+ var paddingMultiplier = clientCipher is null ? (byte) 8 : Math.Max((byte) 8, clientCipher.MinimumSize);
var packetData = message.GetPacket(paddingMultiplier, _clientCompression);
// take a write lock to ensure the outbound packet sequence number is incremented
@@ -1049,19 +1053,19 @@ namespace Renci.SshNet
byte[] hash = null;
var packetDataOffset = 4; // first four bytes are reserved for outbound packet sequence
- if (_clientMac != null)
+ if (clientMac != null)
{
// write outbound packet sequence to start of packet data
Pack.UInt32ToBigEndian(_outboundPacketSequence, packetData);
// calculate packet hash
- hash = _clientMac.ComputeHash(packetData);
+ hash = clientMac.ComputeHash(packetData);
}
// Encrypt packet data
- if (_clientCipher != null)
+ if (clientCipher != null)
{
- packetData = _clientCipher.Encrypt(packetData, packetDataOffset, packetData.Length - packetDataOffset);
+ packetData = clientCipher.Encrypt(packetData, packetDataOffset, packetData.Length - packetDataOffset);
packetDataOffset = 0;
}
|
still getting two exceptions
|
with nuget lbrary:
|
Interesting. Message type 52 is SSH_MSG_USERAUTH_SUCCESS... |
i think i have found the root of this issue. it looks like in this scenario it throws that different types of exceptions like Message type 52 and the "data" |
Ah right, yes, I would expect something like that to result in strange/undefined behaviour. I don't think there would be anything worth changing in the library for this scenario. |
@okarpov Thanks for answering, so that someone may find your command in the future. |
This is with the latest nuget package
System.ArgumentException: data
at Renci.SshNet.Security.Cryptography.BlockCipher.Encrypt(Byte[] input, Int32 offset, Int32 length)
at Renci.SshNet.Session.SendMessage(Message message)
at Renci.SshNet.PasswordAuthenticationMethod.Authenticate(Session session)
at Renci.SshNet.ClientAuthentication.TryAuthenticate(ISession session, AuthenticationState authenticationState, String[] allowedAuthenticationMethods, SshAuthenticationException& authenticationException)
at Renci.SshNet.ClientAuthentication.Authenticate(IConnectionInfoInternal connectionInfo, ISession session)
at Renci.SshNet.ConnectionInfo.Authenticate(ISession session, IServiceFactory serviceFactory)
at Renci.SshNet.Session.ConnectAsync(CancellationToken cancellationToken)
at Renci.SshNet.BaseClient.CreateAndConnectSessionAsync(CancellationToken cancellationToken)
at Renci.SshNet.BaseClient.ConnectAsync(CancellationToken cancellationToken)
The text was updated successfully, but these errors were encountered: