x/crypto/ssh client.NewSession: Provide initial data or an already open channel?

68 views
Skip to first unread message

glenn

unread,
Apr 26, 2022, 6:31:31 PM4/26/22
to golang-nuts
I would like to send some initial data when creating a new ssh session. Is there any reason why NewSession doesn't allow callers to do this? Session doesn't export the underlying channel either, so opening a channel and directly initializing the Session isn't an option either.

func (c *Client) NewSession() (*Session, error) {   
    ch, in, err := c.OpenChannel("session", nil)
    if err != nil {
        return nil, er
    }
    return newSession(ch, in)
 }

Brian Candler

unread,
Apr 27, 2022, 1:48:29 AM4/27/22
to golang-nuts
> Session doesn't export the underlying channel either, so opening a channel and directly initializing the Session isn't an option

Because it isn't meaningful to do this.

As far as I understand it, a session is a type of channel. When you want to open a session, actually you open a channel of type "session".  One channel cannot carry multiple sessions, because a session *is* a channel.  Equally, you cannot open an untyped channel and then "convert" it to a session later; you have to specify this at the time you create it.

See:

Note that "opening a session" is simply a variant of SSH_MSG_CHANNEL_OPEN, with type "session".

> I would like to send some initial data when creating a new ssh session. Is there any reason why NewSession doesn't allow callers to do this?

Presumably because the session open could fail. You need to wait for the session to be opened successfully before sending data on it.

See:

   The remote side then decides whether it can open the channel, and responds with either SSH_MSG_CHANNEL_OPEN_CONFIRMATION or SSH_MSG_CHANNEL_OPEN_FAILURE.

Reply all
Reply to author
Forward
0 new messages