Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.Snip.TLSOctetConnection

The snip octet connection carried over TLS, in both roles.

  This is the TLS counterpart of StreamSec.Snip.SSHOctetConnection: it supplies
  the five Raw* transport primitives that TsnipBaseOctetConnection frames snip
  messages over, plus the IsnifChannelBinding token that the Snif KAPA
  binds its authentication to.

  ONE base, TWO very different plumbings - hence the buffer in the base:

    * CLIENT (TsnipClientTLSOctetConnection) is PULL-driven. It owns a raw
      stSocket and a TLS content layer and refills the buffer itself, blocking
      on the socket, because TsnicClassClient calls SendRequest then sits in
      WaitForMessage/ReadResponse on the application's own thread.

    * SERVER (TsnipServerTLSOctetConnection) is PUSH-driven. It hangs off an
      iAppTransport belonging to the async TLS server, whose reactor hands it
      already-decrypted plaintext on an I/O thread (AddIn) and must never be
      blocked. The snip/Snif request loop therefore runs on its own thread and
      blocks in WaitForFrame, which waits on the buffer's event.

  EVERY WAIT HERE IS THREE-VALUED (TsnipWaitOutcome), because the two ways a
  wait can come back empty need opposite answers: a bound that expired leaves a
  connection that is still usable, while a closed transport does not, and a
  Boolean makes the first indistinguishable from the second. The bounds
  themselves are off by default - ConnectTimeout and ReadTimeout are whatever
  the owning component stamps on - so an unbounded wait is still exactly the
  wait this transport always had.

  Both ends read through the same buffer and the same framing, so the wire
  format is identical to the SSH transport's.

  CHANNEL BINDING: GetChannelBinding returns the RFC 9266 'tls-exporter' token -
  RFC 8446 sec.7.5 TLS-Exporter('EXPORTER-Channel-Binding', "", 32) - taken from
  the live TLS connection at each end. Because a TLS 1.3 exporter value is a
  function of the exporter_master_secret, an attacker who terminates one TLS
  connection and opens another cannot make the two tokens agree, which is what
  stops a KAPA response being relayed across channels. It is EMPTY on anything
  but a completed TLS 1.3 handshake, and every consumer fails closed on empty -
  so a snip-over-TLS deployment that must authenticate with KAPA requires
  TLS 1.3 (the default for both components in this framework).

Feature notes: Snif remoting framework (concepts)

Classes, interfaces and records

classTsnipTLSOctetConnection

inherits from TsnipBaseOctetConnection

implements IsnifChannelBinding

Transport-neutral half of the snip-over-TLS connection: the inbound plaintext buffer, the Raw* implementations on top of it, and the channel binding. A descendant supplies the four Transport* primitives and (if it is pull-driven) a Refill.

constructor Create; destructor Destroy; override; procedure AddIn(aData: Pointer; aLen: Integer);
Appends decrypted inbound plaintext and wakes a blocked reader. Called by the push-driven server end from the reactor's I/O thread; harmless (but unused) on the client end.
procedure SignalPeerClosed;
Marks the inbound direction finished and wakes any blocked reader, so WaitForFrame stops rather than parking forever.
property ConnectTimeout: Cardinal read fConnectTimeout write fConnectTimeout;
Milliseconds the ROLE HANDSHAKE may wait for the peer's connect (server end) or accept (client end) frame. Full description »
property ReadTimeout: Cardinal read fReadTimeout write fReadTimeout;
Milliseconds an ORDINARY read may wait for the next frame once the role handshake is done. cSnipNoTimeout - the default - waits for ever, because a snip connection is SUPPOSED to sit quiet: it exists so either end can speak later, and a long-poll consumer would be broken by a bound it never asked for. Set it when the application knows its own traffic pattern.

classTsnipClientTLSOctetConnection

inherits from TsnipTLSOctetConnection

CLIENT end: owns a connected stSocket and the TLS client content layer that was handshaked over it, and drives both itself. Hand it a socket + layer that are already through the TLS handshake; it takes over their lifetime.

constructor Create; destructor Destroy; override; procedure Connect(aSocket: tAbstractSocket; aLayer : TCustomTLS_ContentLayer);
Takes ownership of aSocket and aLayer - both must already be through the TLS handshake - and runs the snip connect exchange over them.
function SendHeartbeat: Boolean;
Sends ONE empty TLS application-data record (RFC 8446 permits zero-length application_data fragments): authenticated traffic that re-arms the peer's idle deadline and any NAT binding on the path, yet delivers ZERO application bytes, so neither snip end ever sees it. Full description »
function ReadRequest(const aRequest: TsnifRequest): Boolean; override; function ReadResponse(const aResponse: TsnifResponse): Boolean; override; function WaitForMessage: TsnipMessageKind; override;

interfaceIsnipTLSTransportInfo

WHAT THE TLS HANDSHAKE UNDER A SNIP CONNECTION DECIDED, reached the way a snif service method reaches the channel binding - by Supports on TsnifClassServer.CurrentContext.Connection:

var lInfo: IsnipTLSTransportInfo; if Supports(TsnifClassServer.CurrentContext.Connection, IsnipTLSTransportInfo,lInfo) and (lInfo.TransportInfo <> nil) then lCert := lInfo.TransportInfo.PeerCertificate;

TsnipTLSServer.CurrentTransportInfo and CurrentPeerCertificate do exactly that for the calling thread. Only the server end implements it: on the client end the peer is the server, whose certificate the client's own engine checked against the host name it was given.

function GetTransportInfo: iTLSConnectionInfo; property TransportInfo: iTLSConnectionInfo read GetTransportInfo;
The async TLS server's iTLSConnectionInfo for the connection this snip channel runs on, or nil when the transport offers none. Same contract as there: it reads through to the live TLS session, answers its empty values once that session has closed, and the certificate it reports has already passed the engine's trust configuration.

classTsnipServerTLSOctetConnection

SERVER end: hangs off an async-TLS-server iAppTransport. Plaintext is pushed in with AddIn from the reactor thread; the snip request loop runs on the session's own thread (see StreamSec.Snip.TLSServer). Mirrors TsnipServerSSHOctetConnection, including its request/response demultiplexing for server-initiated callbacks into the client.

constructor Create; destructor Destroy; override; procedure Connect(const aTransport: iAppTransport); virtual;
Binds to the transport and runs the snip accept exchange. Blocks until the client's connect message arrives, so call it from the serving thread.
procedure Detach;
Marks the connection finished and unblocks the serving thread. Called from the reactor's I/O thread when the TLS session closes. Full description »
function WaitData(aMSec: Cardinal): TsnipWaitOutcome;
Blocks until a complete inbound snip frame is buffered, aMSec expires, or the connection ends, and says WHICH. Full description »
function ReadRequest(const aRequest: TsnifRequest): Boolean; override; function ReadResponse(const aResponse: TsnifResponse): Boolean; override; function WaitForMessage: TsnipMessageKind; override; property RemoteAddress: string read GetRemoteAddress;
The peer's address as the transport reports it, or '' when there is no transport yet or it has already gone. Full description »
property TransportInfo: iTLSConnectionInfo read GetTransportInfo;
What the TLS handshake decided - see IsnipTLSTransportInfo. nil before Connect, and when the transport does not implement iTLSConnectionInfo (every transport TsmAsyncTLSServer creates does). Taken once in Connect and kept for the life of this object, so it is safe to read from any thread once Connect has returned; its members answer their empty values after the TLS session has closed.
property PeerCertificate: iCertificate read GetPeerCertificate;
The certificate the client authenticated with when the server requested one (mTLS), nil otherwise and after the TLS session has closed. Full description »