drieseng преди 4 години
родител
ревизия
a06522c3d6

+ 1 - 1
README.md

@@ -1,4 +1,4 @@
-SSH.NET
+ ![Logo](images/logo/png/SS-NET-icon-h50.png) SSH.NET
 =======
 SSH.NET is a Secure Shell (SSH-2) library for .NET, optimized for parallelism.
 

Файловите разлики са ограничени, защото са твърде много
+ 33 - 0
images/logo/ai/SS-NET-icon-white.ai


Файловите разлики са ограничени, защото са твърде много
+ 33 - 0
images/logo/ai/SS-NET-icon.ai


Файловите разлики са ограничени, защото са твърде много
+ 33 - 0
images/logo/ai/SS-NET-white.ai


Файловите разлики са ограничени, защото са твърде много
+ 33 - 0
images/logo/ai/SS-NET.ai


BIN
images/logo/png/SS-NET-h50.png


BIN
images/logo/png/SS-NET-h500.png


BIN
images/logo/png/SS-NET-icon-h50.png


BIN
images/logo/png/SS-NET-icon-h500.png


BIN
images/logo/png/SS-NET-icon-white-h50.png


BIN
images/logo/png/SS-NET-icon-white-h500.png


BIN
images/logo/png/SS-NET-white-h50.png


BIN
images/logo/png/SS-NET-white-h500.png


+ 1 - 0
images/logo/svg/SS-NET-icon-white.svg

@@ -0,0 +1 @@
+<svg id="white" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 198.39 246.71"><defs><style>.cls-1,.cls-2{fill:#f6f6f6;}.cls-2{opacity:0;}</style></defs><rect class="cls-1" y="38.32" width="170.08" height="170.08" rx="28.35"/><path class="cls-2" d="M89.21-24.14v70.8l2.93,2.93,49.62,49.62L92.14,148.83l-2.93,2.93v70.81l17.07-17.07,99.22-99.22,7.07-7.07-7.07-7.07L106.28-7.07,89.21-24.14Z" transform="translate(-14.17 24.14)"/><polygon class="cls-1" points="85.04 24.14 85.04 66.66 141.73 123.36 85.04 180.05 85.04 222.57 184.25 123.36 85.04 24.14"/></svg>

+ 1 - 0
images/logo/svg/SS-NET-icon.svg

@@ -0,0 +1 @@
+<svg id="VS_Purple_mixed" data-name="VS Purple mixed" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 198.39 246.71"><defs><style>.cls-1{fill:#3c3c3b;}.cls-2{fill:#e30613;opacity:0;}.cls-3{fill:#008d36;}</style></defs><rect class="cls-1" y="38.32" width="170.08" height="170.08" rx="28.35"/><path class="cls-2" d="M89.21-24.14v70.8l2.93,2.93,49.62,49.62L92.14,148.83l-2.93,2.93v70.81l17.07-17.07,99.22-99.22,7.07-7.07-7.07-7.07L106.28-7.07,89.21-24.14Z" transform="translate(-14.17 24.14)"/><polygon class="cls-3" points="85.04 24.14 85.04 66.66 141.73 123.36 85.04 180.05 85.04 222.57 184.25 123.36 85.04 24.14"/></svg>

Файловите разлики са ограничени, защото са твърде много
+ 0 - 0
images/logo/svg/SS-NET-white.svg


Файловите разлики са ограничени, защото са твърде много
+ 0 - 0
images/logo/svg/SS-NET.svg


+ 119 - 0
src/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_TerminatedByLineFeedWithoutCarriageReturn.cs

@@ -0,0 +1,119 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
+using Renci.SshNet.Connection;
+using Renci.SshNet.Tests.Common;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Net.Sockets;
+using System.Text;
+
+namespace Renci.SshNet.Tests.Classes.Connection
+{
+    [TestClass]
+    public class ProtocolVersionExchangeTest_ServerResponseValid_TerminatedByLineFeedWithoutCarriageReturn
+    {
+        private AsyncSocketListener _server;
+        private ProtocolVersionExchange _protocolVersionExchange;
+        private string _clientVersion;
+        private TimeSpan _timeout;
+        private IPEndPoint _serverEndPoint;
+        private List<byte> _dataReceivedByServer;
+        private byte[] _serverIdentification;
+        private bool _clientDisconnected;
+        private Socket _client;
+        private SshIdentification _actual;
+
+        [TestInitialize]
+        public void Setup()
+        {
+            Arrange();
+            Act();
+        }
+
+        [TestCleanup]
+        public void Cleanup()
+        {
+            if (_server != null)
+            {
+                _server.Dispose();
+                _server = null;
+            }
+
+            if (_client != null)
+            {
+                _client.Shutdown(SocketShutdown.Both);
+                _client.Close();
+                _client = null;
+            }
+        }
+
+        protected void Arrange()
+        {
+            _clientVersion = "SSH-2.0-Renci.SshNet.SshClient.0.0.1";
+            _timeout = TimeSpan.FromSeconds(5);
+            _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);
+            _dataReceivedByServer = new List<byte>();
+            _serverIdentification = Encoding.UTF8.GetBytes("Welcome stranger!\n\nSSH-Zero-OurSSHAppliance\n\0");
+
+            _server = new AsyncSocketListener(_serverEndPoint);
+            _server.Start();
+            _server.BytesReceived += (bytes, socket) =>
+            {
+                _dataReceivedByServer.AddRange(bytes);
+                socket.Send(_serverIdentification);
+                socket.Shutdown(SocketShutdown.Send);
+            };
+            _server.Disconnected += (socket) => _clientDisconnected = true;
+
+            _client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+            _client.Connect(_serverEndPoint);
+
+            _protocolVersionExchange = new ProtocolVersionExchange();
+        }
+
+        protected void Act()
+        {
+            _actual = _protocolVersionExchange.Start(_clientVersion, _client, _timeout);
+        }
+
+        [TestMethod]
+        public void StartShouldReturnIdentificationOfServer()
+        {
+            Assert.IsNotNull(_actual);
+            Assert.AreEqual("Zero", _actual.ProtocolVersion);
+            Assert.AreEqual("OurSSHAppliance", _actual.SoftwareVersion);
+            Assert.IsNull(_actual.Comments);
+        }
+
+        [TestMethod]
+        public void ClientIdentificationWasSentToServer()
+        {
+            var expected = Encoding.UTF8.GetBytes(_clientVersion);
+
+            Assert.AreEqual(expected.Length + 2, _dataReceivedByServer.Count);
+
+            Assert.IsTrue(expected.SequenceEqual(_dataReceivedByServer.Take(expected.Length)));
+            Assert.AreEqual(Session.CarriageReturn, _dataReceivedByServer[_dataReceivedByServer.Count - 2]);
+            Assert.AreEqual(Session.LineFeed, _dataReceivedByServer[_dataReceivedByServer.Count - 1]);
+        }
+
+        [TestMethod]
+        public void ClientRemainsConnected()
+        {
+            Assert.IsTrue(_client.Connected);
+            Assert.IsFalse(_clientDisconnected);
+        }
+
+        [TestMethod]
+        public void ClientDidNotReadPastIdentification()
+        {
+            var buffer = new byte[1];
+
+            var bytesReceived = _client.Receive(buffer);
+            Assert.AreEqual(1, bytesReceived);
+            Assert.AreEqual(0x00, buffer[0]);
+        }
+    }
+}

+ 14 - 3
src/Renci.SshNet/Connection/ProtocolVersionExchange.cs

@@ -133,10 +133,21 @@ namespace Renci.SshNet.Connection
                                                                    PacketDump.Create(buffer.ToArray(), 2)));
                 }
 
-                if (byteRead == Session.LineFeed && buffer.Count > startPosition + 1 && buffer[buffer.Count - 2] == Session.CarriageReturn)
+                if (byteRead == Session.LineFeed)
                 {
-                    // Return current line without CRLF
-                    return Encoding.UTF8.GetString(buffer.ToArray(), startPosition, buffer.Count - (startPosition + 2));
+                    if (buffer.Count > startPosition + 1 && buffer[buffer.Count - 2] == Session.CarriageReturn)
+                    {
+                        // Return current line without CRLF
+                        return Encoding.UTF8.GetString(buffer.ToArray(), startPosition, buffer.Count - (startPosition + 2));
+                    }
+                    else
+                    {
+                        // Even though RFC4253 clearly indicates that the identification string should be terminated
+                        // by a CR LF we also support banners and identification strings that are terminated by a LF
+
+                        // Return current line without LF
+                        return Encoding.UTF8.GetString(buffer.ToArray(), startPosition, buffer.Count - (startPosition + 1));
+                    }
                 }
             }
 

Някои файлове не бяха показани, защото твърде много файлове са промени