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

Add a way to open an agent forwarding channel #344

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions russh/src/server/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ pub struct Session {
}
#[derive(Debug)]
pub enum Msg {
ChannelOpenAgent {
channel_ref: ChannelRef,
},
ChannelOpenSession {
channel_ref: ChannelRef,
},
Expand Down Expand Up @@ -206,6 +209,23 @@ impl Handle {
}
}

/// Open an agent forwarding channel. This can be used once the client has
/// confirmed that it allows agent forwarding. See
/// [PROTOCOL.agent](https://datatracker.ietf.org/doc/html/draft-miller-ssh-agent).
pub async fn channel_open_agent(&self) -> Result<Channel<Msg>, Error> {
let (sender, receiver) = unbounded_channel();
let channel_ref = ChannelRef::new(sender);
let window_size_ref = channel_ref.window_size().clone();

self.sender
.send(Msg::ChannelOpenAgent { channel_ref })
.await
.map_err(|_| Error::SendError)?;

self.wait_channel_confirmation(receiver, window_size_ref)
.await
}

/// Request a session channel (the most basic type of
/// channel). This function returns `Ok(..)` immediately if the
/// connection is authenticated, but the channel only becomes
Expand Down Expand Up @@ -535,6 +555,10 @@ impl Session {
Some(Msg::Channel(id, ChannelMsg::WindowAdjusted { new_size })) => {
debug!("window adjusted to {:?} for channel {:?}", new_size, id);
}
Some(Msg::ChannelOpenAgent { channel_ref }) => {
let id = self.channel_open_agent()?;
self.channels.insert(id, channel_ref);
}
Some(Msg::ChannelOpenSession { channel_ref }) => {
let id = self.channel_open_session()?;
self.channels.insert(id, channel_ref);
Expand Down
Loading