Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.SSH.ClientChannel

Feature notes: SSH implementation notes

Classes, interfaces and records

interfaceiSSHClientChannelEvents

procedure DoConnected(aRemoteChannel : UInt32; aRemoteWindowSize: Integer; aRemotePacketSize: Integer); procedure DoDisconnected(aErrorCode : UInt32; const aErrorMessage: string); procedure DoRequestReply(const aSuccess: Boolean); procedure RemoveFromBroker; procedure IncreaseWindow(aAdd: UInt32); procedure ResetLocalWindow; procedure CloseLocalWindow; procedure WriteChannelData(const aData : tBytes; aOffset: Integer; aCount : Integer); procedure DiscardChannelData(aCount: Integer);
Counts aCount octets of extended data (a server's stderr) against the channel's receive window without keeping them.
procedure ConnectionEnded;
The connection under the channel has ended: the broker's thread has stopped, so nothing more arrives on the channel and nothing can be sent.

interfaceiSSHClient

Minimal client-role abstraction implemented by the SSH client component (TstCustomSSHClient). Code that only needs to open a fresh session channel over an already-authenticated connection can depend on this narrow interface instead of the whole component.

function CreateChannel: iSSHWindowedChannel;
Opens and connects a new "session" channel (using the component's default window/packet sizes) and returns it for running a shell/exec/subsystem. Requires the connection to be authenticated (Login done) so the channel Broker exists; this is purely the client side of the SSH connection.

classtSSHClientChannelBroker

(no public members)

interfaceiSSHClientChannel

inherits from iSSHWindowedChannel

function GetBroker: tSSHClientChannelBroker; function GetErrorCode: UInt32; function GetErrorMessage: string; function GetLocalChannel: UInt32; function GetRemoteChannel: UInt32; function GetRequestState: tRequestState; function GetPeerEOF: Boolean; function GetSessionID: tBytes; procedure ConnectToHost(const aHostToConnect : string; aPortToConnect : UInt32; const aOriginatorAddress: string; aOriginatorPort : UInt32); procedure RequestSubSystem(const aName: string); procedure SendEOF;
Half-close: send SSH_MSG_CHANNEL_EOF, meaning "no more data from us" while staying open to receive. Sending CHANNEL_CLOSE instead is a hard teardown -- RFC 4254 section 5.3 forbids the peer sending after it, so a reply still in flight is lost. Idempotent; ignored once CHANNEL_CLOSE has been sent.
function InputStream: TStream; procedure FreeInputStream(aStream: TStream); property Broker: tSSHClientChannelBroker read GetBroker; property ErrorCode: UInt32 read GetErrorCode; property ErrorMessage: string read GetErrorMessage; property LocalChannel: UInt32 read GetLocalChannel; property RemoteChannel: UInt32 read GetRemoteChannel; property RequestState: tRequestState read GetRequestState; property PeerEOF: Boolean read GetPeerEOF;
True once no more data will arrive: the peer has sent SSH_MSG_CHANNEL_EOF, or SSH_MSG_CHANNEL_CLOSE, or the connection has ended. What had arrived before may still be waiting to be read. EOF does not change State and does not close the channel; see the matching comment on iSSHServerChannel.PeerEOF.
property SessionID: tBytes read GetSessionID;
SessionID: the SSH session identifier (first-KEX exchange hash, bound to the host key). Mirrors the broker's transport SessionID; used as the channel-binding token for the Snif KAPA transcript. Empty if unbound.

interfaceiSSHGetSemaphore

function GetSemaphore: Cardinal;

classtSSHClientChannel

(no public members)

interfaceiSSHListenerClient

Implemented by an object that wants to receive server-INITIATED channel opens on a client connection -- i.e. the sink for "forwarded-tcpip" channels after the client sets up remote (-R) port forwarding with a tcpip-forward GlobalRequest. TstCustomSSHForwardingClient implements this; register it via the client's AddListener / the broker's AddListener. This is a client-side concept (the client is normally the one that opens channels; a listener lets it accept them too).

procedure SetBroker(aBroker: tSSHClientChannelBroker);
Called by AddListener/RemoveListener to hand the listener the broker it is attached to (or nil on detach). An app does not call this directly; the implementer typically re-registers itself on the broker and clears the reference on nil. Internal wiring.
procedure RemoveFromBroker;
Called when the broker is tearing down all channels so the listener can drop its broker reference. Internal cleanup wiring; not an app entry point.
function HandleOpen(const aRequest: string; const aBuf : tBytes; aOffset : Integer; aCount : Integer) : tSSHClientChannel;
Called by the broker's read thread for each inbound SSH_MSG_CHANNEL_OPEN whose channel type matches aRequest (aBuf/aOffset/aCount hold the type-specific open payload, e.g. the connected/originator address+port for "forwarded-tcpip"). Full description »

interfaceiSSHLocalRawEvents

procedure Close; function RecvLength: Integer; function Recv(const aBuffer: tBytes; aOffset, aCount : Integer; aBlock : Boolean = True) : Integer; function Send(const aBuffer: tBytes; aOffset, aCount : Integer) : UInt32;

interfaceiSSHLocalTcpIpRawEvents

inherits from iSSHLocalRawEvents

procedure Connect(const aChannel : iSSHClientChannel; const aHostToConnect : string; aPortToConnect : UInt32; const aOriginatorAddress: string; aOriginatorPort : UInt32);

classeSSHClientChannelError

inherits from Exception

(no public members)

classtSSHClientChannelBroker

inherits from TThread

The per-connection multiplexer for the SSH "ssh-connection" service on the client side. It runs on its own thread reading channel-layer messages (types 80..100) off the transport and dispatching them to the matching channel objects, and it provides the encode-and-send side for opening channels, sending data, adjusting windows and global requests. One broker is created by TstCustomSSHClient on a successful Login and owns all channels of that connection. Apps normally reach it indirectly through the client component's CreateChannel/AddListener/GlobalRequest helpers rather than constructing it themselves.

constructor Create(const aTransport: iSSHtransport; aChannels : Integer);
Creates the broker over an already-established, authenticated transport and starts its read thread immediately. aChannels is the maximum number of concurrent local channels (the local-channel-id space). Called by the client component after Login; apps rarely construct this directly.
destructor Destroy; override;
Stops the read thread and disconnects every remaining channel before freeing. A channel whose own Close is taking it off the broker on another thread meanwhile is waited for, so the broker is not freed under it. An app does not call this directly; the owning client component frees the broker when the connection closes.
function Connect(const aChannel : iSSHClientChannelEvents; const aType : string; aWindowSize : UInt32; aPacketSize : UInt32) : UInt32; overload;
Allocates a free local-channel slot for aChannel and sends SSH_MSG_CHANNEL_OPEN of the given type ('session', 'direct-tcpip', ...) with the requested flow- control window and packet size. Full description »
function Connect(const aChannel : iSSHClientChannelEvents; const aType : string; aWindowSize : UInt32; aPacketSize : UInt32; const aBuf : tBytes) : UInt32; overload;
Same as above but appends aBuf as the channel-type-specific open payload (e.g. the target host/port and originator for a 'direct-tcpip' forwarding channel). Used internally by tSSHClientChannel.ConnectToHost. » member page
function Send(aRemoteChannel: UInt32; const aData : tBytes; aOffset, aCount : Integer) : UInt32;
Sends aCount bytes of channel data on the remote channel id, honoring the channel framing, and returns aCount. Called by tSSHClientChannel.Send (which enforces the remote window); apps write through the channel's iTransport.Send, not here.
procedure IncreaseWindow(aLocalChannel: UInt32; aAdd : UInt32);
Sends a CHANNEL_WINDOW_ADJUST granting the peer aAdd more bytes to send on the channel bound to aLocalChannel, addressed to the peer's number for it, and resets that channel's local receive window. Called by the channel once its whole window has been taken in - data read, extended data discarded; internal flow control.
function GlobalRequest(const aRequestName : string; const aWantReply : Boolean; const aRequestData : tBytes; out aResponseData: tBytes) : Boolean;
Sends a connection-wide (not per-channel) SSH_MSG_GLOBAL_REQUEST, e.g. "tcpip-forward"/"cancel-tcpip-forward" to set up or tear down remote (-R) port forwarding. Full description »
procedure RequestSubSystem(aRemoteChannel: UInt32; const aName: string);
Sends a "subsystem" CHANNEL_REQUEST (want_reply=True) for aName on the remote channel, e.g. to start "sftp". Invoked by tSSHClientChannel.RequestSubSystem; apps request a subsystem through the channel, not the broker directly.
procedure Close(aRemoteChannel: UInt32);
Sends SSH_MSG_CHANNEL_CLOSE to aRemoteChannel, the peer's number for the channel (the protocol's recipient channel). Driven by tSSHClientChannel.Close as part of the channel-teardown handshake; not an app entry point.
procedure SendEOF(aRemoteChannel: UInt32);
Sends SSH_MSG_CHANNEL_EOF ("I will send no more data on this channel").
function GetLocalChannel(aLocalChannel: UInt32): iSSHClientChannel;
Returns the iSSHClientChannel currently bound to aLocalChannel (nil if the slot is empty or the id is out of range). Useful to look up a live channel by its local id, e.g. from a listener that accepted a server-opened channel.
procedure AddListener(const aListener: iSSHListenerClient);
Registers a listener to receive server-initiated channel opens (see iSSHListenerClient / HandleOpen), i.e. the sink for "forwarded-tcpip" remote- forwarding channels. The listener is immediately given this broker via SetBroker. Client-side operation.
procedure RemoveListener(const aListener: iSSHListenerClient);
Removes a previously added listener so it no longer receives server-initiated opens; a no-op if it was never registered.
function GetSessionID: tBytes;
Returns the SSH session identifier (the first key-exchange hash) from the transport, or nil if unbound. Used as a channel-binding token (e.g. in the Snif KAPA transcript). Same value on both peers of the connection.
property ReadTimeout: Cardinal read fReadTimeout write SetReadTimeout;
Timeout, in milliseconds, that a channel's blocking Recv waits for data before returning empty (INFINITE by default). Full description »
property SessionID: tBytes read GetSessionID;
Read-only view of GetSessionID: the connection's SSH session id (first-KEX hash), for channel-binding / diagnostics. Identical on client and server.

classtSSHClientChannel

constructor Create(const aBroker : tSSHClientChannelBroker; aWindowSize: UInt32; aPacketSize: UInt32); destructor Destroy; override;

Types (enumerations, sets, aliases)

enumtRequestState

  tRequestState = (rsNone,rsRequesting,rsSuccess,rsFailure);

typetSSHClientChannelClass

  tSSHClientChannelClass = class of tSSHClientChannel;