Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The problem with PuTTY Client #156

Open
ileamo opened this issue May 2, 2023 · 1 comment
Open

The problem with PuTTY Client #156

ileamo opened this issue May 2, 2023 · 1 comment

Comments

@ileamo
Copy link

ileamo commented May 2, 2023

I run example:

cargo run -p russh --example echoserver

It works as expected using OpenSSH's Client.
However with PuTTY, no data is sent.

Client versions:

[...DEBUG russh::ssh_read] Ok("SSH-2.0-PuTTY_Release_0.78\r\n") 
[...DEBUG russh::ssh_read] Ok("SSH-2.0-OpenSSH_for_Windows_8.1\r\n")
@ileamo
Copy link
Author

ileamo commented May 4, 2023

After analyzing the PuTTY logs, I found that PuTTY does not start transferring data until it receives the SSH2_MSG_CHANNEL_WINDOW_ADJUST packet from the server.
Unfortunately, I did not find a public function in russh crate that sends this packet, so I added my own dirty function for testing.

With the following fixes, the echoserver example worked as expected with the PuTTY client:

diff --git a/russh/examples/echoserver.rs b/russh/examples/echoserver.rs
index 356f1b3..16e294d 100644
--- a/russh/examples/echoserver.rs
+++ b/russh/examples/echoserver.rs
@@ -80,6 +80,30 @@ impl server::Handler for Server {
         Ok((self, server::Auth::Accept))
     }
 
+    async fn pty_request(
+        self,
+        channel: ChannelId,
+        _term: &str,
+        _col_width: u32,
+        _row_height: u32,
+        _pix_width: u32,
+        _pix_height: u32,
+        _modes: &[(Pty, u32)],
+        mut session: Session,
+    ) -> Result<(Self, Session), Self::Error> {
+        session.channel_window_adjust(channel);
+        Ok((self, session))
+    }
+
     async fn data(
         mut self,
         channel: ChannelId,
diff --git a/russh/src/server/session.rs b/russh/src/server/session.rs
index 9bb2025..dc72df5 100644
--- a/russh/src/server/session.rs
+++ b/russh/src/server/session.rs
@@ -605,6 +605,23 @@ impl Session {
         }
     }
 
+    pub fn channel_window_adjust(&mut self, channel: ChannelId) {
+        if let Some(ref mut enc) = self.common.encrypted {
+            if let Some(channel) = enc.channels.get_mut(&channel) {
+                assert!(channel.confirmed);
+                if channel.wants_reply {
+                    channel.wants_reply = false;
+                    debug!("channel_window_adjust {:?}", channel);
+                    push_packet!(enc.write, {
+                        enc.write.push(msg::CHANNEL_WINDOW_ADJUST);
+                        enc.write.push_u32_be(0x100);
+                        enc.write.push_u32_be(0x200000);
+                    });
+                }
+            }
+        }
+    }
+
     /// Send a "failure" reply to a global request.
     pub fn channel_failure(&mut self, channel: ChannelId) {
         if let Some(ref mut enc) = self.common.encrypted {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant