1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 03:22:48 -05:00

Stream-oriented agent forwarding on Unix.

Historically, because of the way Windows Pageant's IPC works, PuTTY's
agent forwarding has always been message-oriented. The channel
implementation in agentf.c deals with receiving a data stream from the
remote agent client and breaking it up into messages, and then it
passes each message individually to agent_query().

On Unix, this is more work than is really needed, and I've always
meant to get round to doing the more obvious thing: making an agent
forwarding channel into simply a stream-oriented proxy, passing raw
data back and forth between the SSH channel and the local AF_UNIX
socket without having to know or care about the message boundaries in
the stream.

The portfwdmgr_connect_socket() facility introduced by the previous
commit is the missing piece of infrastructure to make that possible.
Now, the agent client module provides an API that includes a callback
you can pass to portfwdmgr_connect_socket() to open a streamed agent
connection, and the agent forwarding setup function tries to use that
where possible, only falling back to the message-based agentf.c system
if it can't be done. On Windows, the new piece of agent-client API
returns failure, so we still fall back to agentf.c there.

There are two benefits to doing it this way. One is that it's just
simpler and more robust: if PuTTY isn't trying to parse the agent
connection, then it has less work to do and fewer places to introduce
bugs. The other is that it's futureproof against changes in the agent
protocol: if any kind of extension is ever introduced that requires
keeping state within a single agent connection, or that changes the
protocol itself so that agentf's message-boundary detection stops
working, then this forwarding system will still work.
This commit is contained in:
Simon Tatham
2020-01-01 16:46:44 +00:00
parent 09954a87c2
commit ae1148267d
5 changed files with 105 additions and 3 deletions

View File

@ -125,17 +125,48 @@ static void agent_select_result(int fd, int event)
agent_cancel_query(conn);
}
static const char *agent_socket_path(void)
{
return getenv("SSH_AUTH_SOCK");
}
struct agent_connect_ctx {
SockAddr *addr;
};
Socket *agent_connect(void *vctx, Plug *plug)
{
agent_connect_ctx *ctx = (agent_connect_ctx *)vctx;
return sk_new(ctx->addr, 0, false, false, false, false, plug);
}
agent_connect_ctx *agent_get_connect_ctx(void)
{
const char *path = agent_socket_path();
if (!path)
return NULL;
agent_connect_ctx *ctx = snew(agent_connect_ctx);
ctx->addr = unix_sock_addr(path);
return ctx;
}
void agent_free_connect_ctx(agent_connect_ctx *ctx)
{
sk_addr_free(ctx->addr);
sfree(ctx);
}
agent_pending_query *agent_query(
strbuf *query, void **out, int *outlen,
void (*callback)(void *, void *, int), void *callback_ctx)
{
char *name;
const char *name;
int sock;
struct sockaddr_un addr;
int done;
agent_pending_query *conn;
name = getenv("SSH_AUTH_SOCK");
name = agent_socket_path();
if (!name || strlen(name) >= sizeof(addr.sun_path))
goto failure;