ddn.net.ssh.agent_client

Asynchronous ssh-agent client over a supplied byte transport.

The client drives the OpenSSH agent protocol (identity listing and signing) over any SshTransport: the Unix connector in this module, the EVE adapter, or scripted transports in tests. All operations are non-blocking: pump moves bytes and advances one step; callers poll progress afterwards.

The client never opens sockets itself and never blocks on user confirmation - an agent holding back a signature until the user approves simply surfaces as SshAgentProgress.waiting.

Types 5

Progress of an agent operation.

wouldBlockOperation is running and needs transport readiness
doneOperation completed successfully
errorThe operation failed with a typed error

An in-flight or completed agent operation.

Fields
private SshAgentProgress progress_
private string errorMessage_
private SshAgentIdentitiesAnswer identities_
private SshAgentSignAnswer signature_
private bool isSign_
Methods
SshAgentProgress progress() @property constReturns: current progress.
bool done() @property constReturns: whether the operation reached a terminal state.
string errorMessage() @property constReturns: the error message when progress is error.
const(SshAgentIdentitiesAnswer) identities() @property constReturns: the listed identities (valid when done and the operation was a listing).
const(SshAgentSignAnswer) signature() @property constReturns: the signature (valid when done and the operation was a sign request).
Constructors

Non-blocking ssh-agent client over a byte transport.

Ownership: the client references but does not own the transport; the caller keeps it alive and closes it.

Fields
private SshTransport transport_
private ubyte[] writeQueue_
private size_t writePos_
private ubyte[] readBuffer_
private SshAgentOperation current_
private const(ubyte)[] signKeyBlob_
private const(ubyte)[] signData_
private uint signFlags_
private Duration operationTimeout_
private MonoTime operationDeadline_
private bool unusable_
Methods
void setOperationTimeout(Duration timeout) @safe pure nothrowSets a deadline applied to every operation started afterwards.
SshAgentOperation requestIdentities()Starts an identity listing.
SshAgentOperation sign(const(ubyte)[] keyBlob, const(ubyte)[] data, uint flags)Starts a signature request.
SshAgentProgress pump()Advances the active operation one step.
private void queueWrite(const(ubyte)[] data) @safe pure
private bool flushWrites() @trusted
private void pumpReads() @trusted
private bool tryDecodeCompleteResponse() @safe
private void fail(string message) @safe
private void requireIdle() @trusted
private void armOperationDeadline() @safe nothrow
Constructors
this(SshTransport transport)Constructs a client over a transport.

An SshSigner backed by an SshAgentClient.

Signing is asynchronous: the first sign call starts the agent request and reports SshProgress.WAIT; later calls pump the agent client and continue the same operation until the agent confirms or fails. The application drives the agent transport independently of the SSH session, so a delayed confirmation (for example a hardware-token approval) never blocks the session pump.

Fields
private SshAgentClient client_
private const(ubyte)[] keyBlob_
private SshPublicKeyInfo publicKey_
private SshAgentOperation pending_
private string pendingAlgorithm_
Methods
SshPublicKeyInfo publicKey() @property constReturns: the public key offer, never null.
SshSignResult sign(scope const(ubyte)[] requestData, string signatureAlgorithm)Signs the request data through the agent, continuing a pending operation when called again.
private SshSignResult signChecked(scope const(ubyte)[] requestData, string signatureAlgorithm)
bool signatureFlagsForTest(string keyAlgorithm, string signatureAlgorithm, out uint flags) static @safe pure nothrowExposes the flag mapping for unittest verification.
private bool signatureFlags(string keyAlgorithm, string signatureAlgorithm, out uint flags) static @safe pure nothrow
Constructors
this(SshAgentClient client, const(ubyte)[] keyBlob, SshPublicKeyInfo publicKey)Constructs a signer for one agent identity.
Fields
private Socket socket_
private bool open_
Methods
ptrdiff_t read(ubyte[] buffer) @safe
ptrdiff_t write(const(ubyte)[] data) @safe
void flush() @safe
void close() @safe
bool isOpen() @property const @safe pure
Constructors
this(Socket socket)Wraps a connected socket.

Functions 3

fnSshTransport connectUnixAgent(string path = null, Duration timeout = Duration.zero)Connects to the agent socket named by SSH_AUTH_SOCK.
private fnbool awaitConnect(int fd, Duration timeout) @trusted nothrow
private fnbool connectSucceeded(int fd) @trusted nothrow