Skip to content

Commit a1f46d4

Browse files
committed
Register for SSH_MSG_GLOBAL_REQUEST right before authentication.
Use link to issue in corresponding test.
1 parent 1e94070 commit a1f46d4

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/Renci.SshNet.Tests/Classes/SessionTest_Connected_GlobalRequestMessageAfterAuthenticationRace.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
using System;
2-
using System.Net.Sockets;
3-
using System.Threading;
1+
using System.Net.Sockets;
42
using Microsoft.VisualStudio.TestTools.UnitTesting;
53
using Renci.SshNet.Messages.Connection;
64

75
namespace Renci.SshNet.Tests.Classes
86
{
97
/// <summary>
10-
/// Test for https://github.com/sshnet/SSH.NET/pull/9.
8+
/// Test for https://github.com/sshnet/SSH.NET/issues/8.
119
/// </summary>
1210
[TestClass]
1311
public class SessionTest_Connected_GlobalRequestMessageAfterAuthenticationRace : SessionTest_ConnectedBase

src/Renci.SshNet/Session.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,6 @@ public void Connect()
590590

591591
// Some server implementations might sent this message first, prior establishing encryption algorithm
592592
RegisterMessage("SSH_MSG_USERAUTH_BANNER");
593-
594-
// Modern versions of OpenSSH server use this generic message for various proprietary extensions of the SSH protocol.
595-
RegisterMessage("SSH_MSG_GLOBAL_REQUEST");
596593

597594
// mark the message listener threads as started
598595
_messageListenerCompleted.Reset();
@@ -621,11 +618,13 @@ public void Connect()
621618
throw new SshException("Username is not specified.");
622619
}
623620

621+
// Some servers send a global request immediately after successful authentication
622+
// Avoid race condition by already enabling SSH_MSG_GLOBAL_REQUEST before authentication
623+
RegisterMessage("SSH_MSG_GLOBAL_REQUEST");
624+
624625
ConnectionInfo.Authenticate(this, _serviceFactory);
625626
_isAuthenticated = true;
626627

627-
Thread.Sleep(2000);
628-
629628
// Register Connection messages
630629
RegisterMessage("SSH_MSG_REQUEST_SUCCESS");
631630
RegisterMessage("SSH_MSG_REQUEST_FAILURE");

0 commit comments

Comments
 (0)