ddn.net.ssh.session

SSH client session implementation.

Drives the SSH protocol over a caller-supplied transport: the identification exchange first, then the packet layer and key exchange phases. The session implements the public ddn.api.net.ssh.SshSession contract; pumping is explicit and every potentially-blocking step reports progress instead of blocking.

The session is single-threaded and non-reentrant, owns all protocol state for the connection, and references - but does not own - the transport.

Types 5

Session limits and defaults from the support matrix.

bytes = 1024UL * 1024 * 1024Rekey after this many bytes sent or received
packets = 1UL << 28Rekey after this many packets in one direction
intervalSeconds = 3600Rekey after this much time
identificationLineMax = 255Maximum identification line length including the terminator
preBannerLinesMax = 64Maximum lines before the identification string
preBannerBytesMax = 8192Maximum total pre-banner bytes
handshakeTimeoutSeconds = 30Default handshake deadline
writeQueueMax = 8 * 1024 * 1024Session write queue bound
stagingMax = 256 * 1024Maximum undecoded bytes staged between the transport and the packet layer; the packet layer re-validates its exact bounds
readBudgetPerPump = 128 * 1024Maximum transport bytes moved into staging per pump call
authAttemptsMax = 20Session-wide authentication attempt bound
keepAliveMaxUnanswered = 3Maximum keepalive requests allowed to stay unanswered

Configurable rekey thresholds (RFC 4253 section 9).

The defaults mirror SshRekeyLimits; every threshold applies to the bytes and packets moved under one installed direction-key set and resets at each NEWKEYS boundary. timeoutSeconds bounds a single rekey exchange against a stalled peer.

Fields
ulong bytesRekey after this many bytes sent or received under one key set
ulong packetsRekey after this many packets sent or received in one direction
long intervalSecondsRekey after this much time since the keys were installed
long timeoutSecondsFail the session when a rekey exchange takes longer than this

Global-request-operation implementation driven by session pumping.

Replies arrive in request order without identifiers; the session keeps the FIFO that pairs them.

Methods
Kind kind() @property constThe request flavour (package bookkeeping).
string bindAddress() @property constThe bind address sent on the wire.
ushort requestedPort() @property constThe requested bind port (0 when allocation was requested).
void completeGlobalReply(bool accepted, ushort allocatedPort)Completes the operation from the peer's reply.
void failLocal(SshError error)Completes the operation with a local failure before sending.
SshProgress progress() @property const
bool done() @property const
SshError error() @property const
bool accepted() @property const
ushort boundPort() @property const
void cancel()
Constructors
this(Kind kind, string bindAddress, ushort requestedPort)Constructs a global request operation.
Nested Templates
KindGlobal request flavour for reply bookkeeping.
Methods
SshSessionImpl create(SshTransport transport, SshAlgorithmPreferences preferences = SshAlgorithmPreferences .recommended()) staticCreates a session over a transport.
SshSessionState state() @property const
SshError sessionError() @property const
void setAlgorithmPreferences(scope const SshAlgorithmPreferences prefs)Sets algorithm preferences before the handshake starts.
void setClock(MonoTime delegate() clock)Sets the monotonic clock used for handshake deadlines.
void setKeepAlive(Duration interval)Configures keepalive requests; the transport phase acts on them.
void setRekeyLimits(SshRekeyConfig config)Configures automatic rekey thresholds; non-positive members revert that threshold to the default.
SshProgress pump()Advances all session state machines by one step.
SshWaitState waitState() @property const
bool rekeying() @property const
void requestRekey()Requests a key re-exchange at the next legal opportunity.
string peerIdentification() @property const
void setHostKeyVerifier(SshHostKeyVerifier verifier)Installs the host-key verifier consulted during key exchange.
void setUsername(string username) @safe pureSets the user name presented during authentication.
SshAuthOperation authenticatePublicKey(SshSigner signer)Starts (or resumes) public-key authentication with an application-owned signer. While an attempt is pending the same operation is returned; protocol requests are never duplicated.
SshAuthOperation authenticatePassword(SshPasswordProvider provider)Starts (or resumes) password authentication with an application-owned credential provider. While an attempt is pending the same operation is returned; protocol requests are never duplicated.
SshAuthOperation authenticateKeyboardInteractive( SshKeyboardInteractiveProvider provider)Starts (or resumes) keyboard-interactive authentication with a non-blocking, application-owned challenge provider.
string username() const @safe pure nothrowReturns: the configured user name.
inout(ubyte[32]) sessionId() inout @safe pure nothrowReturns: the session identifier bytes for signed requests.
void queueAuthPacket(const(ubyte)[] payload) @trustedQueues an authentication packet; a null payload is a no-op used when the request awaits an asynchronous credential.
SshChannelOpenOperation openSessionChannel( scope const SshChannelOpenOptions options = SshChannelOpenOptions .init)Opens a session channel for exec, shell, or subsystem requests.
SshChannelOpenOperation openDirectTcpIpChannel(string host, ushort port, string originatorAddress, ushort originatorPort, scope const SshChannelOpenOptions options = SshChannelOpenOptions .init)Opens a direct TCP/IP channel to a destination reachable from the server.
SshRemoteForwardOperation requestRemoteForward(string bindAddress, ushort bindPort)
SshGlobalRequestOperation cancelRemoteForward(string bindAddress, ushort bindPort)
size_t channelCount() @property const
void disconnect(ushort reason, string description)Disconnects: sends nothing until the packet layer exists, then flushes pending writes and closes the transport.
void queueChannelPacket(const(ubyte)[] payload) @trustedQueues a channel message through the session packet path.
void channelConsumed(SshChannelImpl channel, size_t bytes)Records receive-window consumption by a channel read and sends WINDOW_ADJUST when the threshold is reached.
void grantReceiveCredit(SshChannelImpl channel)Sends an accumulated receive-window re-grant when the channel's pending consumption crossed the replenish threshold.
void channelProtocolViolation(string message)Reports a channel flow-control violation to the session.
bool canQueueChannelBytes(size_t n)Returns: whether a channel packet of n further bytes still fits into the session write-queue budget.
size_t channelBacklogRoom() constReturns: aggregate room available to channel application backlogs.
void reserveChannelBacklog(size_t bytes)Records bytes accepted into a channel-owned backlog.
void releaseChannelBacklog(size_t bytes)Records bytes moved out of a channel-owned backlog.
string serverSignatureAlgorithms() const @propertyReturns: the server's advertised server-sig-algs list, or an empty string when the server did not send EXT_INFO.
void ensureServiceRequested()Sends the ssh-userauth service request once, when authentication starts.
Constructors
this(SshTransport transport, SshAlgorithmPreferences preferences = SshAlgorithmPreferences .recommended())Constructs a session over a transport.
Nested Templates
LineStatus
LineEnd