Skip to content

Commit 93a5c20

Browse files
authored
Merge branch 'develop' into aesgcm-netframework
2 parents 8c1c534 + 7c07b10 commit 93a5c20

Some content is hidden

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

44 files changed

+2234
-1047
lines changed

.editorconfig

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -456,22 +456,22 @@ dotnet_diagnostic.SA1601.severity = none
456456
# SA1648: <inheritdoc> must be used with inheriting class
457457
#
458458
# This rule is disabled by default, hence we need to explicitly enable it.
459-
dotnet_diagnostic.SA1648.severity = error
459+
dotnet_diagnostic.SA1648.severity = warning
460460

461461
# SX1101: Do not prefix local members with 'this.'
462462
#
463463
# This rule is disabled by default, hence we need to explicitly enable it.
464-
dotnet_diagnostic.SX1101.severity = error
464+
dotnet_diagnostic.SX1101.severity = warning
465465

466466
# SX1309: Field names must begin with underscore
467467
#
468468
# This rule is disabled by default, hence we need to explicitly enable it.
469-
dotnet_diagnostic.SX1309.severity = error
469+
dotnet_diagnostic.SX1309.severity = warning
470470

471471
# SX1309S: Static field names must begin with underscore
472472
#
473473
# This rule is disabled by default, hence we need to explicitly enable it.
474-
dotnet_diagnostic.SX1309S.severity = error
474+
dotnet_diagnostic.SX1309S.severity = warning
475475

476476
#### Meziantou.Analyzer rules ####
477477

@@ -608,7 +608,7 @@ MA0053.class_with_virtual_member_shoud_be_sealed = true
608608
# MA0112: Use 'Count > 0' instead of 'Any()'
609609
#
610610
# This rule is disabled by default, hence we need to explicitly enable it.
611-
dotnet_diagnostic.MA0112.severity = error
611+
dotnet_diagnostic.MA0112.severity = warning
612612

613613
# MA0165: Make interpolated string
614614
dotnet_diagnostic.MA0165.severity = none
@@ -646,7 +646,7 @@ dotnet_diagnostic.CA1008.severity = none
646646
#
647647
# Even when enabled, this diagnostic does not appear to be reported for assemblies without CLSCompliantAttribute.
648648
# We reported this issue as https://github.com/dotnet/roslyn-analyzers/issues/6563.
649-
dotnet_diagnostic.CA1014.severity = error
649+
dotnet_diagnostic.CA1014.severity = warning
650650

651651
# CA1051: Do not declare visible instance fields
652652
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1051
@@ -1003,19 +1003,19 @@ dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
10031003

10041004
dotnet_naming_rule.private_fields_camel_case_begins_with_underscore.symbols = private_fields
10051005
dotnet_naming_rule.private_fields_camel_case_begins_with_underscore.style = camel_case_begins_with_underscore
1006-
dotnet_naming_rule.private_fields_camel_case_begins_with_underscore.severity = error
1006+
dotnet_naming_rule.private_fields_camel_case_begins_with_underscore.severity = warning
10071007

10081008
dotnet_naming_rule.private_static_fields_camel_case_begins_with_underscore.symbols = private_static_fields
10091009
dotnet_naming_rule.private_static_fields_camel_case_begins_with_underscore.style = camel_case_begins_with_underscore
1010-
dotnet_naming_rule.private_static_fields_camel_case_begins_with_underscore.severity = error
1010+
dotnet_naming_rule.private_static_fields_camel_case_begins_with_underscore.severity = warning
10111011

10121012
dotnet_naming_rule.private_static_readonly_fields_pascal_case.symbols = private_static_readonly_fields
10131013
dotnet_naming_rule.private_static_readonly_fields_pascal_case.style = pascal_case
1014-
dotnet_naming_rule.private_static_readonly_fields_pascal_case.severity = error
1014+
dotnet_naming_rule.private_static_readonly_fields_pascal_case.severity = warning
10151015

10161016
dotnet_naming_rule.private_const_fields_pascal_case.symbols = private_const_fields
10171017
dotnet_naming_rule.private_const_fields_pascal_case.style = pascal_case
1018-
dotnet_naming_rule.private_const_fields_pascal_case.severity = error
1018+
dotnet_naming_rule.private_const_fields_pascal_case.severity = warning
10191019

10201020
# Symbol specifications
10211021

@@ -1067,7 +1067,7 @@ dotnet_naming_style.camel_case_begins_with_underscore.capitalization = camel_cas
10671067
#### .NET Compiler Platform general options ####
10681068

10691069
# Change the default rule severity for all analyzer rules that are enabled by default
1070-
dotnet_analyzer_diagnostic.severity = error
1070+
dotnet_analyzer_diagnostic.severity = warning
10711071

10721072
#### .NET Compiler Platform code refactoring rules ####
10731073

.github/workflows/build.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ jobs:
1616

1717
- name: Setup .NET
1818
uses: actions/setup-dotnet@v4
19-
with:
20-
dotnet-version: 9.0.x
2119

2220
- name: Build Unit Tests .NET
2321
run: dotnet build -f net9.0 test/Renci.SshNet.Tests/
@@ -65,8 +63,6 @@ jobs:
6563

6664
- name: Setup .NET
6765
uses: actions/setup-dotnet@v4
68-
with:
69-
dotnet-version: 9.0.x
7066

7167
- name: Build Solution
7268
run: dotnet build Renci.SshNet.sln
@@ -118,11 +114,9 @@ jobs:
118114

119115
- name: Setup .NET
120116
uses: actions/setup-dotnet@v4
121-
with:
122-
dotnet-version: 9.0.x
123117

124118
- name: Setup WSL2
125-
uses: Vampire/setup-wsl@v5
119+
uses: Vampire/setup-wsl@f40fb59d850112c9a292b0218bca8271305b9127 # v5.0.0
126120
with:
127121
distribution: Ubuntu-24.04
128122

.github/workflows/docs.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ jobs:
2727
- name: Setup Pages
2828
uses: actions/configure-pages@v5
2929

30-
- name: Setup .NET 8.0
30+
- name: Setup .NET
3131
uses: actions/setup-dotnet@v4
32-
with:
33-
dotnet-version: 8.x
3432

3533
- name: Setup docfx
3634
run: dotnet tool update -g docfx

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,11 @@ The tests always log to the console. See the [Logging documentation](https://ssh
4141
### Wireshark
4242

4343
Wireshark is able to dissect initial connection packets, such as key exchange, before encryption happens. Enter "ssh" as the display filter. See https://wiki.wireshark.org/SSH.md for more information.
44+
45+
The Debug build of SSH.NET has helpers to also allow dissection of the encrypted traffic by dumping the session keys in a format that Wireshark understands. Set a value for `SshNetLoggingConfiguration.WiresharkKeyLogFilePath` before connecting, and supply the same value to Wireshark in Edit -> Preferences -> Protocols -> SSH -> "Key log filename".
46+
47+
```c#
48+
using Renci.SshNet;
49+
50+
SshNetLoggingConfiguration.WiresharkKeyLogFilePath = @"C:\tmp\sshkeylogfile.txt";
51+
```

Directory.Build.props

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
<SignAssembly>true</SignAssembly>
1010
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)Renci.SshNet.snk</AssemblyOriginatorKeyFile>
1111
<GenerateDocumentationFile>true</GenerateDocumentationFile>
12+
<EnablePackageValidation>true</EnablePackageValidation>
1213
<LangVersion>latest</LangVersion>
1314
<WarningLevel>9999</WarningLevel>
15+
</PropertyGroup>
16+
17+
<PropertyGroup Condition="'$(Configuration)' == 'Release' Or '$(CI)' != ''">
1418
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1519
</PropertyGroup>
1620

Directory.Packages.props

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,14 @@
88
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.5.1" />
99
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
1010
<PackageVersion Include="coverlet.msbuild" Version="6.0.4" />
11-
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1">
12-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13-
<PrivateAssets>all</PrivateAssets>
14-
</PackageVersion>
11+
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
1512
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.188" />
16-
17-
<!-- Must be kept at version 1.0.0, see https://github.com/sshnet/SSH.NET/pull/1288 for details. -->
18-
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="1.0.0" />
19-
<PackageVersion Include="Microsoft.Bcl.Cryptography" Version="10.0.0-preview.3.25171.5" />
2013

21-
<!-- No reason to require later than 6.0.0 at this time. -->
22-
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
23-
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="9.0.2" />
24-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
25-
<PackageVersion Include="MSTest.TestAdapter" Version="3.8.2" />
26-
<PackageVersion Include="MSTest.TestFramework" Version="3.8.2" />
14+
<!-- Should stay on LTS .NET releases. -->
15+
<PackageVersion Include="Microsoft.Bcl.Cryptography" Version="10.0.0-preview.3.25171.5" />
16+
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
17+
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="9.0.3" />
18+
<PackageVersion Include="MSTest" Version="3.8.3" />
2719
<PackageVersion Include="Moq" Version="4.20.72" />
2820
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.7.115" />
2921
<PackageVersion Include="PolySharp" Version="1.15.0" />

README.md

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ SSH.NET is a Secure Shell (SSH-2) library for .NET, optimized for parallelism.
88

99
## Key Features
1010

11-
* Execution of SSH command using both synchronous and asynchronous methods
11+
* Execution of SSH commands using both synchronous and asynchronous methods
1212
* SFTP functionality for both synchronous and asynchronous operations
1313
* SCP functionality
14-
* Remote, dynamic and local port forwarding
14+
* Remote, dynamic and local port forwarding
1515
* Interactive shell/terminal implementation
16-
* Authentication via publickey, password and keyboard-interactive methods, including multi-factor
16+
* Authentication via public key, password and keyboard-interactive methods, including multi-factor
1717
* Connection via SOCKS4, SOCKS5 or HTTP proxy
1818

1919
## How to Use
@@ -52,12 +52,12 @@ using (var client = new SftpClient("sftp.foo.com", "guest", "pwd"))
5252

5353
The main types provided by this library are:
5454

55-
* Renci.SshNet.SshClient
56-
* Renci.SshNet.SftpClient
57-
* Renci.SshNet.ScpClient
58-
* Renci.SshNet.PrivateKeyFile
59-
* Renci.SshNet.SshCommand
60-
* Renci.SshNet.ShellStream
55+
* [Renci.SshNet.SshClient](https://sshnet.github.io/SSH.NET/api/Renci.SshNet.SshClient.html)
56+
* [Renci.SshNet.SftpClient](https://sshnet.github.io/SSH.NET/api/Renci.SshNet.SftpClient.html)
57+
* [Renci.SshNet.PrivateKeyFile](https://sshnet.github.io/SSH.NET/api/Renci.SshNet.PrivateKeyFile.html)
58+
* [Renci.SshNet.SshCommand](https://sshnet.github.io/SSH.NET/api/Renci.SshNet.SshCommand.html)
59+
* [Renci.SshNet.ForwardedPort](https://sshnet.github.io/SSH.NET/api/Renci.SshNet.ForwardedPort.html)
60+
* [Renci.SshNet.ShellStream](https://sshnet.github.io/SSH.NET/api/Renci.SshNet.ShellStream.html)
6161

6262
## Additional Documentation
6363

@@ -106,11 +106,6 @@ The main types provided by this library are:
106106
* ssh.com format ("BEGIN SSH2 ENCRYPTED PRIVATE KEY")
107107
* OpenSSH key format ("BEGIN OPENSSH PRIVATE KEY")
108108
* PuTTY private key format ("PuTTY-User-Key-File-2", "PuTTY-User-Key-File-3")
109-
* DSA in
110-
* OpenSSL traditional PEM format ("BEGIN DSA PRIVATE KEY")
111-
* OpenSSL PKCS#8 PEM format ("BEGIN PRIVATE KEY", "BEGIN ENCRYPTED PRIVATE KEY")
112-
* ssh.com format ("BEGIN SSH2 ENCRYPTED PRIVATE KEY")
113-
* PuTTY private key format ("PuTTY-User-Key-File-2", "PuTTY-User-Key-File-3")
114109
* ECDSA 256/384/521 in
115110
* OpenSSL traditional PEM format ("BEGIN EC PRIVATE KEY")
116111
* OpenSSL PKCS#8 PEM format ("BEGIN PRIVATE KEY", "BEGIN ENCRYPTED PRIVATE KEY")
@@ -158,7 +153,8 @@ Private keys in PuTTY private key format can be encrypted using the following ci
158153
* rsa-sha2-512
159154
* rsa-sha2-256
160155
* ssh-rsa
161-
* ssh-dss
156+
157+
OpenSSH certificate authentication is supported for all of the above, e.g. ssh-ed25519-cert-v01<span></span>@openssh.com.
162158

163159
## Message Authentication Code
164160

@@ -187,17 +183,17 @@ Private keys in PuTTY private key format can be encrypted using the following ci
187183

188184
The library has no special requirements to build, other than an up-to-date .NET SDK. See also [CONTRIBUTING.md](https://github.com/sshnet/SSH.NET/blob/develop/CONTRIBUTING.md).
189185

190-
## Using Pre-Release NuGet Package
186+
## Using Pre-Release NuGet Packages
191187

192-
If you need an unreleased bugfix or feature, you can use the Pre-Release NuGet packages from the `develop` branch which are published to the [GitHub NuGet Registry](https://github.com/sshnet/SSH.NET/pkgs/nuget/SSH.NET).
193-
In order to pull packages from the registry you first have to create a Personal Access Token with the `read:packages` permissions. Then add a NuGet Source for SSH.NET:
194-
195-
Note: you may have to add `--store-password-in-clear-text` on non-Windows platforms.
188+
Pre-release NuGet packages are published from the `develop` branch to the [GitHub NuGet Registry](https://github.com/sshnet/SSH.NET/pkgs/nuget/SSH.NET).
189+
In order to pull packages from the registry, create a Personal Access Token with the `read:packages` permissions. Then add a package source for SSH.NET:
196190

197191
```
198192
dotnet nuget add source --name SSH.NET --username <username> --password <personalaccesstoken> https://nuget.pkg.github.com/sshnet/index.json
199193
```
200194

195+
Note: you may have to add `--store-password-in-clear-text` on non-Windows platforms.
196+
201197
Then you can add the the package as described [here](https://github.com/sshnet/SSH.NET/pkgs/nuget/SSH.NET).
202198

203199
## Supporting SSH.NET

docfx/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
href: examples.md
55
- name: API
66
href: api/
7+
- name: Logging
8+
href: logging.md

global.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "9.0.100",
4-
"rollForward": "latestMajor"
3+
"version": "9.0.200",
4+
"rollForward": "latestFeature"
55
}
66
}

src/Renci.SshNet/Abstractions/StreamExtensions.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#if NETFRAMEWORK || NETSTANDARD2_0
2+
using System;
23
using System.IO;
34
using System.Threading.Tasks;
45

@@ -8,8 +9,15 @@ internal static class StreamExtensions
89
{
910
public static ValueTask DisposeAsync(this Stream stream)
1011
{
11-
stream.Dispose();
12-
return default;
12+
try
13+
{
14+
stream.Dispose();
15+
return default;
16+
}
17+
catch (Exception exc)
18+
{
19+
return new ValueTask(Task.FromException(exc));
20+
}
1321
}
1422
}
1523
}

src/Renci.SshNet/Channels/Channel.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ internal abstract class Channel : IChannel
1717
{
1818
private readonly Lock _serverWindowSizeLock = new Lock();
1919
private readonly Lock _messagingLock = new Lock();
20+
private readonly Lock _sendDataLock = new Lock();
2021
private readonly uint _initialWindowSize;
2122
private readonly ISession _session;
2223
private readonly ILogger _logger;
@@ -340,19 +341,22 @@ public void SendData(byte[] data, int offset, int size)
340341
return;
341342
}
342343

343-
var totalBytesToSend = size;
344-
while (totalBytesToSend > 0)
344+
lock (_sendDataLock)
345345
{
346-
var sizeOfCurrentMessage = GetDataLengthThatCanBeSentInMessage(totalBytesToSend);
346+
var totalBytesToSend = size;
347+
while (totalBytesToSend > 0)
348+
{
349+
var sizeOfCurrentMessage = GetDataLengthThatCanBeSentInMessage(totalBytesToSend);
347350

348-
var channelDataMessage = new ChannelDataMessage(RemoteChannelNumber,
349-
data,
350-
offset,
351-
sizeOfCurrentMessage);
352-
_session.SendMessage(channelDataMessage);
351+
var channelDataMessage = new ChannelDataMessage(RemoteChannelNumber,
352+
data,
353+
offset,
354+
sizeOfCurrentMessage);
355+
_session.SendMessage(channelDataMessage);
353356

354-
totalBytesToSend -= sizeOfCurrentMessage;
355-
offset += sizeOfCurrentMessage;
357+
totalBytesToSend -= sizeOfCurrentMessage;
358+
offset += sizeOfCurrentMessage;
359+
}
356360
}
357361
}
358362

0 commit comments

Comments
 (0)