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)
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);
procedure SignalPeerClosed;
property ConnectTimeout: Cardinal read fConnectTimeout write fConnectTimeout;
property ReadTimeout: Cardinal read fReadTimeout write fReadTimeout;
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);
function SendHeartbeat: Boolean;
function ReadRequest(const aRequest: TsnifRequest): Boolean; override;
function ReadResponse(const aResponse: TsnifResponse): Boolean; override;
function WaitForMessage: TsnipMessageKind; override;
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;
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;
procedure Detach;
function WaitData(aMSec: Cardinal): TsnipWaitOutcome;
function ReadRequest(const aRequest: TsnifRequest): Boolean; override;
function ReadResponse(const aResponse: TsnifResponse): Boolean; override;
function WaitForMessage: TsnipMessageKind; override;
property RemoteAddress: string read GetRemoteAddress;
property TransportInfo: iTLSConnectionInfo read GetTransportInfo;
property PeerCertificate: iCertificate read GetPeerCertificate;