203 Commits

Author SHA1 Message Date
Jean-Sebastien Carle bcaf354ccb Significantly improve performance of ShellStream's Expect methods (#1207)
* Significantly improved performance and fixed bug with ShellStream's Expect methods.

* Fix whitespace.

* Fixed test.

* Improve ShellStream Expect

* Fixed typo.

* Doubled expectBuffer's default size and added a large expect test.

* Added guard clauses to ShellStream constructor and adjusted Common_CreateMoreChannelsThanMaxSessions test.

* Fixed XMLDoc spelling mistakes.

---------

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
Co-authored-by: Wojciech Nagórski <wojciech.nagorski@intel.com>
2024-02-13 13:41:47 +01:00
Wojciech Nagórski 3bfac50ad0 Improve ShellStream Expect (#1315) 2024-02-11 23:06:25 +01:00
Wojciech Nagórski dec04f26e0 2023.0.2 version (#1314) 2024-02-11 20:15:11 +01:00
Rob Hague e23f381dea Add tests and benchmarks for ShellStream.Read and Expect (#1313)
Most of them are ignored because they fail.
2024-02-11 10:00:38 +01:00
Ferenc Vizkeleti 2d0e03b8ce Added SshCommand.InputStream to allow writing to stdin of SshCommand (#1293)
* Making all unit tests pass locally.
Excluded MD5 tests on net462 because I get System.InvalidOperationException: 'This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.'
SshdConfig: do not throw for "Include", just do nothing.
Modified failing dos2unix parameters in Dockerfile.TestServer.
Forceing LF line ending for key files used by integration tests, otherwise using them causes error.
SftpClientTest.Test_Sftp_Multiple_Async_Upload_And_Download_10Files_5MB_Each times out for maxFiles=10, decreasing to 2 to make the test pass.

* Added SshCommand.InputStream.

* Added an integration test for SshCommand.InputStream.

* Reverting changes made to unit tests unrelated to this PR.

* Moved ChannelInputStream's EOF sending from Write to Dispose. Replace SshCommand.InputStream with CreateInputStream to emphasise that a (disposable) resource is created here. EndExecute also closes the _inputStream to make sure that EOF is sent (in case the user forgot to dispose the input stream). Added more unit tests: sending the input one byte at a time, not disposing the input stream, calling CreateInputStream before BeginExecute or AfterEndExecute throws exception.

* Fixing review comments.

* Fix build error after #1286

---------

Co-authored-by: ferenc.vizkeleti <ferenc.vizkeleti@innopay.hu>
Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2024-02-06 18:02:19 +01:00
Rob Hague bfe6718fce Allow the integration tests to run on .NET Framework (#1286)
* Allow the integration tests to run on .NET Framework

* Update appveyor.yml

* Update appveyor.yml

---------

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2024-02-06 13:30:01 +01:00
Rob Hague 47eabe7574 Tweak semaphore usage in Session (#1304)
- Change _connectAndLazySemaphoreInitLock to a SemaphoreSlim and use it in
  ConnectAsync.
- Rename it to _connectLock and only use it for connecting. Replace its
  other usages (on SessionSemaphore and NextChannelNumber) with Interlocked
  operations.
- Remove AuthenticationConnection semaphore. This static member placed a
  process-wide limit on the number of connections an application can make.
  I agree with the argument in
  https://github.com/sshnet/SSH.NET/issues/409#issuecomment-457415542
  (and in several other issues/PRs) that this should not be something
  that the library attempts to control.

The last change broke a few tests which do things like making 100 connections.
I was tempted to delete these tests as I don't think they have much value, but
instead I just limited their concurrency.

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2024-02-06 13:16:11 +01:00
Wojciech Nagórski 0371af9aaf Integration benchmark tests (#1298)
* Integration benchmark tests

* Fixes

* Write with encoding

* Update src/Renci.SshNet/Common/SshDataStream.cs

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

* Add more benchmarks

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2024-01-28 11:05:42 +01:00
Rob Hague 4c2dcd5613 Upgrade packages (#1279) 2023-12-29 05:06:50 +01:00
Rob Hague 2b53e462dd Authenticate with ssh-rsa by default (#1283) 2023-12-28 20:55:07 +01:00
Rob Hague b0d01df91f Try to stabilise a few tests (#1278)
* Try to stabilise a few tests

* Fix random 0 buffer sizes

---------

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2023-12-22 08:37:30 +01:00
Rob Hague 24838e6173 Make keys immutable (#1264)
This makes it easier to reason about Key instances in e.g.
DigitalSignature implementations, because we know that the
Key is initialised with its data and will not change.

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2023-12-21 23:12:15 +01:00
Rob Hague 34b5123f0a Send the client key exchange init in Connect (#1274)
* Send the client key exchange init in Connect

* Add a test

---------

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2023-12-21 06:54:32 +01:00
Jacob Slusser f172ac587c Removes MessageAttribute in favor of properties on Message class (#1270)
* Exludes the test projects from code coverage reports

* Removes MessageAttribute in favor of properties on Message class

* Benchmark for removal of MessageAttribute
2023-12-10 17:46:35 +01:00
Rob Hague f45af38628 Replace SemaphoreLight with SemaphoreSlim (#1265)
This paves the way for asynchronous synchronisation via WaitAsync
(and eliminates a timing test which sometimes fails in CI)

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2023-12-09 08:52:31 +01:00
Jacob Slusser 4c4883eed0 Standardizes additional file types in .editorconfig (#1266)
* Updates .gitignore to exclude test results

* Adds .editorconfig for xml, csproj, and props files

Formats xml, csproj, and props files

* Hides stylecop.json from Solution Explorer projects
2023-12-09 07:39:33 +01:00
Rob Hague 6d9d03205b Rebased AsyncResult fix (#1184)
* 🐛 AsyncResult contains invalid value

- AsyncResult should contain invalid value immediately after async operation is marked as completed
- there was race condition problems with callback method which is invoked on different thread so updating of value is done without any synchronization. So in some cases async operation is marked as completed but async result value is not yet updated and contains invalid value

* Revert test

---------

Co-authored-by: Miroslav Pokorný <m.pokorny@quadient.com>
2023-12-04 09:48:56 +01:00
Rob Hague a027c76d7a Fail with a friendlier error message when response has not been set (#1245)
Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2023-12-02 14:16:22 +01:00
Scott Xu 4c7bd35a71 Add support for .NET 8.0 (#1255)
* Add support for .NET 8.0

* Fix CA1512: Use 'ArgumentOutOfRangeException.ThrowIfNegative' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1512)

* Use `ThrowIfGreaterThan` instead of `ThrowIfNegative`+calculation, to supply the correct parameter name.

* .NET 8 is faster :-)

* Use the explicit version, in case newer version SDK breaks our tests
2023-12-01 22:56:48 +01:00
Wojciech Nagórski d3641a0676 Test integration tests (#1250)
* Test integration tests

* Update appveyor.yml

* Update appveyor.yml

* Update Dockerfile

* Update appveyor.yml

* test?

* Test

* Enable docker

* Update appveyor.yml

* Update appveyor.yml

* Fix & Show additional information

* Try to fix connection problems

* Fix build

* remove artifacts

* Enable logging

* Log Information only

* Update appveyor.yml

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

* Update appveyor.yml

* Update appveyor.yml

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

* Update appveyor.yml

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

* Update appveyor.yml

* Update appveyor.yml

* Update appveyor.yml

* Update appveyor.yml

* Update appveyor.yml

* Update appveyor.yml

* Update appveyor.yml

* Update appveyor.yml

* Update appveyor.yml

* sleep after restarting

* Update RemoteSshd.cs

* Fix tests

* Dispose ports

* Small improvements

* Fix build

* Small fixes

* Revert not related changes

* Test linux and windows

* fix

* test_script

* Use real commands

* Fixes

* fix?

* Add Appveyor TestLogger

* Fix linux tests

* Fix tests

* Try to fix tests

* Revert

* Give time before

* fix

* revert

* Give some time to process all messages after connect

* ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound

* fix netsh

* trace

* Update appveyor.yml

* Update appveyor.yml

* etl2pcapng

* Update appveyor.yml

???

* Update appveyor.yml

* Update appveyor.yml

* Update appveyor.yml

* Update appveyor.yml

* come on !!

* Update appveyor.yml

* Fixes tests for linux

* Reverts

* Fix build

* Update TestMethodForPlatformAttribute.cs

* Update TestMethodForPlatformAttribute.cs

* Update appveyor.yml

* Issue #1253

* Install .NET SDK

* next try

* fix?

* try

* Finishing

* Fixes

* apt-get install dotnet-sdk-7.0

* Finish?

* Add environment APPVEYOR_BAKE_IMAGE

* Update test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_TimeoutConnectingToServer.cs

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

* Fix review

* Fix

* Update appveyor.yml

* Update appveyor.yml

* Delete .runsettings

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
Co-authored-by: Robert Hague <rh@johnstreetcapital.com>
Co-authored-by: Scott Xu <scott-xu@msn.com>
2023-11-30 19:19:00 +01:00
Pedro Fonseca 4ce18d305e Use hardware-accelerated AES CryptoServiceProvider (#865)
* Add FEATURE_AES_CSP to use hardware-accelerated AesCryptoServiceProvider
Reduces CPU usage dramatically, allowing more performance on slower machines

* Restructure, move most of the feature code to AesCipher.cs
Fix padding for non-AES blockciphers
Fix IV exception for non-AES blockciphers

* Fix the AES Padding
It looks like the legacy code doesn't correctly remove padding, so this code needs to do the same.

* fix rebase issues
restructure AES CSP code into its own class

* Minor fixes

* Rework based on suggestions

* Move all changes to AesCypher.cs, as per Rob-Hague suggestion
Remove FEATURE_AES_CSP conditional
Fix OFB CipherMode

* update AesCipherTest.cs generator

* Fix continuous session encrypt/decrypt
(preserve IV between calls when Padding is None)

* Reduce CTR memory usage in Net 6+
Small performance increase in CTR buffer mode
Cosmetic changes

* Factor out the implementations and re-add the existing constructor

* remove ctor; revert tests; remove unused _iv member

* Reorder Encryption cipher preference list

* Remove redundant AES tests
Add tests for stream cipher state preservation

* Refactor ArrayXOR()

* Add test for IV overflow

* Performance bump for AES CTR (thanks @robhague)

* fix merge conflict

* Move AesCipherMode enum to its own file

---------

Co-authored-by: Pedro Fonseca <pfonseca@qti.qualcomm.com>
Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2023-11-28 12:59:06 +01:00
se006 daa1accaf6 Fix avoidable exception when data length is too long (#823)
* Data lengths longer than stream position when data lengths are greater than int.maxvalue are ignored and do not throw an exception

* Removed unreachable test

* Do not try to load the data (just ignore it)

---------

Co-authored-by: Steve Evans <sevans1@oeconnection.com>
Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2023-11-19 07:32:08 +01:00
Scott Xu f9f2b0e5f4 Expose SshIdentificationReceived event (#1195)
* Fix https://github.com/sshnet/SSH.NET/issues/1191

* Expose `SshIdentificationReceived` event so that lib consumer can adjust based on server identification

* revert unrelated code style change

* revert OpenSSH 6.6 related tests

* revert ConnectionBase

* Add unit tests

* Rename to `ServerIdentificationReceived`

* rename
2023-11-16 14:35:59 +01:00
Wojciech Nagórski 54d01621aa Enable trace logging for Integration tests (#1242) 2023-11-16 08:58:22 +01:00
Rob Hague 5021f6d4bb Use System.Security.Cryptography in AesCipher (#1235)
* Use System.Security.Cryptography in AesCipher

* don't set the IV - it is unused by ECB

* Dispose ciphers in Session if applicable

---------

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2023-11-16 07:05:22 +01:00
Pedro Fonseca 2eec748b18 Improve SFTP performance on medium/high latency connections (#866)
* Improve SFTP performance on medium-high latency connections
- Increases maxPendingReads from 10 to 100
- Increases socket send/receive buffer to 10 SSH packets (320K)

* Fix merge

* Adjust SFTP FileReader testcases to accept new MaxPendingReads values

* Fix CreateSftpFileReader testcase, make it dependant on MaxPendingReads constant

---------

Co-authored-by: Pedro Fonseca <pfonseca@qti.qualcomm.com>
2023-11-13 06:08:57 +01:00
Rob Hague 823bc1b67b Use CollectionAssert in ListDirectory tests (#1166)
* Use CollectionAssert in ListDirectory tests

* Indent the braces

---------

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2023-11-13 06:07:26 +01:00
Robert Hague 09ad44a823 Remove unused symbols 2023-11-11 18:47:46 +01:00
Robert Hague 0829fce6e4 Use shared Data folder for client keys in integration tests 2023-11-11 18:47:46 +01:00
Robert Hague 1fc6360cf8 Remove duplicate GetManifestResourceStream helpers 2023-11-11 17:39:34 +01:00
Robert Hague d36e7f552d Add OpenSSH public key files
Generated with

puttygen Key.OPENSSH.ECDSA.Encrypted.txt -o Key.OPENSSH.ECDSA.Encrypted.pub -O public-openssh
puttygen Key.OPENSSH.ECDSA.txt -o Key.OPENSSH.ECDSA.pub -O public-openssh
puttygen Key.OPENSSH.ECDSA384.Encrypted.txt -o Key.OPENSSH.ECDSA384.Encrypted.pub -O public-openssh
puttygen Key.OPENSSH.ECDSA384.txt -o Key.OPENSSH.ECDSA384.pub -O public-openssh
puttygen Key.OPENSSH.ECDSA521.Encrypted.txt -o Key.OPENSSH.ECDSA521.Encrypted.pub -O public-openssh
puttygen Key.OPENSSH.ECDSA521.txt -o Key.OPENSSH.ECDSA521.pub -O public-openssh
puttygen Key.OPENSSH.ED25519.Encrypted.txt -o Key.OPENSSH.ED25519.Encrypted.pub -O public-openssh
puttygen Key.OPENSSH.ED25519.txt -o Key.OPENSSH.ED25519.pub -O public-openssh
puttygen Key.OPENSSH.RSA.Encrypted.txt -o Key.OPENSSH.RSA.Encrypted.pub -O public-openssh
puttygen Key.OPENSSH.RSA.txt -o Key.OPENSSH.RSA.pub -O public-openssh

and so forth. Some whose ciphers are unsupported by puttygen were generated with e.g.

sudo ssh-keygen -f Key.RSA.Encrypted.Des.CBC.12345.txt -y > Key.RSA.Encrypted.Des.CBC.12345.pub
2023-11-11 17:39:34 +01:00
Robert Hague 9d6f3ef979 Normalize the OpenSSH files
Change the data to be in 64-wide columns instead of 70, and add a newline
at the end of the file. ssh-keygen does not like it otherwise.

puttygen Key.OPENSSH.ECDSA.Encrypted.txt -O private-openssh-new -C Key.OPENSSH.ECDSA.Encrypted
puttygen Key.OPENSSH.ECDSA.txt -O private-openssh-new -C Key.OPENSSH.ECDSA
puttygen Key.OPENSSH.ECDSA384.Encrypted.txt -O private-openssh-new -C Key.OPENSSH.ECDSA384.Encrypted
puttygen Key.OPENSSH.ECDSA384.txt -O private-openssh-new -C Key.OPENSSH.ECDSA384
puttygen Key.OPENSSH.ECDSA521.Encrypted.txt -O private-openssh-new -C Key.OPENSSH.ECDSA521.Encrypted
puttygen Key.OPENSSH.ECDSA521.txt -O private-openssh-new -C Key.OPENSSH.ECDSA521
puttygen Key.OPENSSH.ED25519.Encrypted.txt -O private-openssh-new -C Key.OPENSSH.ED25519.Encrypted
puttygen Key.OPENSSH.ED25519.txt -O private-openssh-new -C Key.OPENSSH.ED25519
puttygen Key.OPENSSH.RSA.Encrypted.txt -O private-openssh-new -C Key.OPENSSH.RSA.Encrypted
puttygen Key.OPENSSH.RSA.txt -O private-openssh-new -C Key.OPENSSH.RSA

(the -C flag changes the comment, otherwise puttygen refuses to do anything)
2023-11-11 17:39:34 +01:00
Robert Hague 60ba1dd090 Change the passphrase of Key.OPENSSH.ED25519.Encrypted to "12345" 2023-11-11 17:39:33 +01:00
Robert Hague 6ec6dc13fd Remove byte order mark, set eol=lf in key files 2023-11-11 17:39:33 +01:00
Rob Hague 826222f6fe Increase test coverage for AesCipher (#1232)
* Increase test coverage for AesCipher

The tests were generated by a script which is also added for posterity.
The script works by running "openssl enc [...]" (via WSL) to generate the
expected encrypted values, and also verifies those values against the .NET
BCL implementation as an extra validation (it uncovered a difference in
CFB mode between the two relating to the feedback size).

* Fix OfbCipherMode

It was an exact copy of CfbCipherMode
2023-11-05 09:45:30 +01:00
Gert Driesen 508fc87d2a Fix analyzer errors in Renci.SshNet and Renci.SshNet.TestTools.OpenSSH (#1229)
* Fix analyzer errors in Renci.SshNet and Renci.SshNet.TestTools.OpenSSH.
Suppress all errors in unit tests and integration tests.

* Update unit tests now that we pass 'mode' as argument name when we throw ArgumentException.

* Remove stale comment and add unit tests for SshData.ReadBytes(int length).

* Remove unnessary suppression.

* Remove Visual Studio magic.

* Removed duplicate source file.

* Clarified that suppression hides a false positive.

* Remove suppressions for S2372.

* Update ReadExtensionPair() to return concrete dictionary.
2023-11-01 11:33:42 +01:00
Wojciech Nagórski 8e2363360d Update Nugets 10/2023 (#1214)
* Update Nugets 10/2023

* Fix
2023-10-16 15:06:18 +02:00
Rob Hague 46796094f1 Delete more dummy tests (#1213) 2023-10-15 08:25:22 +02:00
Wojciech Nagórski f1297dec75 Move test projects (#1212)
* Move test projects to test folder.
Move global.json to root of repo.
Update solution items in solution.

* Move test projects to test folder.
Move global.json to root of repo.
Update solution items in solution.
Update appveyor configuration/

* Attempt to have appveyor use the correct .NET SDK.

* Update .NET SDK to version 7.0.402.

* Move Data folder below Renci.SshNet.Tests.

* Make csinst less chatty.

* Move Data folder directly below test folder as it's used by multiple test projects.

* Remove CS1591 nowarn from concrete test projects as this is already defined in the Directory.Build.props that is in the test folder.

* Fix integration test after moving test projects

---------

Co-authored-by: drieseng <gert.driesen@telenet.be>
2023-10-14 22:16:11 +02:00
Gert Driesen 3ecbd1071d Fix some (lots of) issues reported by analyzers. (#1125)
Fix some (lots of) issues reported by analyzers.
2023-05-24 20:37:46 +02:00
Wojciech Nagórski cf8510013d Removing old target frameworks (#1109)
Remove support for legacy / deprecated target frameworks while adding support for .NET 6.0 (and higher).
The supported target frameworks are now:
* .NETFramework 4.6.2 (and higher)
* .NET Standard 2.0
* .NET 6.0 (and higher)
2023-05-06 22:32:10 +02:00
drieseng 852efaf9f9 Modify SocketAbstraction.CanWrite to return false when socket is null. 2016-09-21 21:29:59 +02:00
drieseng 59923ceca0 Added tests and some slashdocs for ForwardedPortStatus. 2016-07-23 17:58:42 +02:00
drieseng 1d5d58e17c Rename HashAlgorithmFactory to CryptoAbstraction, and move it to the Renci.SshNet.Abstractions namespace. 2016-07-23 10:49:21 +02:00
drieseng 521a174f59 Tag some more tests as long running or performance related. 2016-07-15 21:46:35 +02:00
Gert Driesen 3aff05a4e0 Remove unused variable. 2016-07-09 19:20:24 +02:00
drieseng 6cf058a312 Add support for .NET Core 1.0 (.NETStandard 1.3).
Introduce FileSystemAbstraction.
2016-07-02 16:31:37 +02:00
drieseng f5b5542684 Improved exception messages.
Avoid magic numbers.
Improve test coverage.
2016-06-17 12:01:00 +02:00
drieseng ec9fc0f317 Fix imports. 2016-06-15 21:33:19 +02:00
drieseng ee3f679aa3 Separate creating, enabling/disabling, activating/deactivating of messages into SshMessageFactory.
Huge performance improvement in micro-benchmark.
Work in progress.
2016-06-14 22:28:49 +02:00