Skip to content

Commit 0305f88

Browse files
committed
Merge branch 'develop' into readallbytes
2 parents f3bb926 + 13bcb77 commit 0305f88

File tree

136 files changed

+1228
-13163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+1228
-13163
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ dotnet_code_quality.CA1828.api_surface = all
719719
dotnet_diagnostic.CA1852.severity = none
720720

721721
# CA1848: don't enforce LoggerMessage pattern
722-
dotnet_diagnostic.CA1848.severity = suggestion
722+
dotnet_diagnostic.CA1848.severity = silent
723723

724724
# CA1859: Change return type for improved performance
725725
#

src/Renci.SshNet/.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,6 @@ dotnet_diagnostic.MA0042.severity = none
194194

195195
# S3236: Caller information arguments should not be provided explicitly
196196
dotnet_diagnostic.S3236.severity = none
197+
198+
# S3358: Ternary operators should not be nested
199+
dotnet_diagnostic.S3358.severity = none

src/Renci.SshNet/Common/Extensions.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Diagnostics;
43
using System.Globalization;
54
#if !NET
65
using System.IO;
@@ -9,7 +8,6 @@
98
using System.Net.Sockets;
109
using System.Numerics;
1110
using System.Runtime.CompilerServices;
12-
using System.Text;
1311
using System.Threading;
1412

1513
using Renci.SshNet.Abstractions;
@@ -156,22 +154,6 @@ public static void SetIgnoringObjectDisposed(this EventWaitHandle waitHandle)
156154
}
157155
}
158156

159-
/// <summary>
160-
/// Prints out the specified bytes.
161-
/// </summary>
162-
/// <param name="bytes">The bytes.</param>
163-
internal static void DebugPrint(this IEnumerable<byte> bytes)
164-
{
165-
var sb = new StringBuilder();
166-
167-
foreach (var b in bytes)
168-
{
169-
_ = sb.AppendFormat(CultureInfo.CurrentCulture, "0x{0:x2}, ", b);
170-
}
171-
172-
Debug.WriteLine(sb.ToString());
173-
}
174-
175157
internal static void ValidatePort(this uint value, [CallerArgumentExpression(nameof(value))] string argument = null)
176158
{
177159
if (value > IPEndPoint.MaxPort)

src/Renci.SshNet/ConnectionInfo.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
using Microsoft.Extensions.Logging;
99

10+
using Org.BouncyCastle.Crypto.Agreement;
11+
1012
using Renci.SshNet.Common;
1113
using Renci.SshNet.Compression;
1214
using Renci.SshNet.Messages.Authentication;
@@ -357,12 +359,13 @@ public ConnectionInfo(string host, int port, string username, ProxyTypes proxyTy
357359
{ "ecdh-sha2-nistp256", () => new KeyExchangeECDH256() },
358360
{ "ecdh-sha2-nistp384", () => new KeyExchangeECDH384() },
359361
{ "ecdh-sha2-nistp521", () => new KeyExchangeECDH521() },
360-
{ "diffie-hellman-group-exchange-sha256", () => new KeyExchangeDiffieHellmanGroupExchangeSha256() },
361-
{ "diffie-hellman-group-exchange-sha1", () => new KeyExchangeDiffieHellmanGroupExchangeSha1() },
362-
{ "diffie-hellman-group16-sha512", () => new KeyExchangeDiffieHellmanGroup16Sha512() },
363-
{ "diffie-hellman-group14-sha256", () => new KeyExchangeDiffieHellmanGroup14Sha256() },
364-
{ "diffie-hellman-group14-sha1", () => new KeyExchangeDiffieHellmanGroup14Sha1() },
365-
{ "diffie-hellman-group1-sha1", () => new KeyExchangeDiffieHellmanGroup1Sha1() },
362+
{ "diffie-hellman-group-exchange-sha256", () => new KeyExchangeDiffieHellmanGroupExchange("diffie-hellman-group-exchange-sha256", HashAlgorithmName.SHA256) },
363+
{ "diffie-hellman-group16-sha512", () => new KeyExchangeDiffieHellman("diffie-hellman-group16-sha512", DHStandardGroups.rfc3526_4096, HashAlgorithmName.SHA512) },
364+
{ "diffie-hellman-group18-sha512", () => new KeyExchangeDiffieHellman("diffie-hellman-group18-sha512", DHStandardGroups.rfc3526_8192, HashAlgorithmName.SHA512) },
365+
{ "diffie-hellman-group14-sha256", () => new KeyExchangeDiffieHellman("diffie-hellman-group14-sha256", DHStandardGroups.rfc3526_2048, HashAlgorithmName.SHA256) },
366+
{ "diffie-hellman-group-exchange-sha1", () => new KeyExchangeDiffieHellmanGroupExchange("diffie-hellman-group-exchange-sha1", HashAlgorithmName.SHA1) },
367+
{ "diffie-hellman-group14-sha1", () => new KeyExchangeDiffieHellman("diffie-hellman-group14-sha1", DHStandardGroups.rfc3526_2048, HashAlgorithmName.SHA1) },
368+
{ "diffie-hellman-group1-sha1", () => new KeyExchangeDiffieHellman("diffie-hellman-group1-sha1", DHStandardGroups.rfc2409_1024, HashAlgorithmName.SHA1) },
366369
};
367370

368371
Encryptions = new OrderedDictionary<string, CipherInfo>

src/Renci.SshNet/ISubsystemSession.cs

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Threading;
3+
using System.Threading.Tasks;
34

45
using Microsoft.Extensions.Logging;
56

@@ -49,66 +50,45 @@ internal interface ISubsystemSession : IDisposable
4950
void Disconnect();
5051

5152
/// <summary>
52-
/// Waits a specified time for a given <see cref="WaitHandle"/> to get signaled.
53+
/// Waits a specified time for a given <see cref="WaitHandle"/> to be signaled.
5354
/// </summary>
5455
/// <param name="waitHandle">The handle to wait for.</param>
55-
/// <param name="millisecondsTimeout">The number of milliseconds wait for <paramref name="waitHandle"/> to get signaled, or <c>-1</c> to wait indefinitely.</param>
56+
/// <param name="millisecondsTimeout">The number of milliseconds to wait for <paramref name="waitHandle"/> to be signaled, or <c>-1</c> to wait indefinitely.</param>
5657
/// <exception cref="SshException">The connection was closed by the server.</exception>
5758
/// <exception cref="SshException">The channel was closed.</exception>
5859
/// <exception cref="SshOperationTimeoutException">The handle did not get signaled within the specified timeout.</exception>
5960
void WaitOnHandle(WaitHandle waitHandle, int millisecondsTimeout);
6061

6162
/// <summary>
62-
/// Blocks the current thread until the specified <see cref="WaitHandle"/> gets signaled, using a
63-
/// 32-bit signed integer to specify the time interval in milliseconds.
63+
/// Asynchronously waits for a given <see cref="WaitHandle"/> to be signaled.
6464
/// </summary>
6565
/// <param name="waitHandle">The handle to wait for.</param>
66-
/// <param name="millisecondsTimeout">To number of milliseconds to wait for <paramref name="waitHandle"/> to get signaled, or <c>-1</c> to wait indefinitely.</param>
67-
/// <returns>
68-
/// <see langword="true"/> if <paramref name="waitHandle"/> received a signal within the specified timeout;
69-
/// otherwise, <see langword="false"/>.
70-
/// </returns>
66+
/// <param name="millisecondsTimeout">The number of milliseconds to wait for <paramref name="waitHandle"/> to be signaled, or <c>-1</c> to wait indefinitely.</param>
67+
/// <param name="cancellationToken">The cancellation token to observe.</param>
7168
/// <exception cref="SshException">The connection was closed by the server.</exception>
7269
/// <exception cref="SshException">The channel was closed.</exception>
73-
/// <remarks>
74-
/// The blocking wait is also interrupted when either the established channel is closed, the current
75-
/// session is disconnected or an unexpected <see cref="Exception"/> occurred while processing a channel
76-
/// or session event.
77-
/// </remarks>
78-
bool WaitOne(WaitHandle waitHandle, int millisecondsTimeout);
70+
/// <exception cref="SshOperationTimeoutException">The handle did not get signaled within the specified timeout.</exception>
71+
/// <returns>A <see cref="Task"/> representing the wait.</returns>
72+
Task WaitOnHandleAsync(WaitHandle waitHandle, int millisecondsTimeout, CancellationToken cancellationToken);
7973

8074
/// <summary>
81-
/// Blocks the current thread until the specified <see cref="WaitHandle"/> gets signaled, using a
82-
/// 32-bit signed integer to specify the time interval in milliseconds.
75+
/// Asynchronously waits for a given <see cref="TaskCompletionSource{T}"/> to complete.
8376
/// </summary>
84-
/// <param name="waitHandleA">The first handle to wait for.</param>
85-
/// <param name="waitHandleB">The second handle to wait for.</param>
86-
/// <param name="millisecondsTimeout">To number of milliseconds to wait for a <see cref="WaitHandle"/> to get signaled, or <c>-1</c> to wait indefinitely.</param>
87-
/// <returns>
88-
/// <c>0</c> if <paramref name="waitHandleA"/> received a signal within the specified timeout and <c>1</c>
89-
/// if <paramref name="waitHandleB"/> received a signal within the specified timeout, or <see cref="WaitHandle.WaitTimeout"/>
90-
/// if no object satisfied the wait.
91-
/// </returns>
77+
/// <typeparam name="T">The type of the result which is being awaited.</typeparam>
78+
/// <param name="tcs">The handle to wait for.</param>
79+
/// <param name="millisecondsTimeout">The number of milliseconds to wait for <paramref name="tcs"/> to complete, or <c>-1</c> to wait indefinitely.</param>
80+
/// <param name="cancellationToken">The cancellation token to observe.</param>
9281
/// <exception cref="SshException">The connection was closed by the server.</exception>
9382
/// <exception cref="SshException">The channel was closed.</exception>
94-
/// <remarks>
95-
/// <para>
96-
/// The blocking wait is also interrupted when either the established channel is closed, the current
97-
/// session is disconnected or an unexpected <see cref="Exception"/> occurred while processing a channel
98-
/// or session event.
99-
/// </para>
100-
/// <para>
101-
/// When both <paramref name="waitHandleA"/> and <paramref name="waitHandleB"/> are signaled during the call,
102-
/// then <c>0</c> is returned.
103-
/// </para>
104-
/// </remarks>
105-
int WaitAny(WaitHandle waitHandleA, WaitHandle waitHandleB, int millisecondsTimeout);
83+
/// <exception cref="SshOperationTimeoutException">The handle did not get signaled within the specified timeout.</exception>
84+
/// <returns>A <see cref="Task"/> representing the wait.</returns>
85+
Task<T> WaitOnHandleAsync<T>(TaskCompletionSource<T> tcs, int millisecondsTimeout, CancellationToken cancellationToken);
10686

10787
/// <summary>
10888
/// Waits for any of the elements in the specified array to receive a signal, using a 32-bit signed
10989
/// integer to specify the time interval.
11090
/// </summary>
111-
/// <param name="waitHandles">A <see cref="WaitHandle"/> array - constructed using <see cref="CreateWaitHandleArray(WaitHandle[])"/> - containing the objects to wait for.</param>
91+
/// <param name="waitHandles">A <see cref="WaitHandle"/> array - constructed using <see cref="CreateWaitHandleArray"/> - containing the objects to wait for.</param>
11292
/// <param name="millisecondsTimeout">To number of milliseconds to wait for a <see cref="WaitHandle"/> to get signaled, or <c>-1</c> to wait indefinitely.</param>
11393
/// <returns>
11494
/// The array index of the first non-system object that satisfied the wait.
@@ -121,16 +101,6 @@ internal interface ISubsystemSession : IDisposable
121101
/// </remarks>
122102
int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout);
123103

124-
/// <summary>
125-
/// Creates a <see cref="WaitHandle"/> array that is composed of system objects and the specified
126-
/// elements.
127-
/// </summary>
128-
/// <param name="waitHandles">A <see cref="WaitHandle"/> array containing the objects to wait for.</param>
129-
/// <returns>
130-
/// A <see cref="WaitHandle"/> array that is composed of system objects and the specified elements.
131-
/// </returns>
132-
WaitHandle[] CreateWaitHandleArray(params WaitHandle[] waitHandles);
133-
134104
/// <summary>
135105
/// Creates a <see cref="WaitHandle"/> array that is composed of system objects and the specified
136106
/// elements.

src/Renci.SshNet/Messages/Transport/KeyExchangeDhGroupExchangeGroup.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ namespace Renci.SshNet.Messages.Transport
99
/// </summary>
1010
public class KeyExchangeDhGroupExchangeGroup : Message
1111
{
12-
private byte[] _safePrime;
13-
private byte[] _subGroup;
12+
internal byte[] SafePrimeBytes { get; private set; }
13+
internal byte[] SubGroupBytes { get; private set; }
1414

1515
/// <inheritdoc />
1616
public override string MessageName
@@ -38,7 +38,7 @@ public override byte MessageNumber
3838
/// </value>
3939
public BigInteger SafePrime
4040
{
41-
get { return _safePrime.ToBigInteger(); }
41+
get { return SafePrimeBytes.ToBigInteger(); }
4242
}
4343

4444
/// <summary>
@@ -49,7 +49,7 @@ public BigInteger SafePrime
4949
/// </value>
5050
public BigInteger SubGroup
5151
{
52-
get { return _subGroup.ToBigInteger(); }
52+
get { return SubGroupBytes.ToBigInteger(); }
5353
}
5454

5555
/// <summary>
@@ -64,9 +64,9 @@ protected override int BufferCapacity
6464
{
6565
var capacity = base.BufferCapacity;
6666
capacity += 4; // SafePrime length
67-
capacity += _safePrime.Length; // SafePrime
67+
capacity += SafePrimeBytes.Length; // SafePrime
6868
capacity += 4; // SubGroup length
69-
capacity += _subGroup.Length; // SubGroup
69+
capacity += SubGroupBytes.Length; // SubGroup
7070

7171
return capacity;
7272
}
@@ -77,17 +77,17 @@ protected override int BufferCapacity
7777
/// </summary>
7878
protected override void LoadData()
7979
{
80-
_safePrime = ReadBinary();
81-
_subGroup = ReadBinary();
80+
SafePrimeBytes = ReadBinary();
81+
SubGroupBytes = ReadBinary();
8282
}
8383

8484
/// <summary>
8585
/// Called when type specific data need to be saved.
8686
/// </summary>
8787
protected override void SaveData()
8888
{
89-
WriteBinaryString(_safePrime);
90-
WriteBinaryString(_subGroup);
89+
WriteBinaryString(SafePrimeBytes);
90+
WriteBinaryString(SubGroupBytes);
9191
}
9292

9393
internal override void Process(Session session)

src/Renci.SshNet/Security/GroupExchangeHashData.cs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Numerics;
32

43
using Renci.SshNet.Common;
54

@@ -9,8 +8,6 @@ internal sealed class GroupExchangeHashData : SshData
98
{
109
private byte[] _serverVersion;
1110
private byte[] _clientVersion;
12-
private byte[] _prime;
13-
private byte[] _subGroup;
1411

1512
public string ServerVersion
1613
{
@@ -36,17 +33,9 @@ public string ClientVersion
3633

3734
public uint MaximumGroupSize { get; set; }
3835

39-
public BigInteger Prime
40-
{
41-
private get { return _prime.ToBigInteger(); }
42-
set { _prime = value.ToByteArray(isBigEndian: true); }
43-
}
36+
public byte[] Prime { get; set; }
4437

45-
public BigInteger SubGroup
46-
{
47-
private get { return _subGroup.ToBigInteger(); }
48-
set { _subGroup = value.ToByteArray(isBigEndian: true); }
49-
}
38+
public byte[] SubGroup { get; set; }
5039

5140
public byte[] ClientExchangeValue { get; set; }
5241

@@ -79,9 +68,9 @@ protected override int BufferCapacity
7968
capacity += 4; // PreferredGroupSize
8069
capacity += 4; // MaximumGroupSize
8170
capacity += 4; // Prime length
82-
capacity += _prime.Length; // Prime
71+
capacity += Prime.Length; // Prime
8372
capacity += 4; // SubGroup length
84-
capacity += _subGroup.Length; // SubGroup
73+
capacity += SubGroup.Length; // SubGroup
8574
capacity += 4; // ClientExchangeValue length
8675
capacity += ClientExchangeValue.Length; // ClientExchangeValue
8776
capacity += 4; // ServerExchangeValue length
@@ -107,8 +96,8 @@ protected override void SaveData()
10796
Write(MinimumGroupSize);
10897
Write(PreferredGroupSize);
10998
Write(MaximumGroupSize);
110-
WriteBinaryString(_prime);
111-
WriteBinaryString(_subGroup);
99+
WriteBinaryString(Prime);
100+
WriteBinaryString(SubGroup);
112101
WriteBinaryString(ClientExchangeValue);
113102
WriteBinaryString(ServerExchangeValue);
114103
WriteBinaryString(SharedKey);

src/Renci.SshNet/Security/KeyExchange.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ protected bool CanTrustHostKey(KeyHostAlgorithm host)
482482
/// <summary>
483483
/// Validates the exchange hash.
484484
/// </summary>
485-
/// <returns>true if exchange hash is valid; otherwise false.</returns>
485+
/// <returns><see langword="true"/> if exchange hash is valid; otherwise <see langword="false"/>.</returns>
486486
protected abstract bool ValidateExchangeHash();
487487

488488
private protected bool ValidateExchangeHash(byte[] encodedKey, byte[] encodedSignature)

0 commit comments

Comments
 (0)