这是indexloc提供的服务,不要输入任何密码
Skip to content

read() blocks after calling request_auth_agent_forwarding() #200

@z-image

Description

@z-image

Hello,

I'm new to both rust and ssh2-rs, so excuse me if I'm just doing something stupid.

Here's simplest case that I can't get working:

use std::net::TcpStream;
use ssh2::Session;
use std::io::Read;

fn main() {
    let remote_user = "john";
    let remote_addr = "tester.example.com:22";
    let remote_cmd = "echo $SSH_AUTH_SOCK; ssh-add -l";

    let stream = TcpStream::connect(&remote_addr).unwrap();

    let mut sess = Session::new().unwrap();
    sess.set_tcp_stream(stream);
    sess.handshake().unwrap();
    sess.userauth_agent(remote_user).unwrap();

    let mut channel = sess.channel_session().unwrap();
    channel.handle_extended_data(ssh2::ExtendedData::Merge).unwrap();
    // channel.request_auth_agent_forwarding().unwrap();

    channel.exec(remote_cmd).unwrap();

    let mut out = String::new();
    channel.read_to_string(&mut out).unwrap();

    channel.close().unwrap();
    channel.wait_close().unwrap();

    let _exit_status = channel.exit_status().unwrap();

    println!("{}", out);
}

It works as expected if there's no request_auth_agent_forwarding():

Could not open a connection to your authentication agent.

But if I start agent forwarding it just hangs there. If i remove the ssh-add part and leave only the echo I see the SSH_AUTH_SCOKET is set up ok.

I think the problem is that ssh-agent connection coming back from server to client somehow messes with my read_to_string(). I guess the local agent is supposed to write() back to server at this moment and that's why my read would block.

Any ideas how to go about this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions