Browse Source

Register for SSH_MSG_GLOBAL_REQUEST right before authentication.
Use link to issue in corresponding test.

drieseng 9 years ago
parent
commit
a1f46d40c2

+ 2 - 4
src/Renci.SshNet.Tests/Classes/SessionTest_Connected_GlobalRequestMessageAfterAuthenticationRace.cs

@@ -1,13 +1,11 @@
-using System;
-using System.Net.Sockets;
-using System.Threading;
+using System.Net.Sockets;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Renci.SshNet.Messages.Connection;
 
 namespace Renci.SshNet.Tests.Classes
 {
     /// <summary>
-    /// Test for https://github.com/sshnet/SSH.NET/pull/9.
+    /// Test for https://github.com/sshnet/SSH.NET/issues/8.
     /// </summary>
     [TestClass]
     public class SessionTest_Connected_GlobalRequestMessageAfterAuthenticationRace : SessionTest_ConnectedBase

+ 4 - 5
src/Renci.SshNet/Session.cs

@@ -590,9 +590,6 @@ namespace Renci.SshNet
 
                     //  Some server implementations might sent this message first, prior establishing encryption algorithm
                     RegisterMessage("SSH_MSG_USERAUTH_BANNER");
-					
-					// Modern versions of OpenSSH server use this generic message for various proprietary extensions of the SSH protocol.
-                    RegisterMessage("SSH_MSG_GLOBAL_REQUEST");					
 
                     // mark the message listener threads as started
                     _messageListenerCompleted.Reset();
@@ -621,11 +618,13 @@ namespace Renci.SshNet
                         throw new SshException("Username is not specified.");
                     }
 
+                    // Some servers send a global request immediately after successful authentication
+                    // Avoid race condition by already enabling SSH_MSG_GLOBAL_REQUEST before authentication
+                    RegisterMessage("SSH_MSG_GLOBAL_REQUEST");
+
                     ConnectionInfo.Authenticate(this, _serviceFactory);
                     _isAuthenticated = true;
 
-                    Thread.Sleep(2000);
-
                     //  Register Connection messages
                     RegisterMessage("SSH_MSG_REQUEST_SUCCESS");
                     RegisterMessage("SSH_MSG_REQUEST_FAILURE");