@@ -577,14 +577,14 @@ public void Connect()
577
577
578
578
lock ( this )
579
579
{
580
- // If connected don't connect again
580
+ // If connected don't connect again
581
581
if ( IsConnected )
582
582
return ;
583
583
584
- // reset connection specific information
584
+ // Reset connection specific information
585
585
Reset ( ) ;
586
586
587
- // Build list of available messages while connecting
587
+ // Build list of available messages while connecting
588
588
_sshMessageFactory = new SshMessageFactory ( ) ;
589
589
590
590
switch ( ConnectionInfo . ProxyType )
@@ -606,10 +606,14 @@ public void Connect()
606
606
break ;
607
607
}
608
608
609
+ // Immediately send the identification string since the spec states both sides MUST send an identification string
610
+ // when the connection has been established
611
+ SocketAbstraction . Send ( _socket , Encoding . UTF8 . GetBytes ( string . Format ( CultureInfo . InvariantCulture , "{0}\x0D \x0A " , ClientVersion ) ) ) ;
612
+
609
613
Match versionMatch ;
610
614
611
- // Get server version from the server,
612
- // ignore text lines which are sent before if any
615
+ // Get server version from the server,
616
+ // ignore text lines which are sent before if any
613
617
while ( true )
614
618
{
615
619
var serverVersion = SocketReadLine ( _socket , ConnectionInfo . Timeout ) ;
@@ -623,11 +627,11 @@ public void Connect()
623
627
}
624
628
}
625
629
626
- // Set connection versions
630
+ // Set connection versions
627
631
ConnectionInfo . ServerVersion = ServerVersion ;
628
632
ConnectionInfo . ClientVersion = ClientVersion ;
629
633
630
- // Get server SSH version
634
+ // Get server SSH version
631
635
var version = versionMatch . Result ( "${protoversion}" ) ;
632
636
633
637
var softwareName = versionMatch . Result ( "${softwareversion}" ) ;
@@ -639,9 +643,7 @@ public void Connect()
639
643
throw new SshConnectionException ( string . Format ( CultureInfo . CurrentCulture , "Server version '{0}' is not supported." , version ) , DisconnectReason . ProtocolVersionNotSupported ) ;
640
644
}
641
645
642
- SocketAbstraction . Send ( _socket , Encoding . UTF8 . GetBytes ( string . Format ( CultureInfo . InvariantCulture , "{0}\x0D \x0A " , ClientVersion ) ) ) ;
643
-
644
- // Register Transport response messages
646
+ // Register Transport response messages
645
647
RegisterMessage ( "SSH_MSG_DISCONNECT" ) ;
646
648
RegisterMessage ( "SSH_MSG_IGNORE" ) ;
647
649
RegisterMessage ( "SSH_MSG_UNIMPLEMENTED" ) ;
@@ -650,29 +652,29 @@ public void Connect()
650
652
RegisterMessage ( "SSH_MSG_KEXINIT" ) ;
651
653
RegisterMessage ( "SSH_MSG_NEWKEYS" ) ;
652
654
653
- // Some server implementations might sent this message first, prior establishing encryption algorithm
655
+ // Some server implementations might sent this message first, prior to establishing encryption algorithm
654
656
RegisterMessage ( "SSH_MSG_USERAUTH_BANNER" ) ;
655
657
656
- // mark the message listener threads as started
658
+ // Mark the message listener threads as started
657
659
_messageListenerCompleted . Reset ( ) ;
658
660
659
- // Start incoming request listener
661
+ // Start incoming request listener
660
662
ThreadAbstraction . ExecuteThread ( ( ) => MessageListener ( ) ) ;
661
663
662
- // Wait for key exchange to be completed
664
+ // Wait for key exchange to be completed
663
665
WaitOnHandle ( _keyExchangeCompletedWaitHandle ) ;
664
666
665
- // If sessionId is not set then its not connected
667
+ // If sessionId is not set then its not connected
666
668
if ( SessionId == null )
667
669
{
668
670
Disconnect ( ) ;
669
671
return ;
670
672
}
671
673
672
- // Request user authorization service
674
+ // Request user authorization service
673
675
SendMessage ( new ServiceRequestMessage ( ServiceName . UserAuthentication ) ) ;
674
676
675
- // Wait for service to be accepted
677
+ // Wait for service to be accepted
676
678
WaitOnHandle ( _serviceAccepted ) ;
677
679
678
680
if ( string . IsNullOrEmpty ( ConnectionInfo . Username ) )
@@ -687,7 +689,7 @@ public void Connect()
687
689
ConnectionInfo . Authenticate ( this , _serviceFactory ) ;
688
690
_isAuthenticated = true ;
689
691
690
- // Register Connection messages
692
+ // Register Connection messages
691
693
RegisterMessage ( "SSH_MSG_REQUEST_SUCCESS" ) ;
692
694
RegisterMessage ( "SSH_MSG_REQUEST_FAILURE" ) ;
693
695
RegisterMessage ( "SSH_MSG_CHANNEL_OPEN_CONFIRMATION" ) ;
@@ -2003,6 +2005,8 @@ private void MessageListener()
2003
2005
break ;
2004
2006
}
2005
2007
2008
+ Console . WriteLine ( "RECEIVED MESSAGe " + message . GetType ( ) ) ;
2009
+
2006
2010
// process message
2007
2011
message . Process ( this ) ;
2008
2012
}
0 commit comments