@@ -3,6 +3,7 @@ package agent
33import (
44 "io"
55 "os"
6+ "strings"
67 "sync"
78
89 "github.com/pkg/errors"
@@ -16,6 +17,12 @@ const (
1617 defaultNamedPipe = "\\ \\ .\\ pipe\\ openssh-ssh-agent"
1718)
1819
20+ /*
21+ * Cygwin/MSYS2 `SSH_AUTH_SOCK` implementations from ssh-agent(1) are performed using an
22+ * emulated socket rather than a true AF_UNIX socket. As such, those implementations are
23+ * incompatible and a user should either utilize the Win32-OpenSSH implementation found
24+ * in Windows 10/11 or utilize another alternative that support valid AF_UNIX sockets.
25+ */
1926func GetSSHAuthSocket () string {
2027 sshAuthSocket := os .Getenv ("SSH_AUTH_SOCK" )
2128 if sshAuthSocket != "" {
@@ -29,27 +36,30 @@ func GetSSHAuthSocket() string {
2936}
3037
3138func ForwardToRemote (client * ssh.Client , addr string ) error {
32- channels := client .HandleChannelOpen (channelType )
33- if channels == nil {
34- return errors .New ("agent: already have handler for " + channelType )
35- }
36- conn , err := npipe .Dial (addr )
37- if err != nil {
38- return err
39- }
40- conn .Close ()
39+ if strings .Contains (addr , "\\ \\ .\\ pipe\\ " ) {
40+ channels := client .HandleChannelOpen (channelType )
41+ if channels == nil {
42+ return errors .New ("agent: already have handler for " + channelType )
43+ }
44+ conn , err := npipe .Dial (addr )
45+ if err != nil {
46+ return err
47+ }
48+ conn .Close ()
4149
42- go func () {
43- for ch := range channels {
44- channel , reqs , err := ch .Accept ()
45- if err != nil {
46- continue
50+ go func () {
51+ for ch := range channels {
52+ channel , reqs , err := ch .Accept ()
53+ if err != nil {
54+ continue
55+ }
56+ go ssh .DiscardRequests (reqs )
57+ go forwardNamedPipe (channel , addr )
4758 }
48- go ssh .DiscardRequests (reqs )
49- go forwardNamedPipe (channel , addr )
50- }
51- }()
52- return nil
59+ }()
60+ return nil
61+ }
62+ return gosshagent .ForwardToRemote (client , addr )
5363}
5464
5565func RequestAgentForwarding (session * ssh.Session ) error {
0 commit comments