فهرست منبع

Make placeholders for HTTP proxy support
Fix compilation error for Silverlight and WindowsPhone

olegkap_cp 13 سال پیش
والد
کامیت
62ae94d39a

+ 3 - 1
Renci.SshClient/Renci.SshNet/ProxyTypes.cs

@@ -15,6 +15,8 @@ namespace Renci.SshNet
         /// <summary>A SOCKS4 proxy server.</summary>
         Socks4,
         /// <summary>A SOCKS5 proxy server.</summary>
-        Socks5
+        Socks5,
+        /// <summary>A HTTP proxy server.</summary>
+        Http,
     }
 }

+ 32 - 9
Renci.SshClient/Renci.SshNet/Session.cs

@@ -407,6 +407,7 @@ namespace Renci.SshNet
             this.ClientVersion = string.Format(CultureInfo.CurrentCulture, "SSH-2.0-Renci.SshNet.SshClient.0.0.1");
         }
 
+
         /// <summary>
         /// Connects to the server.
         /// </summary>
@@ -449,6 +450,10 @@ namespace Renci.SshNet
                             this.SocketConnect(this.ConnectionInfo.ProxyHost, this.ConnectionInfo.ProxyPort);
                             this.ConnectSocks5(this._socket);
                             break;
+                        case ProxyTypes.Http:
+                            this.SocketConnect(this.ConnectionInfo.ProxyHost, this.ConnectionInfo.ProxyPort);
+                            this.ConnectHttp(this._socket);
+                            break;
                         default:
                             break;
                     }
@@ -548,17 +553,30 @@ namespace Renci.SshNet
 
                         if (!this._isAuthenticated)
                         {
-                            //  Ensure that authentication method is allowed
-                            if (!noneConnectionInfo.AllowedAuthentications.Contains(this.ConnectionInfo.Name))
+                            //  TODO:   Replace this logic here with multiple authentication suppurt
+                            var supportedConnectionInfos = (from c in new[] { this.ConnectionInfo }
+                                                            where noneConnectionInfo.AllowedAuthentications.Contains(this.ConnectionInfo.Name)
+                                                            select c).ToList();
+
+                            if (supportedConnectionInfos.Count > 0)
+                            {
+                                foreach (var connectionInfo in supportedConnectionInfos)
+                                {
+                                    //  Authenticate using provided connection info object
+                                    connectionInfo.Authenticate(this);
+
+                                    if (connectionInfo.IsAuthenticated)
+                                    {
+                                        this._isAuthenticated = this.ConnectionInfo.IsAuthenticated;
+                                        this.ConnectionInfo = connectionInfo;
+                                        break;
+                                    }
+                                }
+                            }
+                            else 
                             {
                                 throw new SshAuthenticationException("User authentication method is not supported.");
                             }
-
-                            //  In future, if more then one authentication methods are supported perform the check here.
-                            //  Authenticate using provided connection info object
-                            this.ConnectionInfo.Authenticate(this);
-
-                            this._isAuthenticated = this.ConnectionInfo.IsAuthenticated;
                         }
                     }
 
@@ -663,7 +681,7 @@ namespace Renci.SshNet
                 return;
 
             if (this._keyExchangeInProgress && !(message is IKeyExchangedAllowed))
-            { 
+            {
                 //  Wait for key exchange to be completed
                 this.WaitHandle(this._keyExchangeCompletedWaitHandle);
             }
@@ -1848,6 +1866,11 @@ namespace Renci.SshNet
 
         }
 
+        private void ConnectHttp(Socket socket)
+        {
+            throw new NotImplementedException();
+        }
+
         /// <summary>
         /// Raises the <see cref="ErrorOccured"/> event.
         /// </summary>

+ 6 - 6
Renci.SshClient/Renci.SshNet/ShellStream.cs

@@ -252,7 +252,7 @@ namespace Renci.SshNet
                 do
                 {
                     if (this._incoming.Count > 0)
-                        text = this._encoding.GetString(this._incoming.ToArray());
+                        text = this._encoding.GetString(this._incoming.ToArray(), 0, this._incoming.Count);
 
                     if (text.Length > 0)
                     {
@@ -309,7 +309,7 @@ namespace Renci.SshNet
             lock (this._incoming)
             {
                 if (this._incoming.Count > 0)
-                    text = this._encoding.GetString(this._incoming.ToArray());
+                    text = this._encoding.GetString(this._incoming.ToArray(), 0, this._incoming.Count);
 
                 var match = regex.Match(text.ToString());
                 while (!match.Success)
@@ -317,7 +317,7 @@ namespace Renci.SshNet
                     Monitor.Wait(this._incoming);
 
                     if (this._incoming.Count > 0)
-                        text = this._encoding.GetString(this._incoming.ToArray());
+                        text = this._encoding.GetString(this._incoming.ToArray(), 0, this._incoming.Count);
 
                     match = regex.Match(text.ToString());
                 }
@@ -343,14 +343,14 @@ namespace Renci.SshNet
             lock (this._incoming)
             {
                 if (this._incoming.Count > 0)
-                    text = this._encoding.GetString(this._incoming.ToArray());
+                    text = this._encoding.GetString(this._incoming.ToArray(), 0, this._incoming.Count);
 
                 var index = text.ToString().IndexOf("\r\n");
                 while (index < 0)
                 {
                     Monitor.Wait(this._incoming);
                     if (this._incoming.Count > 0)
-                    text = this._encoding.GetString(this._incoming.ToArray());
+                        text = this._encoding.GetString(this._incoming.ToArray(), 0, this._incoming.Count);
 
                     index = text.ToString().IndexOf("\r\n");
                 }
@@ -378,7 +378,7 @@ namespace Renci.SshNet
             lock (this._incoming)
             {
                 if (this._incoming.Count > 0)
-                    text = this._encoding.GetString(this._incoming.ToArray());
+                    text = this._encoding.GetString(this._incoming.ToArray(), 0, this._incoming.Count);
 
                 this._incoming.Clear();
             }