SCP performs a transfer by running scp on the server with the remote path
embedded in a command. On a shell-based server that command is interpreted
by a shell, so a path that is not quoted to suit that shell can be executed
as a command on the server (GHSA-mggc-4xg6-vcxf); on a non-shell-based
server the path is used literally and must not be quoted at all. The right
encoding therefore depends on the server, and no single transformation is
safe for every server.
Rather than default this choice, obsolete the ScpClient constructors that
implicitly used DoubleQuote and add constructors that take an
IRemotePathTransformation explicitly, so callers must choose one suited to
their server and trust environment. DoubleQuote remains the default for the
obsolete constructors, so existing behaviour is unchanged. Document the
consideration on ScpClient and IRemotePathTransformation, and recommend
using SFTP.
* Bump actions/checkout from 4 to 5
* Bump actions/upload-pages-artifact from 3 to 4
* Bump actions/download-artifact from 4 to 5
* Bump the dependencies group with 5 updates
* fix
* fix locally failing portforwarding tests
port already in use
---------
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Rob Hague <rob.hague00@gmail.com>
* Fixes spelling errors in comments, private members, and public members in test projects
* Adds en-GB as spell checker option; reverts notable cases of American English
* convert file UTF-16 LE BOM -> UTF-8
---------
Co-authored-by: Rob Hague <rob.hague00@gmail.com>
* Update SonarAnalyzer.CSharp
* fix S3993: Custom attributes should be marked with "System.AttributeUsageAttribute"
https://rules.sonarsource.com/csharp/RSPEC-3993/
* fix S6966: Awaitable method should be used
Introduced abstractions for CancellationTokenSource.CancelAsync()
and Stream.DisposeAsync() to avoid #ifdef.
Supressed pipeStream.WriteAsync because it deadlocks the test.
I assume because PipeStream doesn't override WriteAsync.
https://rules.sonarsource.com/csharp/RSPEC-6966/
temp
* fix S3431: "[ExpectedException]" should not be used
Removed the Connect() from Multifactor_PublicKeyWithEmptyPassPhrase
because the Exception is already thrown in the factory.
https://rules.sonarsource.com/csharp/RSPEC-3431/
* fix S2325: Methods and properties that don't access instance data should be static
This one is pretty redundant with CA1822 (which is also disabled in the
tests).
It caught a few more cases in the library itself, most of which can't
be changed because they are public API.
https://rules.sonarsource.com/csharp/RSPEC-2325/
* fix S127: "for" loop stop conditions should be invariant
not sure if this one is worth having. The only cases it found
are imho legitimate or not worth fixing, so I supressed them.
https://rules.sonarsource.com/csharp/RSPEC-127/
* fix S1964: An abstract class should have both abstract and concrete methods
Suppressed for public APIs, changed ExtendedReplyInfo to interface.
https://rules.sonarsource.com/csharp/RSPEC-1694/
* Remove redundant test
this is already covered by Test_PrivateKey_SSH2_Encrypted_ShouldThrowSshPassPhraseNullOrEmptyExceptionWhenPassphraseIsNull
* Revert "fix S2325: Methods and properties that don't access instance data should be static"
suppress it instead
This reverts commit 2020604958.
* Revert "fix S127: "for" loop stop conditions should be invariant"
suppress it instead
This reverts commit 1d8b4ac335.
* 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>
* 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>
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>
* 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>
* 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
* Fix a few issues with ShellStream
The main change is to replace the Queue<byte> with a byte[] and a couple of
variables which index the start and end of the data. The remainder is mainly
slightly more careful locking semantics.
It also implements Expect(string) separately so that it can work on the bytes
and skip a lot of encoding work (this is where I wish ShellStream derived from
StreamReader).
One possibly contentious point: in fixing the Write behaviour I chose to
remove the "outgoing" buffer and immediately send the data across the channel.
Write(string) and WriteLine(string) were already doing this, and I felt it
was better to change Write(byte[]) to match rather than changing the string
methods.
* Integrate expectSize (as "windowSize" parameter)
* Rename "windowSize" to "lookback"
---------
Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
* 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>
* 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>