'Rust thrussh library client example fails at channel_open_session

In thrussh's documentation they have server and client example code.

Code based on the example server code has been working fine in various projects. However, the client example fails at the line:

let mut channel = session.channel_open_session().await.unwrap();

The error I get is this:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Disconnect', src/main.rs:121:64
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I'm not sure what is causing the panic as everything works fine up until that point. The server calls both finished_auth() and channel_open_confirmation() but never gets to call channel_open_session(). I've been looking through the source but I can't seem to identify what's wrong.

Here's the full code

use thrussh_keys::*;
use thrussh::*;

let ssh_config = thrussh::client::Config::default();
let ssh_config = Arc::new(ssh_config);
let sh = Client {};

let key = thrussh_keys::load_secret_key("server.key", passphrase).unwrap();
let mut agent = thrussh_keys::agent::client::AgentClient::connect_env().await.unwrap();
agent.add_identity(&key, &[]).await.unwrap();
let mut session = thrussh::client::connect(ssh_config, format!("localhost:{}", config.port), sh)
    .await
    .unwrap();
println!("connected");
if session
    .authenticate_future(config.user, key.clone_public_key(), agent)
    .await
    .1
    .unwrap()
{
    println!("session authenticated");
    let mut channel = session.channel_open_session().await.unwrap();
    channel.data(&b"Hello, world!"[..]).await.unwrap();
    if let Some(msg) = channel.wait().await {
        println!("{:?}", msg)
    }
}

the code on the server side is the same as the server example aside from writing the key to disk so that it can be used in the client code.



Solution 1:[1]

I guess the channel open response package was consumed by the fn channel_open_confirmation for some reason. Therefore, the wait_channel_confirmation will be pending for receiving the confirmation package for ever.

If you comment out the function implementation channel_open_confirmation for Client, it should work.

The trait does have a default implementation for this method, which sends out the OpenChannelMsg.

So, the demo is improper, unluckily, I have no access to report this issue.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1