From 1b881f5df30491c7a6e1fb5957d3c0fe25170805 Mon Sep 17 00:00:00 2001 From: oleg Date: Tue, 20 Dec 2016 11:39:51 -0500 Subject: [PATCH 001/128] Change how clientExchangeValue is calculated (#130) --- .../Classes/Common/BigIntegerTest.cs | 61 +++++++++++++++++++ src/Renci.SshNet/Common/BigInteger.cs | 36 ++++++++--- 2 files changed, 88 insertions(+), 9 deletions(-) diff --git a/src/Renci.SshNet.Tests/Classes/Common/BigIntegerTest.cs b/src/Renci.SshNet.Tests/Classes/Common/BigIntegerTest.cs index e41228404..dc8bddc0b 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/BigIntegerTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/BigIntegerTest.cs @@ -16,6 +16,7 @@ using System.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; using Renci.SshNet.Common; +using System.Text.RegularExpressions; #if FEATURE_NUMERICS_BIGINTEGER using BigInteger = System.Numerics.BigInteger; #else @@ -1650,6 +1651,66 @@ public void Zero() Assert.AreEqual(0, zero.Sign); } + [TestMethod] + public void TestClientExhcangeGenerationItem130() + { + var test = "1090748135619415929450294929359784500348155124953172211774101106966150168922785639028532473848836817769712164169076432969224698752674677662739994265785437233596157045970922338040698100507861033047312331823982435279475700199860971612732540528796554502867919746776983759391475987142521315878719577519148811830879919426939958487087540965716419167467499326156226529675209172277001377591248147563782880558861083327174154014975134893125116015776318890295960698011614157721282527539468816519319333337503114777192360412281721018955834377615480468479252748867320362385355596601795122806756217713579819870634321561907813255153703950795271232652404894983869492174481652303803498881366210508647263668376514131031102336837488999775744046733651827239395353540348414872854639719294694323450186884189822544540647226987292160693184734654941906936646576130260972193280317171696418971553954161446191759093719524951116705577362073481319296041201283516154269044389257727700289684119460283480452306204130024913879981135908026983868205969318167819680850998649694416907952712904962404937775789698917207356355227455066183815847669135530549755439819480321732925869069136146085326382334628745456398071603058051634209386708703306545903199608523824513729625136659128221100967735450519952404248198262813831097374261650380017277916975324134846574681307337017380830353680623216336949471306191686438249305686413380231046096450953594089375540285037292470929395114028305547452584962074309438151825437902976012891749355198678420603722034900311364893046495761404333938686140037848030916292543273684533640032637639100774502371542479302473698388692892420946478947733800387782741417786484770190108867879778991633218628640533982619322466154883011452291890252336487236086654396093853898628805813177559162076363154436494477507871294119841637867701722166609831201845484078070518041336869808398454625586921201308185638888082699408686536045192649569198110353659943111802300636106509865023943661829436426563007917282050894429388841748885398290707743052973605359277515749619730823773215894755121761467887865327707115573804264519206349215850195195364813387526811742474131549802130246506341207020335797706780705406945275438806265978516209706795702579244075380490231741030862614968783306207869687868108423639971983209077624758080499988275591392787267627182442892809646874228263172435642368588260139161962836121481966092745325488641054238839295138992979335446110090325230955276870524611359124918392740353154294858383359"; + BigInteger prime; + BigInteger.TryParse(test, NumberStyles.Number, NumberFormatInfo.CurrentInfo, out prime); + + BigInteger group = 2; + var bitLength = prime.BitLength; + + BigInteger clientExchangeValue; + do + { + var randomValue = BigInteger.Random(bitLength); + + //clientExchangeValue = BigInteger.ModPow(group, randomValue, prime); + clientExchangeValue = (group ^ randomValue) % prime; + } while (clientExchangeValue < 1 || clientExchangeValue > (prime - 1)); + } + + [TestMethod] + public void TestClientExhcangeGenerationGroup1() + { + var test = "00FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF"; + BigInteger prime; + BigInteger.TryParse(test, NumberStyles.AllowHexSpecifier, NumberFormatInfo.CurrentInfo, out prime); + + BigInteger group = 2; + var bitLength = prime.BitLength; + + BigInteger clientExchangeValue; + do + { + var randomValue = BigInteger.Random(bitLength); + + //clientExchangeValue = BigInteger.ModPow(group, randomValue, prime); + clientExchangeValue = (group ^ randomValue) % prime; + } while (clientExchangeValue < 1 || clientExchangeValue > (prime - 1)); + } + + [TestMethod] + public void TestClientExhcangeGenerationGroup14() + { + var test = "00FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF"; + BigInteger prime; + BigInteger.TryParse(test, NumberStyles.AllowHexSpecifier, NumberFormatInfo.CurrentInfo, out prime); + + BigInteger group = 2; + var bitLength = prime.BitLength; + + BigInteger clientExchangeValue; + do + { + var randomValue = BigInteger.Random(bitLength); + + //clientExchangeValue = BigInteger.ModPow(group, randomValue, prime); + clientExchangeValue = (group ^ randomValue) % prime; + } while (clientExchangeValue < 1 || clientExchangeValue > (prime - 1)); + } + private static void AssertEqual(byte[] a, byte[] b) { Assert.IsTrue(a.IsEqualTo(b)); diff --git a/src/Renci.SshNet/Common/BigInteger.cs b/src/Renci.SshNet/Common/BigInteger.cs index 7cbba88c5..73cce8bdf 100644 --- a/src/Renci.SshNet/Common/BigInteger.cs +++ b/src/Renci.SshNet/Common/BigInteger.cs @@ -165,18 +165,36 @@ public static BigInteger PositiveMod(BigInteger dividend, BigInteger divisor) } /// - /// Generates random number. + /// Generates a new, random of the specified length. /// - /// Length of random number in bits. - /// - /// A random number. - /// + /// The number of bits for the new number. + /// A random number of the specified length. public static BigInteger Random(int bitLength) { - var bytesArray = new byte[bitLength / 8 + (((bitLength % 8) > 0) ? 1 : 0)]; - CryptoAbstraction.GenerateRandom(bytesArray); - bytesArray[bytesArray.Length - 1] = (byte)(bytesArray[bytesArray.Length - 1] & 0x7F); // Ensure not a negative value - return new BigInteger(bytesArray); + int dwords = bitLength >> 5; + int remBits = bitLength & 0x1F; + + if (remBits != 0) + dwords++; + + BigInteger ret = new BigInteger(1, new uint[(uint)dwords + 1]); + byte[] random = new byte[dwords << 2]; + + CryptoAbstraction.GenerateRandom(random); + Buffer.BlockCopy(random, 0, ret._data, 0, (int)dwords << 2); + + if (remBits != 0) + { + uint mask = (uint)(0x01 << (remBits - 1)); + ret._data[dwords - 1] |= mask; + + mask = (uint)(0xFFFFFFFF >> (32 - remBits)); + ret._data[dwords - 1] &= mask; + } + else + ret._data[dwords - 1] |= 0x80000000; + + return ret; } #endregion SSH.NET additions From 78679a3c30e689aeb2ad8990aa4db6d71b48db99 Mon Sep 17 00:00:00 2001 From: oleg Date: Tue, 20 Dec 2016 13:10:50 -0500 Subject: [PATCH 002/128] Add ClientIP to client info to allow select client IP that should be used for connection (#132) --- src/Renci.SshNet/ConnectionInfo.cs | 70 ++++++++++++++++++++++++++++++ src/Renci.SshNet/Session.cs | 2 +- 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/Renci.SshNet/ConnectionInfo.cs b/src/Renci.SshNet/ConnectionInfo.cs index ba8f38b93..6e13755ae 100644 --- a/src/Renci.SshNet/ConnectionInfo.cs +++ b/src/Renci.SshNet/ConnectionInfo.cs @@ -9,6 +9,7 @@ using Renci.SshNet.Messages.Authentication; using Renci.SshNet.Security.Cryptography.Ciphers.Modes; using Renci.SshNet.Security.Cryptography.Ciphers; +using System.Net; namespace Renci.SshNet { @@ -205,6 +206,14 @@ public class ConnectionInfo : IConnectionInfoInternal /// public string ClientVersion { get; internal set; } + /// + /// Gets the client ip to use for connection when client has multiple IP addresses availble. + /// + /// + /// The client ip to use for connection. + /// + public IPAddress ClientIP { get; internal set; } + /// /// Gets the current client compression algorithm. /// @@ -263,6 +272,66 @@ public ConnectionInfo(string host, int port, string username, params Authenticat /// is null. /// No specified. public ConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, params AuthenticationMethod[] authenticationMethods) + : this(host, DefaultPort, username, null, ProxyTypes.None, null, 0, null, null, authenticationMethods) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The host. + /// The username. + /// The client IP to be used. + /// The authentication methods. + /// is null. + /// is a zero-length string. + /// is a zero-length string. + /// is null. + /// is a zero-length string. + public ConnectionInfo(string host, string username, IPAddress clientIP, params AuthenticationMethod[] authenticationMethods) + : this(host, DefaultPort, username, clientIP, ProxyTypes.None, null, 0, null, null, authenticationMethods) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The host. + /// The port. + /// The username. + /// The client IP to be used. + /// The authentication methods. + /// is null. + /// is null, a zero-length string or contains only whitespace characters. + /// is not within and . + /// is null. + /// is null, a zero-length string or contains only whitespace characters. + public ConnectionInfo(string host, int port, string username, IPAddress clientIP, params AuthenticationMethod[] authenticationMethods) + : this(host, port, username, clientIP, ProxyTypes.None, null, 0, null, null, authenticationMethods) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Connection host. + /// Connection port. + /// Connection username. + /// The client IP to be used. + /// Type of the proxy. + /// The proxy host. + /// The proxy port. + /// The proxy username. + /// The proxy password. + /// The authentication methods. + /// is null. + /// is null, a zero-length string or contains only whitespace characters. + /// is not within and . + /// is not and is null. + /// is not and is not within and . + /// is null. + /// No specified. + public ConnectionInfo(string host, int port, string username, IPAddress clientIP, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, params AuthenticationMethod[] authenticationMethods) { if (host == null) throw new ArgumentNullException("host"); @@ -386,6 +455,7 @@ public ConnectionInfo(string host, int port, string username, ProxyTypes proxyTy Host = host; Port = port; Username = username; + ClientIP = clientIP; ProxyType = proxyType; ProxyHost = proxyHost; diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs index e26743098..0bebddfcf 100644 --- a/src/Renci.SshNet/Session.cs +++ b/src/Renci.SshNet/Session.cs @@ -1600,7 +1600,7 @@ internal static string ToHex(byte[] bytes) /// An error occurred trying to establish the connection. private void SocketConnect(string host, int port) { - var ipAddress = DnsAbstraction.GetHostAddresses(host)[0]; + var ipAddress = ConnectionInfo.ClientIP ?? DnsAbstraction.GetHostAddresses(host)[0]; var ep = new IPEndPoint(ipAddress, port); DiagnosticAbstraction.Log(string.Format("Initiating connection to '{0}:{1}'.", host, port)); From 6d8f545bb41737444a53610b9ee83e04b6fbbd9e Mon Sep 17 00:00:00 2001 From: Gert Driesen Date: Thu, 29 Dec 2016 21:27:19 +0100 Subject: [PATCH 003/128] Introduce VS 2017 solution and MSBuild-based .NET Core project * Introduced VS 2017 solution * Use MSBuild-based project for .NET Core. * Removed Renci.SshNet.NETCore project from VS 2015 solution (as only VS 2017 supports MSBuild-based project for .NET Core) * Added build script since MSBuild v15.0 cannot be used to build the VS 2012 solution (pfffff). --- build/build.cmd | 12 ++ build/build.proj | 27 ++-- .../Renci.SshNet.NETCore.csproj | 117 ++++++++++++++++++ .../Renci.SshNet.NETCore.xproj | 19 --- src/Renci.SshNet.NETCore/project.json | 90 -------------- src/Renci.SshNet.VS2015.sln | 24 +--- src/Renci.SshNet.VS2017.sln | 117 ++++++++++++++++++ 7 files changed, 265 insertions(+), 141 deletions(-) create mode 100644 build/build.cmd create mode 100644 src/Renci.SshNet.NETCore/Renci.SshNet.NETCore.csproj delete mode 100644 src/Renci.SshNet.NETCore/Renci.SshNet.NETCore.xproj delete mode 100644 src/Renci.SshNet.NETCore/project.json create mode 100644 src/Renci.SshNet.VS2017.sln diff --git a/build/build.cmd b/build/build.cmd new file mode 100644 index 000000000..146c26fbc --- /dev/null +++ b/build/build.cmd @@ -0,0 +1,12 @@ +@echo off + +set MSBUILD14_EXE=%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe +set MSBUILD15_EXE=%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\\MSBuild\15.0\bin\MSBuild.exe + +call "%MSBUILD14_EXE%" build.proj /t:Clean +call "%MSBUILD15_EXE%" build.proj /t:Clean + +call "%MSBUILD14_EXE%" build.proj /t:Build +call "%MSBUILD15_EXE%" build.proj /t:Build + +call "%MSBUILD15_EXE%" build.proj /t:Package /p:ReleaseVersion=%1 \ No newline at end of file diff --git a/build/build.proj b/build/build.proj index 9b257de53..96708a6c2 100644 --- a/build/build.proj +++ b/build/build.proj @@ -1,5 +1,5 @@ - + Release @@ -11,9 +11,17 @@ $(MSBuildThisFileDirectory)..\src\Renci.SshNet.VS2012.sln + 14.0 + true $(MSBuildThisFileDirectory)..\src\Renci.SshNet.VS2015.sln + 14.0 + true + + + $(MSBuildThisFileDirectory)..\src\Renci.SshNet.VS2017.sln + 15.0 @@ -54,11 +62,11 @@ - + Configuration=Release - + @@ -67,22 +75,23 @@ FileName="$(MSBuildThisFileDirectory)target\nuget\nuget.exe"/> - - + + - + Configuration=Release + - + @@ -90,12 +99,12 @@ - + - + diff --git a/src/Renci.SshNet.NETCore/Renci.SshNet.NETCore.csproj b/src/Renci.SshNet.NETCore/Renci.SshNet.NETCore.csproj new file mode 100644 index 000000000..872901d03 --- /dev/null +++ b/src/Renci.SshNet.NETCore/Renci.SshNet.NETCore.csproj @@ -0,0 +1,117 @@ + + + + SSH.NET + netstandard1.3 + true + true + Renci.SshNet + ../Renci.SshNet.snk + true + true + false + false + false + false + false + false + false + false + false + + + + + + %(RecursiveDir)%(Filename)%(Extension) + + + + + + 1.6.0 + + + + + + 4.0.1 + + + [1.2.0] + + + 4.0.11 + + + 4.0.1 + + + 4.0.0 + + + 4.0.11 + + + 4.1.0 + + + 4.0.1 + + + 4.0.1 + + + 4.1.0 + + + 4.0.0 + + + 4.1.0 + + + 4.0.1 + + + 4.1.0 + + + 4.2.0 + + + 4.1.0 + + + 4.0.11 + + + 4.0.0 + + + 4.0.10 + + + 4.0.1 + + + 4.0.1 + + + 4.0.1 + + + + + $(DefineConstants);FEATURE_ENCODING_ASCII;FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_DIRECTORYINFO_ENUMERATEFILES;FEATURE_MEMORYSTREAM_TRYGETBUFFER;FEATURE_REFLECTION_TYPEINFO;FEATURE_RNG_CREATE;FEATURE_SOCKET_TAP;FEATURE_SOCKET_EAP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_SETSOCKETOPTION;FEATURE_SOCKET_POLL;FEATURE_DNS_TAP;FEATURE_STREAM_TAP;FEATURE_THREAD_COUNTDOWNEVENT;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_HASH_MD5;FEATURE_HASH_SHA1_CREATE;FEATURE_HASH_SHA256_CREATE;FEATURE_HASH_SHA384_CREATE;FEATURE_HASH_SHA512_CREATE;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512 + + + + portable + + + + none + + + diff --git a/src/Renci.SshNet.NETCore/Renci.SshNet.NETCore.xproj b/src/Renci.SshNet.NETCore/Renci.SshNet.NETCore.xproj deleted file mode 100644 index e1ed5223e..000000000 --- a/src/Renci.SshNet.NETCore/Renci.SshNet.NETCore.xproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 8e8229eb-6780-4a8a-b470-e2023fa55ab5 - Renci.SshNet - .\obj - .\bin\ - v4.5.2 - - - 2.0 - - - \ No newline at end of file diff --git a/src/Renci.SshNet.NETCore/project.json b/src/Renci.SshNet.NETCore/project.json deleted file mode 100644 index 22ab4e45b..000000000 --- a/src/Renci.SshNet.NETCore/project.json +++ /dev/null @@ -1,90 +0,0 @@ -{ - "title": "SSH.NET", - "configurations": { - "debug": { - "buildOptions": { - "debugType": "portable", - "define": [ "DEBUG", "TRACE" ] - } - }, - "release": { - "buildOptions": { - "debugType": "none", - "define": [ "TRACE" ] - } - } - }, - "buildOptions": { - "outputName": "Renci.SshNet", - "keyFile": "../Renci.SshNet.snk", - "compile": { - "include": [ - "../Renci.SshNet/**/*.cs" - ], - "exclude": [ - "../Renci.SshNet/Properties/AssemblyInfo.cs" - ] - }, - "optimize": true, - "xmlDoc": true, - "warningsAsErrors": true - }, - "frameworks": { - "netstandard1.3": { - "dependencies": { - "Microsoft.CSharp": "4.0.1", - "SshNet.Security.Cryptography": "[1.2.0]", - "System.Diagnostics.Debug": "4.0.11", - "System.Diagnostics.Tools": "4.0.1", - "System.Diagnostics.TraceSource": "4.0.0", - "System.Globalization": "4.0.11", - "System.IO": "4.1.0", - "System.IO.FileSystem": "4.0.1", - "System.IO.FileSystem.Primitives": "4.0.1", - "System.Linq": "4.1.0", - "System.Net.NameResolution": "4.0.0", - "System.Net.Sockets": "4.1.0", - "System.Reflection.Extensions": "4.0.1", - "System.Runtime.Extensions": "4.1.0", - "System.Security.Cryptography.Algorithms": "4.2.0", - "System.Text.RegularExpressions": "4.1.0", - "System.Threading": "4.0.11", - "System.Threading.Thread": "4.0.0", - "System.Threading.ThreadPool": "4.0.10", - "System.Threading.Timer": "4.0.1", - "System.Xml.XmlDocument": "4.0.1", - "System.Xml.XPath.XmlDocument": "4.0.1" - }, - "buildOptions": { - "define": [ - "FEATURE_ENCODING_ASCII", - "FEATURE_DIAGNOSTICS_TRACESOURCE", - "FEATURE_DIRECTORYINFO_ENUMERATEFILES", - "FEATURE_MEMORYSTREAM_TRYGETBUFFER", - "FEATURE_REFLECTION_TYPEINFO", - "FEATURE_RNG_CREATE", - "FEATURE_SOCKET_TAP", - "FEATURE_SOCKET_EAP", - "FEATURE_SOCKET_SYNC", - "FEATURE_SOCKET_SETSOCKETOPTION", - "FEATURE_SOCKET_POLL", - "FEATURE_DNS_TAP", - "FEATURE_STREAM_TAP", - "FEATURE_THREAD_COUNTDOWNEVENT", - "FEATURE_THREAD_THREADPOOL", - "FEATURE_THREAD_SLEEP", - "FEATURE_HASH_MD5", - "FEATURE_HASH_SHA1_CREATE", - "FEATURE_HASH_SHA256_CREATE", - "FEATURE_HASH_SHA384_CREATE", - "FEATURE_HASH_SHA512_CREATE", - "FEATURE_HMAC_MD5", - "FEATURE_HMAC_SHA1", - "FEATURE_HMAC_SHA256", - "FEATURE_HMAC_SHA384", - "FEATURE_HMAC_SHA512" - ] - } - } - } -} diff --git a/src/Renci.SshNet.VS2015.sln b/src/Renci.SshNet.VS2015.sln index 9ad41ee38..8171be891 100644 --- a/src/Renci.SshNet.VS2015.sln +++ b/src/Renci.SshNet.VS2015.sln @@ -37,12 +37,10 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Renci.SshNet.Shared.Tests", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Renci.SshNet.WindowsPhone8.Tests", "..\test\Renci.SshNet.WindowsPhone8.Tests\Renci.SshNet.WindowsPhone8.Tests.csproj", "{26F0D644-B3EF-47DF-8040-E9E4B2E63884}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Renci.SshNet.NETCore", "Renci.SshNet.NETCore\Renci.SshNet.NETCore.xproj", "{8E8229EB-6780-4A8A-B470-E2023FA55AB5}" -EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution - ..\test\Renci.SshNet.Shared.Tests\Renci.SshNet.Shared.Tests.projitems*{fae3948f-a438-458e-8e0e-7f6e39a5dd8a}*SharedItemsImports = 13 ..\test\Renci.SshNet.Shared.Tests\Renci.SshNet.Shared.Tests.projitems*{26f0d644-b3ef-47df-8040-e9e4b2e63884}*SharedItemsImports = 4 + ..\test\Renci.SshNet.Shared.Tests\Renci.SshNet.Shared.Tests.projitems*{fae3948f-a438-458e-8e0e-7f6e39a5dd8a}*SharedItemsImports = 13 EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -183,26 +181,6 @@ Global {26F0D644-B3EF-47DF-8040-E9E4B2E63884}.Release|x86.ActiveCfg = Release|x86 {26F0D644-B3EF-47DF-8040-E9E4B2E63884}.Release|x86.Build.0 = Release|x86 {26F0D644-B3EF-47DF-8040-E9E4B2E63884}.Release|x86.Deploy.0 = Release|x86 - {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Debug|ARM.ActiveCfg = Debug|Any CPU - {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Debug|ARM.Build.0 = Debug|Any CPU - {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Debug|x64.ActiveCfg = Debug|Any CPU - {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Debug|x64.Build.0 = Debug|Any CPU - {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Debug|x86.ActiveCfg = Debug|Any CPU - {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Debug|x86.Build.0 = Debug|Any CPU - {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|Any CPU.Build.0 = Release|Any CPU - {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|ARM.ActiveCfg = Release|Any CPU - {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|ARM.Build.0 = Release|Any CPU - {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|x64.ActiveCfg = Release|Any CPU - {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|x64.Build.0 = Release|Any CPU - {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|x86.ActiveCfg = Release|Any CPU - {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Renci.SshNet.VS2017.sln b/src/Renci.SshNet.VS2017.sln new file mode 100644 index 000000000..00469f612 --- /dev/null +++ b/src/Renci.SshNet.VS2017.sln @@ -0,0 +1,117 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26014.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{2D6CAE62-D053-476F-9BDD-2B1F27FA9C5D}" + ProjectSection(SolutionItems) = preProject + ..\build\build.cmd = ..\build\build.cmd + ..\build\build.proj = ..\build\build.proj + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nuget", "nuget", "{94EE3919-19FA-4D9B-8DA9-249050B15232}" + ProjectSection(SolutionItems) = preProject + ..\build\nuget\SSH.NET.nuspec = ..\build\nuget\SSH.NET.nuspec + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sandcastle", "sandcastle", "{A6C3FFD3-16A5-44D3-8C1F-3613D6DD17D1}" + ProjectSection(SolutionItems) = preProject + ..\build\sandcastle\SSH.NET.shfbproj = ..\build\sandcastle\SSH.NET.shfbproj + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Renci.SshNet", "Renci.SshNet\Renci.SshNet.csproj", "{2F5F8C90-0BD1-424F-997C-7BC6280919D1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Renci.SshNet.Tests", "Renci.SshNet.Tests\Renci.SshNet.Tests.csproj", "{C45379B9-17B1-4E89-BC2E-6D41726413E8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Renci.SshNet.NET35", "Renci.SshNet.NET35\Renci.SshNet.NET35.csproj", "{DD1C552F-7F48-4269-ABB3-2E4C89B7E43A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Renci.SshNet.NETCore", "Renci.SshNet.NETCore\Renci.SshNet.NETCore.csproj", "{8E8229EB-6780-4A8A-B470-E2023FA55AB5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|ARM = Debug|ARM + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|ARM = Release|ARM + Release|Mixed Platforms = Release|Mixed Platforms + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2F5F8C90-0BD1-424F-997C-7BC6280919D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2F5F8C90-0BD1-424F-997C-7BC6280919D1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2F5F8C90-0BD1-424F-997C-7BC6280919D1}.Debug|ARM.ActiveCfg = Debug|Any CPU + {2F5F8C90-0BD1-424F-997C-7BC6280919D1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {2F5F8C90-0BD1-424F-997C-7BC6280919D1}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {2F5F8C90-0BD1-424F-997C-7BC6280919D1}.Debug|x64.ActiveCfg = Debug|Any CPU + {2F5F8C90-0BD1-424F-997C-7BC6280919D1}.Debug|x86.ActiveCfg = Debug|Any CPU + {2F5F8C90-0BD1-424F-997C-7BC6280919D1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2F5F8C90-0BD1-424F-997C-7BC6280919D1}.Release|Any CPU.Build.0 = Release|Any CPU + {2F5F8C90-0BD1-424F-997C-7BC6280919D1}.Release|ARM.ActiveCfg = Release|Any CPU + {2F5F8C90-0BD1-424F-997C-7BC6280919D1}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {2F5F8C90-0BD1-424F-997C-7BC6280919D1}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {2F5F8C90-0BD1-424F-997C-7BC6280919D1}.Release|x64.ActiveCfg = Release|Any CPU + {2F5F8C90-0BD1-424F-997C-7BC6280919D1}.Release|x86.ActiveCfg = Release|Any CPU + {C45379B9-17B1-4E89-BC2E-6D41726413E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C45379B9-17B1-4E89-BC2E-6D41726413E8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C45379B9-17B1-4E89-BC2E-6D41726413E8}.Debug|ARM.ActiveCfg = Debug|Any CPU + {C45379B9-17B1-4E89-BC2E-6D41726413E8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {C45379B9-17B1-4E89-BC2E-6D41726413E8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {C45379B9-17B1-4E89-BC2E-6D41726413E8}.Debug|x64.ActiveCfg = Debug|Any CPU + {C45379B9-17B1-4E89-BC2E-6D41726413E8}.Debug|x86.ActiveCfg = Debug|Any CPU + {C45379B9-17B1-4E89-BC2E-6D41726413E8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C45379B9-17B1-4E89-BC2E-6D41726413E8}.Release|Any CPU.Build.0 = Release|Any CPU + {C45379B9-17B1-4E89-BC2E-6D41726413E8}.Release|ARM.ActiveCfg = Release|Any CPU + {C45379B9-17B1-4E89-BC2E-6D41726413E8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {C45379B9-17B1-4E89-BC2E-6D41726413E8}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {C45379B9-17B1-4E89-BC2E-6D41726413E8}.Release|x64.ActiveCfg = Release|Any CPU + {C45379B9-17B1-4E89-BC2E-6D41726413E8}.Release|x86.ActiveCfg = Release|Any CPU + {DD1C552F-7F48-4269-ABB3-2E4C89B7E43A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DD1C552F-7F48-4269-ABB3-2E4C89B7E43A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DD1C552F-7F48-4269-ABB3-2E4C89B7E43A}.Debug|ARM.ActiveCfg = Debug|Any CPU + {DD1C552F-7F48-4269-ABB3-2E4C89B7E43A}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {DD1C552F-7F48-4269-ABB3-2E4C89B7E43A}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {DD1C552F-7F48-4269-ABB3-2E4C89B7E43A}.Debug|x64.ActiveCfg = Debug|Any CPU + {DD1C552F-7F48-4269-ABB3-2E4C89B7E43A}.Debug|x86.ActiveCfg = Debug|Any CPU + {DD1C552F-7F48-4269-ABB3-2E4C89B7E43A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DD1C552F-7F48-4269-ABB3-2E4C89B7E43A}.Release|Any CPU.Build.0 = Release|Any CPU + {DD1C552F-7F48-4269-ABB3-2E4C89B7E43A}.Release|ARM.ActiveCfg = Release|Any CPU + {DD1C552F-7F48-4269-ABB3-2E4C89B7E43A}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {DD1C552F-7F48-4269-ABB3-2E4C89B7E43A}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {DD1C552F-7F48-4269-ABB3-2E4C89B7E43A}.Release|x64.ActiveCfg = Release|Any CPU + {DD1C552F-7F48-4269-ABB3-2E4C89B7E43A}.Release|x86.ActiveCfg = Release|Any CPU + {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Debug|ARM.ActiveCfg = Debug|Any CPU + {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Debug|ARM.Build.0 = Debug|Any CPU + {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Debug|x64.ActiveCfg = Debug|Any CPU + {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Debug|x64.Build.0 = Debug|Any CPU + {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Debug|x86.ActiveCfg = Debug|Any CPU + {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Debug|x86.Build.0 = Debug|Any CPU + {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|Any CPU.Build.0 = Release|Any CPU + {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|ARM.ActiveCfg = Release|Any CPU + {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|ARM.Build.0 = Release|Any CPU + {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|x64.ActiveCfg = Release|Any CPU + {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|x64.Build.0 = Release|Any CPU + {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|x86.ActiveCfg = Release|Any CPU + {8E8229EB-6780-4A8A-B470-E2023FA55AB5}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {94EE3919-19FA-4D9B-8DA9-249050B15232} = {2D6CAE62-D053-476F-9BDD-2B1F27FA9C5D} + {A6C3FFD3-16A5-44D3-8C1F-3613D6DD17D1} = {2D6CAE62-D053-476F-9BDD-2B1F27FA9C5D} + EndGlobalSection + GlobalSection(TestCaseManagementSettings) = postSolution + CategoryFile = Renci.SshNet1.vsmdi + EndGlobalSection +EndGlobal From 9747d9caefad1dc760aed67744ef6107c66e27af Mon Sep 17 00:00:00 2001 From: Gert Driesen Date: Fri, 30 Dec 2016 13:14:35 +0100 Subject: [PATCH 004/128] Revert "Add ClientIP to client info to allow select client IP that should be used for connection (#132)" This reverts commit 78679a3c30e689aeb2ad8990aa4db6d71b48db99. --- src/Renci.SshNet/ConnectionInfo.cs | 70 ------------------------------ src/Renci.SshNet/Session.cs | 2 +- 2 files changed, 1 insertion(+), 71 deletions(-) diff --git a/src/Renci.SshNet/ConnectionInfo.cs b/src/Renci.SshNet/ConnectionInfo.cs index 6e13755ae..ba8f38b93 100644 --- a/src/Renci.SshNet/ConnectionInfo.cs +++ b/src/Renci.SshNet/ConnectionInfo.cs @@ -9,7 +9,6 @@ using Renci.SshNet.Messages.Authentication; using Renci.SshNet.Security.Cryptography.Ciphers.Modes; using Renci.SshNet.Security.Cryptography.Ciphers; -using System.Net; namespace Renci.SshNet { @@ -206,14 +205,6 @@ public class ConnectionInfo : IConnectionInfoInternal /// public string ClientVersion { get; internal set; } - /// - /// Gets the client ip to use for connection when client has multiple IP addresses availble. - /// - /// - /// The client ip to use for connection. - /// - public IPAddress ClientIP { get; internal set; } - /// /// Gets the current client compression algorithm. /// @@ -272,66 +263,6 @@ public ConnectionInfo(string host, int port, string username, params Authenticat /// is null. /// No specified. public ConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, params AuthenticationMethod[] authenticationMethods) - : this(host, DefaultPort, username, null, ProxyTypes.None, null, 0, null, null, authenticationMethods) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The host. - /// The username. - /// The client IP to be used. - /// The authentication methods. - /// is null. - /// is a zero-length string. - /// is a zero-length string. - /// is null. - /// is a zero-length string. - public ConnectionInfo(string host, string username, IPAddress clientIP, params AuthenticationMethod[] authenticationMethods) - : this(host, DefaultPort, username, clientIP, ProxyTypes.None, null, 0, null, null, authenticationMethods) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The host. - /// The port. - /// The username. - /// The client IP to be used. - /// The authentication methods. - /// is null. - /// is null, a zero-length string or contains only whitespace characters. - /// is not within and . - /// is null. - /// is null, a zero-length string or contains only whitespace characters. - public ConnectionInfo(string host, int port, string username, IPAddress clientIP, params AuthenticationMethod[] authenticationMethods) - : this(host, port, username, clientIP, ProxyTypes.None, null, 0, null, null, authenticationMethods) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// Connection host. - /// Connection port. - /// Connection username. - /// The client IP to be used. - /// Type of the proxy. - /// The proxy host. - /// The proxy port. - /// The proxy username. - /// The proxy password. - /// The authentication methods. - /// is null. - /// is null, a zero-length string or contains only whitespace characters. - /// is not within and . - /// is not and is null. - /// is not and is not within and . - /// is null. - /// No specified. - public ConnectionInfo(string host, int port, string username, IPAddress clientIP, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, params AuthenticationMethod[] authenticationMethods) { if (host == null) throw new ArgumentNullException("host"); @@ -455,7 +386,6 @@ public ConnectionInfo(string host, int port, string username, IPAddress clientIP Host = host; Port = port; Username = username; - ClientIP = clientIP; ProxyType = proxyType; ProxyHost = proxyHost; diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs index 0bebddfcf..e26743098 100644 --- a/src/Renci.SshNet/Session.cs +++ b/src/Renci.SshNet/Session.cs @@ -1600,7 +1600,7 @@ internal static string ToHex(byte[] bytes) /// An error occurred trying to establish the connection. private void SocketConnect(string host, int port) { - var ipAddress = ConnectionInfo.ClientIP ?? DnsAbstraction.GetHostAddresses(host)[0]; + var ipAddress = DnsAbstraction.GetHostAddresses(host)[0]; var ep = new IPEndPoint(ipAddress, port); DiagnosticAbstraction.Log(string.Format("Initiating connection to '{0}:{1}'.", host, port)); From d95276d8614a503309c7248f99e233bdea3bb4bb Mon Sep 17 00:00:00 2001 From: Gert Driesen Date: Wed, 4 Jan 2017 18:51:09 +0100 Subject: [PATCH 005/128] Document the fact that we now use VS 2017 to build the .NET Standard 1.3 flavor of SSH.NET. --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b83365f93..21e11db1c 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ This project was inspired by **Sharp.SSH** library which was ported from java an **SSH.NET** supports the following target frameworks: * .NET Framework 3.5 * .NET Framework 4.0 (and higher) -* .NET Platform Standard 1.3 +* .NET Standard 1.3 * Silverlight 4 * Silverlight 5 * Windows Phone 7.1 @@ -64,6 +64,7 @@ Software | net35 | net40 | netstandard1.3 | sl4 | sl5 | --------------------------------- | :---: | :---: | :------------: | :-: | :-: | :--: | :-: | :-----: | Windows Phone SDK 8.0 | | | | x | x | x | x | Visual Studio 2012 Update 5 | x | x | | x | x | x | x | -Visual Studio 2015 Update 3 | x | x | x | | x | | x | x +Visual Studio 2015 Update 3 | x | x | | | x | | x | x +Visual Studio 2017 | | x | x | | | | | [![NDepend](http://download-codeplex.sec.s-msft.com/Download?ProjectName=sshnet&DownloadId=629750)](http://ndepend.com) From 3f28d8c1758a10b9f08d9cbcf4008aec268ffbd8 Mon Sep 17 00:00:00 2001 From: Gert Driesen Date: Sun, 8 Jan 2017 15:15:59 +0100 Subject: [PATCH 006/128] Revert changes in BigInteger.Random(int bitLength) from commit 1b881f5df30491c7a6e1fb5957d3c0fe25170805. Fixes issue #147. --- .../Classes/Common/BigIntegerTest.cs | 14 ++++++++++ src/Renci.SshNet/Common/BigInteger.cs | 28 +++---------------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/Renci.SshNet.Tests/Classes/Common/BigIntegerTest.cs b/src/Renci.SshNet.Tests/Classes/Common/BigIntegerTest.cs index dc8bddc0b..0ab772d03 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/BigIntegerTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/BigIntegerTest.cs @@ -1651,6 +1651,20 @@ public void Zero() Assert.AreEqual(0, zero.Sign); } + [TestMethod] + public void Random() + { + var max = "26432534714839143538998938508341375449389492936207135611931371046236385860280414659368073862189301615603000443463893527273703804361856647266218472759410964268979057798543462774631912259980510080575520846081682603934587649566608158932346151315049355432937004801361578344502537300865702429436253728164365180058583916866804254965536833106467354901266304654706123552932560896874808786957654734387252964281680963136344135750381838556467139236094522411774117748615141352874979928570068255439327082539676660277104989857941859821396157749462154431239343148671646397611770487668571604363151098131876313773395912355145689712506"; + BigInteger maxBigInt; + Assert.IsTrue(BigInteger.TryParse(max, NumberStyles.Number, NumberFormatInfo.CurrentInfo, out maxBigInt)); + + var random = BigInteger.One; + while (random <= BigInteger.One || random >= maxBigInt) + { + random = BigInteger.Random(2048); + } + } + [TestMethod] public void TestClientExhcangeGenerationItem130() { diff --git a/src/Renci.SshNet/Common/BigInteger.cs b/src/Renci.SshNet/Common/BigInteger.cs index 73cce8bdf..611b74dde 100644 --- a/src/Renci.SshNet/Common/BigInteger.cs +++ b/src/Renci.SshNet/Common/BigInteger.cs @@ -171,30 +171,10 @@ public static BigInteger PositiveMod(BigInteger dividend, BigInteger divisor) /// A random number of the specified length. public static BigInteger Random(int bitLength) { - int dwords = bitLength >> 5; - int remBits = bitLength & 0x1F; - - if (remBits != 0) - dwords++; - - BigInteger ret = new BigInteger(1, new uint[(uint)dwords + 1]); - byte[] random = new byte[dwords << 2]; - - CryptoAbstraction.GenerateRandom(random); - Buffer.BlockCopy(random, 0, ret._data, 0, (int)dwords << 2); - - if (remBits != 0) - { - uint mask = (uint)(0x01 << (remBits - 1)); - ret._data[dwords - 1] |= mask; - - mask = (uint)(0xFFFFFFFF >> (32 - remBits)); - ret._data[dwords - 1] &= mask; - } - else - ret._data[dwords - 1] |= 0x80000000; - - return ret; + var bytesArray = new byte[bitLength / 8 + (((bitLength % 8) > 0) ? 1 : 0)]; + CryptoAbstraction.GenerateRandom(bytesArray); + bytesArray[bytesArray.Length - 1] = (byte) (bytesArray[bytesArray.Length - 1] & 0x7F); // Ensure not a negative value + return new BigInteger(bytesArray); } #endregion SSH.NET additions From ffda76a15b8bea686bf3846496b11a00fa9a83a8 Mon Sep 17 00:00:00 2001 From: Toni Spets Date: Thu, 12 Jan 2017 18:00:29 +0200 Subject: [PATCH 007/128] Remove unused variables, fixes mcs warnings on Mono --- src/Renci.SshNet/ScpClient.NET.cs | 2 -- src/Renci.SshNet/ScpClient.cs | 1 - 2 files changed, 3 deletions(-) diff --git a/src/Renci.SshNet/ScpClient.NET.cs b/src/Renci.SshNet/ScpClient.NET.cs index c3a3ce103..73b1770d4 100644 --- a/src/Renci.SshNet/ScpClient.NET.cs +++ b/src/Renci.SshNet/ScpClient.NET.cs @@ -202,7 +202,6 @@ private void InternalDownload(IChannelSession channel, Stream input, FileSystemI SendConfirmation(channel); // Send reply // Read directory - var mode = long.Parse(match.Result("${mode}")); var filename = match.Result("${filename}"); DirectoryInfo newDirectoryInfo; @@ -230,7 +229,6 @@ private void InternalDownload(IChannelSession channel, Stream input, FileSystemI // Read file SendConfirmation(channel); // Send reply - var mode = match.Result("${mode}"); var length = long.Parse(match.Result("${length}")); var fileName = match.Result("${filename}"); diff --git a/src/Renci.SshNet/ScpClient.cs b/src/Renci.SshNet/ScpClient.cs index a3f5e13f9..dfdec27c9 100644 --- a/src/Renci.SshNet/ScpClient.cs +++ b/src/Renci.SshNet/ScpClient.cs @@ -231,7 +231,6 @@ public void Download(string filename, Stream destination) // Read file SendConfirmation(channel); // Send reply - var mode = match.Result("${mode}"); var length = long.Parse(match.Result("${length}")); var fileName = match.Result("${filename}"); From 0b04aaa79d7abbbeb4b47105b0c154f3cb5ceb43 Mon Sep 17 00:00:00 2001 From: Gert Driesen Date: Sun, 22 Jan 2017 11:12:37 +0100 Subject: [PATCH 008/128] Add more tests for .NET 3.5 test project. --- .../Renci.SshNet.Tests.NET35.csproj | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/Renci.SshNet.Tests.NET35/Renci.SshNet.Tests.NET35.csproj b/src/Renci.SshNet.Tests.NET35/Renci.SshNet.Tests.NET35.csproj index 9fdeeb6a3..a9ea6dbfe 100644 --- a/src/Renci.SshNet.Tests.NET35/Renci.SshNet.Tests.NET35.csproj +++ b/src/Renci.SshNet.Tests.NET35/Renci.SshNet.Tests.NET35.csproj @@ -40,7 +40,7 @@ - + ..\..\packages\Moq.4.2.1409.1722\lib\net35\Moq.dll @@ -77,6 +77,9 @@ Classes\ForwardedPortStatusTest_Stopping.cs + + Classes\BaseClientTest_Connected_KeepAlivesNotSentConcurrently.cs + Classes\Channels\ChannelDirectTcpipTest.cs @@ -839,6 +842,45 @@ Classes\SessionTest.HttpProxy.cs + + Classes\SessionTest_Connected.cs + + + Classes\SessionTest_ConnectedBase.cs + + + Classes\SessionTest_Connected_ConnectionReset.cs + + + Classes\SessionTest_Connected_Disconnect.cs + + + Classes\SessionTest_Connected_GlobalRequestMessageAfterAuthenticationRace.cs + + + Classes\SessionTest_Connected_ServerAndClientDisconnectRace.cs + + + Classes\SessionTest_Connected_ServerSendsBadPacket.cs + + + Classes\SessionTest_Connected_ServerSendsDisconnectMessage.cs + + + Classes\SessionTest_Connected_ServerSendsDisconnectMessageAndShutsDownSocket.cs + + + Classes\SessionTest_Connected_ServerShutsDownSendAfterSendingIncompletePacket.cs + + + Classes\SessionTest_Connected_ServerShutsDownSocket.cs + + + Classes\SessionTest_NotConnected.cs + + + Classes\SessionTest_SocketConnected_BadPacketAndDispose.cs + Classes\SftpClientTest.ChangeDirectory.cs @@ -1304,7 +1346,7 @@ - +