mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-09-10 17:25:51 +00:00
use extension members for CryptoAbstractions
This commit is contained in:
@@ -10,77 +10,5 @@ namespace Renci.SshNet.Abstractions
|
||||
private static readonly RandomNumberGenerator Randomizer = RandomNumberGenerator.Create();
|
||||
|
||||
internal static readonly SecureRandom SecureRandom = new SecureRandom(new CryptoApiRandomGenerator(Randomizer));
|
||||
|
||||
/// <summary>
|
||||
/// Generates a <see cref="byte"/> array of the specified length, and fills it with a
|
||||
/// cryptographically strong random sequence of values.
|
||||
/// </summary>
|
||||
/// <param name="length">The length of the array generate.</param>
|
||||
public static byte[] GenerateRandom(int length)
|
||||
{
|
||||
var random = new byte[length];
|
||||
Randomizer.GetBytes(random);
|
||||
return random;
|
||||
}
|
||||
|
||||
public static byte[] HashMD5(byte[] source)
|
||||
{
|
||||
#if NET
|
||||
return MD5.HashData(source);
|
||||
#else
|
||||
using (var md5 = MD5.Create())
|
||||
{
|
||||
return md5.ComputeHash(source);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static byte[] HashSHA1(byte[] source)
|
||||
{
|
||||
#if NET
|
||||
return SHA1.HashData(source);
|
||||
#else
|
||||
using (var sha1 = SHA1.Create())
|
||||
{
|
||||
return sha1.ComputeHash(source);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static byte[] HashSHA256(byte[] source)
|
||||
{
|
||||
#if NET
|
||||
return SHA256.HashData(source);
|
||||
#else
|
||||
using (var sha256 = SHA256.Create())
|
||||
{
|
||||
return sha256.ComputeHash(source);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static byte[] HashSHA384(byte[] source)
|
||||
{
|
||||
#if NET
|
||||
return SHA384.HashData(source);
|
||||
#else
|
||||
using (var sha384 = SHA384.Create())
|
||||
{
|
||||
return sha384.ComputeHash(source);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static byte[] HashSHA512(byte[] source)
|
||||
{
|
||||
#if NET
|
||||
return SHA512.HashData(source);
|
||||
#else
|
||||
using (var sha512 = SHA512.Create())
|
||||
{
|
||||
return sha512.ComputeHash(source);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#nullable enable
|
||||
namespace System.Security.Cryptography
|
||||
{
|
||||
internal static class MD5Extensions
|
||||
{
|
||||
extension(MD5)
|
||||
{
|
||||
#if !NET
|
||||
public static byte[] HashData(byte[] source)
|
||||
{
|
||||
using (var md5 = MD5.Create())
|
||||
{
|
||||
return md5.ComputeHash(source);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#nullable enable
|
||||
namespace System.Security.Cryptography
|
||||
{
|
||||
internal static class RandomNumberGeneratorExtensions
|
||||
{
|
||||
#if !NET
|
||||
private static readonly RandomNumberGenerator Randomizer = RandomNumberGenerator.Create();
|
||||
#endif
|
||||
|
||||
extension(RandomNumberGenerator)
|
||||
{
|
||||
#if !NET
|
||||
public static byte[] GetBytes(int length)
|
||||
{
|
||||
var random = new byte[length];
|
||||
Randomizer.GetBytes(random);
|
||||
return random;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace System.Security.Cryptography
|
||||
{
|
||||
internal static class SHA1Extensions
|
||||
{
|
||||
extension(SHA1)
|
||||
{
|
||||
#if !NET
|
||||
public static byte[] HashData(byte[] source)
|
||||
{
|
||||
using (var sha1 = SHA1.Create())
|
||||
{
|
||||
return sha1.ComputeHash(source);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#nullable enable
|
||||
namespace System.Security.Cryptography
|
||||
{
|
||||
internal static class SHA256Extensions
|
||||
{
|
||||
extension(SHA256)
|
||||
{
|
||||
#if !NET
|
||||
public static byte[] HashData(byte[] source)
|
||||
{
|
||||
using (var sha256 = SHA256.Create())
|
||||
{
|
||||
return sha256.ComputeHash(source);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#nullable enable
|
||||
namespace System.Security.Cryptography
|
||||
{
|
||||
internal static class SHA384Extensions
|
||||
{
|
||||
extension(SHA384)
|
||||
{
|
||||
#if !NET
|
||||
public static byte[] HashData(byte[] source)
|
||||
{
|
||||
using (var sha384 = SHA384.Create())
|
||||
{
|
||||
return sha384.ComputeHash(source);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#nullable enable
|
||||
namespace System.Security.Cryptography
|
||||
{
|
||||
internal static class SHA512Extensions
|
||||
{
|
||||
extension(SHA512)
|
||||
{
|
||||
#if !NET
|
||||
public static byte[] HashData(byte[] source)
|
||||
{
|
||||
using (var sha512 = SHA512.Create())
|
||||
{
|
||||
return sha512.ComputeHash(source);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Security;
|
||||
|
||||
namespace Renci.SshNet.Common
|
||||
@@ -104,9 +104,9 @@ namespace Renci.SshNet.Common
|
||||
HostKeyName = host.Name;
|
||||
KeyLength = host.Key.KeyLength;
|
||||
|
||||
_lazyFingerPrint = new Lazy<byte[]>(() => CryptoAbstraction.HashMD5(HostKey));
|
||||
_lazyFingerPrint = new Lazy<byte[]>(() => MD5.HashData(HostKey));
|
||||
|
||||
_lazyFingerPrintSHA256 = new Lazy<string>(() => Convert.ToBase64String(CryptoAbstraction.HashSHA256(HostKey)).TrimEnd('='));
|
||||
_lazyFingerPrintSHA256 = new Lazy<string>(() => Convert.ToBase64String(SHA256.HashData(HostKey)).TrimEnd('='));
|
||||
|
||||
_lazyFingerPrintMD5 = new Lazy<string>(() =>
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Compression;
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace Renci.SshNet.Messages
|
||||
var paddingLength = GetPaddingLength(paddingMultiplier, excludePacketLengthFieldWhenPadding ? packetLength - 4 : packetLength);
|
||||
|
||||
// add padding bytes
|
||||
var paddingBytes = CryptoAbstraction.GenerateRandom(paddingLength);
|
||||
var paddingBytes = RandomNumberGenerator.GetBytes(paddingLength);
|
||||
sshDataStream.Write(paddingBytes, 0, paddingLength);
|
||||
|
||||
var packetDataLength = GetPacketDataLength(messageLength, paddingLength);
|
||||
@@ -127,7 +127,7 @@ namespace Renci.SshNet.Messages
|
||||
WriteBytes(sshDataStream);
|
||||
|
||||
// add padding bytes
|
||||
var paddingBytes = CryptoAbstraction.GenerateRandom(paddingLength);
|
||||
var paddingBytes = RandomNumberGenerator.GetBytes(paddingLength);
|
||||
sshDataStream.Write(paddingBytes, 0, paddingLength);
|
||||
|
||||
return sshDataStream.ToArray();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Renci.SshNet.Abstractions;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Renci.SshNet.Messages.Transport
|
||||
{
|
||||
@@ -12,7 +12,7 @@ namespace Renci.SshNet.Messages.Transport
|
||||
/// </summary>
|
||||
public KeyExchangeInitMessage()
|
||||
{
|
||||
Cookie = CryptoAbstraction.GenerateRandom(16);
|
||||
Cookie = RandomNumberGenerator.GetBytes(16);
|
||||
}
|
||||
|
||||
#region Message Properties
|
||||
|
||||
@@ -9,7 +9,6 @@ using System.Text;
|
||||
using Org.BouncyCastle.Crypto.Generators;
|
||||
using Org.BouncyCastle.Crypto.Parameters;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Security;
|
||||
using Renci.SshNet.Security.Cryptography.Ciphers;
|
||||
@@ -103,7 +102,7 @@ namespace Renci.SshNet
|
||||
cipherKey = keyData.Take(32);
|
||||
cipherIV = new byte[16];
|
||||
|
||||
macKey = CryptoAbstraction.HashSHA1(Encoding.UTF8.GetBytes("putty-private-key-file-mac-key" + _passPhrase)).Take(20);
|
||||
macKey = SHA1.HashData(Encoding.UTF8.GetBytes("putty-private-key-file-mac-key" + _passPhrase)).Take(20);
|
||||
hmac = new HMACSHA1(macKey);
|
||||
|
||||
break;
|
||||
@@ -124,7 +123,7 @@ namespace Renci.SshNet
|
||||
hmac = new HMACSHA256(Array.Empty<byte>());
|
||||
break;
|
||||
case "2":
|
||||
var macKey = CryptoAbstraction.HashSHA1(Encoding.UTF8.GetBytes("putty-private-key-file-mac-key"));
|
||||
var macKey = SHA1.HashData(Encoding.UTF8.GetBytes("putty-private-key-file-mac-key"));
|
||||
hmac = new HMACSHA1(macKey);
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Common;
|
||||
|
||||
namespace Renci.SshNet.Security
|
||||
@@ -228,7 +228,7 @@ namespace Renci.SshNet.Security
|
||||
{
|
||||
get
|
||||
{
|
||||
return Convert.ToBase64String(CryptoAbstraction.HashSHA256(CertificateAuthorityKey)).TrimEnd('=');
|
||||
return Convert.ToBase64String(SHA256.HashData(CertificateAuthorityKey)).TrimEnd('=');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Org.BouncyCastle.Crypto.Agreement;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using Org.BouncyCastle.Crypto.Agreement;
|
||||
using Org.BouncyCastle.Crypto.Generators;
|
||||
using Org.BouncyCastle.Crypto.Parameters;
|
||||
|
||||
@@ -70,7 +72,7 @@ namespace Renci.SshNet.Security
|
||||
/// </returns>
|
||||
protected override byte[] Hash(byte[] hashData)
|
||||
{
|
||||
return CryptoAbstraction.HashSHA256(hashData);
|
||||
return SHA256.HashData(hashData);
|
||||
}
|
||||
|
||||
private void Session_KeyExchangeEcdhReplyMessageReceived(object sender, MessageEventArgs<KeyExchangeEcdhReplyMessage> e)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Org.BouncyCastle.Asn1.Sec;
|
||||
using Org.BouncyCastle.Asn1.X9;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Org.BouncyCastle.Asn1.Sec;
|
||||
using Org.BouncyCastle.Asn1.X9;
|
||||
|
||||
namespace Renci.SshNet.Security
|
||||
{
|
||||
@@ -59,7 +59,7 @@ namespace Renci.SshNet.Security
|
||||
/// </returns>
|
||||
protected override byte[] Hash(byte[] hashData)
|
||||
{
|
||||
return CryptoAbstraction.HashSHA256(hashData);
|
||||
return SHA256.HashData(hashData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Org.BouncyCastle.Asn1.Sec;
|
||||
using Org.BouncyCastle.Asn1.X9;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Org.BouncyCastle.Asn1.Sec;
|
||||
using Org.BouncyCastle.Asn1.X9;
|
||||
|
||||
namespace Renci.SshNet.Security
|
||||
{
|
||||
@@ -59,7 +59,7 @@ namespace Renci.SshNet.Security
|
||||
/// </returns>
|
||||
protected override byte[] Hash(byte[] hashData)
|
||||
{
|
||||
return CryptoAbstraction.HashSHA384(hashData);
|
||||
return SHA384.HashData(hashData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Org.BouncyCastle.Asn1.Sec;
|
||||
using Org.BouncyCastle.Asn1.X9;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Org.BouncyCastle.Asn1.Sec;
|
||||
using Org.BouncyCastle.Asn1.X9;
|
||||
|
||||
namespace Renci.SshNet.Security
|
||||
{
|
||||
@@ -59,7 +59,7 @@ namespace Renci.SshNet.Security
|
||||
/// </returns>
|
||||
protected override byte[] Hash(byte[] hashData)
|
||||
{
|
||||
return CryptoAbstraction.HashSHA512(hashData);
|
||||
return SHA512.HashData(hashData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using Org.BouncyCastle.Crypto.Agreement;
|
||||
using Org.BouncyCastle.Crypto.Generators;
|
||||
@@ -86,7 +87,7 @@ namespace Renci.SshNet.Security
|
||||
/// </returns>
|
||||
protected override byte[] Hash(byte[] hashData)
|
||||
{
|
||||
return CryptoAbstraction.HashSHA256(hashData);
|
||||
return SHA256.HashData(hashData);
|
||||
}
|
||||
|
||||
private void Session_KeyExchangeHybridReplyMessageReceived(object sender, MessageEventArgs<KeyExchangeHybridReplyMessage> e)
|
||||
@@ -128,7 +129,7 @@ namespace Renci.SshNet.Security
|
||||
var x25519PublicKey = new X25519PublicKeyParameters(serverExchangeValue, _mlkemDecapsulator.EncapsulationLength);
|
||||
_x25519Agreement.CalculateAgreement(x25519PublicKey, secret, _mlkemDecapsulator.SecretLength);
|
||||
|
||||
SharedKey = CryptoAbstraction.HashSHA256(secret);
|
||||
SharedKey = SHA256.HashData(secret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using Org.BouncyCastle.Crypto.Agreement;
|
||||
using Org.BouncyCastle.Crypto.Generators;
|
||||
@@ -86,7 +87,7 @@ namespace Renci.SshNet.Security
|
||||
/// </returns>
|
||||
protected override byte[] Hash(byte[] hashData)
|
||||
{
|
||||
return CryptoAbstraction.HashSHA512(hashData);
|
||||
return SHA512.HashData(hashData);
|
||||
}
|
||||
|
||||
private void Session_KeyExchangeEcdhReplyMessageReceived(object sender, MessageEventArgs<KeyExchangeEcdhReplyMessage> e)
|
||||
@@ -129,7 +130,7 @@ namespace Renci.SshNet.Security
|
||||
Array.Resize(ref secret, sntrup761SecretLength + _x25519Agreement.AgreementSize);
|
||||
_x25519Agreement.CalculateAgreement(x25519PublicKey, secret, sntrup761SecretLength);
|
||||
|
||||
SharedKey = CryptoAbstraction.HashSHA512(secret);
|
||||
SharedKey = SHA512.HashData(secret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Renci.SshNet.Tests.Classes
|
||||
{
|
||||
@@ -17,7 +18,7 @@ namespace Renci.SshNet.Tests.Classes
|
||||
[TestMethod]
|
||||
public void CryptoAbstraction_GenerateRandom_ShouldPerformNoOpWhenDataIsZeroLength()
|
||||
{
|
||||
Assert.AreEqual(0, CryptoAbstraction.GenerateRandom(0).Length);
|
||||
Assert.AreEqual(0, RandomNumberGenerator.GetBytes(0).Length);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -25,8 +26,8 @@ namespace Renci.SshNet.Tests.Classes
|
||||
{
|
||||
var dataLength = new Random().Next(1, 100);
|
||||
|
||||
var dataA = CryptoAbstraction.GenerateRandom(dataLength);
|
||||
var dataB = CryptoAbstraction.GenerateRandom(dataLength);
|
||||
var dataA = RandomNumberGenerator.GetBytes(dataLength);
|
||||
var dataB = RandomNumberGenerator.GetBytes(dataLength);
|
||||
|
||||
Assert.AreEqual(dataLength, dataA.Length);
|
||||
Assert.AreEqual(dataLength, dataB.Length);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Messages.Connection;
|
||||
using Renci.SshNet.Tests.Common;
|
||||
@@ -101,7 +101,7 @@ namespace Renci.SshNet.Tests.Classes.Messages.Connection
|
||||
var random = new Random();
|
||||
|
||||
var localChannelNumber = (uint)random.Next(0, int.MaxValue);
|
||||
var data = CryptoAbstraction.GenerateRandom(random.Next(10, 20));
|
||||
var data = RandomNumberGenerator.GetBytes(random.Next(10, 20));
|
||||
var offset = random.Next(0, data.Length - 1);
|
||||
var size = random.Next(0, data.Length - offset);
|
||||
|
||||
@@ -135,7 +135,7 @@ namespace Renci.SshNet.Tests.Classes.Messages.Connection
|
||||
var random = new Random();
|
||||
|
||||
var localChannelNumber = (uint)random.Next(0, int.MaxValue);
|
||||
var data = CryptoAbstraction.GenerateRandom(random.Next(10, 20));
|
||||
var data = RandomNumberGenerator.GetBytes(random.Next(10, 20));
|
||||
|
||||
var offset = random.Next(0, data.Length - 1);
|
||||
var size = random.Next(0, data.Length - offset);
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Sftp;
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Renci.SshNet.Tests.Classes
|
||||
|
||||
_bufferSize = (uint)random.Next(1, int.MaxValue);
|
||||
_openAsyncResult = new SftpOpenAsyncResult(null, null);
|
||||
_handle = CryptoAbstraction.GenerateRandom(random.Next(1, 10));
|
||||
_handle = RandomNumberGenerator.GetBytes(random.Next(1, 10));
|
||||
_statAsyncResult = new SFtpStatAsyncResult(null, null);
|
||||
_fileName = random.Next().ToString();
|
||||
_chunkSize = (uint)random.Next(1, int.MaxValue);
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Sftp;
|
||||
using Renci.SshNet.Tests.Common;
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Renci.SshNet.Tests.Classes
|
||||
|
||||
_bufferSize = (uint)random.Next(1, int.MaxValue);
|
||||
_openAsyncResult = new SftpOpenAsyncResult(null, null);
|
||||
_handle = CryptoAbstraction.GenerateRandom(random.Next(1, 10));
|
||||
_handle = RandomNumberGenerator.GetBytes(random.Next(1, 10));
|
||||
_statAsyncResult = new SFtpStatAsyncResult(null, null);
|
||||
_fileName = random.Next().ToString();
|
||||
_chunkSize = (uint)random.Next(1000, 5000);
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Sftp;
|
||||
using Renci.SshNet.Tests.Common;
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Renci.SshNet.Tests.Classes
|
||||
|
||||
_bufferSize = (uint)random.Next(1, int.MaxValue);
|
||||
_openAsyncResult = new SftpOpenAsyncResult(null, null);
|
||||
_handle = CryptoAbstraction.GenerateRandom(random.Next(1, 10));
|
||||
_handle = RandomNumberGenerator.GetBytes(random.Next(1, 10));
|
||||
_statAsyncResult = new SFtpStatAsyncResult(null, null);
|
||||
_fileName = random.Next().ToString();
|
||||
_chunkSize = (uint)random.Next(1000, int.MaxValue);
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Sftp;
|
||||
using Renci.SshNet.Tests.Common;
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Renci.SshNet.Tests.Classes
|
||||
|
||||
_bufferSize = (uint)random.Next(1, int.MaxValue);
|
||||
_openAsyncResult = new SftpOpenAsyncResult(null, null);
|
||||
_handle = CryptoAbstraction.GenerateRandom(random.Next(1, 10));
|
||||
_handle = RandomNumberGenerator.GetBytes(random.Next(1, 10));
|
||||
_statAsyncResult = new SFtpStatAsyncResult(null, null);
|
||||
_fileName = random.Next().ToString();
|
||||
_chunkSize = (uint)random.Next(1000, 5000);
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Sftp;
|
||||
using Renci.SshNet.Tests.Common;
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Renci.SshNet.Tests.Classes
|
||||
|
||||
_bufferSize = (uint)random.Next(1, int.MaxValue);
|
||||
_openAsyncResult = new SftpOpenAsyncResult(null, null);
|
||||
_handle = CryptoAbstraction.GenerateRandom(random.Next(1, 10));
|
||||
_handle = RandomNumberGenerator.GetBytes(random.Next(1, 10));
|
||||
_statAsyncResult = new SFtpStatAsyncResult(null, null);
|
||||
_fileName = random.Next().ToString();
|
||||
_chunkSize = (uint)random.Next(1000, int.MaxValue);
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Sftp;
|
||||
using Renci.SshNet.Tests.Common;
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Renci.SshNet.Tests.Classes
|
||||
|
||||
_bufferSize = (uint)random.Next(1, int.MaxValue);
|
||||
_openAsyncResult = new SftpOpenAsyncResult(null, null);
|
||||
_handle = CryptoAbstraction.GenerateRandom(random.Next(1, 10));
|
||||
_handle = RandomNumberGenerator.GetBytes(random.Next(1, 10));
|
||||
_statAsyncResult = new SFtpStatAsyncResult(null, null);
|
||||
_fileName = random.Next().ToString();
|
||||
_chunkSize = (uint)random.Next(1000, 5000);
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Sftp;
|
||||
using Renci.SshNet.Tests.Common;
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Renci.SshNet.Tests.Classes
|
||||
_maxPendingReads = 100;
|
||||
_bufferSize = (uint)random.Next(1, int.MaxValue);
|
||||
_openAsyncResult = new SftpOpenAsyncResult(null, null);
|
||||
_handle = CryptoAbstraction.GenerateRandom(random.Next(1, 10));
|
||||
_handle = RandomNumberGenerator.GetBytes(random.Next(1, 10));
|
||||
_statAsyncResult = new SFtpStatAsyncResult(null, null);
|
||||
_fileName = random.Next().ToString();
|
||||
_chunkSize = (uint)random.Next(1000, 5000);
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Sftp;
|
||||
using Renci.SshNet.Tests.Common;
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Renci.SshNet.Tests.Classes
|
||||
|
||||
_bufferSize = (uint)random.Next(1, int.MaxValue);
|
||||
_openAsyncResult = new SftpOpenAsyncResult(null, null);
|
||||
_handle = CryptoAbstraction.GenerateRandom(random.Next(1, 10));
|
||||
_handle = RandomNumberGenerator.GetBytes(random.Next(1, 10));
|
||||
_statAsyncResult = new SFtpStatAsyncResult(null, null);
|
||||
_fileName = random.Next().ToString();
|
||||
_chunkSize = (uint)random.Next(1, int.MaxValue);
|
||||
|
||||
@@ -10,7 +10,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Compression;
|
||||
using Renci.SshNet.Connection;
|
||||
@@ -174,7 +173,7 @@ namespace Renci.SshNet.Tests.Classes
|
||||
var serviceAcceptMessage = ServiceAcceptMessageBuilder.Create(ServiceName.UserAuthentication)
|
||||
.Build(ServerOutboundPacketSequence);
|
||||
|
||||
var hash = CryptoAbstraction.HashSHA256(serviceAcceptMessage);
|
||||
var hash = SHA256.HashData(serviceAcceptMessage);
|
||||
|
||||
var packet = new byte[serviceAcceptMessage.Length - 4 + hash.Length];
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
@@ -7,7 +8,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Channels;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Sftp;
|
||||
@@ -78,10 +78,10 @@ namespace Renci.SshNet.Tests.Classes.Sftp
|
||||
|
||||
#endregion SftpSession.Connect()
|
||||
|
||||
_handle = CryptoAbstraction.GenerateRandom(random.Next(1, 10));
|
||||
_handle = RandomNumberGenerator.GetBytes(random.Next(1, 10));
|
||||
_offset = (uint)random.Next(1, 5);
|
||||
_length = (uint)random.Next(30, 50);
|
||||
_data = CryptoAbstraction.GenerateRandom((int)_length);
|
||||
_data = RandomNumberGenerator.GetBytes((int)_length);
|
||||
_sftpReadRequestBytes = new SftpReadRequestBuilder().WithProtocolVersion(_protocolVersion)
|
||||
.WithRequestId(2)
|
||||
.WithHandle(_handle)
|
||||
|
||||
+3
-3
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
@@ -6,7 +7,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Channels;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Sftp;
|
||||
@@ -81,10 +81,10 @@ namespace Renci.SshNet.Tests.Classes.Sftp
|
||||
#endregion SftpSession.Connect()
|
||||
|
||||
_path = random.Next().ToString();
|
||||
_handle = CryptoAbstraction.GenerateRandom(4);
|
||||
_handle = RandomNumberGenerator.GetBytes(4);
|
||||
_offset = (uint)random.Next(1, 5);
|
||||
_length = (uint)random.Next(30, 50);
|
||||
_data = CryptoAbstraction.GenerateRandom(200);
|
||||
_data = RandomNumberGenerator.GetBytes(200);
|
||||
_sftpOpenRequestBytes = new SftpOpenRequestBuilder().WithProtocolVersion(_protocolVersion)
|
||||
.WithRequestId(2)
|
||||
.WithFileName(_path)
|
||||
|
||||
+3
-3
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
@@ -6,7 +7,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Channels;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Sftp;
|
||||
@@ -81,10 +81,10 @@ namespace Renci.SshNet.Tests.Classes.Sftp
|
||||
#endregion SftpSession.Connect()
|
||||
|
||||
_path = random.Next().ToString();
|
||||
_handle = CryptoAbstraction.GenerateRandom(4);
|
||||
_handle = RandomNumberGenerator.GetBytes(4);
|
||||
_offset = (uint)random.Next(1, 5);
|
||||
_length = (uint)random.Next(30, 50);
|
||||
_data = CryptoAbstraction.GenerateRandom(200);
|
||||
_data = RandomNumberGenerator.GetBytes(200);
|
||||
_sftpOpenRequestBytes = new SftpOpenRequestBuilder().WithProtocolVersion(_protocolVersion)
|
||||
.WithRequestId(2)
|
||||
.WithFileName(_path)
|
||||
|
||||
+3
-3
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
@@ -6,7 +7,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Channels;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Sftp;
|
||||
@@ -76,10 +76,10 @@ namespace Renci.SshNet.Tests.Classes.Sftp
|
||||
|
||||
#endregion SftpSession.Connect()
|
||||
|
||||
_handle = CryptoAbstraction.GenerateRandom(4);
|
||||
_handle = RandomNumberGenerator.GetBytes(4);
|
||||
_offset = (uint)random.Next(1, 5);
|
||||
_length = (uint)random.Next(30, 50);
|
||||
_data = CryptoAbstraction.GenerateRandom(200);
|
||||
_data = RandomNumberGenerator.GetBytes(200);
|
||||
_sftpReadRequestBytes = new SftpReadRequestBuilder().WithProtocolVersion(_protocolVersion)
|
||||
.WithRequestId(2)
|
||||
.WithHandle(_handle)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
@@ -10,7 +11,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Channels;
|
||||
using Renci.SshNet.Common;
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace Renci.SshNet.Tests.Classes
|
||||
public void Channel_DataReceived_MoreThanBufferSize()
|
||||
{
|
||||
// Test buffer resizing
|
||||
byte[] expectedData = CryptoAbstraction.GenerateRandom(BufferSize * 3);
|
||||
byte[] expectedData = RandomNumberGenerator.GetBytes(BufferSize * 3);
|
||||
_channelSessionStub.Receive(expectedData);
|
||||
|
||||
byte[] actualData = new byte[expectedData.Length + 1];
|
||||
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Channels;
|
||||
using Renci.SshNet.Common;
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Renci.SshNet.Tests.Classes
|
||||
_terminalModes = new Dictionary<TerminalModes, uint>();
|
||||
_bufferSize = random.Next(100, 1000);
|
||||
|
||||
_data = CryptoAbstraction.GenerateRandom(_bufferSize - 10);
|
||||
_data = RandomNumberGenerator.GetBytes(_bufferSize - 10);
|
||||
_offset = random.Next(1, 5);
|
||||
_count = _data.Length - _offset - random.Next(1, 10);
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
@@ -7,7 +8,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Channels;
|
||||
using Renci.SshNet.Common;
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace Renci.SshNet.Tests.Classes
|
||||
_terminalModes = new Dictionary<TerminalModes, uint>();
|
||||
_bufferSize = random.Next(100, 1000);
|
||||
|
||||
_data = CryptoAbstraction.GenerateRandom((_bufferSize * 2) + 10);
|
||||
_data = RandomNumberGenerator.GetBytes((_bufferSize * 2) + 10);
|
||||
_offset = 0;
|
||||
_count = _data.Length;
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
@@ -7,7 +8,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Channels;
|
||||
using Renci.SshNet.Common;
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Renci.SshNet.Tests.Classes
|
||||
_terminalModes = new Dictionary<TerminalModes, uint>();
|
||||
_bufferSize = random.Next(100, 1000);
|
||||
|
||||
_data = CryptoAbstraction.GenerateRandom(_bufferSize);
|
||||
_data = RandomNumberGenerator.GetBytes(_bufferSize);
|
||||
_offset = 0;
|
||||
_count = _data.Length;
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
@@ -7,7 +8,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Channels;
|
||||
using Renci.SshNet.Common;
|
||||
|
||||
@@ -53,8 +53,8 @@ namespace Renci.SshNet.Tests.Classes
|
||||
_terminalModes = new Dictionary<TerminalModes, uint>();
|
||||
_bufferSize = random.Next(100, 1000);
|
||||
|
||||
_bufferData = CryptoAbstraction.GenerateRandom(_bufferSize);
|
||||
_data = CryptoAbstraction.GenerateRandom(_bufferSize - 10);
|
||||
_bufferData = RandomNumberGenerator.GetBytes(_bufferSize);
|
||||
_data = RandomNumberGenerator.GetBytes(_bufferSize - 10);
|
||||
_offset = 0;
|
||||
_count = _data.Length;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
@@ -7,7 +8,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Channels;
|
||||
using Renci.SshNet.Common;
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Renci.SshNet.Tests.Classes
|
||||
_terminalModes = new Dictionary<TerminalModes, uint>();
|
||||
_bufferSize = random.Next(100, 1000);
|
||||
|
||||
_bufferData = CryptoAbstraction.GenerateRandom(_bufferSize);
|
||||
_bufferData = RandomNumberGenerator.GetBytes(_bufferSize);
|
||||
_data = new byte[0];
|
||||
_offset = 0;
|
||||
_count = _data.Length;
|
||||
|
||||
+3
-3
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
@@ -7,7 +8,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Channels;
|
||||
using Renci.SshNet.Common;
|
||||
|
||||
@@ -53,8 +53,8 @@ namespace Renci.SshNet.Tests.Classes
|
||||
_terminalModes = new Dictionary<TerminalModes, uint>();
|
||||
_bufferSize = random.Next(100, 1000);
|
||||
|
||||
_bufferData = CryptoAbstraction.GenerateRandom(_bufferSize - 60);
|
||||
_data = CryptoAbstraction.GenerateRandom(_bufferSize + 100);
|
||||
_bufferData = RandomNumberGenerator.GetBytes(_bufferSize - 60);
|
||||
_data = RandomNumberGenerator.GetBytes(_bufferSize + 100);
|
||||
_offset = 0;
|
||||
_count = _bufferSize - _bufferData.Length - random.Next(1, 10);
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
@@ -7,7 +8,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Channels;
|
||||
using Renci.SshNet.Common;
|
||||
using Renci.SshNet.Tests.Common;
|
||||
@@ -55,8 +55,8 @@ namespace Renci.SshNet.Tests.Classes
|
||||
_terminalModes = new Dictionary<TerminalModes, uint>();
|
||||
_bufferSize = random.Next(100, 1000);
|
||||
|
||||
_bufferData = CryptoAbstraction.GenerateRandom(_bufferSize - 60);
|
||||
_data = CryptoAbstraction.GenerateRandom(_bufferSize - _bufferData.Length + random.Next(1, 10));
|
||||
_bufferData = RandomNumberGenerator.GetBytes(_bufferSize - 60);
|
||||
_data = RandomNumberGenerator.GetBytes(_bufferSize - _bufferData.Length + random.Next(1, 10));
|
||||
_offset = 0;
|
||||
_count = _data.Length;
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
@@ -7,7 +8,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Channels;
|
||||
using Renci.SshNet.Common;
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Renci.SshNet.Tests.Classes
|
||||
_terminalModes = new Dictionary<TerminalModes, uint>();
|
||||
_bufferSize = random.Next(100, 1000);
|
||||
|
||||
_bufferData = CryptoAbstraction.GenerateRandom(_bufferSize - 60);
|
||||
_bufferData = RandomNumberGenerator.GetBytes(_bufferSize - 60);
|
||||
_data = new byte[0];
|
||||
_offset = 0;
|
||||
_count = _data.Length;
|
||||
|
||||
Reference in New Issue
Block a user