API Reference
StreamSec.SSH.Client
SSH Client Component Unit
Feature notes: SSH implementation notes
Classes, interfaces and records
classTstCustomSSHClient
inherits from TstCustomSSH
implements iSSHGetAuthData, iSSHClient
constructor Create(aOwner: TComponent); override;
Standard component constructor. Seeds the client defaults an app relies on: 1 MB channel window, 32 KB packet size, MaxChannels=16 and (on Win32) an INFINITE channel read timeout. Apps normally drop the component and let this run rather than calling it explicitly.
» member page
destructor Destroy; override;
Closes any live connection (see Close) before the component is freed; an app does not call this directly. Not supported while ConnectToHost, Login or RequestService runs on another thread: the call would go on with a client that has been freed.
» member page
procedure SuggestRequiredUnits(aProc: tGetStringMethod); override;
procedure ConnectToHost;
Step 1 of the connect sequence: opens the transport socket and runs the SSH version exchange plus key exchange (host-key verification, cipher/MAC/kex negotiation from the option lists).
Full description »
function RequestService(const aServiceName: string): Boolean;
Sends an SSH service-request for an arbitrary service name after ConnectToHost. Login already requests 'ssh-userauth' and 'ssh-connection' for you, so an app only needs this to reach a non-standard service; requesting 'ssh-connection' here also spins up the channel Broker. A Close from another thread cancels it as it cancels ConnectToHost, and then no Broker is made.
» member page
function Login(const aUsername: string; const aService : string = '') : Boolean;
Step 2: authenticates as aUsername, running the methods configured in UserAuthOptions (publickey via ClientKey, password via Password / OnGetClientPassword, etc.) until one succeeds.
Full description »
function CreateChannel(aWindowSize, aPacketSize: Integer) : iSSHClientChannel; overload;
Step 3: opens a new session channel with an explicit flow-control window and maximum packet size, then connects it. Use the parameterless overload to take DefaultWindowSize/DefaultPacketSize. Requires a prior successful Login (raises otherwise). This is the app's entry point for running a shell/exec/subsystem on the channel returned.
» member page
function CreateChannel: iSSHWindowedChannel; overload;
Convenience session-channel opener using DefaultWindowSize/DefaultPacketSize; the common case for opening a shell or exec channel.
» member page
function CreateChannel(const aHostToConnect : string; aPortToConnect : UInt32; const aOriginatorAddress: string; aOriginatorPort : UInt32) : iSSHClientChannel; overload;
Opens a "direct-tcpip" channel: the client asks the server to connect onward to aHostToConnect:aPortToConnect and tunnels that TCP stream over SSH (local port forwarding, -L in OpenSSH terms). aOriginatorAddress/Port describe the local peer for logging. Uses the default window/packet sizes.
» member page
function CreateChannel(aWindowSize, aPacketSize: Integer; const aHostToConnect : string; aPortToConnect : UInt32; const aOriginatorAddress: string; aOriginatorPort : UInt32) : iSSHClientChannel; overload;
Same direct-tcpip forwarding channel as above but with an explicit window and packet size; use when the default sizes are unsuitable for the tunnelled load.
» member page
function GlobalRequest(const aRequestName : string; const aWantReply : Boolean; const aRequestData : tBytes; out aResponseData: tBytes) : Boolean;
Sends a connection-wide (not per-channel) global request, e.g. "tcpip-forward" to set up remote port forwarding (-R). With aWantReply=True it blocks for the reply and returns success plus aResponseData. Requires a prior Login (raises otherwise). Routed through the channel Broker.
» member page
procedure AddListener(const aListener: iSSHListenerClient);
Registers a listener that the server can open channels toward, i.e. the sink for server-initiated "forwarded-tcpip" channels after a tcpip-forward GlobalRequest (remote forwarding). Requires a prior Login (raises otherwise).
» member page
procedure RemoveListener(const aListener: iSSHListenerClient);
Unregisters a listener previously passed to AddListener; a no-op if not connected/logged in.
» member page
procedure Close;
Tears the connection down: sends SSH_MSG_DISCONNECT if the connection is still up, closes the socket and stops/frees the channel Broker thread.
Full description »
property Connected: Boolean read GetConnected;
True from the moment ConnectToHost has made its transport, before it connects (independent of whether Login has run). Poll this to know if the component currently holds a live connection. False again once Close has closed it, or once a call that Close cancelled has ended.
» member page
property Broker: tSSHClientChannelBroker read fChannelBroker;
The channel broker created on a successful Login; owns all open channels and dispatches incoming ones. Read-only; an app uses it directly only for lower-level channel/listener management beyond the CreateChannel helpers.
» member page
property Password: string read fPassword write SetPassword;
The password used for 'password' authentication during Login when set non-empty (and it is not a change-password prompt). Leave empty to source the password from the OnGetClientPassword callback instead. Client-side credential.
» member page
property KexOptions;
Ordered list of key-exchange algorithms the client offers (and their preference). Edit to enable/disable or reorder kex methods (e.g. to require a post-quantum or curve25519 kex); the negotiated one is chosen during ConnectToHost.
» member page
property CipherC2SOptions;
Client-to-server bulk cipher options: the symmetric ciphers the client offers for data it sends. Reorder/disable to enforce a cipher policy on the outbound direction.
» member page
property CipherS2COptions;
Server-to-client bulk cipher options: the ciphers the client accepts for inbound data. Kept separate from C2S because SSH negotiates each direction independently.
» member page
property MacC2SOptions;
Client-to-server MAC options (integrity of outbound records). Ignored for an AEAD cipher that carries its own tag; otherwise set the accepted HMAC list.
» member page
property MacS2COptions;
Server-to-client MAC options (integrity of inbound records); the inbound counterpart of MacC2SOptions.
» member page
property CompressionC2SOptions;
Client-to-server compression options; typically "none" plus optional zlib. Enable per your policy for outbound data.
» member page
property CompressionS2COptions;
Server-to-client compression options; the inbound counterpart of CompressionC2SOptions.
» member page
property ServerKeyOptions;
The set of server host-key (signature) algorithms the client will accept and verify during ConnectToHost.
Full description »
property ServerDSSKey;
Pins the server's expected DSS/DSA host key. Assign to verify the server against a known key instead of accepting any key; this replaces the ssh-dss entries in ServerKeyOptions. On the client this is a verify-only public key. A component that yields no DSA key for ServerDSSKeyIdentifier pins nothing and accepts nothing: the component stays assigned and no ssh-dss entry is registered.
» member page
property ServerDSSKeyIdentifier;
Selects which stored key the ServerDSSKey component should use, by identifier, when that component holds more than one key.
» member page
property ServerRSAKey;
Pins the server's expected RSA host key (see ServerDSSKey). Client-side this is used only to verify the server's signature, never to sign.
» member page
property ServerRSAKeyIdentifier;
Identifier selecting the specific key within the ServerRSAKey component.
» member page
property ServerEdDSAKey;
Pins the server's expected Ed25519/Ed448 host key for verification (see ServerDSSKey). The algorithm name, ssh-ed25519 or ssh-ed448, is taken from the key's curve. A TstEdDSAPublicKey or a TstSSHPublicKeyList holding the server's public key is what a client normally assigns.
» member page
property ServerEdDSAKeyIdentifier;
Identifier selecting the specific key within the ServerEdDSAKey component.
» member page
property ServerECDSAKey;
Pins the server's expected ECDSA (nistp256/384/521) host key for verification (see ServerDSSKey). The algorithm name is taken from the key's curve. A TstECDSAPublicKey or a TstSSHPublicKeyList holding the server's public key is what a client normally assigns.
» member page
property ServerECDSAKeyIdentifier;
Identifier selecting the specific key within the ServerECDSAKey component.
» member page
property VersionClient;
The SSH identification banner this client sends (defaults to "SSH-2.0-StreamSecTools4.0"). Override to masquerade or advertise a custom client version. On the client this is the string SENT; the server side uses its own VersionServer.
» member page
property MaxChannels;
Upper bound on concurrently open channels for this connection (default 16), used to size the channel Broker created at Login. Raise it if the app opens many simultaneous sessions/forwards.
» member page
property DefaultWindowSize;
Default per-channel flow-control window (default 1 MB) used by the parameterless CreateChannel overloads. Larger windows improve throughput on high-latency links at the cost of memory.
» member page
property DefaultPacketSize;
Default maximum SSH packet size (default 32 KB) for channels opened without an explicit size.
» member page
property ChannelReadTimeout: Cardinal read fChannelReadTimeout write SetChannelReadTimeout {$IFDEF WIN32}default INFINITE{$ENDIF};
Blocking timeout (ms) for reads on channels; propagated to the Broker at Login. Defaults to INFINITE on Win32 so a channel read waits indefinitely; set a finite value to make channel reads time out.
» member page
property ClientKey: TstCustomMPKey read fClientKey write SetClientKey;
The client's own key component used for 'publickey' authentication during Login. Assign the private-key holder (RSA/ECDSA/EdDSA/DSS); the matching SSH public-key wire format is selected automatically. Required only when UserAuthOptions includes publickey.
» member page
property ClientKeyIdentifier: string read fClientKeyIdentifier write SetClientKeyIdentifier;
Identifier selecting which key inside ClientKey to use when that component stores several (passed through to the key component's GetKey).
» member page
property UserAuthOptions: tSSHClientUserAuthOptionList read fUserAuthOptions write SetUserAuthOptions;
The ordered list of user-authentication methods the client attempts during Login. RegisterDefaultOptions seeds 'password' and 'publickey' (the two methods the client auth layer implements). Configure this to match what the server allows and the credentials the app has provided.
» member page
property OnSetKey;
Fires while the server's host key is being installed during key exchange, letting the app inspect the key and accept or reject it (the hook for a trust-on-first-use / known-hosts prompt). Set aOK False in the handler to abort the connection.
» member page
property OnServerHelloString: tStringEvent read fOnServerHelloString write SetOnServerHelloString;
Fires during ConnectToHost with each line the server sends before its version string (RFC 4253 section 4.2: lines that do not begin with "SSH-"), on the connecting thread. Use it to log or show them. At most 1,024 such lines are read; one more ends the connection with SSH_MSG_DISCONNECT reason 8 (protocol version not supported).
» member page
property OnDebug: tDebugEvent read fOnDebug write SetOnDebug;
Fires when the server sends an SSH_MSG_DEBUG packet. Use it to surface server-side debug/diagnostic text (aAlwaysDisplay signals messages the server asks be shown to the user).
» member page
property OnSetBanner: tSetBannerEvent read fOnSetBanner write SetOnSetBanner;
Fires when the server sends an authentication banner (SSH_MSG_USERAUTH_BANNER), e.g. a legal/login notice, during Login. Display aBanner to the user.
» member page
property OnGetClientPassword: tGetClientPasswordEvent read fOnGetClientPassword write SetOnGetClientPassword;
Called during 'password' authentication when Password is empty (or a change-password is requested) to obtain the password interactively. Return it in the var parameter; aChange indicates the server is asking for a new password. The provided string is wiped after use.
» member page
classTstCustomTCPSSHClient
inherits from TstCustomSSHClient
property Host: string read GetHost write SetHost;
Target hostname or IP the client connects to. This is the abstract TCP base: GetHost/SetHost here are empty virtual stubs, so a concrete descendant that owns a real socket (TstSSHSocketClient) overrides them to store the value on its transport. An application sets Host before calling ConnectToHost/Login.
» member page
property Port: Integer read GetPort write SetPort default 22;
Target TCP port (SSH default 22). As with Host, the getter/setter are virtual: here SetPort does nothing and GetPort just returns 22, so a socket-owning descendant (TstSSHSocketClient) overrides both to store the value on its socket. Set it before connecting.
» member page
inherits from TstCustomSSHClient
property OnRawConnect;
Fires once the outbound TCP connection to the server is established, before the SSH handshake begins. Use it to note the transport is up (e.g. start a connect-time timeout or update UI) independently of Login completing. This is the client's outbound-connect counterpart to the server-side OnRawAccept.
» member page
property OnRawClose;
Fires when the client-side socket closes, whether from an explicit Close/ Destroy or a connection failure. Use it to react to disconnection (e.g. update UI state or trigger a reconnect).
» member page
property OnRawRecvLength;
Fires when the client asks the socket how many bytes are available to read without blocking. Of interest mainly for the same raw-traffic instrumentation as OnRawSend/OnRawRecv; rarely needed by ordinary application code.
Full description »
property OnRawRecv;
Fires after each raw byte receive on the underlying TCP socket. Together with OnRawSend this lets an application observe or capture the raw encrypted SSH stream, e.g. for logging or a custom traffic monitor.
» member page
property OnRawSend;
Fires after each raw byte send on the underlying TCP socket. Useful to log, meter, or packet-capture the encrypted SSH wire traffic (bandwidth accounting or transport troubleshooting) without needing to understand SSH framing.
» member page
Types (enumerations, sets, aliases)
proctStringEvent
tStringEvent = procedure (Sender: TObject; const aStr: string) of object;
proctDebugEvent
tDebugEvent = procedure (Sender: TObject;
aAlwaysDisplay: Boolean;
const aMessage : string;
const aLanguageTag : string) of object;
proctSetBannerEvent
tSetBannerEvent = procedure (Sender : TObject;
const aBanner: string;
const aLang : string) of object;
proctGetClientPasswordEvent
tGetClientPasswordEvent = procedure (Sender : TObject;
const aUsername: string;
aChange : Boolean;
var aPassword: string) of object;
proctGetAuthDataEvent
tGetAuthDataEvent = procedure(Sender : TObject;
const aUsername: string;
const aMethod : string;
aChange : Boolean;
var aResult : tBytes) of object;