sshnet / SSH.NET

SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.
http://sshnet.github.io/SSH.NET/
MIT License
3.88k stars 917 forks source link

Add support for Zlib compression (.NET 6.0 onward only) #1326

Closed scott-xu closed 2 months ago

scott-xu commented 4 months ago

This PR adds support for zlib@openssh.com described in https://www.openssh.com/txt/draft-miller-secsh-compression-delayed-00.txt

Resolves https://github.com/sshnet/SSH.NET/issues/1130 Resolves https://github.com/sshnet/SSH.NET/issues/559 Resolves https://github.com/sshnet/SSH.NET/issues/336 Resolves https://github.com/sshnet/SSH.NET/issues/119

Notes:

  1. This PR only adds compression support for .NET 6.0+.
  2. "none" is the first and preferred compression method which means no compression by default, just like ssh_config:

    Compression Specifies whether to use compression. The argument must be yes or no (the default).

    The description of ssh -C option explains the reason:

    Compression is desirable on modem lines and other slow connections, but will only slow down things on fast networks.

  3. zlib (pre-auth) is not supported in OpenSSH server (sshd) but is listed in OpenSSH client (ssh). Since it is not easy to do integration-test for zlib (pre-auth), this PR does not add zlib (pre-auth).
scott-xu commented 3 months ago

With this PR, SSH.NET targeted to frameworks below .NET 6.0 can easily use 3rd party library to do the compression. For example: https://github.com/scott-xu/SSH.NET.Ionic.Zlib/blob/main/src/SshNet.IonicZlib/ZLib.cs

scott-xu commented 3 months ago

The decompression works when receive SSH_MSG_GLOBAL_REQUEST. The decompression stops working when receive SSH_MSG_CHANNEL_OPEN_CONFIRMATION (compared with non-compression mode). It tries to decompress byte array: [20 13 74 63 12 112 208 192 0 16]. No idea what's going on here. Thoughts? @Rob-Hague

scott-xu commented 3 months ago

Ready to review @Rob-Hague @WojciechNagorski

scott-xu commented 3 months ago

Nice. Is there a reason for not testing "zlib" as well?

Because sshd doesn't support "zlib"(pre-auth) anymore.

Rob-Hague commented 2 months ago

Thanks, this is good to merge.

scott-xu commented 2 months ago

@WojciechNagorski Is there any other thing I can do to get this merged? Thanks!

WojciechNagorski commented 2 months ago

Yes. You can ask @Rob-Hague for review. I do not have time now.

Rob-Hague commented 2 months ago

I approved it but it needs CODEOWNERS approval:

image

No rush

WojciechNagorski commented 2 months ago

I've added @Rob-Hague to code owners.

scott-xu commented 2 months ago

Perfect!