Subject: compression

compression

From: Dave Hayden <dave_at_panic.com>
Date: Thu, 26 Jul 2012 17:55:15 -0700

Is compression supposed to work? It looks like when you set the LIBSSH2_FLAG_COMPRESS flag, it sets up the compression methods in kex and then tries to do compression during userauth. The server (OpenSSH is all I've got to test against) apparently expects userauth to be uncompressed. Here's a fix that works in my case--moving the comp method aside after kex then back again in _libssh2_channel_open. I'm not totally familiar with libssh2's guts, so there's probably a better way to do this (maybe using session->state instead?). Using _libssh2_channel_open like that seems a little sketchy to me.

Hope this helps,
-Dave

diff -r -u /Users/dave/Desktop/libssh2-1.4.2/src/channel.c src/channel.c
--- /Users/dave/Desktop/libssh2-1.4.2/src/channel.c 2012-05-18 14:29:03.000000000 -0700
+++ src/channel.c 2012-07-26 17:20:11.000000000 -0700
@@ -140,7 +140,10 @@
     };
     unsigned char *s;
     int rc;
-
+
+ session->local.comp = session->local.agreed_comp;
+ session->remote.comp = session->remote.agreed_comp;
+
     if (session->open_state == libssh2_NB_state_idle) {
         session->open_channel = NULL;
         session->open_packet = NULL;
diff -r -u /Users/dave/Desktop/libssh2-1.4.2/src/comp.c src/comp.c
--- /Users/dave/Desktop/libssh2-1.4.2/src/comp.c 2011-10-25 14:30:50.000000000 -0700
+++ src/comp.c 2012-07-26 16:48:27.000000000 -0700
@@ -355,7 +355,7 @@
 }
 
 static const LIBSSH2_COMP_METHOD comp_method_zlib = {
- "zlib",
+ "zlib_at_openssh.com",
     1, /* yes, this compresses */
     comp_method_zlib_init,
     comp_method_zlib_comp,
diff -r -u /Users/dave/Desktop/libssh2-1.4.2/src/libssh2_priv.h src/libssh2_priv.h
--- /Users/dave/Desktop/libssh2-1.4.2/src/libssh2_priv.h 2012-01-27 05:34:03.000000000 -0800
+++ src/libssh2_priv.h 2012-07-26 17:06:46.000000000 -0700
@@ -465,6 +465,7 @@
     uint32_t seqno;
     void *mac_abstract;
 
+ const LIBSSH2_COMP_METHOD *agreed_comp;
     const LIBSSH2_COMP_METHOD *comp;
     void *comp_abstract;
 
diff -r -u /Users/dave/Desktop/libssh2-1.4.2/src/session.c src/session.c
--- /Users/dave/Desktop/libssh2-1.4.2/src/session.c 2012-04-18 13:24:04.000000000 -0700
+++ src/session.c 2012-07-26 17:31:59.000000000 -0700
@@ -720,6 +720,13 @@
             return _libssh2_error(session, rc,
                                   "Unable to exchange encryption keys");
 
+ /* Remainder of startup shouldn't use compression. We restore it
+ in _libssh2_channel_open() */
+ session->local.agreed_comp = session->local.comp;
+ session->remote.agreed_comp = session->remote.comp;
+ session->local.comp = NULL;
+ session->remote.comp = NULL;
+
         session->startup_state = libssh2_NB_state_sent2;
     }
 
diff -r -u /Users/dave/Desktop/libssh2-1.4.2/src/transport.c src/transport.c
--- /Users/dave/Desktop/libssh2-1.4.2/src/transport.c 2012-03-16 08:39:58.000000000 -0700
+++ src/transport.c 2012-07-26 16:21:06.000000000 -0700
@@ -723,7 +723,7 @@
 
     encrypted = (session->state & LIBSSH2_STATE_NEWKEYS) ? 1 : 0;
 
- if (encrypted && session->local.comp->compress) {
+ if (encrypted && session->local.comp && session->local.comp->compress) {
         /* the idea here is that these function must fail if the output gets
            larger than what fits in the assigned buffer so thus they don't
            check the input size as we don't know how much it compresses */

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2012-07-27