Skip to content

ssh: Add knownhosts and agent modules - #15

Open
pjbgf wants to merge 2 commits into
mainfrom
ssh-helpers
Open

pjbgf wants to merge 2 commits into
mainfrom
ssh-helpers

Conversation

@pjbgf

@pjbgf pjbgf commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Companion to go-git/go-git#2641.

Adds ssh/knownhosts and ssh/agent modules: the full known_hosts and SSH agent implementations go-git vendored from skeema/knownhosts and xanzy/ssh-agent, which go-git v6 moves to internal packages trimmed to its defaults. Neither module depends on go-git. The agent module keeps Pageant and the Windows named pipe and returns an *Agent that owns and closes its connection. Upstream LICENSE files and commits are recorded in each module.

Commits:

  • ssh/knownhosts: Add algorithm-aware known_hosts module
  • ssh/agent: Add SSH agent module with Pageant support

Copilot AI balanced review requested due to automatic review settings November 19, 2026 03:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

go-git v6 stops carrying a vendored copy of github.com/skeema/knownhosts
and imports this module for its default known_hosts checking instead.
Callers can also use it directly to build a host key callback and look
up the host key algorithms known for a host, then set them on go-git's
`HostKeyCallbackHelper`.

The code is go-git's copy of skeema/knownhosts v1.3.0 (commit
9485bdec8ed5), with the go-git trace call removed so the module only
depends on golang.org/x/crypto. Its tests come along, with shadowed
errors and unchecked `Close` calls fixed. The upstream LICENSE and
NOTICE are kept.

The ported files are excluded from the style-only linters so they stay
comparable with upstream. Correctness linters still run on them.

Assisted-by: Claude Opus 5.5
Signed-off-by: Paulo Gomes <paulo@entire.io>
go-git v6 stops exporting its vendored copy of github.com/xanzy/ssh-agent.
Its internal default keeps SSH_AUTH_SOCK and the Windows OpenSSH agent
pipe, and drops Pageant. The full client moves here.

New returns an *Agent that embeds the x/crypto ExtendedAgent and owns
the connection to the agent. Close closes it and is safe to call more
than once. Upstream returned the connection separately, and returned
nil for the Windows named pipe, so the pipe could never be closed.
Pageant has no connection, so Close marks the Pageant adapter closed
and later requests fail with os.ErrClosed, as they do on a closed
pipe. A closed agent never signs. Signers plugs into go-git's
PublicKeysCallback, and AuthMethod into a plain ssh.ClientConfig.
Errors for a missing agent wrap ErrAgentNotFound.

The discovery code comes from go-git's copy of xanzy/ssh-agent v0.3.3
(commit 0fa644ba07f4), with the go-git trace calls removed. The
upstream LICENSE and the MIT headers of the Windows files are kept.
The Pageant mapping now builds its slice with unsafe.Slice so go vet
passes on Windows. The Pageant size limit and errors, exported only on
Windows upstream, are unexported. Callers only ever saw them wrapped
by the agent client, and the first tag of the module would freeze
them. The Pageant query also checks the message length before reading
its length prefix.

go-git has no tests for this code. New tests serve an in-memory keyring
over a Unix socket, or a named pipe on Windows, and check the signers,
an SSH handshake through AuthMethod, and that Close releases the
connection or, for Pageant, makes later requests fail. The existing CI
matrix already runs every module on windows-latest.

Assisted-by: Claude Opus 5.5
Signed-off-by: Paulo Gomes <paulo@entire.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants