handleMSG_CHANNEL_OPEN method

void handleMSG_CHANNEL_OPEN(
  1. MSG_CHANNEL_OPEN msg,
  2. SerializableInput packetS
)

Handles server-initiated Channel to client. e.g. for remote port forwarding, or SSH agent request.

Implementation

void handleMSG_CHANNEL_OPEN(MSG_CHANNEL_OPEN msg, SerializableInput packetS) {
  if (tracePrint != null) {
    tracePrint('$hostport: MSG_CHANNEL_OPEN type=${msg.channelType}');
  }
  if (msg.channelType == 'auth-agent@openssh.com' && agentForwarding) {
    Channel channel = acceptChannel(msg);
    channel.agentChannel = true;
    writeCipher(MSG_CHANNEL_OPEN_CONFIRMATION(
        channel.remoteId, channel.localId, channel.windowS, maxPacketSize));
  } else if (msg.channelType == 'forwarded-tcpip') {
    MSG_CHANNEL_OPEN_TCPIP openTcpIp = MSG_CHANNEL_OPEN_TCPIP()
      ..deserialize(packetS);
    Forward forward =
        forwardingRemote == null ? null : forwardingRemote[openTcpIp.dstPort];
    if (forward == null || remoteForward == null) {
      if (print != null) {
        print('unknown port open ${openTcpIp.dstPort}');
      }
      writeCipher(MSG_CHANNEL_OPEN_FAILURE(msg.senderChannel, 0, '', ''));
    } else {
      Channel channel = acceptChannel(msg);
      remoteForward(channel, forward.targetHost, forward.targetPort,
          openTcpIp.srcHost, openTcpIp.srcPort);
      writeCipher(MSG_CHANNEL_OPEN_CONFIRMATION(
          channel.remoteId, channel.localId, channel.windowS, maxPacketSize));
    }
  } else {
    if (print != null) {
      print('unknown channel open ${msg.channelType}');
    }
    writeCipher(MSG_CHANNEL_OPEN_FAILURE(msg.senderChannel, 0, '', ''));
  }
}