Commit Graph
1546 Commits
Author SHA1 Message Date
Scott Xu 889f4f66ca Enable all net48 integration tests (#1456)
* Enable all net48 integration tests

* Skip ECDsa in net48 integration tests

* Stabilise tests

* Stabilise tests

* Stabilise tests

* Stabilise tests

* Spelling
2024-08-02 14:32:08 +02:00
Scott XuandWojciech Nagórski 58c85ee79c Use BCL ECDiffieHellman for KeyExchange instead of BouncyCastle (.NET 8.0 onward only) (#1371)
* Use BCL ECDiffieHellman for KeyExchange (.NET 8.0 onward only)

* Add back an empty line

* Remove the BouncyCastle dependency when target .NET 8.0 onward.

* Run KeyExchangeAlgorithmTests for .NET 6.0

* Build Renci.SshNet.IntegrationTests.csproj for net6.0

* Update filter

* Add back BouncyCastle as fallback

* Add back the missing `SendMessage`

* Run ECDH KEX integration tests under .NET48

* Use SshNamedCurves instead of SecNamedCurves for BouncyCastle.
BCL supports both names. See https://github.com/dotnet/runtime/blob/main/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/OidLookup.cs#L200-L202

* typo

* Fix build

* Use System.Security.Cryptography namespace if NET8_0_OR_GREATER;
Use one parameter constructor for class ECDomainParameters

* Separate BCL and BouncyCastle implementation

---------

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2024-07-31 23:06:14 +02:00
252c732c5e Integrate with Nerdbank.GitVersioning (#1299)
* GeneratePackageOnBuild
IncludeSymbols

* Add packages to artifacts

* Update src/Renci.SshNet/Renci.SshNet.csproj

Co-authored-by: Rob Hague <rob.hague00@gmail.com>

* Update Renci.SshNet.csproj

Co-authored-by: Rob Hague <rob.hague00@gmail.com>

* Delete build/nuget/SSH.NET.nuspec

* Delete SSH.NET.nuspec from .sln file

* Update Renci.SshNet.csproj

* Update build.proj

* init nbgv

* Include version.json in "Solution Items"

* Update Directory.Build.props

* define publicReleaseRefSpec

* update version.json

* update version.json

* set cloud build number

* fix https://github.com/sshnet/SSH.NET/issues/1292

* remove unexpected code format

* Delete version from csproj

* move nbgv from Directory.Build.props to Renci.SshNet.csproj as only this particular project needs versioning.
include package version in ThisAssembly and use nuget package version for the SSH client version. Since we define the precision of nuget package to "build", it has 3 digits. Nuget package version is unique which should be suffient.

* Use package from CI feed

* Bump version to 2024.0.1; Update version precision

* Some tweaks:

- Remove the "release" section. I don't think we will use that for now
- Remove the "cloudBuild" section. Changing the CI build number doesn't seem that useful
- In the "nugetPackageVersion" section:
  - Remove "precision". It defaults to build
  - Add "semVer"=2. This makes the package version e.g. 2024.1.1-prerelease.1 instead
    of 2024.1.1-prerelease-0001
- In "assemblyVersion" change "precision" to revision. Doesn't seem to change anything, I
  was just copying nbgv's setup: https://github.com/dotnet/Nerdbank.GitVersioning/blob/main/version.json
- Make sure there are no '-' in the softwareversion string (change the test to a regex)

* Revert unnecessary test changes; remove unnecessary tests

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
Co-authored-by: Robert Hague <rh@johnstreetcapital.com>
2024-07-27 09:45:41 +02:00
486b69dc98 Add support for AEAD ChaCha20Poly1305 Cipher (#1416)
* Implements ChaCha20 cipher algorithm.

* Implements chacha20-poly1305@openssh.com

* Update Cipher.cs

* Update ChaCha20Poly1305Cipher.cs

* Note that the length of the concatenation of 'packet_length',
'padding_length', 'payload', and 'random padding' MUST be a multiple
of the cipher block size or 8, whichever is larger.
See https://www.rfc-editor.org/rfc/rfc4253#section-6

* Use Chaos.Nacl Poly1305Donna

* Fix build. Fix typo. Update README

* Update README.md

* Fix build

* Remove trailing whitespace

* Fix build

* Change to BouncyCastle

* Inherit from SymmetricCipher instead of StreamCipher since StreamCipher is deleted

* Resolve conflicts

* Move field to local variable

* Compute poly key stream once

* Update test/Renci.SshNet.IntegrationTests/CipherTests.cs

Co-authored-by: Rob Hague <rob.hague00@gmail.com>

* Fix build; Add net48 integration test in CI

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2024-07-27 09:43:48 +02:00
Scott XuandWojciech Nagórski c614f54f0a Zlib compression uses BouncyCastle as a fallback if BCL does not support. (#1453)
Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2024-07-25 12:24:44 +02:00
Scott Xu 9f429f720f Remove Chaos.Nacl (#1455) 2024-07-25 11:00:12 +02:00
Scott XuandWojciech Nagórski 28301ab329 Ed25519 is now based on BouncyCastle instead of Chaos.NaCl (#1448)
* Ed25519 is now based on BouncyCastle instead of Chaos.NaCl

* Generate PublicKey and fix NullReferenceException

* Rectify variable name

---------

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2024-07-24 06:23:22 +02:00
Scott XuandWojciech Nagórski 71e2909dec Curve25519 KEX is now based on BouncyCastle instead of Chaos.NaCl (#1447)
* Curve25519 KEX is now based on BouncyCastle instead of Chaos.NaCl

* Abstract SecureRandom

---------

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2024-07-23 21:40:09 +02:00
mus65andRobert Hague 4cc1278d7c Clean up Abstractions / use HashData (#1451)
* Clean up Abstractions / use HashData

- replace usages of GenerateRandom(byte[]) with GenerateRandom(int)
- remove Create() functions and make use of static HashData methods
  on .NET 6+, see https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1850
- Remove unused ReflectionAbstraction

* Use Abstractions for HashData

Co-authored-by: Robert Hague <rh@johnstreetcapital.com>

---------

Co-authored-by: Robert Hague <rh@johnstreetcapital.com>
2024-07-23 14:17:11 +02:00
Rob HagueandWojciech Nagórski 8ea108af1c Drop legacy algorithms part 1 (#1442)
This drops some of the algorithms long-considered legacy/insecure.

The idea is both to improve the theoretical security of the library by not offering
these algorithms, and to improve the practical security of the library by not having
hand-written, barely tested crypto code.

The overarching goal is for the library to have minimal exposure to crypto
implementation, relying firstly on the .NET base libraries, and secondly on
third-party providers, such as BouncyCastle.

This change covers deleting the cipher algorithms arcfour, blowfish, twofish, cast.
It covers deleting the MD5-based and truncated HMAC algorithms.

These were all disabled in OpenSSH server (sshd) in 2014[^1]:

> sshd(8): The default set of ciphers and MACs has been altered to
> remove unsafe algorithms. In particular, CBC ciphers and arcfour*
> are disabled by default.
>
> The full set of algorithms remains available if configured
> explicitly via the Ciphers and MACs sshd_config options.

and in the client in 2016[^2]:

> This release disables a number of legacy cryptographic algorithms
> by default in ssh:
>
>  * Several ciphers blowfish-cbc, cast128-cbc, all arcfour variants
>    and the rijndael-cbc aliases for AES.
>
>  * MD5-based and truncated HMAC algorithms.
>
> These algorithms are already disabled by default in sshd.

This change also drops PKCS5Padding, which is a line-for-line copy of PKCS7Padding,
and StreamCipher, which is now unused (and useless anyway).

[^1]: https://www.openssh.com/txt/release-6.7
[^2]: https://www.openssh.com/txt/release-7.2

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2024-07-17 08:20:10 +02:00
mus65andRob Hague 9a950b56fe Replace internal BouncyCastle with NuGet package (#1370)
* Replace internal BouncyCastle with NuGet package

* fix NullReference in KeyExchangeECDH

for some reason d24fe2006f introduced
its own names here which (as far as I can see) were never part
of the original BouncyCastle.

Switched to the correct names.

* Update to BouncyCastle 2.3.1

* Update to BouncyCastle 2.4.0

* fix Conflict between Zlib class and BouncyCastle namespace

CA1724: The type name Zlib conflicts in whole or in part with the namespace name 'Org.BouncyCastle.Utilities.Zlib'. Change either name to eliminate the conflict.

We can't change either, so suppress the warning.

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2024-07-16 22:47:23 +02:00
Rob Hague 5ab8f3edcb Stabilise some more tests (#1438)
* Stabilise some more tests

* just increase the timeout
2024-07-16 11:12:47 +02:00
mus65 f512a41a1b Don't treat NuGet audit Warnings as Errors and fix warning (#1443)
.NET 9 Preview 6 now also scans transitive dependencies, which
causes a build failure in the test projects:

warning NU1902: Package 'BouncyCastle.Cryptography' 2.2.1 has a known moderate severity vulnerability, https://github.com/advisories/GHSA-8xfc-gm6g-vgpv

Don't treat these as errors and update Testcontainers to fix the warning.
2024-07-13 12:07:56 +02:00
doerigandMartin Dörig 1f356b41c9 Allow empty softwareversion string (#822) (#1441)
Co-authored-by: Martin Dörig <martin.doerig@protecdata.ch>
2024-07-10 13:21:40 +02:00
Rob Hague ffd43dade7 Remove some #ifdefs with System.Memory (#1434) 2024-07-05 09:22:46 +02:00
c552d0d60b Ref System.Memory for net462 and netstandard2.0 (#1417)
* Ref System.Memory for net462 and netstandard2.0.
Use System.Buffers.Binary.BinaryPrimitives instead of Renci.SshNet.Common.Pack

* Remove unnecessary `AsSpan()`

* Apply suggestions from code review

* that's what I get for being lazy

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
Co-authored-by: Robert Hague <rh@johnstreetcapital.com>
2024-07-04 13:14:09 +02:00
Rob Hague 8e8829ef96 Docs updates (#1432)
* Use /// <value> instead of /// <returns> for properties

* misc doc updates in SshCommand

* Update README
2024-07-04 10:31:07 +02:00
Rob Hague 56318a4e12 Make ZlibOpenSsh public (#1433) 2024-07-04 10:30:25 +02:00
Rob Hague a553152195 Set version to 2024.1.0 (#1429) 2024.1.0 2024-06-28 07:14:59 +02:00
Rob HagueandWojciech Nagórski 3bc568471e Add SshCommand.ExecuteAsync (#1426)
* Add SshCommand.ExecuteAsync

After the previous change (#1423), this basically entails swapping out the
IAsyncResult for a TaskCompletionSource and hooking up the cancellation/timeout
logic.

As with the prior Begin/End implementation, the initiation of the command
(SendExecRequest) happens synchronously, so there's a bit of room for improvement
there, but otherwise it is the Task-based async that we know and like.

I chose to make it void (Task)- returning instead of string like in the existing
overloads, so that OutputStream is not automatically consumed (and encoded as a
string) when that may not be desired. As in #650, I was initially considering
changing the other overloads to be void-returning as well, but decided that it was
not worth the break since most people will probably want to change over to
ExecuteAsync anyway.

* Update examples

---------

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2024-06-19 13:02:19 +02:00
Rob HagueandWojciech Nagórski 919af754df Remove unnecessary DNS lookup in Connect (#1412)
The library currently performs a DNS lookup of the desired host, takes the first
returned IP address and connects to that. Instead, we can just pass the hostname
down to System.Net.Sockets which will do the right thing, potentially trying
multiple addresses if needed.

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2024-06-18 07:41:00 +02:00
27fad71353 On SOCKS5 proxy: set hostname, not always IP (#1072)
* On SOCKS5 proxy:
The library always resolves the hostname to the IP. Some SOCKS5 proxies don't allow you to specify the IP, they want to resolve the hostname themselves.

The patch sends the proxy the same specified value, IP, or hostname.

* refactor

---------

Co-authored-by: Jordi Vaca <jjvaca@indra.es>
Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2024-06-16 12:37:26 +02:00
6933e0961c Fix netconf framing protocol (#946)
* Updated NETCONF framing protocol detection to check both client & server capabilities

This fixes an issue where the NetConfSession would expect the
framing protocol to be used if ServerCapabilities contained 1.1,
however the server would actually be using the legacy protocol as
the client only advertises support for 1.0.

* fix NETCONF to comply with RFC6242 for framing protocol

* netcconf client - fix null ptr exception on dispose

* netcconf client - provide example usage in xml doc

* add comment

---------

Co-authored-by: Jason Larke <jason.larke@curtin.edu.au>
Co-authored-by: Todd Schavey <todd.schavey@ge.com>
Co-authored-by: Robert Hague <rh@johnstreetcapital.com>
Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2024-06-16 11:41:41 +02:00
0effbd7b51 Updated NETCONF framing protocol detection to check both client & server capabilities (#639)
* Updated NETCONF framing protocol detection to check both client & server capabilities

This fixes an issue where the NetConfSession would expect the
framing protocol to be used if ServerCapabilities contained 1.1,
however the server would actually be using the legacy protocol as
the client only advertises support for 1.0.

* add comment

---------

Co-authored-by: Jason Larke <jason.larke@curtin.edu.au>
Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2024-06-16 11:39:31 +02:00
mus65andRob Hague 1b71e8fea4 fix build with .NET 9.0 SDK (#1427)
* .NET 9: fix CA1872

see https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1872

* .NET 9: fix CA2022

see https://github.com/dotnet/roslyn-analyzers/pull/7208

Most of these could be safely ignored because of the following assert.
As far as I can see, The SftpFileStream.Read() implementation guarentees
that the specified number of bytes is read anyway.

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2024-06-16 11:35:20 +02:00
Scott XuandRob Hague 9dc7db9de8 Support creating Shell(Stream) without PTY (#1419)
* Support creating Shell(Stream) without PTY
Fixes https://github.com/sshnet/SSH.NET/issues/1418

* Add integration test for "PermitTTY no"

* Fix Integration Test

* Remove duplicate shell request

* Put common operations in a shared constructor. Update xml doc comments.

* Update comments and method overriding

* Update per code review

* Update integration tests

* Renaming

* Make `bufferSize` optional

* Try fix the test

* Update per code review

* try agian

* try again

* docs

* doc

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2024-06-16 10:27:06 +02:00
Dejan Varmedja 830e504244 Rename SftpFileSytemInformation to SftpFileSystemInformation (#1425) 2024-06-12 12:36:16 +02:00
Rob Hague ac395dd64c A couple of changes/fixes in SshCommand (#1423)
* Send "signal" and set the wait handle on completion always

* Make ExitStatus nullable
2024-06-09 21:44:44 +02:00
Paulus LucasandRob Hague bb51335b3b doc: Update examples.md (#1421)
* doc: Update examples.md

* tweaks

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2024-06-04 23:21:27 +02:00
mus65 dda27a3177 fix flaky SFTP file time tests (#1414)
* fix flaky SFTP file time tests

These asserts currently assume that DateTime.Now and the
creation timestamp on the server happen within the same second.

Note that I didn't change the asserts below where an explicit
timestamp is set. From my understanding, these should not be affected.

example: https://ci.appveyor.com/project/drieseng/ssh-net/builds/49850731/job/u6lk0cyipbxkp4jd

* remove asserts
2024-06-04 21:55:38 +02:00
Rob HagueandWojciech Nagórski fdbc4d3e36 Fix a few issues with PipeStream (#1399)
Apply similar treatment to PipeStream as #1322 did to ShellStream

PipeStream now behaves much more Stream-like. In particular, it performs partial
reads (instead of blocking until a certain amount of data is available), blocks
until data is available (instead of returning 0 prematurely) and removes the
Stream-unlike properties `BlockLastReadBuffer` and `MaxBufferLength`.

Sadly I gave up trying to make a benchmark compatible with all the quirks of the
previous implementation, but a dumb throughput test (reading and writing simultaneously)
shows about 5.2GB/s with this implementation compared to 140MB/s previously.

Some cleanup of its usage in the library followed.

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2024-05-23 15:30:05 +02:00
Rob Hague 49aed6f219 Relax the RSA/DSA decision for SSH2 keys (#1190) 2024-05-22 20:37:00 +02:00
Rob Hague 452c1a23ce dotnet pack in CI (#1400)
* dotnet pack in CI

and delete the old build script

* Update appveyor.yml
2024-05-22 20:36:15 +02:00
Rob Hague b09b4f5360 Delete CountdownEventTests (#1409)
We have been using the BCL version since #1117
2024-05-22 20:35:10 +02:00
mus65 7d52787ce3 make ConnectShouldActivateKeepAliveIfSessionIs test less flaky (#1410)
* make ConnectShouldActivateKeepAliveIfSessionIs test less flaky

wait longer and expect at least two instead of exactly two.

example: https://ci.appveyor.com/project/drieseng/ssh-net/builds/49849877/job/9rrtw6j8eu3i5p8o?fullLog=true

* fix net462 build
2024-05-21 13:05:46 +02:00
mus65 b4722b86e8 Enable nullable on NetConf/Scp/SshClient (#1392)
* Enable nullable on NetConf/Scp/SshClient

* fix formatting

* improve directoryCounter check

* disable nullable warnings on old frameworks

since the libraries are missing a lot of nullable attributes
in the old frameworks, this causes a lot of false positive
nullable warnings.

Simply disable these warnings for old frameworks.
2024-05-21 13:05:20 +02:00
mus65 23323aa217 use Regex Source Generator for .NET 7+ (#1401)
* use Regex Source Generator for .NET 7+

fixes #1131

* use shorter pattern for GeneratedRegex
2024-05-20 17:27:53 +02:00
Rob Hague aa70718a86 More AsyncSocketListener patchwork (#1408)
* More AsyncSocketListener patchwork

This is Whack-a-mole part 2 in diagnosing or preventing the test host from crashing in CI.

* Fix test
2024-05-19 11:11:25 +02:00
mus65andRob Hague 1143ad3d24 fix flaky Sftp_BeginUploadFile test (#1402)
* fix flaky Sftp_BeginUploadFile test

this test can randomly fail because it assumes that the callback
has been called when the AsyncWaitHandle was set. But this is not
necessarily the case because AsyncResult.SetAsCompleted does it
the other way around.

example: https://ci.appveyor.com/project/drieseng/ssh-net/builds/49831002/job/1237d4lg46j22pf0

* use ManualResetEventSlim

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2024-05-18 21:25:03 +02:00
mus65andRob Hague fcb4ea2a1b fix flaky ReceiveOnServerSocketShouldReturnZero test (#1404)
* fix flaky ReceiveOnServerSocketShouldReturnZero test

ReceiveOnServerSocketShouldReturnZero assumed that the disconnect
already happened on the server side, but it never waits for this.
This could cause ServerSocket.Receive to still return valid data
and fail the test.

example: https://ci.appveyor.com/project/drieseng/ssh-net/builds/49836561/job/wen5tjd1c7wgxrfh

* Update test/Renci.SshNet.Tests/Classes/SessionTest_Connected_Disconnect.cs

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2024-05-18 18:15:52 +02:00
mus65andRob Hague fe5ed423a0 fix flaky Connectivity Tests (#1403)
these two tests were not waiting for the interruption (all other usages
of BreakConnections() did). This could cause random failures because
e.g. the wrong exception is thrown.

example: https://ci.appveyor.com/project/drieseng/ssh-net/builds/49831433/job/4urb0upx63bvxcgu

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2024-05-18 14:17:10 +02:00
mus65andRobert Hague c0a353a4de Cleanup formatting and style and enforce it in CI (#1380)
* Preparation to enforce formatting and style in CI

- enabled IDE0055 to enforce formatting on build
- disabled SA1137 and SA1025 because they are already
  covered by IDE0055
- disabled SA1021 because it conflicts with csharp_space_after_cast

* Cleanup formatting and style on codebase

This commit has no manual changes, it is the result
of running "dotnet format whitespace" and "dotnet format style"

* new formatting fixes after merge

* appveyor: set git autocrlf

as suggested by sharwell to hopefully fix Windows CI.

* use autocrlf input

to hopefully fix Linux tests

* fix formatting

* use autocrlf input for Linux only

* set csharp_space_after_cast to false

* Revert SA1021 suppression

---------

Co-authored-by: Robert Hague <rh@johnstreetcapital.com>
2024-05-17 22:34:27 +02:00
Rob Hague 1de33c469e Documentation updates (#1395)
- Update README to point to https://sshnet.github.io/SSH.NET rather than the CHM file
- Add a CONTRIBUTING.md with some how-tos

For https://sshnet.github.io/SSH.NET:

- Use the repo README as the landing page to keep them in sync
- Combine the API-per-TFM pages to just one "API" page
- Add a couple more examples
- Add a GitHub link in the header.
2024-05-10 11:38:47 +02:00
Rob Hague 0cfeb6bb94 Tweak AsyncSocketListener in tests (#1382)
* Tweak AsyncSocketListener in tests

Some CI runs have been crashing lately from within AsyncSocketListener.
This moves a bit of disconnection & exception handling around. It probably won't
fix the underlying tests which would have otherwise failed, but it might stop the
process from outright crashing.

Also reference the same code for the integration tests.

* Simplify the diff

* Stabilise a couple of tests
2024-05-10 11:37:01 +02:00
Rob Hague f9908a22b5 Use System.Security.Cryptography for RSA (#1373)
* Use BCL for RSA

* Restore benchmark (with quirks for old code)

* Fixup benchmark (remove compatibility with old code)

* cosmetic tweaks

* Add a regression test for #1388
2024-05-10 11:35:21 +02:00
mus65 749a0e0074 drop obsolete #if directives (#1394) 2024-05-06 21:22:09 +02:00
mus65 6e42d1fcd3 gitattributes: set diff=csharp on cs files (#1393) 2024-05-06 21:20:51 +02:00
Igor MilavecandRob Hague 59840ecdba Fix SocketAsyncEventArgsAwaitable calling continuation multiple times (#918)
* Fix SocketAsyncEventArgsAwaitable calling continuation multiple times

* Use Interlocked.Exchange

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2024-04-27 22:43:42 +02:00
4e1e2436af Fix ArgumentException usage in BlockCipher (#818)
Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2024-04-27 20:52:34 +02:00
c8b527397a Handle timeout correctly on Socks5 Proxy (#1342)
* Add timeouts when reading from sockets in Socks5Connector

* Add a Socks5 timeout test for a connection reply

---------

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2024-04-27 20:49:24 +02:00