Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.Snip.TLSClient

The snip client over TLS - the drop-in counterpart of StreamSec.Snip.Client's
  TsnipClient, with the SSH transport replaced by a raw stSocket carrying TLS.

  Same shape as the SSH client: it descends from TsnicClassClient, builds and
  configures its own transport component in the constructor, publishes that
  component (with an inert setter, because the client owns it), and Start does
  the whole bring-up - connect, handshake, open the snip channel, log the Snif
  user in.

  TWO TIERS, ONE BODY, the same division of labour StreamSec.Mobile.TLSClient
  uses. TsnipCustomTLSClient does all the work and acquires its engine through
  the virtual GetNewTLSServer; TsnipTLSClient overrides that to CREATE AND OWN
  one (the shape described above, unchanged); TsnipAdvancedTLSClient overrides
  nothing there, so it takes an EXTERNAL engine through a settable TLSServer and
  falls back to the process-wide GlobalServer when none is assigned.

  The advanced tier exists because an engine is expensive and a connection is
  not: building and tearing one down costs several times what the handshake it
  serves does, so a process that opens many short-lived snip connections wants
  ONE engine - one set of trust anchors, one client identity, one suite policy -
  behind all of them.

  The transport component here is a TsmSimpleTLSInternalServer. Despite the
  name it is the configuration/identity holder for BOTH TLS roles; this client
  uses its client side (TLSAddClientSession). Reach into it for anything the
  published properties below do not cover: trust anchors
  (LoadRootCertsFromFile), a client identity for mutual TLS (ImportFromPFX),
  suite/group/signature policy (Options).

  TLS 1.3 IS THE POINT, not just a default. The Snif KAPA binds itself to
  the RFC 9266 tls-exporter value of this connection, and that value only exists
  after a TLS 1.3 handshake - see StreamSec.Snip.TLSOctetConnection. KAPA login
  fails closed against a 1.2 peer.

Feature notes: Snif remoting framework (concepts)

Classes, interfaces and records

classTsnipCustomTLSClient

inherits from TsnicClassClient

The body of the client, with no opinion about WHERE its TLS engine comes from: it is acquired through the virtual GetNewTLSServer and reached through ActiveTLSServer, the same seam StreamSec.Mobile.TLSClient's TsmCustomTLSClient uses. Abstract in role rather than in Delphi - it carries no platform attribute and is never registered on the palette; the two tiers below are.

constructor Create(AOwner: TComponent); override;
Constructs the client and, in the self-owning tier, the TsmSimpleTLSInternalServer it configures TLS through. An app rarely calls this directly: it runs when the component is dropped on a form or created in code. Configure trust and (optional) client identity on TLSServer, set Host/Port and the Snif credentials, then Start. » member page
destructor Destroy; override;
Stops a live connection first, as Stop does, while the engine it runs on is still there - so a client may be freed, or freed by its Owner, while it is connected. Then deregisters from a borrowed engine under the engine's notify lock before the inherited teardown, so that freeing a client on any thread cannot damage the free-notification list the other clients of a shared engine use. » member page
procedure Start;
Brings the client fully up: opens the TCP connection, runs the TLS handshake (advertising AlpnToken), opens the snip channel over it, then logs the Snif user in with the Tunnel Bound KAPA using SnifUsername/SnifPassword. Full description »
procedure Stop;
Tears the connection down: closes the snip channel (which sends a TLS close_notify and closes the socket) and detaches it from the client. Freeing the client does the same for a connection that is still up. » member page
function LoginKAPA(const aSecret: tBytes; out aSessionKey: tBytes): Boolean;
The full-control variant of the login Start performs: supply the optional client-side pepper (it must equal the one used at registration; nil when none was used) and receive the negotiated session key. Full description »
procedure StartTransport;
The bring-up half of Start, without the Snif login: connect, handshake and open the snip channel. Use it when the application picks its own authentication (e.g. LoginKAPA, or mutual-TLS-only with no Snif login). » member page
function RecoverAccount: Boolean;
OTP account recovery - the lost-password path (KAPA.txt section 7), driven end to end by this component: 1. Full description »
property MaxFrameSize: Integer read fMaxFrameSize write SetMaxFrameSize default cSnipDefaultMaxFrameSize;
Maximum inbound frame BODY in octets (at least 1; default 16 MiB). TLS/QUIC also use it for the AddIn buffered-plaintext ceiling. A message is one frame: size this for the largest legitimate message, including padding. A peer can make this end buffer about one frame per connection. Changes apply only to connections created afterwards, never to live framers. » member page
property PadRequestsTo: Integer read fPadRequestsTo write fPadRequestsTo default 0;
FRAME PADDING - see TsnipBaseOctetConnection. Zero, the default, changes nothing.

A client pads what it SENDS, which is requests, and may require what it RECEIVES, which is responses. Set the SAME pair here as on the server: which number applies follows from the kind of frame, not from which end you are. » member page
property PadResponsesTo: Integer read fPadResponsesTo write fPadResponsesTo default 0; property RequirePadding: Boolean read fRequirePadding write fRequirePadding default False;
Refuses an inbound response that is not padded to PadResponsesTo. Turn it on once the server pads: a server that stops padding has taken the property away, and without this the client cannot tell. » member page
property Host: string read fHost write SetHost;
Host name or address of the snip server to connect to. When ServerName is empty this is also the name the server certificate must match, so prefer a DNS name over a literal address. » member page
property Port: Word read fPort write SetPort default cSnipDefaultPort;
TCP port of the snip server (default 4443). » member page
property ServerName: string read fServerName write SetServerName;
The name sent as SNI and required of the server certificate. Leave it empty to use Host. Set it when connecting to an address (or through a tunnel) whose certificate carries a different name. » member page
property AlpnToken: string read fAlpnToken write SetAlpnToken;
ALPN identifier offered for snip (default 'snip'). It must match the server plugin's AlpnToken, or the server will not route the connection to its snip protocol. » member page
property SnifUsername: string read fSnifUsername write SetSnifUsername;
Snif (application-layer) credentials. After the snip channel is up, Start runs the Tunnel Bound KAPA login over the remote 'StreamSec.Snif.AkeAuthentication.AkeLogin' object with these; failure drops the connection and raises. They identify the application user, which is distinct from any TLS client certificate the transport authenticated with. » member page
property SnifPassword: string read fSnifPassword write SetSnifPassword;
Snif password paired with SnifUsername; stretched client-side (Argon2id) into the KAPA response and never sent to the server. Set it before Start. » member page
property OnOTPCode: tSnipOTPCodeEvent read fOnOTPCode write fOnOTPCode;
Fired by RecoverAccount once the one-time code has been requested: collect it from the user (modal dialog, console prompt - block as long as needed) and return it in aCode. Set aCancel, or leave aCode empty, to abandon recovery. Fired on RecoverAccount's calling thread. » member page
property OnNewPassword: tSnipNewPasswordEvent read fOnNewPassword write fOnNewPassword;
Fired by RecoverAccount after the one-time code has logged in: collect the replacement password. Set aCancel, or leave aNewPassword empty, to abandon recovery (fails closed; the single-use code is already spent). » member page
property RecoveryHeartbeatInterval: Cardinal read fRecoveryHeartbeatInterval write fRecoveryHeartbeatInterval default cSnipRecoveryHeartbeatMSec;
Milliseconds between the empty TLS records RecoverAccount sends while an event handler waits on the user (default 15000; 0 disables). Each is invisible to the application protocol on both ends but re-arms the server's idle deadline and any NAT binding on the path. » member page
property HandshakeTimeout: Cardinal read fHandshakeTimeout write fHandshakeTimeout default cSnipHandshakeTimeoutMSec;
Milliseconds the WHOLE TLS handshake may take, from the ClientHello to the point the connection is Encrypted (default 20000). Full description »
property ReadTimeout: Cardinal read fReadTimeout write fReadTimeout default cSnipNoTimeout;
Milliseconds a reply may take once the snip channel is up (default 0 = wait for ever), stamped onto the connection at StartTransport. Full description »
property OnConfigureLayer: tSnipTLSLayerEvent read fOnConfigureLayer write fOnConfigureLayer;
Fired on the fresh client session BEFORE the ClientHello is built, right after the base has set OfferTLS13, the host name and the ALPN token - the client-side counterpart of the server's OnTLSAddContentLayer. Full description »
property OnTransportReady: tSnipTLSLayerEvent read fOnTransportReady write fOnTransportReady;
Fired after the TLS handshake has completed and before the snip connect exchange, so the session is fully established and nothing of the application protocol has moved yet. Full description »

classTsnipTLSClient — component reference

inherits from TsnipCustomTLSClient

The self-contained tier: it CREATES AND OWNS the TLS configuration component, so a client dropped on a form works with no other component wired up. Bare name rather than an adjective, matching the client families in this library - the adjective marks the tier that takes an external engine.

property TLSServer;
The TLS configuration and identity component, created and owned here. Reach into it for trust anchors (LoadRootCertsFromFile / LoadTrustedCertsFromFile), a client certificate for mutual TLS (ImportFromPFX) and policy (Options: suites, groups, signature schemes). Full description »

classTsnipAdvancedTLSClient — component reference

inherits from TsnipCustomTLSClient

The tier that takes an EXTERNAL engine, so several clients share one set of trust anchors, one client identity and one suite policy - and pay for building that once instead of once per connection. Leaving TLSServer nil falls back to the process-wide GlobalServer, which is what makes this work with no wiring at all in an application that already has one.

IT NEVER CHANGES THE ENGINE'S ROLE. The engine is the application's and may be accepting connections at the same time, so its ClientOrServer is the application's business - set it to cosClientSide on an engine used only for connecting out. What this tier does do is bring the engine up for client use once (CheckLoaded + TLSSetupClient, the supported route) rather than poking its internals on every connect; see PrepareEngine for why that is the whole of it.

ONE ENGINE, MANY CLIENTS, CONCURRENTLY: each connection gets its own content layer from TLSAddClientSession, and the engine serializes the session list internally, so two clients sharing an engine may hand-shake on two threads. Attaching a client to the engine, re-pointing it and freeing it are serialized against every other client of that engine as well, so clients may be created, pointed at a shared engine and freed on any thread. What is NOT shared is a client instance: one connection at a time, as with the self-owning tier.

DFM NOTE. This tier and TsnipTLSClient publish the same property name with opposite ownership, so changing an existing form's component from one class to the other does not carry the reference across: the self-owning tier's engine is a named child of the client, and a stored "TLSServer = Client1.TLSServer" line cannot resolve against a class that creates no child. It fails quietly - the reference stays nil and this tier falls back to GlobalServer - so re-assign TLSServer after such a change.

property TLSServer;
The TLS configuration and identity component to use, owned by the application (or by another component) and NOT freed here. Full description »

Types (enumerations, sets, aliases)

proctSnipOTPCodeEvent

Account-recovery interaction events (see RecoverAccount). Fired on RecoverAccount's calling thread; the handler may block for as long as the user needs - a background heartbeat keeps the idle connection alive meanwhile. Set aCancel (or return an empty value) to abandon recovery; RecoverAccount then fails closed.

  tSnipOTPCodeEvent = procedure(Sender: TObject; const aUserName: string;
                                var aCode: string;
                                var aCancel: Boolean) of object;

proctSnipNewPasswordEvent

  tSnipNewPasswordEvent = procedure(Sender: TObject; const aUserName: string;
                                    var aNewPassword: string;
                                    var aCancel: Boolean) of object;

proctSnipTLSLayerEvent

The two per-connection TLS hooks as EVENTS, so an application can reach them without descending. The argument list matches StreamSec.Mobile.TLSClient's tTLSClientLayerEvent deliberately: Delphi matches method-pointer types structurally, so ONE handler method can serve a snip client and a protocol client alike - which is what lets an application's resumption-ticket store attach to either. Each is fired by the matching protected virtual AFTER that virtual has done its own work, so a descendant that overrides the virtual and does not call inherited replaces the event along with it.

  tSnipTLSLayerEvent = procedure(Sender: TObject;
                                 const aLayer: TCustomTLS_ContentLayer) of object;