Skip to content

Commit

Permalink
ssh.PublicKeysCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
abakum committed Jul 17, 2024
1 parent b46b8a7 commit 97e732b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
19 changes: 6 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This repository contains a library for Go that provides a native
[PuTTY][putty] Pageant SSH agent implementation compatible with the
[golang.org/x/crypto/ssh/agent][go-ssh-agent] package.

This package, rather unsuprisingly, only works with Windows.
This package, works with Windows and Unix/Linux platforms.
See below for alternatives on Unix/Linux platforms.

[putty]: https://www.chiark.greenend.org.uk/~sgtatham/
Expand All @@ -34,12 +34,9 @@ func main() {
}
defer agentConn.Close()
sshAgent := agent.NewClient(agentConn)
signers, err := sshAgent.Signers()
if err != nil {
// failed to get signers from Pageant
}

config := ssh.ClientConfig{
Auth: []ssh.AuthMethod{ssh.PublicKeys(signers...)},
Auth: []ssh.AuthMethod{ssh.PublicKeysCallback(sshAgent.Signers)},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
User: "somebody",
}
Expand All @@ -60,11 +57,9 @@ as Pageant, but over a `Unix domain socket` instead of shared memory.
The path to this socket is exposed through the environment variable
`SSH_AUTH_SOCK`.

Replace the connection to Pageant with one to the socket:
```golang
// instead of this:
agentConn, err := pageant.NewConn()
// do this:
// works like
agentConn, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))
```

Expand All @@ -77,12 +72,10 @@ The `ssh-agent` daemon of `OpenSSH for Windows` used `Named Pipe` `\\.\pipe\open
The `sshd` daemon of `OpenSSH for Windows` used `Unix domain socket` like `/tmp/somepath`<br>
for some versions of Windows it works: look `sc query afunix`

Replace the connection to Pageant with one to the socket:
```golang
// instead of this:
agentConn, err := pageant.NewConn()
// do this:
agentConn, err := winio.DialPipe(os.Getenv("SSH_AUTH_SOCK"), nil)
// works like
agentConn, err := winio.DialPipe(`\\.\pipe\openssh-ssh-agent`, nil)
```


Expand Down
17 changes: 9 additions & 8 deletions pageant_ssh_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build sshtest
// +build sshtest

package pageant
Expand All @@ -11,13 +12,13 @@ import (
)

// This test requires all of the following to work:
// - build tag sshtest is active
// - environment variable PAGEANT_TEST_SSH_ADDR is set to a valid SSH
// server address (host:port)
// - environment variable PAGEANT_TEST_SSH_USER is set to a user name
// that the SSH server recognizes
// - Pageant is running on the local machine
// - Pageant has a key that is authorized for the user on the server
// - build tag sshtest is active
// - environment variable PAGEANT_TEST_SSH_ADDR is set to a valid SSH
// server address (host:port)
// - environment variable PAGEANT_TEST_SSH_USER is set to a user name
// that the SSH server recognizes
// - Pageant is running on the local machine or `ssh-add -l` lists key
// - Pageant has a key that is authorized for the user on the server or `ssh-add -l` lists such key
func TestSSHConnect(t *testing.T) {
pageantConn, err := NewConn()
if err != nil {
Expand All @@ -31,7 +32,7 @@ func TestSSHConnect(t *testing.T) {
}
sshUser := os.Getenv("PAGEANT_TEST_SSH_USER")
config := ssh.ClientConfig{
Auth: []ssh.AuthMethod{ssh.PublicKeys(signers...)},
Auth: []ssh.AuthMethod{ssh.PublicKeysCallback(sshAgent.Signers)},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
User: sshUser,
}
Expand Down

0 comments on commit 97e732b

Please sign in to comment.