public Channel(string servername, string rd, int cid, ISSHChannel channel, Socket socket) { _serverName = servername; _remoteDescription = rd; _connectionID = cid; _wroteClosedLog = false; _channel = new SynchronizedSSHChannel(channel); _socket = new SynchronizedSocket(socket); _buffer = new byte[0x1000]; _channelReady = new ManualResetEvent(false); }
/// <summary> /// Constructor /// </summary> /// <param name="channel">SSH channel</param> /// <param name="x11sock">a socket which is already established the connection with the X11 server</param> /// <param name="spoofedAuthProtocolName">spoofed authorization protocol name</param> /// <param name="spoofedAuthCookie">spoofed authorization cookie</param> /// <param name="authProtocolName">authorization protocol name actually used for the authorization</param> /// <param name="authCookie">authorization cookie actually used for the authorization</param> public X11ChannelHandler( ISSHChannel channel, IX11Socket x11sock, string spoofedAuthProtocolName, byte[] spoofedAuthCookie, string authProtocolName, byte[] authCookie) { _channel = channel; _x11Sock = x11sock; _spoofedAuthProtocolName = Encoding.ASCII.GetBytes(spoofedAuthProtocolName ?? ""); _spoofedAuthCookie = spoofedAuthCookie ?? new byte[0]; _authProtocolName = Encoding.ASCII.GetBytes(authProtocolName ?? ""); _authCookie = authCookie ?? new byte[0]; }
public ChannelHandler(ISSHChannel channelOperator) { _operator = channelOperator; }
public RemotePortForwardingReply OnRemotePortForwardingRequest(RemotePortForwardingRequest request, ISSHChannel channel) { try { if (!_profile.AllowsForeignConnection && !IsLoopbackAddress(request.OriginatorIp)) { return(RemotePortForwardingReply.Reject( RemotePortForwardingReply.Reason.AdministrativelyProhibited, "rejected")); } Socket local = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); local.Connect(new IPEndPoint(Util.ResolveHost(_profile.DestinationHost), _profile.DestinationPort)); var newChannel = new Channel( _profile.SSHHost, _profile.DestinationHost, (int)channel.LocalChannel, channel, local); newChannel.StartAsyncReceive(); return(RemotePortForwardingReply.Accept(newChannel)); } catch (Exception ex) { Debug.WriteLine(ex.StackTrace); Util.InterThreadWarning(ex.Message); return(RemotePortForwardingReply.Reject( RemotePortForwardingReply.Reason.AdministrativelyProhibited, "rejected")); } }
public SynchronizedSSHChannel(ISSHChannel ch) { _channel = ch; _closed = false; }
public RemotePortForwardingReply OnRemotePortForwardingRequest(RemotePortForwardingRequest request, ISSHChannel channel) { try { if (!_profile.AllowsForeignConnection && !IsLoopbackAddress(request.OriginatorIp)) { return RemotePortForwardingReply.Reject( RemotePortForwardingReply.Reason.AdministrativelyProhibited, "rejected"); } Socket local = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); local.Connect(new IPEndPoint(Util.ResolveHost(_profile.DestinationHost), _profile.DestinationPort)); var newChannel = new Channel( _profile.SSHHost, _profile.DestinationHost, (int)channel.LocalChannel, channel, local); newChannel.StartAsyncReceive(); return RemotePortForwardingReply.Accept(newChannel); } catch (Exception ex) { Debug.WriteLine(ex.StackTrace); Util.InterThreadWarning(ex.Message); return RemotePortForwardingReply.Reject( RemotePortForwardingReply.Reason.AdministrativelyProhibited, "rejected"); } }
/// <summary> /// Opens channel. /// </summary> /// <param name="connection">SSH connection object</param> /// <param name="command">Remote command</param> /// <param name="millisecondsTimeout">timeout in milliseconds</param> /// <exception cref="SCPClientInvalidStatusException">Channel has been already opened or already closed.</exception> /// <exception cref="SCPClientTimeoutException">Timeout has occurred while waiting for READY status.</exception> public void Open(ISSHConnection connection, string command, int millisecondsTimeout) { if (_status != StreamStatus.NotOpened) throw new SCPClientInvalidStatusException(); ISSHChannel channel = null; SCPClientChannelEventHandler eventHandler = connection.ExecCommand( (ch) => { channel = ch; return new SCPClientChannelEventHandler( new DataReceivedDelegate(OnDataReceived), new ChannelStatusChangedDelegate(OnChannelStatusChanged) ); }, command ); _eventHandler = eventHandler; _channel = channel; if (!_eventHandler.WaitStatus(SCPChannelStatus.READY, millisecondsTimeout)) { throw new SCPClientTimeoutException(); } lock(_statusSync) { if (_status == StreamStatus.NotOpened) { _status = StreamStatus.Opened; } } }
public ChannelEntry(ISSHChannel channel, ISSHChannelEventHandler handler) { this.Channel = channel; this.EventHandler = handler; }
/// <summary> /// Constructor /// </summary> /// <param name="channel">channel object</param> /// <param name="authKeyProvider">authentication key provider</param> public OpenSSHAgentForwardingMessageHandler(ISSHChannel channel, IAgentForwardingAuthKeyProvider authKeyProvider) { _channel = channel; _authKeyProvider = authKeyProvider; }
/// <summary> /// Constructor /// </summary> /// <param name="channel">SSH2 channel object</param> /// <param name="eventHandler">event handler object</param> private SFTPClient(ISSHChannel channel, SFTPClientChannelEventHandler eventHandler) { this._channel = channel; this._eventHandler = eventHandler; }
public SSHChannelHandler(ISSHChannel channelOperator, Action onNormalTermination, Action<string> onAbnormalTermination) { _channelOperator = channelOperator; _onNormalTermination = onNormalTermination; _onAbnormalTermination = onAbnormalTermination; }
public RemotePortForwardingReply OnRemotePortForwardingRequest(RemotePortForwardingRequest request, ISSHChannel channel) { // exception is not handled here. // caller should handle exception appropriately. return(_coreHandler.OnRemotePortForwardingRequest(request, channel)); }
/// <summary> /// Add new channel. /// </summary> /// <param name="channel">channel</param> /// <param name="eventHandler">channel handler</param> public void Add(ISSHChannel channel, ISSHChannelEventHandler eventHandler) { uint channelNumber = channel.LocalChannel; var entry = new ChannelEntry(channel, eventHandler); _dic.TryAdd(channelNumber, entry); #if DEBUG_REPORT_SSHCHANNELS Debug.WriteLine("** CHANNEL ADD " + channelNumber.ToString() + " { " + String.Join(", ", _dic.Keys.OrderBy(n => n).Select(n => n.ToString())) + " }"); #endif }
/// <summary> /// Remove channel. /// </summary> /// <param name="channel">channel</param> public void Remove(ISSHChannel channel) { uint channelNumber = channel.LocalChannel; ChannelEntry entry; _dic.TryRemove(channelNumber, out entry); #if DEBUG_REPORT_SSHCHANNELS Debug.WriteLine("** CHANNEL REMOVE " + channelNumber.ToString() + " { " + String.Join(", ", _dic.Keys.OrderBy(n => n).Select(n => n.ToString())) + " }"); #endif }
public SSHChannelHandler(ISSHChannel channelOperator, Action onNormalTermination, Action <string> onAbnormalTermination) { _channelOperator = channelOperator; _onNormalTermination = onNormalTermination; _onAbnormalTermination = onAbnormalTermination; }
public RemotePortForwardingReply OnRemotePortForwardingRequest(RemotePortForwardingRequest request, ISSHChannel channel) { // exception is not handled here. // caller should handle exception appropriately. return _coreHandler.OnRemotePortForwardingRequest(request, channel); }
internal void OpenForTest(SSHChannel dummyChannel) { if (_status != StreamStatus.NotOpened) throw new SCPClientInvalidStatusException(); SCPClientChannelEventReceiver channelReceiver = new SCPClientChannelEventReceiver( new DataReceivedDelegate(OnDataReceived), new ChannelStatusChangedDelegate(OnChannelStatusChanged) ); _channelReceiver = channelReceiver; _channel = dummyChannel; lock (_statusSync) { if (_status == StreamStatus.NotOpened) { _status = StreamStatus.Opened; } } }
/// <summary> /// Gets a channel event handler for processing the X11 forwarding. /// </summary> /// <remarks> /// This method will be called when the new X11 forwarding channel is created. /// </remarks> /// <param name="channel">channel object</param> /// <returns>a handler object if the connection to the X server was established successfully. otherwise null.</returns> public ISSHChannelEventHandler CreateChannelHandler(ISSHChannel channel) { if (_socketFactory == null) { _protocolEventManager.Trace("[X11] No socket factory"); return null; } var socket = _socketFactory(); try { socket.Connect(_param.Display); } catch (Exception e) { Debug.WriteLine(e.Message); Debug.WriteLine(e.StackTrace); _protocolEventManager.Trace("[X11] Failed to connect to the X server : {0}", e.Message); return null; } _protocolEventManager.Trace("[X11] Connected to the X server."); return new X11ChannelHandler(channel, socket, _spoofedAuthProtocolName, _spoofedAuthCookie, _xAuthProtocolName, _xAuthCookie); }