Try to use compression... (error: unknown compression method)

Jan 30, 2012 at 10:47 AM
Edited Jan 30, 2012 at 10:47 AM

Hi,

I try to use the command out compression function in this library.

First the steps what I have do for activation the command outed function:

1. I have downloaded the DotNetZip library and link the file Ionic.Zlib.dll to the project...

2. Remove the command out from the CompressionAlgorithms dictionary in the ConnectionInfo.cs in the project root

 

this.CompressionAlgorithms = new Dictionary<string, Type>()
            {
                {"none", null}, 
                {"zlib", typeof(Zlib)}, 
                {"zlib@openssh.com", typeof(ZlibOpenSsh)}, 
            };

 

3. Remove all the command outs in the Compression\ZlibStream.cs File

 

public class ZlibStream
    {
        private readonly Ionic.Zlib.ZlibStream _baseStream;

        public ZlibStream(Stream stream, CompressionMode mode)
        {
            switch (mode)
            {
                case CompressionMode.Compress:
                    this._baseStream = new Ionic.Zlib.ZlibStream(stream, Ionic.Zlib.CompressionMode.Compress, Ionic.Zlib.CompressionLevel.Default);
                    break;
                case CompressionMode.Decompress:
                    this._baseStream = new Ionic.Zlib.ZlibStream(stream, Ionic.Zlib.CompressionMode.Decompress, Ionic.Zlib.CompressionLevel.Default);
                    break;
                default:
                    break;
            }

            this._baseStream.FlushMode = Ionic.Zlib.FlushType.Partial;
        }

        public void Write(byte[] buffer, int offset, int count)
        {
            this._baseStream.Write(buffer, offset, count);
        }
    }

4. Change in the Security\KeyExchange.cs file the de/compression find selection from .FirstOrDefault to .LastOrDefault to get a compression mode of the client/server compatible modes.
            //  Determine compression algorithm
            var compressionAlgorithmName = (from b in session.ConnectionInfo.CompressionAlgorithms.Keys
                                            from a in message.CompressionAlgorithmsClientToServer
                                            where a == b
                                            select a).LastOrDefault(); //.FirstOrDefault();
            if (string.IsNullOrEmpty(compressionAlgorithmName))
            {
                throw new SshConnectionException("Compression algorithm not found", DisconnectReason.KeyExchangeFailed);
            }

            //  Determine decompression algorithm
            var decompressionAlgorithmName = (from b in session.ConnectionInfo.CompressionAlgorithms.Keys
                                              from a in message.CompressionAlgorithmsServerToClient
                                              where a == b
                                              select a).LastOrDefault(); //.FirstOrDefault();
            if (string.IsNullOrEmpty(decompressionAlgorithmName))
            {
                throw new SshConnectionException("Decompression algorithm not found", DisconnectReason.KeyExchangeFailed);
            }


I can connect to the SSH server and make a port forwarting for the Remote Desktop (port 3389).

If I start the remote desktop session than I have a port exception with the errormessage:

Ionic.Zlib.ZlibException: Bad state (unknown compression method (0x03))
   at Renci.SshNet.Session.WaitHandle(WaitHandle waitHandle) in E:\MDT\Entwicklung\C#\Remoteverbindung\cs_Remoteverbindung\MDT_Remoteverbindung_VS08_SSH.NET_Library\Renci.SshNet\Session.cs:line 625.
   at Renci.SshNet.Channels.Channel.WaitHandle(WaitHandle waitHandle) in E:\MDT\Entwicklung\C#\Remoteverbindung\cs_Remoteverbindung\MDT_Remoteverbindung_VS08_SSH.NET_Library\Renci.SshNet\Channels\Channel.cs:line 472.
   at Renci.SshNet.Channels.ChannelDirectTcpip.Bind(String remoteHost, UInt32 port, Socket socket) in E:\MDT\Entwicklung\C#\Remoteverbindung\cs_Remoteverbindung\MDT_Remoteverbindung_VS08_SSH.NET_Library\Renci.SshNet\Channels\ChannelDirectTcpip.cs:line 67.
   at Renci.SshNet.ForwardedPortLocal.<>c__DisplayClass2.<InternalStart>b__1() in E:\MDT\Entwicklung\C#\Remoteverbindung\cs_Remoteverbindung\MDT_Remoteverbindung_VS08_SSH.NET_Library\Renci.SshNet\ForwardedPortLocal.NET40.cs:line 52.


Can you help me please to use the command outed compression function. Big big thanks.

Thanks,
Tora
Coordinator
Jan 30, 2012 at 1:15 PM
Edited Jan 30, 2012 at 1:22 PM

Hi,

 

I just did a small test and it seems to be a problem with zlib@openssh.com compression.

If you comment out this one and use only zlib it should work, at least it works for me here.

 

I will take a look at this problem and see what I can do about it but meanwhile see if you can work with zlib compression.

EDIT: Sorry, I'll take it back, it seems to be a probem with other too, it just my server does not support the other one so it defaulted to none and therefore worked, I will keep investigating it and will keep you updated.

Thanks,

Oleg

Coordinator
Jan 30, 2012 at 1:51 PM

ok,

 

I figured out what happens.

 

It looks like that server by default always selects compression method "none".

So even if you specify 2 methods "none" and something else, server will assume none as a selected choice.

Then what happens is when client receives data from the server, it thinks it compressed when in fact it is not, thats why you get bad format error.Just comment out all compression methods other then you want to use and everything will work fine I think.

 

Thanks,

Oleg

May 12, 2012 at 12:45 PM
Edited May 15, 2012 at 9:31 PM

Hi,

Thanks for the info above was very usefully when trying to get the zlib compression working.

Thanks,

Luke